Skip to content

Commit d0f80e3

Browse files
authored
Merge pull request #95 from ryanbreen/feature/cat-ls-tests
feat(coreutils): add comprehensive test suites for cat and ls
2 parents 22badd8 + 7b9ba09 commit d0f80e3

File tree

7 files changed

+885
-0
lines changed

7 files changed

+885
-0
lines changed

kernel/src/main.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -859,6 +859,10 @@ fn kernel_main_continue() -> ! {
859859
test_exec::test_wc_coreutil();
860860
log::info!("=== COREUTIL TEST: which (command location) ===");
861861
test_exec::test_which_coreutil();
862+
log::info!("=== COREUTIL TEST: cat (file concatenation) ===");
863+
test_exec::test_cat_coreutil();
864+
log::info!("=== COREUTIL TEST: ls (directory listing) ===");
865+
test_exec::test_ls_coreutil();
862866

863867
// Test Rust std library support
864868
log::info!("=== STD TEST: Rust std library support ===");

kernel/src/test_exec.rs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2735,3 +2735,61 @@ pub fn test_which_coreutil() {
27352735
}
27362736
}
27372737
}
2738+
2739+
/// Test the `cat` coreutil
2740+
///
2741+
/// Verifies that /bin/cat correctly outputs file contents.
2742+
pub fn test_cat_coreutil() {
2743+
log::info!("Testing cat coreutil (file concatenation)");
2744+
2745+
#[cfg(feature = "testing")]
2746+
let cat_test_elf_buf = crate::userspace_test::get_test_binary("cat_test");
2747+
#[cfg(feature = "testing")]
2748+
let cat_test_elf: &[u8] = &cat_test_elf_buf;
2749+
#[cfg(not(feature = "testing"))]
2750+
let cat_test_elf = &create_hello_world_elf();
2751+
2752+
match crate::process::creation::create_user_process(
2753+
String::from("cat_test"),
2754+
cat_test_elf,
2755+
) {
2756+
Ok(pid) => {
2757+
log::info!("Created cat_test process with PID {:?}", pid);
2758+
log::info!("cat_test: process scheduled for execution.");
2759+
log::info!(" -> Userspace will emit CAT_TEST_PASSED marker if successful");
2760+
}
2761+
Err(e) => {
2762+
log::error!("Failed to create cat_test process: {}", e);
2763+
log::error!("cat_test cannot run without valid userspace process");
2764+
}
2765+
}
2766+
}
2767+
2768+
/// Test the `ls` coreutil
2769+
///
2770+
/// Verifies that /bin/ls correctly lists directory contents.
2771+
pub fn test_ls_coreutil() {
2772+
log::info!("Testing ls coreutil (directory listing)");
2773+
2774+
#[cfg(feature = "testing")]
2775+
let ls_test_elf_buf = crate::userspace_test::get_test_binary("ls_test");
2776+
#[cfg(feature = "testing")]
2777+
let ls_test_elf: &[u8] = &ls_test_elf_buf;
2778+
#[cfg(not(feature = "testing"))]
2779+
let ls_test_elf = &create_hello_world_elf();
2780+
2781+
match crate::process::creation::create_user_process(
2782+
String::from("ls_test"),
2783+
ls_test_elf,
2784+
) {
2785+
Ok(pid) => {
2786+
log::info!("Created ls_test process with PID {:?}", pid);
2787+
log::info!("ls_test: process scheduled for execution.");
2788+
log::info!(" -> Userspace will emit LS_TEST_PASSED marker if successful");
2789+
}
2790+
Err(e) => {
2791+
log::error!("Failed to create ls_test process: {}", e);
2792+
log::error!("ls_test cannot run without valid userspace process");
2793+
}
2794+
}
2795+
}

userspace/tests/Cargo.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,14 @@ path = "wc_test.rs"
324324
name = "which_test"
325325
path = "which_test.rs"
326326

327+
[[bin]]
328+
name = "cat_test"
329+
path = "cat_test.rs"
330+
331+
[[bin]]
332+
name = "ls_test"
333+
path = "ls_test.rs"
334+
327335
[[bin]]
328336
name = "fork_memory_test"
329337
path = "fork_memory_test.rs"

userspace/tests/build.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ BINARIES=(
127127
"tail_test"
128128
"wc_test"
129129
"which_test"
130+
"cat_test"
131+
"ls_test"
130132
)
131133

132134
echo "Building ${#BINARIES[@]} userspace binaries with libbreenix..."

0 commit comments

Comments
 (0)