Add tests for chapter1-3.

testcases
Yifan Wu 5 years ago
parent 278bae2391
commit e5a62b4330

@ -0,0 +1,5 @@
/// Run this as a application on RV64 bare-metal.
fn main() {
println!("Hello, world!");
}

@ -0,0 +1,23 @@
/// rCore application without user_lib.
/// Load it manually to 0x80040000.
/// It should OK.
const SIZE: usize = 10;
const P: u32 = 3;
const STEP: usize = 10000000;
const MOD: u32 = 10007;
fn main() -> ! {
let mut pow = [0u32; SIZE];
let mut index: usize = 0;
pow[index] = 1;
for i in 1..=STEP {
let last = pow[index];
index = (index + 1) % SIZE;
pow[index] = last * P % MOD;
if i % 10000 == 0 {
println!("{}^{}={}", P, i, pow[index]);
}
}
println!("Test power OK!");
loop {}
}

@ -0,0 +1,26 @@
/// rCore application without user_lib.
/// Load it manually to 0x80040000.
/// It should not OK. Kernel should catch the page fault.
const SIZE: usize = 10;
const P: u32 = 3;
const STEP: usize = 10000000;
const MOD: u32 = 10007;
fn main() -> ! {
let mut pow = [0u32; SIZE];
let mut index: usize = 0;
pow[index] = 1;
for i in 1..=STEP {
let last = pow[index];
index = (index + 1) % SIZE;
pow[index] = last * P % MOD;
if i % 10000 == 0 {
println!("{}^{}={}", P, i, pow[index]);
}
if i == STEP / 2 {
// TODO: Modify satp to a malicious value in order to destroy memory access mechanism.
}
}
println!("Test power_bad OK!");
loop {}
}

@ -0,0 +1,15 @@
/// rCore application without user_lib.
/// Load it manually to 0x80040000.
use user_lib::{sys_yield};
fn main() -> ! {
for _ in 0..10 {
for _ in 0..10 {
print!("A");
}
println!();
sys_yield();
}
loop {}
}

@ -0,0 +1,15 @@
/// rCore application without user_lib.
/// Load it manually to 0x80050000.
use user_lib::{sys_yield};
fn main() -> ! {
for _ in 0..10 {
for _ in 0..10 {
print!("B");
}
println!();
sys_yield();
}
loop {}
}
Loading…
Cancel
Save