forked from rcore-os/rCore-Tutorial
-
Notifications
You must be signed in to change notification settings - Fork 2
/
r_usertests.rs
55 lines (51 loc) · 1.18 KB
/
r_usertests.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#![no_std]
#![no_main]
#[macro_use]
extern crate user_lib;
static tests: &[&str] = &[
"r_fantastic_text\0",
"r_forktest\0",
"r_forktest_simple\0",
//"r_forktest2\0",
"r_exit\0",
"r_yield\0",
"r_matrix\0",
"r_matrix_g\0",
"r_hello_world\0",
"r_sleep_simple\0",
"r_sleep\0",
"r_spin\0",
//"r_stack_overflow\0",
"hello\0",
//"forktest\0",
"divzero\0",
"testbss\0",
"faultread\0",
"faultreadkernel\0",
//"exit\0",
//"matrix\0",
//"yield\0",
"badarg\0",
//"sleep\0",
//"forktree\0",
//"spin\0",
];
use user_lib::{exec, fork, waitpid};
#[no_mangle]
pub fn main() -> i32 {
for test in tests {
println!("Usertests: Running {}", test);
let pid = fork();
if pid == 0 {
exec(*test as *const _ as *const u8);
panic!("unreachable!");
} else {
let mut xstate: i32 = Default::default();
let wait_pid = waitpid(pid as usize, &mut xstate);
assert_eq!(pid, wait_pid);
println!("Usertests: Test {} in Process {} exited with code {}", test, pid, xstate);
}
}
println!("Usertests passed!");
0
}