Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 24 additions & 24 deletions kernel/src/test_exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3000,11 +3000,11 @@ pub fn test_shell_pipe() {
}
}

/// Test the `true` coreutil
/// Test the `btrue` coreutil
///
/// Verifies that /bin/true correctly exits with code 0.
/// Verifies that /bin/btrue correctly exits with code 0.
pub fn test_true_coreutil() {
log::info!("Testing true coreutil (exit code 0)");
log::info!("Testing btrue coreutil (exit code 0)");

#[cfg(feature = "testing")]
let true_test_elf_buf = crate::userspace_test::get_test_binary("true_test");
Expand Down Expand Up @@ -3033,11 +3033,11 @@ pub fn test_true_coreutil() {
}
}

/// Test the `false` coreutil
/// Test the `bfalse` coreutil
///
/// Verifies that /bin/false correctly exits with code 1.
/// Verifies that /bin/bfalse correctly exits with code 1.
pub fn test_false_coreutil() {
log::info!("Testing false coreutil (exit code 1)");
log::info!("Testing bfalse coreutil (exit code 1)");

#[cfg(feature = "testing")]
let false_test_elf_buf = crate::userspace_test::get_test_binary("false_test");
Expand Down Expand Up @@ -3066,11 +3066,11 @@ pub fn test_false_coreutil() {
}
}

/// Test the `head` coreutil
/// Test the `bhead` coreutil
///
/// Verifies that /bin/head correctly outputs the first N lines of files.
/// Verifies that /bin/bhead correctly outputs the first N lines of files.
pub fn test_head_coreutil() {
log::info!("Testing head coreutil (first N lines)");
log::info!("Testing bhead coreutil (first N lines)");

#[cfg(feature = "testing")]
let head_test_elf_buf = crate::userspace_test::get_test_binary("head_test");
Expand Down Expand Up @@ -3099,11 +3099,11 @@ pub fn test_head_coreutil() {
}
}

/// Test the `tail` coreutil
/// Test the `btail` coreutil
///
/// Verifies that /bin/tail correctly outputs the last N lines of files.
/// Verifies that /bin/btail correctly outputs the last N lines of files.
pub fn test_tail_coreutil() {
log::info!("Testing tail coreutil (last N lines)");
log::info!("Testing btail coreutil (last N lines)");

#[cfg(feature = "testing")]
let tail_test_elf_buf = crate::userspace_test::get_test_binary("tail_test");
Expand Down Expand Up @@ -3132,11 +3132,11 @@ pub fn test_tail_coreutil() {
}
}

/// Test the `wc` coreutil
/// Test the `bwc` coreutil
///
/// Verifies that /bin/wc correctly counts lines, words, and bytes.
/// Verifies that /bin/bwc correctly counts lines, words, and bytes.
pub fn test_wc_coreutil() {
log::info!("Testing wc coreutil (line/word/byte counts)");
log::info!("Testing bwc coreutil (line/word/byte counts)");

#[cfg(feature = "testing")]
let wc_test_elf_buf = crate::userspace_test::get_test_binary("wc_test");
Expand Down Expand Up @@ -3165,11 +3165,11 @@ pub fn test_wc_coreutil() {
}
}

/// Test the `which` coreutil
/// Test the `bwhich` coreutil
///
/// Verifies that /bin/which correctly locates commands in PATH.
/// Verifies that /bin/bwhich correctly locates commands in PATH.
pub fn test_which_coreutil() {
log::info!("Testing which coreutil (command location)");
log::info!("Testing bwhich coreutil (command location)");

#[cfg(feature = "testing")]
let which_test_elf_buf = crate::userspace_test::get_test_binary("which_test");
Expand Down Expand Up @@ -3198,11 +3198,11 @@ pub fn test_which_coreutil() {
}
}

/// Test the `cat` coreutil
/// Test the `bcat` coreutil
///
/// Verifies that /bin/cat correctly outputs file contents.
/// Verifies that /bin/bcat correctly outputs file contents.
pub fn test_cat_coreutil() {
log::info!("Testing cat coreutil (file concatenation)");
log::info!("Testing bcat coreutil (file concatenation)");

#[cfg(feature = "testing")]
let cat_test_elf_buf = crate::userspace_test::get_test_binary("cat_test");
Expand Down Expand Up @@ -3231,11 +3231,11 @@ pub fn test_cat_coreutil() {
}
}

