update github CI for autotest

This commit is contained in:
Yu Chen 2022-05-15 12:03:05 +08:00
parent 0d9dd75a57
commit 80503e80ee
6 changed files with 115 additions and 55 deletions

View file

@ -18,7 +18,7 @@ fn panic(info: &PanicInfo) -> ! {
unsafe { unsafe {
backtrace(); backtrace();
} }
shutdown() shutdown(255)
} }
unsafe fn backtrace() { unsafe fn backtrace() {

View file

@ -39,7 +39,7 @@ pub fn console_getchar() -> usize {
sbi_call(SBI_CONSOLE_GETCHAR, 0, 0, 0) sbi_call(SBI_CONSOLE_GETCHAR, 0, 0, 0)
} }
pub fn shutdown() -> ! { pub fn shutdown(exit_code: usize) -> ! {
sbi_call(SBI_SHUTDOWN, 0, 0, 0); sbi_call(SBI_SHUTDOWN, 0, 0, 0);
panic!("It should shutdown!"); panic!("It should shutdown!");
} }

View file

@ -74,8 +74,15 @@ pub fn exit_current_and_run_next(exit_code: i32) {
if tid == 0 { if tid == 0 {
let pid = process.getpid(); let pid = process.getpid();
if pid == IDLE_PID { if pid == IDLE_PID {
println!("[kernel] Idle process exit ..."); println!(
crate::sbi::shutdown(); "[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); remove_from_pid2process(pid);
let mut process_inner = process.inner_exclusive_access(); let mut process_inner = process.inner_exclusive_access();

View file

@ -34,7 +34,10 @@ pub fn main(argc: usize, argv: &[&str]) -> i32 {
} else if argc == 2 { } else if argc == 2 {
count = argv[1].to_string().parse::<usize>().unwrap(); count = argv[1].to_string().parse::<usize>().unwrap();
} else { } 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); exit(-1);
} }

View file

@ -8,7 +8,7 @@ use user_lib::{exec, fork, wait};
#[no_mangle] #[no_mangle]
pub fn main() -> i32 { pub fn main() -> i32 {
for i in 0..1000 { for i in 0..50 {
if fork() == 0 { if fork() == 0 {
exec("pipe_large_test\0", &[core::ptr::null::<u8>()]); exec("pipe_large_test\0", &[core::ptr::null::<u8>()]);
} else { } else {

View file

@ -3,75 +3,125 @@
#[macro_use] #[macro_use]
extern crate user_lib; extern crate user_lib;
// item of TESTS : app_name(argv_0), argv_1, argv_2, argv_3, exit_code
static SUCC_TESTS: &[&str] = &[ static SUCC_TESTS: &[(&str, &str, &str, &str, i32)] = &[
"matrix\0", ("cmdline_args\0", "1\0", "2\0", "\0", 0),
"exit\0", ("cmdline_args\0", "1\0", "2\0", "3\0", 0),
"fantastic_text\0", ("matrix\0", "\0", "\0", "\0", 0),
"filetest_simple\0", ("exit\0", "\0", "\0", "\0", 0),
"forktest_simple\0", ("fantastic_text\0", "\0", "\0", "\0", 0),
"forktest\0", ("filetest_simple\0", "\0", "\0", "\0", 0),
"forktest2\0", ("forktest_simple\0", "\0", "\0", "\0", 0),
"forktree\0", ("forktest\0", "\0", "\0", "\0", 0),
"hello_world\0", ("forktest2\0", "\0", "\0", "\0", 0),
"huge_write\0", ("forktree\0", "\0", "\0", "\0", 0),
"mpsc_sem\0", ("hello_world\0", "\0", "\0", "\0", 0),
"phil_din_mutex\0", ("huge_write\0", "\0", "\0", "\0", 0),
"pipe_large_test\0", ("mpsc_sem\0", "\0", "\0", "\0", 0),
"pipetest\0", ("phil_din_mutex\0", "\0", "\0", "\0", 0),
"race_adder_atomic\0", ("pipe_large_test\0", "\0", "\0", "\0", 0),
"race_adder_mutex_blocking\0", ("pipetest\0", "\0", "\0", "\0", 0),
"race_adder_mutex_spin\0", ("race_adder_atomic\0", "\0", "\0", "\0", 0),
"race_adder_arg\0", ("race_adder_mutex_blocking\0", "\0", "\0", "\0", 0),
"sleep_simple\0", ("race_adder_mutex_spin\0", "\0", "\0", "\0", 0),
"sleep\0", ("race_adder_arg\0", "3\0", "\0", "\0", 0),
"sleep_simple\0", ("sleep_simple\0", "\0", "\0", "\0", 0),
"sync_sem\0", ("sleep\0", "\0", "\0", "\0", 0),
"test_condvar\0", ("sleep_simple\0", "\0", "\0", "\0", 0),
"threads_arg\0", ("sync_sem\0", "\0", "\0", "\0", 0),
"threads\0", ("test_condvar\0", "\0", "\0", "\0", 0),
"yield\0", ("threads_arg\0", "\0", "\0", "\0", 0),
"run_pipe_test\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] = &[ static FAIL_TESTS: &[(&str, &str, &str, &str, i32)] = &[
"stack_overflow\0", ("stack_overflow\0", "\0", "\0", "\0", -11),
"race_adder_loop\0", ("race_adder_loop\0", "\0", "\0", "\0", -6),
"priv_csr\0", ("priv_csr\0", "\0", "\0", "\0", -4),
"priv_inst\0", ("priv_inst\0", "\0", "\0", "\0", -4),
"store_fault\0", ("store_fault\0", "\0", "\0", "\0", -11),
"until_timeout\0", ("until_timeout\0", "\0", "\0", "\0", -6),
"stack_overflow\0", ("race_adder\0", "\0", "\0", "\0", -6),
"race_adder\0", ("huge_write_mt\0", "\0", "\0", "\0", -6),
"huge_write_mt\0",
]; ];
use user_lib::{exec, fork, waitpid}; 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 { 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(); let pid = fork();
if pid == 0 { if pid == 0 {
exec(*test, &[core::ptr::null::<u8>()]); exec(test.0, &arr[..]);
panic!("unreachable!"); panic!("unreachable!");
} else { } else {
let mut exit_code: i32 = Default::default(); let mut exit_code: i32 = Default::default();
let wait_pid = waitpid(pid as usize, &mut exit_code); let wait_pid = waitpid(pid as usize, &mut exit_code);
assert_eq!(pid, wait_pid); assert_eq!(pid, wait_pid);
judge(exit_code); if exit_code == test.4 {
// summary apps with exit_code
pass_num = pass_num + 1;
}
println!( println!(
"\x1b[32mUsertests: Test {} in Process {} exited with code {}\x1b[0m", "\x1b[32mUsertests: Test {} in Process {} exited with code {}\x1b[0m",
test, pid, exit_code test.0, pid, exit_code
); );
} }
} }
pass_num
} }
#[no_mangle] #[no_mangle]
pub fn main() -> i32 { pub fn main() -> i32 {
run_tests(SUCC_TESTS, |code| assert!(code == 0)); let succ_num = run_tests(SUCC_TESTS);
run_tests(FAIL_TESTS, |code| assert!(code != 0)); let err_num = run_tests(FAIL_TESTS);
println!("Usertests passed!"); if succ_num == SUCC_TESTS.len() as i32 && err_num == FAIL_TESTS.len() as i32 {
0 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;
} }