forked from LearningOS/rCore-Tutorial-Test-2022S
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathch9b_usertest.rs
58 lines (53 loc) · 1.38 KB
/
ch9b_usertest.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
56
57
58
#![no_std]
#![no_main]
#[macro_use]
extern crate user_lib;
const TESTS: &[&str] = &[
"ch2b_hello_world\0",
"ch2b_power_3\0",
"ch2b_power_5\0",
"ch2b_power_7\0",
"ch3b_yield0\0",
"ch3b_yield1\0",
"ch3b_yield2\0",
"ch5b_exit\0",
"ch5b_forktest_simple\0",
"ch5b_forktest\0",
"ch6b_filetest_simple\0",
"ch6b_cat\0",
"ch7b_pipetest\0",
"ch8b_mpsc_sem\0",
"ch8b_phil_din_mutex\0",
"ch8b_race_adder_mutex_spin\0",
"ch8b_sync_sem\0",
"ch8b_test_condvar\0",
"ch8b_threads\0",
"ch8b_threads_arg\0",
];
const TEST_NUM: usize = TESTS.len();
use user_lib::{exec, fork, waitpid};
#[no_mangle]
pub fn main() -> i32 {
let mut pids = [0; TEST_NUM];
for (i, &test) in TESTS.iter().enumerate() {
println!("Usertests: Running {}", test);
let pid = fork();
if pid == 0 {
exec(&*test, &[core::ptr::null::<u8>()]);
panic!("unreachable!");
} else {
pids[i] = pid;
}
}
let mut xstate: i32 = Default::default();
for (i, &test) in TESTS.iter().enumerate() {
let wait_pid = waitpid(pids[i] as usize, &mut xstate);
assert_eq!(pids[i], wait_pid);
println!(
"\x1b[32mUsertests: Test {} in Process {} exited with code {}\x1b[0m",
test, pids[i], xstate
);
}
println!("Basic usertests passed!");
0
}