/// Test the `ls` coreutil
/// Test the `bls` coreutil
///
/// Verifies that /bin/ls correctly lists directory contents.
/// Verifies that /bin/bls correctly lists directory contents.
pub fn test_ls_coreutil() {
log::info!("Testing ls coreutil (directory listing)");
log::info!("Testing bls coreutil (directory listing)");

#[cfg(feature = "testing")]
let ls_test_elf_buf = crate::userspace_test::get_test_binary("ls_test");
Expand Down
51 changes: 37 additions & 14 deletions scripts/create_ext2_disk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
#
# This script creates an ext2 filesystem image (32MB x86_64, 48MB aarch64) with:
# - Test files for filesystem testing
# - Coreutils binaries in /bin/ (cat, ls, echo, mkdir, rmdir, rm, cp, mv, false, head, tail, wc, which)
# - /sbin/true for PATH order testing
# - Coreutils binaries in /bin/ (bcat, bls, becho, bmkdir, brmdir, brm, bcp, bmv, bfalse, bhead, btail, bwc, bwhich)
# - /sbin/btrue for PATH order testing
# - hello_world binary for exec testing
#
# Requires Docker on macOS (or mke2fs on Linux).
Expand Down Expand Up @@ -56,8 +56,8 @@ else
TESTDATA_FILE="$PROJECT_ROOT/testdata/ext2.img"
fi

# Coreutils to install in /bin
COREUTILS="cat ls echo mkdir rmdir rm cp mv true false head tail wc which"
# Coreutils to install in /bin (b-prefixed Breenix coreutils)
COREUTILS="bcat bls becho bmkdir brmdir brm bcp bmv btrue bfalse bhead btail bwc bwhich"

echo "Creating ext2 disk image..."
echo " Arch: $ARCH"
Expand Down Expand Up @@ -108,19 +108,27 @@ if [[ "$(uname)" == "Darwin" ]]; then
mkdir -p /mnt/ext2
mount /work/$OUTPUT_FILENAME /mnt/ext2

# Create /bin and /sbin directories for coreutils
# Create /bin, /sbin, and /usr/local/test/bin directories
mkdir -p /mnt/ext2/bin
mkdir -p /mnt/ext2/sbin
mkdir -p /mnt/ext2/usr/local/test/bin

# Copy ALL binaries from /binaries directory
# Special handling: true and telnetd go to /sbin, everything else to /bin
# Routing: test binaries (*_test, test_*) -> /usr/local/test/bin
# system binaries (true, telnetd, init) -> /sbin
# everything else -> /bin
echo "Installing all binaries..."
bin_count=0
sbin_count=0
test_count=0
for elf_file in /binaries/*.elf; do
if [ -f "$elf_file" ]; then
bin_name=$(basename "$elf_file" .elf)
if [ "$bin_name" = "true" ] || [ "$bin_name" = "telnetd" ] || [ "$bin_name" = "init" ]; then
if echo "$bin_name" | grep -qE "_test$|^test_"; then
cp "$elf_file" /mnt/ext2/usr/local/test/bin/${bin_name}
chmod 755 /mnt/ext2/usr/local/test/bin/${bin_name}
test_count=$((test_count + 1))
elif [ "$bin_name" = "btrue" ] || [ "$bin_name" = "telnetd" ] || [ "$bin_name" = "init" ]; then
cp "$elf_file" /mnt/ext2/sbin/${bin_name}
chmod 755 /mnt/ext2/sbin/${bin_name}
sbin_count=$((sbin_count + 1))
Expand All @@ -133,6 +141,7 @@ if [[ "$(uname)" == "Darwin" ]]; then
done
echo " Installed $bin_count binaries in /bin"
echo " Installed $sbin_count binaries in /sbin"
echo " Installed $test_count test binaries in /usr/local/test/bin"

# Create /tmp for filesystem write tests
mkdir -p /mnt/ext2/tmp
Expand Down Expand Up @@ -172,8 +181,10 @@ EOF
echo "ext2 filesystem contents:"
echo " Binaries in /bin:"
ls -la /mnt/ext2/bin/ 2>/dev/null || echo " (none)"
echo " Test binaries in /usr/local/test/bin:"
ls -la /mnt/ext2/usr/local/test/bin/ 2>/dev/null || echo " (none)"
echo " Test files:"
find /mnt/ext2 -type f -not -path "/mnt/ext2/bin/*" -exec ls -la {} \;
find /mnt/ext2 -type f -not -path "/mnt/ext2/bin/*" -not -path "/mnt/ext2/usr/local/test/bin/*" -exec ls -la {} \;

# Unmount
umount /mnt/ext2
Expand Down Expand Up @@ -206,19 +217,27 @@ else
MOUNT_DIR=$(mktemp -d)
mount "$OUTPUT_FILE" "$MOUNT_DIR"

# Create /bin and /sbin directories
# Create /bin, /sbin, and /usr/local/test/bin directories
mkdir -p "$MOUNT_DIR/bin"
mkdir -p "$MOUNT_DIR/sbin"
mkdir -p "$MOUNT_DIR/usr/local/test/bin"

# Copy ALL binaries from userspace directory
# Special handling: true and telnetd go to /sbin, everything else to /bin
# Routing: test binaries (*_test, test_*) -> /usr/local/test/bin
# system binaries (true, telnetd, init) -> /sbin
# everything else -> /bin
echo "Installing all binaries..."
bin_count=0
sbin_count=0
test_count=0
for elf_file in "$USERSPACE_DIR"/*.elf; do
if [ -f "$elf_file" ]; then
bin_name=$(basename "$elf_file" .elf)
if [ "$bin_name" = "true" ] || [ "$bin_name" = "telnetd" ] || [ "$bin_name" = "init" ]; then
if echo "$bin_name" | grep -qE '_test$|^test_'; then
cp "$elf_file" "$MOUNT_DIR/usr/local/test/bin/${bin_name}"
chmod 755 "$MOUNT_DIR/usr/local/test/bin/${bin_name}"
test_count=$((test_count + 1))
elif [ "$bin_name" = "btrue" ] || [ "$bin_name" = "telnetd" ] || [ "$bin_name" = "init" ]; then
cp "$elf_file" "$MOUNT_DIR/sbin/${bin_name}"
chmod 755 "$MOUNT_DIR/sbin/${bin_name}"
sbin_count=$((sbin_count + 1))
Expand All @@ -231,6 +250,7 @@ else
done
echo " Installed $bin_count binaries in /bin"
echo " Installed $sbin_count binaries in /sbin"
echo " Installed $test_count test binaries in /usr/local/test/bin"

# Create /tmp for filesystem write tests
mkdir -p "$MOUNT_DIR/tmp"
Expand Down Expand Up @@ -267,7 +287,9 @@ EOF
echo ""
echo "ext2 filesystem contents:"
ls -la "$MOUNT_DIR/bin/"
find "$MOUNT_DIR" -type f -not -path "$MOUNT_DIR/bin/*" -exec ls -la {} \;
echo " Test binaries in /usr/local/test/bin:"
ls -la "$MOUNT_DIR/usr/local/test/bin/" 2>/dev/null || echo " (none)"
find "$MOUNT_DIR" -type f -not -path "$MOUNT_DIR/bin/*" -not -path "$MOUNT_DIR/usr/local/test/bin/*" -exec ls -la {} \;

# Unmount and cleanup
umount "$MOUNT_DIR"
Expand All @@ -287,8 +309,9 @@ if [[ -f "$OUTPUT_FILE" ]]; then
echo " Size: $SIZE"
echo ""
echo "Contents:"
echo " /bin/* - All userspace binaries (coreutils, tests, demos)"
echo " /sbin/true - exit status coreutil (for PATH testing)"
echo " /bin/* - Userspace binaries (coreutils, demos)"
echo " /usr/local/test/bin/* - Test binaries (*_test, test_*)"
echo " /sbin/btrue - exit status coreutil (for PATH testing)"
echo " /sbin/telnetd - telnet daemon"
echo " /hello.txt - test file (1 line)"
echo " /lines.txt - multi-line test file (15 lines) for head/tail/wc"
Expand Down
58 changes: 29 additions & 29 deletions userspace/programs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -235,62 +235,62 @@ path = "src/cow_readonly_test.rs"
name = "cow_signal_test"
path = "src/cow_signal_test.rs"

# Phase 3: Coreutils
# Phase 3: Coreutils (b-prefixed to avoid collision with GNU coreutils)
[[bin]]
name = "true"
path = "src/true.rs"
name = "btrue"
path = "src/btrue.rs"

[[bin]]
name = "false"
path = "src/false.rs"
name = "bfalse"
path = "src/bfalse.rs"

[[bin]]
name = "echo"
path = "src/echo.rs"
name = "becho"
path = "src/becho.rs"

[[bin]]
name = "cat"
path = "src/cat.rs"
name = "bcat"
path = "src/bcat.rs"

[[bin]]
name = "head"
path = "src/head.rs"
name = "bhead"
path = "src/bhead.rs"

[[bin]]
name = "tail"
path = "src/tail.rs"
name = "btail"
path = "src/btail.rs"

[[bin]]
name = "wc"
path = "src/wc.rs"
name = "bwc"
path = "src/bwc.rs"

[[bin]]
name = "which"
path = "src/which.rs"
name = "bwhich"
path = "src/bwhich.rs"

[[bin]]
name = "ls"
path = "src/ls.rs"
name = "bls"
path = "src/bls.rs"

[[bin]]
name = "mkdir"
path = "src/mkdir.rs"
name = "bmkdir"
path = "src/bmkdir.rs"

[[bin]]
name = "rmdir"
path = "src/rmdir.rs"
name = "brmdir"
path = "src/brmdir.rs"

[[bin]]
name = "rm"
path = "src/rm.rs"
name = "brm"
path = "src/brm.rs"

[[bin]]
name = "cp"
path = "src/cp.rs"
name = "bcp"
path = "src/bcp.rs"

[[bin]]
name = "mv"
path = "src/mv.rs"
name = "bmv"
path = "src/bmv.rs"

[[bin]]
name = "resolution"
Expand Down
30 changes: 15 additions & 15 deletions userspace/programs/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -167,21 +167,21 @@ STD_BINARIES=(
"cow_readonly_test"
"cow_signal_test"

# Phase 3: Coreutils
"true"
"false"
"echo"
"cat"
"head"
"tail"
"wc"
"which"
"ls"
"mkdir"
"rmdir"
"rm"
"cp"
"mv"
# Phase 3: Coreutils (b-prefixed)
"btrue"
"bfalse"
"becho"
"bcat"
"bhead"
"btail"
"bwc"
"bwhich"
"bls"
"bmkdir"
"brmdir"
"brm"
"bcp"
"bmv"
"resolution"

# Phase 4: init_shell
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading
Loading