mirror of
https://github.com/rcore-os/rCore-Tutorial-v3.git
synced 2024-11-22 09:26:26 +04:00
update usr apps: usertests.rs cat.rs. now all apps in usertests can run correctly
This commit is contained in:
parent
cc10cd10eb
commit
9a95c7dcb4
@ -9,6 +9,10 @@ use user_lib::{close, open, read, OpenFlags};
|
|||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub fn main(argc: usize, argv: &[&str]) -> i32 {
|
pub fn main(argc: usize, argv: &[&str]) -> i32 {
|
||||||
|
println!("argc = {}", argc);
|
||||||
|
for (i, arg) in argv.iter().enumerate() {
|
||||||
|
println!("argv[{}] = {}", i, arg);
|
||||||
|
}
|
||||||
assert!(argc == 2);
|
assert!(argc == 2);
|
||||||
let fd = open(argv[1], OpenFlags::RDONLY);
|
let fd = open(argv[1], OpenFlags::RDONLY);
|
||||||
if fd == -1 {
|
if fd == -1 {
|
||||||
|
@ -9,12 +9,12 @@ extern crate user_lib;
|
|||||||
|
|
||||||
// item of TESTS : app_name(argv_0), argv_1, argv_2, argv_3, exit_code
|
// item of TESTS : app_name(argv_0), argv_1, argv_2, argv_3, exit_code
|
||||||
static SUCC_TESTS: &[(&str, &str, &str, &str, i32)] = &[
|
static SUCC_TESTS: &[(&str, &str, &str, &str, i32)] = &[
|
||||||
("cat\0", "cat.rs\0", "\0", "\0", 0),
|
("filetest_simple\0", "\0", "\0", "\0", 0),
|
||||||
|
("cat\0", "filea\0", "\0", "\0", 0),
|
||||||
("cmdline_args\0", "1\0", "2\0", "3\0", 0),
|
("cmdline_args\0", "1\0", "2\0", "3\0", 0),
|
||||||
("eisenberg\0", "\0", "\0", "\0", 0),
|
("eisenberg\0", "\0", "\0", "\0", 0),
|
||||||
("exit\0", "\0", "\0", "\0", 0),
|
("exit\0", "\0", "\0", "\0", 0),
|
||||||
("fantastic_text\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_simple\0", "\0", "\0", "\0", 0),
|
||||||
("forktest\0", "\0", "\0", "\0", 0),
|
("forktest\0", "\0", "\0", "\0", 0),
|
||||||
("forktest2\0", "\0", "\0", "\0", 0),
|
("forktest2\0", "\0", "\0", "\0", 0),
|
||||||
@ -57,7 +57,8 @@ use user_lib::{exec, fork, waitpid};
|
|||||||
|
|
||||||
fn run_tests(tests: &[(&str, &str, &str, &str, i32)]) -> i32 {
|
fn run_tests(tests: &[(&str, &str, &str, &str, i32)]) -> i32 {
|
||||||
let mut pass_num = 0;
|
let mut pass_num = 0;
|
||||||
let mut arr: [*const u8; 3] = [
|
let mut arr: [*const u8; 4] = [
|
||||||
|
core::ptr::null::<u8>(),
|
||||||
core::ptr::null::<u8>(),
|
core::ptr::null::<u8>(),
|
||||||
core::ptr::null::<u8>(),
|
core::ptr::null::<u8>(),
|
||||||
core::ptr::null::<u8>(),
|
core::ptr::null::<u8>(),
|
||||||
@ -65,24 +66,27 @@ fn run_tests(tests: &[(&str, &str, &str, &str, i32)]) -> i32 {
|
|||||||
|
|
||||||
for test in tests {
|
for test in tests {
|
||||||
println!("Usertests: Running {}", test.0);
|
println!("Usertests: Running {}", test.0);
|
||||||
|
arr[0] = test.0.as_ptr();
|
||||||
if test.1 != "\0" {
|
if test.1 != "\0" {
|
||||||
arr[0] = test.1.as_ptr();
|
arr[1] = test.1.as_ptr();
|
||||||
|
arr[2] = core::ptr::null::<u8>();
|
||||||
|
arr[3] = core::ptr::null::<u8>();
|
||||||
if test.2 != "\0" {
|
if test.2 != "\0" {
|
||||||
arr[1] = test.2.as_ptr();
|
arr[2] = test.2.as_ptr();
|
||||||
|
arr[3] = core::ptr::null::<u8>();
|
||||||
if test.3 != "\0" {
|
if test.3 != "\0" {
|
||||||
arr[2] = test.3.as_ptr();
|
arr[3] = test.3.as_ptr();
|
||||||
} else {
|
} else {
|
||||||
arr[2] = core::ptr::null::<u8>();
|
arr[3] = core::ptr::null::<u8>();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
arr[1] = core::ptr::null::<u8>();
|
|
||||||
arr[2] = core::ptr::null::<u8>();
|
arr[2] = core::ptr::null::<u8>();
|
||||||
|
arr[3] = core::ptr::null::<u8>();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
arr[0] = core::ptr::null::<u8>();
|
|
||||||
arr[1] = core::ptr::null::<u8>();
|
arr[1] = core::ptr::null::<u8>();
|
||||||
arr[2] = core::ptr::null::<u8>();
|
arr[2] = core::ptr::null::<u8>();
|
||||||
|
arr[3] = core::ptr::null::<u8>();
|
||||||
}
|
}
|
||||||
|
|
||||||
let pid = fork();
|
let pid = fork();
|
||||||
|
Loading…
Reference in New Issue
Block a user