mirror of
https://github.com/rcore-os/rCore-Tutorial-v3.git
synced 2025-01-19 05:27:13 +04:00
update github CI for autotest
This commit is contained in:
parent
87cd106b67
commit
cf00c3ae5d
@ -18,7 +18,7 @@ fn panic(info: &PanicInfo) -> ! {
|
||||
unsafe {
|
||||
backtrace();
|
||||
}
|
||||
shutdown()
|
||||
shutdown(255)
|
||||
}
|
||||
|
||||
unsafe fn backtrace() {
|
||||
|
@ -39,7 +39,7 @@ pub fn console_getchar() -> usize {
|
||||
sbi_call(SBI_CONSOLE_GETCHAR, 0, 0, 0)
|
||||
}
|
||||
|
||||
pub fn shutdown() -> ! {
|
||||
pub fn shutdown(exit_code: usize) -> ! {
|
||||
sbi_call(SBI_SHUTDOWN, 0, 0, 0);
|
||||
panic!("It should shutdown!");
|
||||
}
|
||||
|
@ -74,8 +74,15 @@ pub fn exit_current_and_run_next(exit_code: i32) {
|
||||
if tid == 0 {
|
||||
let pid = process.getpid();
|
||||
if pid == IDLE_PID {
|
||||
println!("[kernel] Idle process exit ...");
|
||||
crate::sbi::shutdown();
|
||||
println!(
|
||||
"[kernel] Idle process exit with exit_code {} ...",
|
||||
exit_code
|
||||
);
|
||||
if exit_code != 0 {
|
||||
crate::sbi::shutdown(255); //255 == -1 for err hint
|
||||
} else {
|
||||
crate::sbi::shutdown(0); //0 for success hint
|
||||
}
|
||||
}
|
||||
remove_from_pid2process(pid);
|
||||
let mut process_inner = process.inner_exclusive_access();
|
||||
|
@ -34,7 +34,10 @@ pub fn main(argc: usize, argv: &[&str]) -> i32 {
|
||||
} else if argc == 2 {
|
||||
count = argv[1].to_string().parse::<usize>().unwrap();
|
||||
} else {
|
||||
println!("ERROR in argv");
|
||||
println!(
|
||||
"ERROR in argv, argc is {}, argv[0] {} , argv[1] {} , argv[2] {}",
|
||||
argc, argv[0], argv[1], argv[2]
|
||||
);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
|
@ -8,7 +8,7 @@ use user_lib::{exec, fork, wait};
|
||||
|
||||
#[no_mangle]
|
||||
pub fn main() -> i32 {
|
||||
for i in 0..1000 {
|
||||
for i in 0..50 {
|
||||
if fork() == 0 {
|
||||
exec("pipe_large_test\0", &[core::ptr::null::<u8>()]);
|
||||
} else {
|
||||
|
@ -3,75 +3,125 @@
|
||||
|
||||
#[macro_use]
|
||||
extern crate user_lib;
|
||||
|
||||
static SUCC_TESTS: &[&str] = &[
|
||||
"matrix\0",
|
||||
"exit\0",
|
||||
"fantastic_text\0",
|
||||
"filetest_simple\0",
|
||||
"forktest_simple\0",
|
||||
"forktest\0",
|
||||
"forktest2\0",
|
||||
"forktree\0",
|
||||
"hello_world\0",
|
||||
"huge_write\0",
|
||||
"mpsc_sem\0",
|
||||
"phil_din_mutex\0",
|
||||
"pipe_large_test\0",
|
||||
"pipetest\0",
|
||||
"race_adder_atomic\0",
|
||||
"race_adder_mutex_blocking\0",
|
||||
"race_adder_mutex_spin\0",
|
||||
"race_adder_arg\0",
|
||||
"sleep_simple\0",
|
||||
"sleep\0",
|
||||
"sleep_simple\0",
|
||||
"sync_sem\0",
|
||||
"test_condvar\0",
|
||||
"threads_arg\0",
|
||||
"threads\0",
|
||||
"yield\0",
|
||||
"run_pipe_test\0",
|
||||
// item of TESTS : app_name(argv_0), argv_1, argv_2, argv_3, exit_code
|
||||
static SUCC_TESTS: &[(&str, &str, &str, &str, i32)] = &[
|
||||
("cmdline_args\0", "1\0", "2\0", "\0", 0),
|
||||
("cmdline_args\0", "1\0", "2\0", "3\0", 0),
|
||||
("matrix\0", "\0", "\0", "\0", 0),
|
||||
("exit\0", "\0", "\0", "\0", 0),
|
||||
("fantastic_text\0", "\0", "\0", "\0", 0),
|
||||
("filetest_simple\0", "\0", "\0", "\0", 0),
|
||||
("forktest_simple\0", "\0", "\0", "\0", 0),
|
||||
("forktest\0", "\0", "\0", "\0", 0),
|
||||
("forktest2\0", "\0", "\0", "\0", 0),
|
||||
("forktree\0", "\0", "\0", "\0", 0),
|
||||
("hello_world\0", "\0", "\0", "\0", 0),
|
||||
("huge_write\0", "\0", "\0", "\0", 0),
|
||||
("mpsc_sem\0", "\0", "\0", "\0", 0),
|
||||
("phil_din_mutex\0", "\0", "\0", "\0", 0),
|
||||
("pipe_large_test\0", "\0", "\0", "\0", 0),
|
||||
("pipetest\0", "\0", "\0", "\0", 0),
|
||||
("race_adder_atomic\0", "\0", "\0", "\0", 0),
|
||||
("race_adder_mutex_blocking\0", "\0", "\0", "\0", 0),
|
||||
("race_adder_mutex_spin\0", "\0", "\0", "\0", 0),
|
||||
("race_adder_arg\0", "3\0", "\0", "\0", 0),
|
||||
("sleep_simple\0", "\0", "\0", "\0", 0),
|
||||
("sleep\0", "\0", "\0", "\0", 0),
|
||||
("sleep_simple\0", "\0", "\0", "\0", 0),
|
||||
("sync_sem\0", "\0", "\0", "\0", 0),
|
||||
("test_condvar\0", "\0", "\0", "\0", 0),
|
||||
("threads_arg\0", "\0", "\0", "\0", 0),
|
||||
("threads\0", "\0", "\0", "\0", 0),
|
||||
("yield\0", "\0", "\0", "\0", 0),
|
||||
("run_pipe_test\0", "\0", "\0", "\0", 0),
|
||||
];
|
||||
|
||||
static FAIL_TESTS: &[&str] = &[
|
||||
"stack_overflow\0",
|
||||
"race_adder_loop\0",
|
||||
"priv_csr\0",
|
||||
"priv_inst\0",
|
||||
"store_fault\0",
|
||||
"until_timeout\0",
|
||||
"stack_overflow\0",
|
||||
"race_adder\0",
|
||||
"huge_write_mt\0",
|
||||
|
||||
static FAIL_TESTS: &[(&str, &str, &str, &str, i32)] = &[
|
||||
("stack_overflow\0", "\0", "\0", "\0", -11),
|
||||
("race_adder_loop\0", "\0", "\0", "\0", -6),
|
||||
("priv_csr\0", "\0", "\0", "\0", -4),
|
||||
("priv_inst\0", "\0", "\0", "\0", -4),
|
||||
("store_fault\0", "\0", "\0", "\0", -11),
|
||||
("until_timeout\0", "\0", "\0", "\0", -6),
|
||||
("race_adder\0", "\0", "\0", "\0", -6),
|
||||
("huge_write_mt\0", "\0", "\0", "\0", -6),
|
||||
];
|
||||
|
||||
use user_lib::{exec, fork, waitpid};
|
||||
|
||||
fn run_tests<F: Fn(i32)>(tests: &[&str], judge: F) {
|
||||
fn run_tests(tests: &[(&str, &str, &str, &str, i32)]) -> i32 {
|
||||
let mut pass_num = 0;
|
||||
let mut arr: [*const u8; 3] = [
|
||||
core::ptr::null::<u8>(),
|
||||
core::ptr::null::<u8>(),
|
||||
core::ptr::null::<u8>(),
|
||||
];
|
||||
|
||||
for test in tests {
|
||||
println!("Usertests: Running {}", test);
|
||||
println!("Usertests: Running {}", test.0);
|
||||
|
||||
if test.1 != "\0" {
|
||||
arr[0] = test.1.as_ptr();
|
||||
if test.2 != "\0" {
|
||||
arr[1] = test.2.as_ptr();
|
||||
if test.3 != "\0" {
|
||||
arr[2] = test.3.as_ptr();
|
||||
} else {
|
||||
arr[2] = core::ptr::null::<u8>();
|
||||
}
|
||||
} else {
|
||||
arr[1] = core::ptr::null::<u8>();
|
||||
arr[2] = core::ptr::null::<u8>();
|
||||
}
|
||||
} else {
|
||||
arr[0] = core::ptr::null::<u8>();
|
||||
arr[1] = core::ptr::null::<u8>();
|
||||
arr[2] = core::ptr::null::<u8>();
|
||||
}
|
||||
|
||||
let pid = fork();
|
||||
if pid == 0 {
|
||||
exec(*test, &[core::ptr::null::<u8>()]);
|
||||
exec(test.0, &arr[..]);
|
||||
panic!("unreachable!");
|
||||
} else {
|
||||
let mut exit_code: i32 = Default::default();
|
||||
let wait_pid = waitpid(pid as usize, &mut exit_code);
|
||||
assert_eq!(pid, wait_pid);
|
||||
judge(exit_code);
|
||||
if exit_code == test.4 {
|
||||
// summary apps with exit_code
|
||||
pass_num = pass_num + 1;
|
||||
}
|
||||
println!(
|
||||
"\x1b[32mUsertests: Test {} in Process {} exited with code {}\x1b[0m",
|
||||
test, pid, exit_code
|
||||
test.0, pid, exit_code
|
||||
);
|
||||
}
|
||||
}
|
||||
pass_num
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub fn main() -> i32 {
|
||||
run_tests(SUCC_TESTS, |code| assert!(code == 0));
|
||||
run_tests(FAIL_TESTS, |code| assert!(code != 0));
|
||||
println!("Usertests passed!");
|
||||
0
|
||||
let succ_num = run_tests(SUCC_TESTS);
|
||||
let err_num = run_tests(FAIL_TESTS);
|
||||
if succ_num == SUCC_TESTS.len() as i32 && err_num == FAIL_TESTS.len() as i32 {
|
||||
println!("Usertests passed!");
|
||||
return 0;
|
||||
}
|
||||
if succ_num != SUCC_TESTS.len() as i32 {
|
||||
println!(
|
||||
"all successed app_num is {} , but only passed {}",
|
||||
SUCC_TESTS.len(),
|
||||
succ_num
|
||||
);
|
||||
}
|
||||
if err_num != FAIL_TESTS.len() as i32 {
|
||||
println!(
|
||||
"all failed app_num is {} , but only passed {}",
|
||||
FAIL_TESTS.len(),
|
||||
err_num
|
||||
);
|
||||
}
|
||||
println!("Usertests failed!");
|
||||
return -1;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user