提交 e5a62b43 编写于 作者: Y Yifan Wu

Add tests for chapter1-3.

上级 278bae23
/// Run this as a application on RV64 bare-metal.
fn main() {
println!("Hello, world!");
}
/// 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 {}
}
\ No newline at end of file
/// 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 {}
}
\ No newline at end of file
/// 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 {}
}
\ No newline at end of file
/// 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 {}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册