add CI autotest, update README
This commit is contained in:
parent
f79bb085a6
commit
39037a97ca
11 changed files with 386 additions and 72 deletions
|
@ -8,9 +8,15 @@ BINS := $(patsubst $(APP_DIR)/%.rs, $(TARGET_DIR)/%.bin, $(APPS))
|
|||
|
||||
OBJDUMP := rust-objdump --arch-name=riscv64
|
||||
OBJCOPY := rust-objcopy --binary-architecture=riscv64
|
||||
CP := cp
|
||||
|
||||
TEST ?=
|
||||
|
||||
elf: $(APPS)
|
||||
@cargo build --release
|
||||
ifeq ($(TEST), 1)
|
||||
@$(CP) $(TARGET_DIR)/usertests $(TARGET_DIR)/initproc
|
||||
endif
|
||||
|
||||
binary: elf
|
||||
$(foreach elf, $(ELFS), $(OBJCOPY) $(elf) --strip-all -O binary $(patsubst $(TARGET_DIR)/%, $(TARGET_DIR)/%.bin, $(elf));)
|
||||
|
|
|
@ -4,40 +4,112 @@
|
|||
#[macro_use]
|
||||
extern crate user_lib;
|
||||
|
||||
static TESTS: &[&str] = &[
|
||||
"exit\0",
|
||||
"fantastic_text\0",
|
||||
"forktest\0",
|
||||
"forktest2\0",
|
||||
"forktest_simple\0",
|
||||
"hello_world\0",
|
||||
"matrix\0",
|
||||
"sleep\0",
|
||||
"sleep_simple\0",
|
||||
"stack_overflow\0",
|
||||
"yield\0",
|
||||
// not in SUCC_TESTS & FAIL_TESTS
|
||||
// count_lines, infloop, user_shell, usertests
|
||||
|
||||
// item of TESTS : app_name(argv_0), argv_1, argv_2, argv_3, exit_code
|
||||
static SUCC_TESTS: &[(&str, &str, &str, &str, i32)] = &[
|
||||
("filetest_simple\0", "\0", "\0", "\0", 0),
|
||||
("cat_filea\0", "\0", "\0", "\0", 0),
|
||||
("exit\0", "\0", "\0", "\0", 0),
|
||||
("fantastic_text\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),
|
||||
("matrix\0", "\0", "\0", "\0", 0),
|
||||
("sleep_simple\0", "\0", "\0", "\0", 0),
|
||||
("sleep\0", "\0", "\0", "\0", 0),
|
||||
("yield\0", "\0", "\0", "\0", 0),
|
||||
];
|
||||
|
||||
static FAIL_TESTS: &[(&str, &str, &str, &str, i32)] = &[("stack_overflow\0", "\0", "\0", "\0", -2)];
|
||||
|
||||
use user_lib::{exec, fork, waitpid};
|
||||
|
||||
#[no_mangle]
|
||||
pub fn main() -> i32 {
|
||||
for test in TESTS {
|
||||
println!("Usertests: Running {}", test);
|
||||
fn run_tests(tests: &[(&str, &str, &str, &str, i32)]) -> i32 {
|
||||
let mut pass_num = 0;
|
||||
let mut arr: [*const u8; 4] = [
|
||||
core::ptr::null::<u8>(),
|
||||
core::ptr::null::<u8>(),
|
||||
core::ptr::null::<u8>(),
|
||||
core::ptr::null::<u8>(),
|
||||
];
|
||||
|
||||
for test in tests {
|
||||
println!("Usertests: Running {}", test.0);
|
||||
arr[0] = test.0.as_ptr();
|
||||
if test.1 != "\0" {
|
||||
arr[1] = test.1.as_ptr();
|
||||
arr[2] = core::ptr::null::<u8>();
|
||||
arr[3] = core::ptr::null::<u8>();
|
||||
if test.2 != "\0" {
|
||||
arr[2] = test.2.as_ptr();
|
||||
arr[3] = core::ptr::null::<u8>();
|
||||
if test.3 != "\0" {
|
||||
arr[3] = test.3.as_ptr();
|
||||
} else {
|
||||
arr[3] = core::ptr::null::<u8>();
|
||||
}
|
||||
} else {
|
||||
arr[2] = core::ptr::null::<u8>();
|
||||
arr[3] = core::ptr::null::<u8>();
|
||||
}
|
||||
} else {
|
||||
arr[1] = core::ptr::null::<u8>();
|
||||
arr[2] = core::ptr::null::<u8>();
|
||||
arr[3] = core::ptr::null::<u8>();
|
||||
}
|
||||
|
||||
let pid = fork();
|
||||
if pid == 0 {
|
||||
exec(*test);
|
||||
exec(test.0);
|
||||
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);
|
||||
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
|
||||
);
|
||||
}
|
||||
}
|
||||
println!("Usertests passed!");
|
||||
0
|
||||
pass_num
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub fn main() -> i32 {
|
||||
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!(
|
||||
"{} of sueecssed apps, {} of failed apps run correctly. \nUsertests passed!",
|
||||
SUCC_TESTS.len(),
|
||||
FAIL_TESTS.len()
|
||||
);
|
||||
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;
|
||||
}
|
||||
|
|
43
user/src/bin/usertests_simple.rs
Normal file
43
user/src/bin/usertests_simple.rs
Normal file
|
@ -0,0 +1,43 @@
|
|||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
#[macro_use]
|
||||
extern crate user_lib;
|
||||
|
||||
static TESTS: &[&str] = &[
|
||||
"exit\0",
|
||||
"fantastic_text\0",
|
||||
"forktest\0",
|
||||
"forktest2\0",
|
||||
"forktest_simple\0",
|
||||
"hello_world\0",
|
||||
"matrix\0",
|
||||
"sleep\0",
|
||||
"sleep_simple\0",
|
||||
"stack_overflow\0",
|
||||
"yield\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);
|
||||
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);
|
||||
println!(
|
||||
"\x1b[32mUsertests: Test {} in Process {} exited with code {}\x1b[0m",
|
||||
test, pid, exit_code
|
||||
);
|
||||
}
|
||||
}
|
||||
println!("Usertests passed!");
|
||||
0
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue