From 9e0854b0114442014cf80ce3224075ae4ff7c6d2 Mon Sep 17 00:00:00 2001 From: Tulio A M Mendes Date: Sat, 14 Mar 2026 12:40:11 -0300 Subject: [PATCH] refactor: reorganize userland into user/cmds// with per-program Makefiles - Move 53 user commands from user/.c to user/cmds//.c - Add user/cmds/common.mk shared build rules for dynamically-linked commands - Add per-program Makefiles for all commands (including fulltest, ldso, pie_test) - Build all .o/.elf into build/user/cmds// (out-of-tree) - Replace [init] test prefix with [test] in fulltest.c, pie_main.c, test scripts - Fix find.c and which.c: use opendir/readdir/closedir instead of raw getdents - Fix ulibc glob.c missing stdio.h include - Fix ulibc -Wno-incompatible-pointer-types for GCC 14+ - Fix test_host_utils.sh which test set -e issue - Doom rootfs path changed to /usr/games/doom - make clean now also cleans ulibc and doom in-tree artifacts Tests: 103/103 smoke, 28/28 unit, 19/19 security, 68/68 host utils, cppcheck clean --- BUILD_GUIDE.md | 2 +- Makefile | 408 ++------- tests/smoke_test.exp | 188 ++-- tests/test_battery.exp | 4 +- tests/test_host_utils.sh | 64 +- user/cmds/awk/Makefile | 3 + user/{ => cmds/awk}/awk.c | 0 user/cmds/basename/Makefile | 3 + user/{ => cmds/basename}/basename.c | 0 user/cmds/cat/Makefile | 3 + user/{ => cmds/cat}/cat.c | 0 user/cmds/chgrp/Makefile | 3 + user/{ => cmds/chgrp}/chgrp.c | 0 user/cmds/chmod/Makefile | 3 + user/{ => cmds/chmod}/chmod.c | 0 user/cmds/chown/Makefile | 3 + user/{ => cmds/chown}/chown.c | 0 user/cmds/clear/Makefile | 3 + user/{ => cmds/clear}/clear.c | 0 user/cmds/common.mk | 34 + user/cmds/cp/Makefile | 3 + user/{ => cmds/cp}/cp.c | 0 user/cmds/cut/Makefile | 3 + user/{ => cmds/cut}/cut.c | 0 user/cmds/date/Makefile | 3 + user/{ => cmds/date}/date.c | 0 user/cmds/dd/Makefile | 3 + user/{ => cmds/dd}/dd.c | 0 user/cmds/df/Makefile | 3 + user/{ => cmds/df}/df.c | 0 user/cmds/dirname/Makefile | 3 + user/{ => cmds/dirname}/dirname.c | 0 user/cmds/dmesg/Makefile | 3 + user/{ => cmds/dmesg}/dmesg.c | 0 user/cmds/du/Makefile | 3 + user/{ => cmds/du}/du.c | 0 user/cmds/echo/Makefile | 3 + user/{ => cmds/echo}/echo.c | 0 user/cmds/env/Makefile | 3 + user/{ => cmds/env}/env.c | 0 user/cmds/find/Makefile | 3 + user/{ => cmds/find}/find.c | 60 +- user/cmds/free/Makefile | 3 + user/{ => cmds/free}/free.c | 0 user/cmds/fulltest/Makefile | 21 + user/{ => cmds/fulltest}/errno.c | 0 user/{ => cmds/fulltest}/fulltest.c | 1218 ++++++++++++------------- user/{ => cmds/fulltest}/user_errno.h | 0 user/cmds/grep/Makefile | 3 + user/{ => cmds/grep}/grep.c | 0 user/cmds/head/Makefile | 3 + user/{ => cmds/head}/head.c | 0 user/cmds/hostname/Makefile | 3 + user/{ => cmds/hostname}/hostname.c | 0 user/cmds/id/Makefile | 3 + user/{ => cmds/id}/id.c | 0 user/cmds/init/Makefile | 3 + user/{ => cmds/init}/init.c | 0 user/cmds/kill/Makefile | 3 + user/{ => cmds/kill}/kill.c | 0 user/cmds/ldso/Makefile | 21 + user/{ => cmds/ldso}/ldso.c | 0 user/cmds/ln/Makefile | 3 + user/{ => cmds/ln}/ln.c | 0 user/cmds/ls/Makefile | 3 + user/{ => cmds/ls}/ls.c | 0 user/cmds/mkdir/Makefile | 3 + user/{ => cmds/mkdir}/mkdir.c | 0 user/cmds/mount/Makefile | 3 + user/{ => cmds/mount}/mount.c | 0 user/cmds/mv/Makefile | 3 + user/{ => cmds/mv}/mv.c | 0 user/cmds/pie_test/Makefile | 30 + user/{ => cmds/pie_test}/pie_func.c | 0 user/{ => cmds/pie_test}/pie_main.c | 8 +- user/cmds/printenv/Makefile | 3 + user/{ => cmds/printenv}/printenv.c | 0 user/cmds/ps/Makefile | 3 + user/{ => cmds/ps}/ps.c | 0 user/cmds/pwd/Makefile | 3 + user/{ => cmds/pwd}/pwd.c | 0 user/cmds/rm/Makefile | 3 + user/{ => cmds/rm}/rm.c | 0 user/cmds/rmdir/Makefile | 3 + user/{ => cmds/rmdir}/rmdir.c | 0 user/cmds/sed/Makefile | 3 + user/{ => cmds/sed}/sed.c | 0 user/cmds/sh/Makefile | 3 + user/{ => cmds/sh}/sh.c | 0 user/cmds/sleep/Makefile | 3 + user/{ => cmds/sleep}/sleep.c | 0 user/cmds/sort/Makefile | 3 + user/{ => cmds/sort}/sort.c | 0 user/cmds/stat/Makefile | 3 + user/{ => cmds/stat}/stat.c | 0 user/cmds/tail/Makefile | 3 + user/{ => cmds/tail}/tail.c | 0 user/cmds/tee/Makefile | 3 + user/{ => cmds/tee}/tee.c | 0 user/cmds/top/Makefile | 3 + user/{ => cmds/top}/top.c | 0 user/cmds/touch/Makefile | 3 + user/{ => cmds/touch}/touch.c | 0 user/cmds/tr/Makefile | 3 + user/{ => cmds/tr}/tr.c | 0 user/cmds/umount/Makefile | 3 + user/{ => cmds/umount}/umount.c | 0 user/cmds/uname/Makefile | 3 + user/{ => cmds/uname}/uname.c | 0 user/cmds/uniq/Makefile | 3 + user/{ => cmds/uniq}/uniq.c | 0 user/cmds/uptime/Makefile | 3 + user/{ => cmds/uptime}/uptime.c | 0 user/cmds/wc/Makefile | 3 + user/{ => cmds/wc}/wc.c | 0 user/cmds/which/Makefile | 3 + user/{ => cmds/which}/which.c | 27 +- user/cmds/who/Makefile | 3 + user/{ => cmds/who}/who.c | 0 user/ulibc/Makefile | 4 +- user/ulibc/src/glob.c | 1 + 121 files changed, 1123 insertions(+), 1123 deletions(-) create mode 100644 user/cmds/awk/Makefile rename user/{ => cmds/awk}/awk.c (100%) create mode 100644 user/cmds/basename/Makefile rename user/{ => cmds/basename}/basename.c (100%) create mode 100644 user/cmds/cat/Makefile rename user/{ => cmds/cat}/cat.c (100%) create mode 100644 user/cmds/chgrp/Makefile rename user/{ => cmds/chgrp}/chgrp.c (100%) create mode 100644 user/cmds/chmod/Makefile rename user/{ => cmds/chmod}/chmod.c (100%) create mode 100644 user/cmds/chown/Makefile rename user/{ => cmds/chown}/chown.c (100%) create mode 100644 user/cmds/clear/Makefile rename user/{ => cmds/clear}/clear.c (100%) create mode 100644 user/cmds/common.mk create mode 100644 user/cmds/cp/Makefile rename user/{ => cmds/cp}/cp.c (100%) create mode 100644 user/cmds/cut/Makefile rename user/{ => cmds/cut}/cut.c (100%) create mode 100644 user/cmds/date/Makefile rename user/{ => cmds/date}/date.c (100%) create mode 100644 user/cmds/dd/Makefile rename user/{ => cmds/dd}/dd.c (100%) create mode 100644 user/cmds/df/Makefile rename user/{ => cmds/df}/df.c (100%) create mode 100644 user/cmds/dirname/Makefile rename user/{ => cmds/dirname}/dirname.c (100%) create mode 100644 user/cmds/dmesg/Makefile rename user/{ => cmds/dmesg}/dmesg.c (100%) create mode 100644 user/cmds/du/Makefile rename user/{ => cmds/du}/du.c (100%) create mode 100644 user/cmds/echo/Makefile rename user/{ => cmds/echo}/echo.c (100%) create mode 100644 user/cmds/env/Makefile rename user/{ => cmds/env}/env.c (100%) create mode 100644 user/cmds/find/Makefile rename user/{ => cmds/find}/find.c (57%) create mode 100644 user/cmds/free/Makefile rename user/{ => cmds/free}/free.c (100%) create mode 100644 user/cmds/fulltest/Makefile rename user/{ => cmds/fulltest}/errno.c (100%) rename user/{ => cmds/fulltest}/fulltest.c (68%) rename user/{ => cmds/fulltest}/user_errno.h (100%) create mode 100644 user/cmds/grep/Makefile rename user/{ => cmds/grep}/grep.c (100%) create mode 100644 user/cmds/head/Makefile rename user/{ => cmds/head}/head.c (100%) create mode 100644 user/cmds/hostname/Makefile rename user/{ => cmds/hostname}/hostname.c (100%) create mode 100644 user/cmds/id/Makefile rename user/{ => cmds/id}/id.c (100%) create mode 100644 user/cmds/init/Makefile rename user/{ => cmds/init}/init.c (100%) create mode 100644 user/cmds/kill/Makefile rename user/{ => cmds/kill}/kill.c (100%) create mode 100644 user/cmds/ldso/Makefile rename user/{ => cmds/ldso}/ldso.c (100%) create mode 100644 user/cmds/ln/Makefile rename user/{ => cmds/ln}/ln.c (100%) create mode 100644 user/cmds/ls/Makefile rename user/{ => cmds/ls}/ls.c (100%) create mode 100644 user/cmds/mkdir/Makefile rename user/{ => cmds/mkdir}/mkdir.c (100%) create mode 100644 user/cmds/mount/Makefile rename user/{ => cmds/mount}/mount.c (100%) create mode 100644 user/cmds/mv/Makefile rename user/{ => cmds/mv}/mv.c (100%) create mode 100644 user/cmds/pie_test/Makefile rename user/{ => cmds/pie_test}/pie_func.c (100%) rename user/{ => cmds/pie_test}/pie_main.c (79%) create mode 100644 user/cmds/printenv/Makefile rename user/{ => cmds/printenv}/printenv.c (100%) create mode 100644 user/cmds/ps/Makefile rename user/{ => cmds/ps}/ps.c (100%) create mode 100644 user/cmds/pwd/Makefile rename user/{ => cmds/pwd}/pwd.c (100%) create mode 100644 user/cmds/rm/Makefile rename user/{ => cmds/rm}/rm.c (100%) create mode 100644 user/cmds/rmdir/Makefile rename user/{ => cmds/rmdir}/rmdir.c (100%) create mode 100644 user/cmds/sed/Makefile rename user/{ => cmds/sed}/sed.c (100%) create mode 100644 user/cmds/sh/Makefile rename user/{ => cmds/sh}/sh.c (100%) create mode 100644 user/cmds/sleep/Makefile rename user/{ => cmds/sleep}/sleep.c (100%) create mode 100644 user/cmds/sort/Makefile rename user/{ => cmds/sort}/sort.c (100%) create mode 100644 user/cmds/stat/Makefile rename user/{ => cmds/stat}/stat.c (100%) create mode 100644 user/cmds/tail/Makefile rename user/{ => cmds/tail}/tail.c (100%) create mode 100644 user/cmds/tee/Makefile rename user/{ => cmds/tee}/tee.c (100%) create mode 100644 user/cmds/top/Makefile rename user/{ => cmds/top}/top.c (100%) create mode 100644 user/cmds/touch/Makefile rename user/{ => cmds/touch}/touch.c (100%) create mode 100644 user/cmds/tr/Makefile rename user/{ => cmds/tr}/tr.c (100%) create mode 100644 user/cmds/umount/Makefile rename user/{ => cmds/umount}/umount.c (100%) create mode 100644 user/cmds/uname/Makefile rename user/{ => cmds/uname}/uname.c (100%) create mode 100644 user/cmds/uniq/Makefile rename user/{ => cmds/uniq}/uniq.c (100%) create mode 100644 user/cmds/uptime/Makefile rename user/{ => cmds/uptime}/uptime.c (100%) create mode 100644 user/cmds/wc/Makefile rename user/{ => cmds/wc}/wc.c (100%) create mode 100644 user/cmds/which/Makefile rename user/{ => cmds/which}/which.c (55%) create mode 100644 user/cmds/who/Makefile rename user/{ => cmds/who}/who.c (100%) diff --git a/BUILD_GUIDE.md b/BUILD_GUIDE.md index f613445..fa0b4a1 100644 --- a/BUILD_GUIDE.md +++ b/BUILD_GUIDE.md @@ -142,7 +142,7 @@ The fulltest binary (`/sbin/fulltest`) runs a comprehensive suite of 102 smoke t - Dynamic linking: lazy PLT resolution, PLT caching - LZ4 initrd decompression -All tests print `[init] ... OK` on success. Any failure calls `sys_exit(1)`. +All tests print `[test] ... OK` on success. Any failure calls `sys_exit(1)`. ### Testing diff --git a/Makefile b/Makefile index 02f123e..4b08b49 100644 --- a/Makefile +++ b/Makefile @@ -78,66 +78,41 @@ ifeq ($(ARCH),x86) USER_LD ?= i686-elf-ld USER_AR ?= i686-elf-ar - FULLTEST_ELF := user/fulltest.elf - ECHO_ELF := user/echo.elf - SH_ELF := user/sh.elf - CAT_ELF := user/cat.elf - LS_ELF := user/ls.elf - MKDIR_ELF := user/mkdir.elf - RM_ELF := user/rm.elf - CP_ELF := user/cp.elf - MV_ELF := user/mv.elf - TOUCH_ELF := user/touch.elf - LN_ELF := user/ln.elf - HEAD_ELF := user/head.elf - TAIL_ELF := user/tail.elf - WC_ELF := user/wc.elf - SORT_ELF := user/sort.elf - UNIQ_ELF := user/uniq.elf - CUT_ELF := user/cut.elf - CHMOD_ELF := user/chmod.elf - CHOWN_ELF := user/chown.elf - CHGRP_ELF := user/chgrp.elf - DATE_ELF := user/date.elf - HOSTNAME_ELF := user/hostname.elf - UPTIME_ELF := user/uptime.elf - MOUNT_ELF := user/mount.elf - UMOUNT_ELF := user/umount.elf - ENV_ELF := user/env.elf - KILL_ELF := user/kill.elf - SLEEP_ELF := user/sleep.elf - CLEAR_ELF := user/clear.elf - PS_ELF := user/ps.elf - DF_ELF := user/df.elf - FREE_ELF := user/free.elf - TEE_ELF := user/tee.elf - BASENAME_ELF := user/basename.elf - DIRNAME_ELF := user/dirname.elf - RMDIR_ELF := user/rmdir.elf - GREP_ELF := user/grep.elf - ID_ELF := user/id.elf - UNAME_ELF := user/uname.elf - DMESG_ELF := user/dmesg.elf - PRINTENV_ELF := user/printenv.elf - TR_ELF := user/tr.elf - DD_ELF := user/dd.elf - PWD_ELF := user/pwd.elf - STAT_ELF := user/stat.elf - SED_ELF := user/sed.elf - AWK_ELF := user/awk.elf - WHO_ELF := user/who.elf - TOP_ELF := user/top.elf - DU_ELF := user/du.elf - FIND_ELF := user/find.elf - WHICH_ELF := user/which.elf - INIT_ELF := user/init.elf - LDSO_ELF := user/ld.so - ULIBC_SO := user/ulibc/libc.so - PIE_SO := user/libpietest.so - PIE_ELF := user/pie_test.elf + # User build output directory + USER_BUILD := build/user + + # List of dynamically-linked user commands (built via user/cmds//Makefile) + USER_CMD_NAMES := echo sh cat ls mkdir rm cp mv touch ln \ + head tail wc sort uniq cut \ + chmod chown chgrp \ + date hostname uptime \ + mount umount env kill sleep \ + clear ps df free tee \ + basename dirname rmdir \ + grep id uname dmesg \ + printenv tr dd pwd stat \ + sed awk who top du find which \ + init + + # ELF paths for dynamically-linked commands + USER_CMD_ELFS := $(foreach cmd,$(USER_CMD_NAMES),$(USER_BUILD)/cmds/$(cmd)/$(cmd).elf) + + # Special builds (not dynamically-linked via common.mk) + FULLTEST_ELF := $(USER_BUILD)/cmds/fulltest/fulltest.elf + LDSO_ELF := $(USER_BUILD)/cmds/ldso/ld.so + PIE_SO := $(USER_BUILD)/cmds/pie_test/libpietest.so + PIE_ELF := $(USER_BUILD)/cmds/pie_test/pie_test.elf + + # ulibc + ULIBC_DIR := user/ulibc + ULIBC_SO := $(USER_BUILD)/ulibc/libc.so + ULIBC_LIB := $(USER_BUILD)/ulibc/libulibc.a + + # doom DOOM_ELF := user/doom/doom.elf + INITRD_IMG := initrd.img - MKINITRD := tools/mkinitrd + MKINITRD := tools/mkinitrd endif # --- ARM64 Configuration --- @@ -214,285 +189,56 @@ iso: $(KERNEL_NAME) $(INITRD_IMG) $(MKINITRD): tools/mkinitrd.c include/xxhash32.h @gcc -Iinclude tools/mkinitrd.c -o $(MKINITRD) -ULIBC_DIR := user/ulibc -ULIBC_LIB := $(ULIBC_DIR)/libulibc.a - -$(ULIBC_LIB): - @$(MAKE) -C $(ULIBC_DIR) CC="$(USER_CC)" AS="$(USER_CC:gcc=as)" AR="$(USER_AR)" LD="$(USER_LD)" --no-print-directory - -$(ULIBC_SO): - @$(MAKE) -C $(ULIBC_DIR) CC="$(USER_CC)" AS="$(USER_CC:gcc=as)" AR="$(USER_AR)" LD="$(USER_LD)" libc.so --no-print-directory - -$(FULLTEST_ELF): user/fulltest.c user/linker.ld - @$(USER_CC) -m32 -I include -ffreestanding -fno-pie -no-pie -nostdlib -Wl,-T,user/linker.ld -o $(FULLTEST_ELF) user/fulltest.c user/errno.c - -# --- Dynamic linking helper: compile .c to PIC .o, link as PIE with crt0 + libc.so --- -ULIBC_CRT0 := $(ULIBC_DIR)/src/crt0.o -DYN_CC := $(USER_CC) -m32 -ffreestanding -nostdlib -O2 -Wall -Wextra -fPIC -fno-plt -I$(ULIBC_DIR)/include -DYN_LD := $(USER_LD) -m elf_i386 --dynamic-linker=/lib/ld.so -T user/dyn_linker.ld -L$(ULIBC_DIR) -rpath /lib - -$(ECHO_ELF): user/echo.c user/dyn_linker.ld $(ULIBC_SO) $(ULIBC_LIB) - @$(DYN_CC) -c user/echo.c -o user/echo.o - @$(DYN_LD) -o $@ $(ULIBC_CRT0) user/echo.o -lc - -$(SH_ELF): user/sh.c user/dyn_linker.ld $(ULIBC_SO) $(ULIBC_LIB) - @$(DYN_CC) -c user/sh.c -o user/sh.o - @$(DYN_LD) -o $@ $(ULIBC_CRT0) user/sh.o -lc - -$(CAT_ELF): user/cat.c user/dyn_linker.ld $(ULIBC_SO) $(ULIBC_LIB) - @$(DYN_CC) -c user/cat.c -o user/cat.o - @$(DYN_LD) -o $@ $(ULIBC_CRT0) user/cat.o -lc - -$(LS_ELF): user/ls.c user/dyn_linker.ld $(ULIBC_SO) $(ULIBC_LIB) - @$(DYN_CC) -c user/ls.c -o user/ls.o - @$(DYN_LD) -o $@ $(ULIBC_CRT0) user/ls.o -lc - -$(MKDIR_ELF): user/mkdir.c user/dyn_linker.ld $(ULIBC_SO) $(ULIBC_LIB) - @$(DYN_CC) -c user/mkdir.c -o user/mkdir.o - @$(DYN_LD) -o $@ $(ULIBC_CRT0) user/mkdir.o -lc - -$(RM_ELF): user/rm.c user/dyn_linker.ld $(ULIBC_SO) $(ULIBC_LIB) - @$(DYN_CC) -c user/rm.c -o user/rm.o - @$(DYN_LD) -o $@ $(ULIBC_CRT0) user/rm.o -lc - -$(CP_ELF): user/cp.c user/dyn_linker.ld $(ULIBC_SO) $(ULIBC_LIB) - @$(DYN_CC) -c user/cp.c -o user/cp.o - @$(DYN_LD) -o $@ $(ULIBC_CRT0) user/cp.o -lc - -$(MV_ELF): user/mv.c user/dyn_linker.ld $(ULIBC_SO) $(ULIBC_LIB) - @$(DYN_CC) -c user/mv.c -o user/mv.o - @$(DYN_LD) -o $@ $(ULIBC_CRT0) user/mv.o -lc - -$(TOUCH_ELF): user/touch.c user/dyn_linker.ld $(ULIBC_SO) $(ULIBC_LIB) - @$(DYN_CC) -c user/touch.c -o user/touch.o - @$(DYN_LD) -o $@ $(ULIBC_CRT0) user/touch.o -lc - -$(LN_ELF): user/ln.c user/dyn_linker.ld $(ULIBC_SO) $(ULIBC_LIB) - @$(DYN_CC) -c user/ln.c -o user/ln.o - @$(DYN_LD) -o $@ $(ULIBC_CRT0) user/ln.o -lc - -$(HEAD_ELF): user/head.c user/dyn_linker.ld $(ULIBC_SO) $(ULIBC_LIB) - @$(DYN_CC) -c user/head.c -o user/head.o - @$(DYN_LD) -o $@ $(ULIBC_CRT0) user/head.o -lc - -$(TAIL_ELF): user/tail.c user/dyn_linker.ld $(ULIBC_SO) $(ULIBC_LIB) - @$(DYN_CC) -c user/tail.c -o user/tail.o - @$(DYN_LD) -o $@ $(ULIBC_CRT0) user/tail.o -lc - -$(WC_ELF): user/wc.c user/dyn_linker.ld $(ULIBC_SO) $(ULIBC_LIB) - @$(DYN_CC) -c user/wc.c -o user/wc.o - @$(DYN_LD) -o $@ $(ULIBC_CRT0) user/wc.o -lc - -$(SORT_ELF): user/sort.c user/dyn_linker.ld $(ULIBC_SO) $(ULIBC_LIB) - @$(DYN_CC) -c user/sort.c -o user/sort.o - @$(DYN_LD) -o $@ $(ULIBC_CRT0) user/sort.o -lc - -$(UNIQ_ELF): user/uniq.c user/dyn_linker.ld $(ULIBC_SO) $(ULIBC_LIB) - @$(DYN_CC) -c user/uniq.c -o user/uniq.o - @$(DYN_LD) -o $@ $(ULIBC_CRT0) user/uniq.o -lc - -$(CUT_ELF): user/cut.c user/dyn_linker.ld $(ULIBC_SO) $(ULIBC_LIB) - @$(DYN_CC) -c user/cut.c -o user/cut.o - @$(DYN_LD) -o $@ $(ULIBC_CRT0) user/cut.o -lc - -$(CHMOD_ELF): user/chmod.c user/dyn_linker.ld $(ULIBC_SO) $(ULIBC_LIB) - @$(DYN_CC) -c user/chmod.c -o user/chmod.o - @$(DYN_LD) -o $@ $(ULIBC_CRT0) user/chmod.o -lc - -$(CHOWN_ELF): user/chown.c user/dyn_linker.ld $(ULIBC_SO) $(ULIBC_LIB) - @$(DYN_CC) -c user/chown.c -o user/chown.o - @$(DYN_LD) -o $@ $(ULIBC_CRT0) user/chown.o -lc - -$(CHGRP_ELF): user/chgrp.c user/dyn_linker.ld $(ULIBC_SO) $(ULIBC_LIB) - @$(DYN_CC) -c user/chgrp.c -o user/chgrp.o - @$(DYN_LD) -o $@ $(ULIBC_CRT0) user/chgrp.o -lc - -$(DATE_ELF): user/date.c user/dyn_linker.ld $(ULIBC_SO) $(ULIBC_LIB) - @$(DYN_CC) -c user/date.c -o user/date.o - @$(DYN_LD) -o $@ $(ULIBC_CRT0) user/date.o -lc - -$(HOSTNAME_ELF): user/hostname.c user/dyn_linker.ld $(ULIBC_SO) $(ULIBC_LIB) - @$(DYN_CC) -c user/hostname.c -o user/hostname.o - @$(DYN_LD) -o $@ $(ULIBC_CRT0) user/hostname.o -lc - -$(UPTIME_ELF): user/uptime.c user/dyn_linker.ld $(ULIBC_SO) $(ULIBC_LIB) - @$(DYN_CC) -c user/uptime.c -o user/uptime.o - @$(DYN_LD) -o $@ $(ULIBC_CRT0) user/uptime.o -lc - -$(INIT_ELF): user/init.c user/dyn_linker.ld $(ULIBC_SO) $(ULIBC_LIB) - @$(DYN_CC) -c user/init.c -o user/init.o - @$(DYN_LD) -o $@ $(ULIBC_CRT0) user/init.o -lc - -$(MOUNT_ELF): user/mount.c user/dyn_linker.ld $(ULIBC_SO) $(ULIBC_LIB) - @$(DYN_CC) -c user/mount.c -o user/mount.o - @$(DYN_LD) -o $@ $(ULIBC_CRT0) user/mount.o -lc - -$(UMOUNT_ELF): user/umount.c user/dyn_linker.ld $(ULIBC_SO) $(ULIBC_LIB) - @$(DYN_CC) -c user/umount.c -o user/umount.o - @$(DYN_LD) -o $@ $(ULIBC_CRT0) user/umount.o -lc - -$(ENV_ELF): user/env.c user/dyn_linker.ld $(ULIBC_SO) $(ULIBC_LIB) - @$(DYN_CC) -c user/env.c -o user/env.o - @$(DYN_LD) -o $@ $(ULIBC_CRT0) user/env.o -lc - -$(KILL_ELF): user/kill.c user/dyn_linker.ld $(ULIBC_SO) $(ULIBC_LIB) - @$(DYN_CC) -c user/kill.c -o user/kill.o - @$(DYN_LD) -o $@ $(ULIBC_CRT0) user/kill.o -lc - -$(SLEEP_ELF): user/sleep.c user/dyn_linker.ld $(ULIBC_SO) $(ULIBC_LIB) - @$(DYN_CC) -c user/sleep.c -o user/sleep.o - @$(DYN_LD) -o $@ $(ULIBC_CRT0) user/sleep.o -lc - -$(CLEAR_ELF): user/clear.c user/dyn_linker.ld $(ULIBC_SO) $(ULIBC_LIB) - @$(DYN_CC) -c user/clear.c -o user/clear.o - @$(DYN_LD) -o $@ $(ULIBC_CRT0) user/clear.o -lc - -$(PS_ELF): user/ps.c user/dyn_linker.ld $(ULIBC_SO) $(ULIBC_LIB) - @$(DYN_CC) -c user/ps.c -o user/ps.o - @$(DYN_LD) -o $@ $(ULIBC_CRT0) user/ps.o -lc - -$(DF_ELF): user/df.c user/dyn_linker.ld $(ULIBC_SO) $(ULIBC_LIB) - @$(DYN_CC) -c user/df.c -o user/df.o - @$(DYN_LD) -o $@ $(ULIBC_CRT0) user/df.o -lc - -$(FREE_ELF): user/free.c user/dyn_linker.ld $(ULIBC_SO) $(ULIBC_LIB) - @$(DYN_CC) -c user/free.c -o user/free.o - @$(DYN_LD) -o $@ $(ULIBC_CRT0) user/free.o -lc - -$(TEE_ELF): user/tee.c user/dyn_linker.ld $(ULIBC_SO) $(ULIBC_LIB) - @$(DYN_CC) -c user/tee.c -o user/tee.o - @$(DYN_LD) -o $@ $(ULIBC_CRT0) user/tee.o -lc - -$(BASENAME_ELF): user/basename.c user/dyn_linker.ld $(ULIBC_SO) $(ULIBC_LIB) - @$(DYN_CC) -c user/basename.c -o user/basename.o - @$(DYN_LD) -o $@ $(ULIBC_CRT0) user/basename.o -lc - -$(DIRNAME_ELF): user/dirname.c user/dyn_linker.ld $(ULIBC_SO) $(ULIBC_LIB) - @$(DYN_CC) -c user/dirname.c -o user/dirname.o - @$(DYN_LD) -o $@ $(ULIBC_CRT0) user/dirname.o -lc - -$(RMDIR_ELF): user/rmdir.c user/dyn_linker.ld $(ULIBC_SO) $(ULIBC_LIB) - @$(DYN_CC) -c user/rmdir.c -o user/rmdir.o - @$(DYN_LD) -o $@ $(ULIBC_CRT0) user/rmdir.o -lc - -$(GREP_ELF): user/grep.c user/dyn_linker.ld $(ULIBC_SO) $(ULIBC_LIB) - @$(DYN_CC) -c user/grep.c -o user/grep.o - @$(DYN_LD) -o $@ $(ULIBC_CRT0) user/grep.o -lc - -$(ID_ELF): user/id.c user/dyn_linker.ld $(ULIBC_SO) $(ULIBC_LIB) - @$(DYN_CC) -c user/id.c -o user/id.o - @$(DYN_LD) -o $@ $(ULIBC_CRT0) user/id.o -lc - -$(UNAME_ELF): user/uname.c user/dyn_linker.ld $(ULIBC_SO) $(ULIBC_LIB) - @$(DYN_CC) -c user/uname.c -o user/uname.o - @$(DYN_LD) -o $@ $(ULIBC_CRT0) user/uname.o -lc - -$(DMESG_ELF): user/dmesg.c user/dyn_linker.ld $(ULIBC_SO) $(ULIBC_LIB) - @$(DYN_CC) -c user/dmesg.c -o user/dmesg.o - @$(DYN_LD) -o $@ $(ULIBC_CRT0) user/dmesg.o -lc - -$(PRINTENV_ELF): user/printenv.c user/dyn_linker.ld $(ULIBC_SO) $(ULIBC_LIB) - @$(DYN_CC) -c user/printenv.c -o user/printenv.o - @$(DYN_LD) -o $@ $(ULIBC_CRT0) user/printenv.o -lc - -$(TR_ELF): user/tr.c user/dyn_linker.ld $(ULIBC_SO) $(ULIBC_LIB) - @$(DYN_CC) -c user/tr.c -o user/tr.o - @$(DYN_LD) -o $@ $(ULIBC_CRT0) user/tr.o -lc - -$(DD_ELF): user/dd.c user/dyn_linker.ld $(ULIBC_SO) $(ULIBC_LIB) - @$(DYN_CC) -c user/dd.c -o user/dd.o - @$(DYN_LD) -o $@ $(ULIBC_CRT0) user/dd.o -lc - -$(PWD_ELF): user/pwd.c user/dyn_linker.ld $(ULIBC_SO) $(ULIBC_LIB) - @$(DYN_CC) -c user/pwd.c -o user/pwd.o - @$(DYN_LD) -o $@ $(ULIBC_CRT0) user/pwd.o -lc - -$(STAT_ELF): user/stat.c user/dyn_linker.ld $(ULIBC_SO) $(ULIBC_LIB) - @$(DYN_CC) -c user/stat.c -o user/stat.o - @$(DYN_LD) -o $@ $(ULIBC_CRT0) user/stat.o -lc - -$(SED_ELF): user/sed.c user/dyn_linker.ld $(ULIBC_SO) $(ULIBC_LIB) - @$(DYN_CC) -c user/sed.c -o user/sed.o - @$(DYN_LD) -o $@ $(ULIBC_CRT0) user/sed.o -lc - -$(AWK_ELF): user/awk.c user/dyn_linker.ld $(ULIBC_SO) $(ULIBC_LIB) - @$(DYN_CC) -c user/awk.c -o user/awk.o - @$(DYN_LD) -o $@ $(ULIBC_CRT0) user/awk.o -lc - -$(WHO_ELF): user/who.c user/dyn_linker.ld $(ULIBC_SO) $(ULIBC_LIB) - @$(DYN_CC) -c user/who.c -o user/who.o - @$(DYN_LD) -o $@ $(ULIBC_CRT0) user/who.o -lc - -$(TOP_ELF): user/top.c user/dyn_linker.ld $(ULIBC_SO) $(ULIBC_LIB) - @$(DYN_CC) -c user/top.c -o user/top.o - @$(DYN_LD) -o $@ $(ULIBC_CRT0) user/top.o -lc - -$(DU_ELF): user/du.c user/dyn_linker.ld $(ULIBC_SO) $(ULIBC_LIB) - @$(DYN_CC) -c user/du.c -o user/du.o - @$(DYN_LD) -o $@ $(ULIBC_CRT0) user/du.o -lc - -$(FIND_ELF): user/find.c user/dyn_linker.ld $(ULIBC_SO) $(ULIBC_LIB) - @$(DYN_CC) -c user/find.c -o user/find.o - @$(DYN_LD) -o $@ $(ULIBC_CRT0) user/find.o -lc - -$(WHICH_ELF): user/which.c user/dyn_linker.ld $(ULIBC_SO) $(ULIBC_LIB) - @$(DYN_CC) -c user/which.c -o user/which.o - @$(DYN_LD) -o $@ $(ULIBC_CRT0) user/which.o -lc - -$(LDSO_ELF): user/ldso.c user/ldso_linker.ld - @$(USER_CC) -m32 -ffreestanding -fno-pie -no-pie -nostdlib -Wl,-T,user/ldso_linker.ld -o $(LDSO_ELF) user/ldso.c - -$(PIE_SO): user/pie_func.c - @$(USER_CC) -m32 -fPIC -fno-plt -c user/pie_func.c -o user/pie_func.o - @$(USER_LD) -m elf_i386 -shared -soname libpietest.so -o $(PIE_SO) user/pie_func.o - -$(PIE_ELF): user/pie_main.c user/pie_linker.ld $(PIE_SO) - @$(USER_CC) -m32 -fPIC -c user/pie_main.c -o user/pie_main.o - @$(USER_LD) -m elf_i386 -pie --dynamic-linker=/lib/ld.so -T user/pie_linker.ld -o $(PIE_ELF) user/pie_main.o $(PIE_SO) -rpath /lib - -# All dynamically-linked user commands -USER_CMDS := $(ECHO_ELF) $(SH_ELF) $(CAT_ELF) $(LS_ELF) $(MKDIR_ELF) $(RM_ELF) \ - $(CP_ELF) $(MV_ELF) $(TOUCH_ELF) $(LN_ELF) \ - $(HEAD_ELF) $(TAIL_ELF) $(WC_ELF) $(SORT_ELF) $(UNIQ_ELF) $(CUT_ELF) \ - $(CHMOD_ELF) $(CHOWN_ELF) $(CHGRP_ELF) \ - $(DATE_ELF) $(HOSTNAME_ELF) $(UPTIME_ELF) \ - $(MOUNT_ELF) $(UMOUNT_ELF) $(ENV_ELF) $(KILL_ELF) $(SLEEP_ELF) \ - $(CLEAR_ELF) $(PS_ELF) $(DF_ELF) $(FREE_ELF) $(TEE_ELF) \ - $(BASENAME_ELF) $(DIRNAME_ELF) $(RMDIR_ELF) \ - $(GREP_ELF) $(ID_ELF) $(UNAME_ELF) $(DMESG_ELF) \ - $(PRINTENV_ELF) $(TR_ELF) $(DD_ELF) $(PWD_ELF) $(STAT_ELF) \ - $(SED_ELF) $(AWK_ELF) $(WHO_ELF) $(TOP_ELF) $(DU_ELF) \ - $(FIND_ELF) $(WHICH_ELF) \ - $(INIT_ELF) - +# --- ulibc build (output into build/user/ulibc/) --- +$(ULIBC_LIB) $(ULIBC_SO): FORCE + @mkdir -p $(USER_BUILD)/ulibc + @$(MAKE) -C $(ULIBC_DIR) CC="$(USER_CC)" AS="$(USER_CC:gcc=as)" AR="$(USER_AR)" LD="$(USER_LD)" \ + libulibc.a libc.so --no-print-directory + @cp -u $(ULIBC_DIR)/libulibc.a $(ULIBC_LIB) + @cp -u $(ULIBC_DIR)/libc.so $(ULIBC_SO) +FORCE: + +# --- Special builds (fulltest, ldso, pie_test) --- +$(FULLTEST_ELF): user/cmds/fulltest/fulltest.c user/cmds/fulltest/errno.c user/linker.ld + @$(MAKE) --no-print-directory -C user/cmds/fulltest TOPDIR=$(CURDIR) USER_CC="$(USER_CC)" + +$(LDSO_ELF): user/cmds/ldso/ldso.c user/ldso_linker.ld + @$(MAKE) --no-print-directory -C user/cmds/ldso TOPDIR=$(CURDIR) USER_CC="$(USER_CC)" + +$(PIE_SO) $(PIE_ELF): user/cmds/pie_test/pie_main.c user/cmds/pie_test/pie_func.c user/pie_linker.ld + @$(MAKE) --no-print-directory -C user/cmds/pie_test TOPDIR=$(CURDIR) USER_CC="$(USER_CC)" USER_LD="$(USER_LD)" + +# --- Dynamically-linked user commands (generic rule via sub-Makefiles) --- +# Use absolute paths so they work from sub-Makefile directories +ABS_ULIBC := $(CURDIR)/$(ULIBC_DIR) +ABS_DYN_CC := $(USER_CC) -m32 -ffreestanding -nostdlib -O2 -Wall -Wextra -fPIC -fno-plt -I$(ABS_ULIBC)/include +ABS_DYN_LD := $(USER_LD) -m elf_i386 --dynamic-linker=/lib/ld.so -T $(CURDIR)/user/dyn_linker.ld -L$(ABS_ULIBC) -rpath /lib --unresolved-symbols=ignore-in-shared-libs + +# Generate build rules for each dynamically-linked command +define USER_CMD_RULE +$(USER_BUILD)/cmds/$(1)/$(1).elf: user/cmds/$(1)/$(1).c user/dyn_linker.ld $(ULIBC_SO) $(ULIBC_LIB) + @$$(MAKE) --no-print-directory -C user/cmds/$(1) TOPDIR=$$(CURDIR) \ + DYN_CC="$$(ABS_DYN_CC)" DYN_LD="$$(ABS_DYN_LD)" CRT0="$(ABS_ULIBC)/src/crt0.o" +endef +$(foreach cmd,$(USER_CMD_NAMES),$(eval $(call USER_CMD_RULE,$(cmd)))) + +# Commands that go to /bin/ in rootfs (all except init) +USER_BIN_NAMES := $(filter-out init,$(USER_CMD_NAMES)) + +# Build INITRD_FILES list: : FSTAB := rootfs/etc/fstab INITRD_FILES := $(FULLTEST_ELF):sbin/fulltest \ - $(INIT_ELF):sbin/init \ - $(ECHO_ELF):bin/echo $(SH_ELF):bin/sh $(CAT_ELF):bin/cat $(LS_ELF):bin/ls \ - $(MKDIR_ELF):bin/mkdir $(RM_ELF):bin/rm $(CP_ELF):bin/cp $(MV_ELF):bin/mv \ - $(TOUCH_ELF):bin/touch $(LN_ELF):bin/ln \ - $(HEAD_ELF):bin/head $(TAIL_ELF):bin/tail $(WC_ELF):bin/wc \ - $(SORT_ELF):bin/sort $(UNIQ_ELF):bin/uniq $(CUT_ELF):bin/cut \ - $(CHMOD_ELF):bin/chmod $(CHOWN_ELF):bin/chown $(CHGRP_ELF):bin/chgrp \ - $(DATE_ELF):bin/date $(HOSTNAME_ELF):bin/hostname $(UPTIME_ELF):bin/uptime \ - $(MOUNT_ELF):bin/mount $(UMOUNT_ELF):bin/umount $(ENV_ELF):bin/env \ - $(KILL_ELF):bin/kill $(SLEEP_ELF):bin/sleep $(CLEAR_ELF):bin/clear \ - $(PS_ELF):bin/ps $(DF_ELF):bin/df $(FREE_ELF):bin/free \ - $(TEE_ELF):bin/tee $(BASENAME_ELF):bin/basename $(DIRNAME_ELF):bin/dirname \ - $(RMDIR_ELF):bin/rmdir \ - $(GREP_ELF):bin/grep $(ID_ELF):bin/id $(UNAME_ELF):bin/uname \ - $(DMESG_ELF):bin/dmesg $(PRINTENV_ELF):bin/printenv $(TR_ELF):bin/tr \ - $(SED_ELF):bin/sed $(AWK_ELF):bin/awk $(WHO_ELF):bin/who \ - $(TOP_ELF):bin/top $(DU_ELF):bin/du $(FIND_ELF):bin/find $(WHICH_ELF):bin/which \ - $(DD_ELF):bin/dd $(PWD_ELF):bin/pwd $(STAT_ELF):bin/stat \ + $(USER_BUILD)/cmds/init/init.elf:sbin/init \ + $(foreach cmd,$(USER_BIN_NAMES),$(USER_BUILD)/cmds/$(cmd)/$(cmd).elf:bin/$(cmd)) \ $(LDSO_ELF):lib/ld.so $(ULIBC_SO):lib/libc.so \ $(PIE_SO):lib/libpietest.so $(PIE_ELF):bin/pie_test \ $(FSTAB):etc/fstab -INITRD_DEPS := $(MKINITRD) $(FULLTEST_ELF) $(USER_CMDS) $(LDSO_ELF) $(ULIBC_SO) $(PIE_SO) $(PIE_ELF) $(FSTAB) + +INITRD_DEPS := $(MKINITRD) $(FULLTEST_ELF) $(USER_CMD_ELFS) $(LDSO_ELF) $(ULIBC_SO) $(PIE_SO) $(PIE_ELF) $(FSTAB) # Include doom.elf if it has been built ifneq ($(wildcard $(DOOM_ELF)),) -INITRD_FILES += $(DOOM_ELF):bin/doom +INITRD_FILES += $(DOOM_ELF):usr/games/doom INITRD_DEPS += $(DOOM_ELF) endif @@ -637,6 +383,8 @@ $(BUILD_DIR)/%.o: $(SRC_DIR)/%.S @$(AS) $(ASFLAGS) $< -o $@ clean: - rm -rf build $(KERNEL_NAME) + rm -rf build $(KERNEL_NAME) $(INITRD_IMG) adros-*.iso + @$(MAKE) -C user/ulibc clean --no-print-directory 2>/dev/null || true + @if [ -f user/doom/Makefile ]; then $(MAKE) -C user/doom clean --no-print-directory 2>/dev/null || true; fi .PHONY: all clean iso run run-arm run-riscv run-mips cppcheck sparse analyzer check test test-1cpu test-battery test-host test-gdb test-all scan-build mkinitrd-asan diff --git a/tests/smoke_test.exp b/tests/smoke_test.exp index bb9bd90..33f1191 100755 --- a/tests/smoke_test.exp +++ b/tests/smoke_test.exp @@ -49,102 +49,102 @@ set tests { {"ATA DMA mode" "\\[ATA\\] Channel 0: DMA mode."} {"SMP CPUs active" "CPU\\(s\\) active."} {"User ring3 entry" "\\[USER\\] enter ring3"} - {"init.elf hello" "\\[init\\] hello from init.elf"} - {"open/read/close" "\\[init\\] open/read/close OK"} - {"overlay copy-up" "\\[init\\] overlay copy-up OK"} - {"lseek/stat/fstat" "\\[init\\] lseek/stat/fstat OK"} - {"dup2 restore" "\\[init\\] dup2 restore tty OK"} - {"kill SIGKILL" "\\[init\\] kill\\(SIGKILL\\) OK"} - {"poll pipe" "\\[init\\] poll\\(pipe\\) OK"} - {"select pipe" "\\[init\\] select\\(pipe\\) OK"} - {"ioctl tty" "\\[init\\] ioctl\\(/dev/tty\\) OK"} - {"job control" "\\[init\\] job control \\(SIGTTIN/SIGTTOU\\) OK"} - {"poll /dev/null" "\\[init\\] poll\\(/dev/null\\) OK"} - {"pty bidirectional" "\\[init\\] pty OK"} - {"setsid/setpgid" "\\[init\\] setsid/setpgid/getpgrp OK"} - {"sigaction SIGUSR1" "\\[init\\] sigaction/kill\\(SIGUSR1\\) OK"} - {"sigreturn" "\\[init\\] sigreturn OK"} - {"tmpfs/mount" "\\[init\\] tmpfs/mount OK"} - {"dev null" "\\[init\\] /dev/null OK"} - {"persist counter" "\\[init\\] /persist/counter="} - {"dev tty write" "\\[init\\] /dev/tty write OK"} - {"diskfs test" "\\[init\\] /disk/test prev="} - {"diskfs mkdir/unlink" "\\[init\\] diskfs mkdir/unlink OK"} - {"diskfs getdents" "\\[init\\] diskfs getdents OK"} - {"isatty" "\\[init\\] isatty OK"} - {"O_NONBLOCK" "\\[init\\] O_NONBLOCK OK"} - {"pipe2/dup3" "\\[init\\] pipe2/dup3 OK"} - {"chdir/getcwd" "\\[init\\] chdir/getcwd OK"} - {"*at syscalls" "\\[init\\] \\*at OK"} - {"rename/rmdir" "\\[init\\] rename/rmdir OK"} - {"getdents multi-fs" "\\[init\\] getdents multi-fs OK"} - {"brk heap" "\\[init\\] brk OK"} - {"mmap/munmap" "\\[init\\] mmap/munmap OK"} - {"clock_gettime" "\\[init\\] clock_gettime OK"} - {"dev zero" "\\[init\\] /dev/zero OK"} - {"dev random" "\\[init\\] /dev/random OK"} - {"procfs" "\\[init\\] procfs OK"} - {"pread/pwrite" "\\[init\\] pread/pwrite OK"} - {"ftruncate" "\\[init\\] ftruncate OK"} - {"symlink/readlink" "\\[init\\] symlink/readlink OK"} - {"access" "\\[init\\] access OK"} - {"sigprocmask" "\\[init\\] sigprocmask/sigpending OK"} - {"alarm SIGALRM" "\\[init\\] alarm/SIGALRM OK"} - {"shmget/shmat" "\\[init\\] shmget/shmat/shmdt OK"} - {"O_APPEND" "\\[init\\] O_APPEND OK"} - {"umask" "\\[init\\] umask OK"} - {"pipe capacity" "\\[init\\] pipe capacity OK"} - {"waitid" "\\[init\\] waitid OK"} - {"setitimer/getitimer" "\\[init\\] setitimer/getitimer OK"} - {"select regfile" "\\[init\\] select regfile OK"} - {"poll regfile" "\\[init\\] poll regfile OK"} - {"hard link" "\\[init\\] hard link OK"} - {"epoll" "\\[init\\] epoll OK"} - {"epollet" "\\[init\\] epollet OK"} - {"inotify" "\\[init\\] inotify OK"} - {"aio" "\\[init\\] aio OK"} - {"nanosleep" "\\[init\\] nanosleep OK"} - {"CLOCK_REALTIME" "\\[init\\] CLOCK_REALTIME OK"} - {"dev urandom" "\\[init\\] /dev/urandom OK"} - {"proc cmdline" "\\[init\\] /proc/cmdline OK"} - {"CoW fork" "\\[init\\] CoW fork OK"} - {"readv/writev" "\\[init\\] readv/writev OK"} - {"fsync" "\\[init\\] fsync OK"} - {"truncate path" "\\[init\\] truncate OK"} - {"getuid/getgid" "\\[init\\] getuid/getgid OK"} - {"chmod" "\\[init\\] chmod OK"} - {"flock" "\\[init\\] flock OK"} - {"times" "\\[init\\] times OK"} - {"gettid" "\\[init\\] gettid OK"} - {"posix_spawn" "\\[init\\] posix_spawn OK"} - {"clock_ns precision" "\\[init\\] clock_ns precision OK"} - {"getppid" "\\[init\\] getppid OK"} - {"waitpid WNOHANG" "\\[init\\] waitpid WNOHANG OK"} - {"SIGSEGV handler" "\\[init\\] SIGSEGV OK"} - {"waitpid 100 children" "\\[init\\] waitpid OK \\(100 children"} - {"lazy PLT" "\\[init\\] lazy PLT OK"} - {"PLT cached" "\\[init\\] PLT cached OK"} + {"init.elf hello" "\\[test\\] hello from init.elf"} + {"open/read/close" "\\[test\\] open/read/close OK"} + {"overlay copy-up" "\\[test\\] overlay copy-up OK"} + {"lseek/stat/fstat" "\\[test\\] lseek/stat/fstat OK"} + {"dup2 restore" "\\[test\\] dup2 restore tty OK"} + {"kill SIGKILL" "\\[test\\] kill\\(SIGKILL\\) OK"} + {"poll pipe" "\\[test\\] poll\\(pipe\\) OK"} + {"select pipe" "\\[test\\] select\\(pipe\\) OK"} + {"ioctl tty" "\\[test\\] ioctl\\(/dev/tty\\) OK"} + {"job control" "\\[test\\] job control \\(SIGTTIN/SIGTTOU\\) OK"} + {"poll /dev/null" "\\[test\\] poll\\(/dev/null\\) OK"} + {"pty bidirectional" "\\[test\\] pty OK"} + {"setsid/setpgid" "\\[test\\] setsid/setpgid/getpgrp OK"} + {"sigaction SIGUSR1" "\\[test\\] sigaction/kill\\(SIGUSR1\\) OK"} + {"sigreturn" "\\[test\\] sigreturn OK"} + {"tmpfs/mount" "\\[test\\] tmpfs/mount OK"} + {"dev null" "\\[test\\] /dev/null OK"} + {"persist counter" "\\[test\\] /persist/counter="} + {"dev tty write" "\\[test\\] /dev/tty write OK"} + {"diskfs test" "\\[test\\] /disk/test prev="} + {"diskfs mkdir/unlink" "\\[test\\] diskfs mkdir/unlink OK"} + {"diskfs getdents" "\\[test\\] diskfs getdents OK"} + {"isatty" "\\[test\\] isatty OK"} + {"O_NONBLOCK" "\\[test\\] O_NONBLOCK OK"} + {"pipe2/dup3" "\\[test\\] pipe2/dup3 OK"} + {"chdir/getcwd" "\\[test\\] chdir/getcwd OK"} + {"*at syscalls" "\\[test\\] \\*at OK"} + {"rename/rmdir" "\\[test\\] rename/rmdir OK"} + {"getdents multi-fs" "\\[test\\] getdents multi-fs OK"} + {"brk heap" "\\[test\\] brk OK"} + {"mmap/munmap" "\\[test\\] mmap/munmap OK"} + {"clock_gettime" "\\[test\\] clock_gettime OK"} + {"dev zero" "\\[test\\] /dev/zero OK"} + {"dev random" "\\[test\\] /dev/random OK"} + {"procfs" "\\[test\\] procfs OK"} + {"pread/pwrite" "\\[test\\] pread/pwrite OK"} + {"ftruncate" "\\[test\\] ftruncate OK"} + {"symlink/readlink" "\\[test\\] symlink/readlink OK"} + {"access" "\\[test\\] access OK"} + {"sigprocmask" "\\[test\\] sigprocmask/sigpending OK"} + {"alarm SIGALRM" "\\[test\\] alarm/SIGALRM OK"} + {"shmget/shmat" "\\[test\\] shmget/shmat/shmdt OK"} + {"O_APPEND" "\\[test\\] O_APPEND OK"} + {"umask" "\\[test\\] umask OK"} + {"pipe capacity" "\\[test\\] pipe capacity OK"} + {"waitid" "\\[test\\] waitid OK"} + {"setitimer/getitimer" "\\[test\\] setitimer/getitimer OK"} + {"select regfile" "\\[test\\] select regfile OK"} + {"poll regfile" "\\[test\\] poll regfile OK"} + {"hard link" "\\[test\\] hard link OK"} + {"epoll" "\\[test\\] epoll OK"} + {"epollet" "\\[test\\] epollet OK"} + {"inotify" "\\[test\\] inotify OK"} + {"aio" "\\[test\\] aio OK"} + {"nanosleep" "\\[test\\] nanosleep OK"} + {"CLOCK_REALTIME" "\\[test\\] CLOCK_REALTIME OK"} + {"dev urandom" "\\[test\\] /dev/urandom OK"} + {"proc cmdline" "\\[test\\] /proc/cmdline OK"} + {"CoW fork" "\\[test\\] CoW fork OK"} + {"readv/writev" "\\[test\\] readv/writev OK"} + {"fsync" "\\[test\\] fsync OK"} + {"truncate path" "\\[test\\] truncate OK"} + {"getuid/getgid" "\\[test\\] getuid/getgid OK"} + {"chmod" "\\[test\\] chmod OK"} + {"flock" "\\[test\\] flock OK"} + {"times" "\\[test\\] times OK"} + {"gettid" "\\[test\\] gettid OK"} + {"posix_spawn" "\\[test\\] posix_spawn OK"} + {"clock_ns precision" "\\[test\\] clock_ns precision OK"} + {"getppid" "\\[test\\] getppid OK"} + {"waitpid WNOHANG" "\\[test\\] waitpid WNOHANG OK"} + {"SIGSEGV handler" "\\[test\\] SIGSEGV OK"} + {"waitpid 100 children" "\\[test\\] waitpid OK \\(100 children"} + {"lazy PLT" "\\[test\\] lazy PLT OK"} + {"PLT cached" "\\[test\\] PLT cached OK"} {"PING network" "\\[PING\\] .*received.*network OK"} {"echo execve" "\\[echo\\] hello from echo"} - {"setuid/setgid" "\\[init\\] setuid/setgid OK"} - {"fcntl F_GETFL/SETFL" "\\[init\\] fcntl F_GETFL/F_SETFL OK"} - {"fcntl FD_CLOEXEC" "\\[init\\] fcntl FD_CLOEXEC OK"} - {"sigsuspend" "\\[init\\] sigsuspend OK"} - {"orphan reparent" "\\[init\\] orphan reparent OK"} - {"proc PID cmdline" "\\[init\\] /proc/PID/cmdline OK"} - {"proc PID status" "\\[init\\] /proc/PID/status OK"} - {"dev console" "\\[init\\] /dev/console OK"} - {"multi-pty" "\\[init\\] multi-pty OK"} - {"dup standalone" "\\[init\\] dup OK"} - {"pipe EOF" "\\[init\\] pipe EOF OK"} - {"readdir /proc" "\\[init\\] readdir /proc OK"} - {"readdir /bin" "\\[init\\] readdir /bin OK"} - {"gettimeofday" "\\[init\\] gettimeofday OK"} - {"mprotect" "\\[init\\] mprotect OK"} - {"madvise" "\\[init\\] madvise OK"} - {"getrlimit/setrlimit" "\\[init\\] getrlimit/setrlimit OK"} - {"uname" "\\[init\\] uname OK"} - {"SMP parallel fork" "\\[init\\] SMP parallel fork OK"} + {"setuid/setgid" "\\[test\\] setuid/setgid OK"} + {"fcntl F_GETFL/SETFL" "\\[test\\] fcntl F_GETFL/F_SETFL OK"} + {"fcntl FD_CLOEXEC" "\\[test\\] fcntl FD_CLOEXEC OK"} + {"sigsuspend" "\\[test\\] sigsuspend OK"} + {"orphan reparent" "\\[test\\] orphan reparent OK"} + {"proc PID cmdline" "\\[test\\] /proc/PID/cmdline OK"} + {"proc PID status" "\\[test\\] /proc/PID/status OK"} + {"dev console" "\\[test\\] /dev/console OK"} + {"multi-pty" "\\[test\\] multi-pty OK"} + {"dup standalone" "\\[test\\] dup OK"} + {"pipe EOF" "\\[test\\] pipe EOF OK"} + {"readdir /proc" "\\[test\\] readdir /proc OK"} + {"readdir /bin" "\\[test\\] readdir /bin OK"} + {"gettimeofday" "\\[test\\] gettimeofday OK"} + {"mprotect" "\\[test\\] mprotect OK"} + {"madvise" "\\[test\\] madvise OK"} + {"getrlimit/setrlimit" "\\[test\\] getrlimit/setrlimit OK"} + {"uname" "\\[test\\] uname OK"} + {"SMP parallel fork" "\\[test\\] SMP parallel fork OK"} {"LZ4 Frame decomp" "\\[INITRD\\] LZ4"} } diff --git a/tests/test_battery.exp b/tests/test_battery.exp index b475d39..bc997c4 100644 --- a/tests/test_battery.exp +++ b/tests/test_battery.exp @@ -153,8 +153,8 @@ set patterns { {"ATA /dev/hda" "\\[ATA\\] /dev/hda detected"} {"INITRD found" "\\[INITRD\\] Found"} {"diskfs mount /disk" "\\[MOUNT\\] diskfs on /dev/hda"} - {"diskfs test" "\\[init\\] /disk/test prev="} - {"diskfs getdents" "\\[init\\] diskfs getdents OK"} + {"diskfs test" "\\[test\\] /disk/test prev="} + {"diskfs getdents" "\\[test\\] diskfs getdents OK"} } set res [wait_for_patterns $serial_log $timeout_sec $patterns] diff --git a/tests/test_host_utils.sh b/tests/test_host_utils.sh index 52bfd6b..7ed2c00 100755 --- a/tests/test_host_utils.sh +++ b/tests/test_host_utils.sh @@ -40,7 +40,7 @@ echo "" # ---------- echo ---------- echo "--- echo ---" -if compile echo_test user/echo.c; then +if compile echo_test user/cmds/echo/echo.c; then out=$("$BUILDDIR/echo_test" hello world) [ "$out" = "hello world" ] && pass "echo basic" || fail "echo basic" "got: $out" @@ -59,7 +59,7 @@ fi # ---------- cat ---------- echo "--- cat ---" -if compile cat_test user/cat.c; then +if compile cat_test user/cmds/cat/cat.c; then echo "hello cat" > "$BUILDDIR/cat_in.txt" out=$("$BUILDDIR/cat_test" "$BUILDDIR/cat_in.txt") [ "$out" = "hello cat" ] && pass "cat file" || fail "cat file" "got: $out" @@ -78,7 +78,7 @@ fi # ---------- head ---------- echo "--- head ---" -if compile head_test user/head.c; then +if compile head_test user/cmds/head/head.c; then printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n" > "$BUILDDIR/head_in.txt" out=$("$BUILDDIR/head_test" "$BUILDDIR/head_in.txt" | wc -l) [ "$out" -eq 10 ] && pass "head default 10" || fail "head default 10" "got $out lines" @@ -96,7 +96,7 @@ fi # ---------- tail ---------- echo "--- tail ---" -if compile tail_test user/tail.c; then +if compile tail_test user/cmds/tail/tail.c; then printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n" > "$BUILDDIR/tail_in.txt" out=$("$BUILDDIR/tail_test" -n 3 "$BUILDDIR/tail_in.txt") expected=$(printf "10\n11\n12") @@ -107,7 +107,7 @@ fi # ---------- wc ---------- echo "--- wc ---" -if compile wc_test user/wc.c; then +if compile wc_test user/cmds/wc/wc.c; then printf "hello world\nfoo bar baz\n" > "$BUILDDIR/wc_in.txt" out=$("$BUILDDIR/wc_test" "$BUILDDIR/wc_in.txt") # Should contain line count (2), word count (5), byte count @@ -119,7 +119,7 @@ fi # ---------- sort ---------- echo "--- sort ---" -if compile sort_test user/sort.c; then +if compile sort_test user/cmds/sort/sort.c; then printf "banana\napple\ncherry\n" | "$BUILDDIR/sort_test" > "$BUILDDIR/sort_out.txt" expected=$(printf "apple\nbanana\ncherry") out=$(cat "$BUILDDIR/sort_out.txt") @@ -135,7 +135,7 @@ fi # ---------- uniq ---------- echo "--- uniq ---" -if compile uniq_test user/uniq.c; then +if compile uniq_test user/cmds/uniq/uniq.c; then printf "aaa\naaa\nbbb\nccc\nccc\n" | "$BUILDDIR/uniq_test" > "$BUILDDIR/uniq_out.txt" expected=$(printf "aaa\nbbb\nccc") out=$(cat "$BUILDDIR/uniq_out.txt") @@ -150,7 +150,7 @@ fi # ---------- cut ---------- echo "--- cut ---" -if compile cut_test user/cut.c; then +if compile cut_test user/cmds/cut/cut.c; then out=$(printf "a:b:c\n" | "$BUILDDIR/cut_test" -d: -f2) [ "$out" = "b" ] && pass "cut -d: -f2" || fail "cut -d: -f2" "got: $out" @@ -165,7 +165,7 @@ fi # ---------- grep ---------- echo "--- grep ---" -if compile grep_test user/grep.c; then +if compile grep_test user/cmds/grep/grep.c; then printf "hello world\nfoo bar\nhello again\n" > "$BUILDDIR/grep_in.txt" out=$("$BUILDDIR/grep_test" hello "$BUILDDIR/grep_in.txt") lines=$(echo "$out" | wc -l) @@ -188,7 +188,7 @@ fi # ---------- tr ---------- echo "--- tr ---" -if compile tr_test user/tr.c; then +if compile tr_test user/cmds/tr/tr.c; then out=$(echo "hello" | "$BUILDDIR/tr_test" 'elo' 'ELO') [ "$out" = "hELLO" ] && pass "tr translate" || fail "tr translate" "got: $out" @@ -200,7 +200,7 @@ fi # ---------- basename ---------- echo "--- basename ---" -if compile basename_test user/basename.c; then +if compile basename_test user/cmds/basename/basename.c; then out=$("$BUILDDIR/basename_test" /usr/bin/foo) [ "$out" = "foo" ] && pass "basename path" || fail "basename path" "got: $out" @@ -215,7 +215,7 @@ fi # ---------- dirname ---------- echo "--- dirname ---" -if compile dirname_test user/dirname.c; then +if compile dirname_test user/cmds/dirname/dirname.c; then out=$("$BUILDDIR/dirname_test" /usr/bin/foo) [ "$out" = "/usr/bin" ] && pass "dirname path" || fail "dirname path" "got: $out" @@ -230,7 +230,7 @@ fi # ---------- tee ---------- echo "--- tee ---" -if compile tee_test user/tee.c; then +if compile tee_test user/cmds/tee/tee.c; then out=$(echo "tee test" | "$BUILDDIR/tee_test" "$BUILDDIR/tee_out.txt") file_content=$(cat "$BUILDDIR/tee_out.txt") [ "$out" = "tee test" ] && pass "tee stdout" || fail "tee stdout" "got: $out" @@ -247,7 +247,7 @@ fi # ---------- dd ---------- echo "--- dd ---" -if compile dd_test user/dd.c; then +if compile dd_test user/cmds/dd/dd.c; then echo "hello dd test data" > "$BUILDDIR/dd_in.txt" "$BUILDDIR/dd_test" if="$BUILDDIR/dd_in.txt" of="$BUILDDIR/dd_out.txt" bs=512 2>/dev/null out=$(cat "$BUILDDIR/dd_out.txt") @@ -258,7 +258,7 @@ fi # ---------- pwd ---------- echo "--- pwd ---" -if compile pwd_test user/pwd.c; then +if compile pwd_test user/cmds/pwd/pwd.c; then out=$("$BUILDDIR/pwd_test") expected=$(pwd) [ -n "$out" ] && pass "pwd output" || fail "pwd output" "empty" @@ -268,7 +268,7 @@ fi # ---------- uname ---------- echo "--- uname ---" -if compile uname_test user/uname.c; then +if compile uname_test user/cmds/uname/uname.c; then out=$("$BUILDDIR/uname_test") [ "$out" = "AdrOS" ] && pass "uname default" || fail "uname default" "got: $out" @@ -287,7 +287,7 @@ fi # ---------- id ---------- echo "--- id ---" -if compile id_test user/id.c; then +if compile id_test user/cmds/id/id.c; then out=$("$BUILDDIR/id_test") echo "$out" | grep -q "uid=" && pass "id uid" || fail "id uid" "got: $out" echo "$out" | grep -q "gid=" && pass "id gid" || fail "id gid" "got: $out" @@ -297,7 +297,7 @@ fi # ---------- printenv ---------- echo "--- printenv ---" -if compile printenv_test user/printenv.c; then +if compile printenv_test user/cmds/printenv/printenv.c; then out=$(HOME=/test/home "$BUILDDIR/printenv_test" HOME) [ "$out" = "/test/home" ] && pass "printenv HOME" || fail "printenv HOME" "got: $out" @@ -313,7 +313,7 @@ fi # ---------- cp ---------- echo "--- cp ---" -if compile cp_test user/cp.c; then +if compile cp_test user/cmds/cp/cp.c; then echo "cp source" > "$BUILDDIR/cp_src.txt" "$BUILDDIR/cp_test" "$BUILDDIR/cp_src.txt" "$BUILDDIR/cp_dst.txt" out=$(cat "$BUILDDIR/cp_dst.txt") @@ -324,7 +324,7 @@ fi # ---------- mv ---------- echo "--- mv ---" -if compile mv_test user/mv.c; then +if compile mv_test user/cmds/mv/mv.c; then echo "mv data" > "$BUILDDIR/mv_src.txt" "$BUILDDIR/mv_test" "$BUILDDIR/mv_src.txt" "$BUILDDIR/mv_dst.txt" [ ! -f "$BUILDDIR/mv_src.txt" ] && pass "mv src removed" || fail "mv src removed" "still exists" @@ -337,10 +337,10 @@ fi # ---------- touch/rm/mkdir/rmdir ---------- echo "--- touch/rm/mkdir/rmdir ---" compile_ok=1 -compile touch_test user/touch.c || compile_ok=0 -compile rm_test user/rm.c || compile_ok=0 -compile mkdir_test user/mkdir.c || compile_ok=0 -compile rmdir_test user/rmdir.c || compile_ok=0 +compile touch_test user/cmds/touch/touch.c || compile_ok=0 +compile rm_test user/cmds/rm/rm.c || compile_ok=0 +compile mkdir_test user/cmds/mkdir/mkdir.c || compile_ok=0 +compile rmdir_test user/cmds/rmdir/rmdir.c || compile_ok=0 if [ "$compile_ok" -eq 1 ]; then "$BUILDDIR/touch_test" "$BUILDDIR/touchfile" [ -f "$BUILDDIR/touchfile" ] && pass "touch create" || fail "touch create" "not created" @@ -359,7 +359,7 @@ fi # ---------- ln ---------- echo "--- ln ---" -if compile ln_test user/ln.c; then +if compile ln_test user/cmds/ln/ln.c; then echo "link target" > "$BUILDDIR/ln_src.txt" "$BUILDDIR/ln_test" -s "$BUILDDIR/ln_src.txt" "$BUILDDIR/ln_link.txt" 2>/dev/null || true if [ -L "$BUILDDIR/ln_link.txt" ]; then @@ -380,7 +380,7 @@ fi # ---------- sed ---------- echo "--- sed ---" -if compile sed_test user/sed.c; then +if compile sed_test user/cmds/sed/sed.c; then out=$(echo "hello world" | "$BUILDDIR/sed_test" 's/world/earth/') [ "$out" = "hello earth" ] && pass "sed s///" || fail "sed s///" "got: $out" @@ -400,7 +400,7 @@ fi # ---------- awk ---------- echo "--- awk ---" -if compile awk_test user/awk.c; then +if compile awk_test user/cmds/awk/awk.c; then out=$(echo "hello world foo" | "$BUILDDIR/awk_test" '{print $2}') [ "$out" = "world" ] && pass "awk print \$2" || fail "awk print \$2" "got: $out" @@ -416,7 +416,7 @@ fi # ---------- who ---------- echo "--- who ---" -if compile who_test user/who.c; then +if compile who_test user/cmds/who/who.c; then out=$("$BUILDDIR/who_test") echo "$out" | grep -q "root" && pass "who output" || fail "who output" "got: $out" else @@ -425,7 +425,7 @@ fi # ---------- find ---------- echo "--- find ---" -if compile find_test user/find.c; then +if compile find_test user/cmds/find/find.c; then mkdir -p "$BUILDDIR/findtest/sub" touch "$BUILDDIR/findtest/a.txt" touch "$BUILDDIR/findtest/b.c" @@ -443,10 +443,10 @@ fi # ---------- which ---------- echo "--- which ---" -if compile which_test user/which.c; then +if compile which_test user/cmds/which/which.c; then # which looks in /bin and /sbin hardcoded, so just check it runs - "$BUILDDIR/which_test" nonexistent_cmd > /dev/null 2>&1 - [ $? -ne 0 ] && pass "which not found" || fail "which not found" "should return nonzero" + "$BUILDDIR/which_test" nonexistent_cmd > /dev/null 2>&1 || rc=$? + [ "${rc:-1}" -ne 0 ] && pass "which not found" || fail "which not found" "should return nonzero" else skip "which (compile failed)" fi diff --git a/user/cmds/awk/Makefile b/user/cmds/awk/Makefile new file mode 100644 index 0000000..a8e832a --- /dev/null +++ b/user/cmds/awk/Makefile @@ -0,0 +1,3 @@ +NAME := awk +SRCS := awk.c +include ../common.mk diff --git a/user/awk.c b/user/cmds/awk/awk.c similarity index 100% rename from user/awk.c rename to user/cmds/awk/awk.c diff --git a/user/cmds/basename/Makefile b/user/cmds/basename/Makefile new file mode 100644 index 0000000..ae20228 --- /dev/null +++ b/user/cmds/basename/Makefile @@ -0,0 +1,3 @@ +NAME := basename +SRCS := basename.c +include ../common.mk diff --git a/user/basename.c b/user/cmds/basename/basename.c similarity index 100% rename from user/basename.c rename to user/cmds/basename/basename.c diff --git a/user/cmds/cat/Makefile b/user/cmds/cat/Makefile new file mode 100644 index 0000000..9df8bae --- /dev/null +++ b/user/cmds/cat/Makefile @@ -0,0 +1,3 @@ +NAME := cat +SRCS := cat.c +include ../common.mk diff --git a/user/cat.c b/user/cmds/cat/cat.c similarity index 100% rename from user/cat.c rename to user/cmds/cat/cat.c diff --git a/user/cmds/chgrp/Makefile b/user/cmds/chgrp/Makefile new file mode 100644 index 0000000..489f82f --- /dev/null +++ b/user/cmds/chgrp/Makefile @@ -0,0 +1,3 @@ +NAME := chgrp +SRCS := chgrp.c +include ../common.mk diff --git a/user/chgrp.c b/user/cmds/chgrp/chgrp.c similarity index 100% rename from user/chgrp.c rename to user/cmds/chgrp/chgrp.c diff --git a/user/cmds/chmod/Makefile b/user/cmds/chmod/Makefile new file mode 100644 index 0000000..6bc44d8 --- /dev/null +++ b/user/cmds/chmod/Makefile @@ -0,0 +1,3 @@ +NAME := chmod +SRCS := chmod.c +include ../common.mk diff --git a/user/chmod.c b/user/cmds/chmod/chmod.c similarity index 100% rename from user/chmod.c rename to user/cmds/chmod/chmod.c diff --git a/user/cmds/chown/Makefile b/user/cmds/chown/Makefile new file mode 100644 index 0000000..8378c53 --- /dev/null +++ b/user/cmds/chown/Makefile @@ -0,0 +1,3 @@ +NAME := chown +SRCS := chown.c +include ../common.mk diff --git a/user/chown.c b/user/cmds/chown/chown.c similarity index 100% rename from user/chown.c rename to user/cmds/chown/chown.c diff --git a/user/cmds/clear/Makefile b/user/cmds/clear/Makefile new file mode 100644 index 0000000..043a0be --- /dev/null +++ b/user/cmds/clear/Makefile @@ -0,0 +1,3 @@ +NAME := clear +SRCS := clear.c +include ../common.mk diff --git a/user/clear.c b/user/cmds/clear/clear.c similarity index 100% rename from user/clear.c rename to user/cmds/clear/clear.c diff --git a/user/cmds/common.mk b/user/cmds/common.mk new file mode 100644 index 0000000..55e047b --- /dev/null +++ b/user/cmds/common.mk @@ -0,0 +1,34 @@ +# Common build rules for AdrOS user commands (dynamically linked) +# Each program Makefile sets NAME and SRCS, then includes this file. +# +# Usage from per-program Makefile: +# NAME := echo +# SRCS := echo.c +# include ../common.mk + +TOPDIR ?= $(abspath ../../..) +BUILDDIR := $(TOPDIR)/build/user/cmds/$(NAME) + +ULIBC_DIR := $(TOPDIR)/user/ulibc +DYN_CC ?= i686-elf-gcc -m32 -ffreestanding -nostdlib -O2 -Wall -Wextra -fPIC -fno-plt -I$(ULIBC_DIR)/include +DYN_LD ?= i686-elf-ld -m elf_i386 --dynamic-linker=/lib/ld.so -T $(TOPDIR)/user/dyn_linker.ld -L$(ULIBC_DIR) -rpath /lib +CRT0 ?= $(ULIBC_DIR)/src/crt0.o + +OBJS := $(addprefix $(BUILDDIR)/,$(SRCS:.c=.o)) +ELF := $(BUILDDIR)/$(NAME).elf + +all: $(ELF) + +$(ELF): $(OBJS) + @echo " LD $@" + @$(DYN_LD) -o $@ $(CRT0) $(OBJS) -lc + +$(BUILDDIR)/%.o: %.c + @mkdir -p $(BUILDDIR) + @echo " CC $<" + @$(DYN_CC) -c $< -o $@ + +clean: + rm -f $(OBJS) $(ELF) + +.PHONY: all clean diff --git a/user/cmds/cp/Makefile b/user/cmds/cp/Makefile new file mode 100644 index 0000000..564ddfd --- /dev/null +++ b/user/cmds/cp/Makefile @@ -0,0 +1,3 @@ +NAME := cp +SRCS := cp.c +include ../common.mk diff --git a/user/cp.c b/user/cmds/cp/cp.c similarity index 100% rename from user/cp.c rename to user/cmds/cp/cp.c diff --git a/user/cmds/cut/Makefile b/user/cmds/cut/Makefile new file mode 100644 index 0000000..ec93ea3 --- /dev/null +++ b/user/cmds/cut/Makefile @@ -0,0 +1,3 @@ +NAME := cut +SRCS := cut.c +include ../common.mk diff --git a/user/cut.c b/user/cmds/cut/cut.c similarity index 100% rename from user/cut.c rename to user/cmds/cut/cut.c diff --git a/user/cmds/date/Makefile b/user/cmds/date/Makefile new file mode 100644 index 0000000..85b48d2 --- /dev/null +++ b/user/cmds/date/Makefile @@ -0,0 +1,3 @@ +NAME := date +SRCS := date.c +include ../common.mk diff --git a/user/date.c b/user/cmds/date/date.c similarity index 100% rename from user/date.c rename to user/cmds/date/date.c diff --git a/user/cmds/dd/Makefile b/user/cmds/dd/Makefile new file mode 100644 index 0000000..d23eaf8 --- /dev/null +++ b/user/cmds/dd/Makefile @@ -0,0 +1,3 @@ +NAME := dd +SRCS := dd.c +include ../common.mk diff --git a/user/dd.c b/user/cmds/dd/dd.c similarity index 100% rename from user/dd.c rename to user/cmds/dd/dd.c diff --git a/user/cmds/df/Makefile b/user/cmds/df/Makefile new file mode 100644 index 0000000..10ee75b --- /dev/null +++ b/user/cmds/df/Makefile @@ -0,0 +1,3 @@ +NAME := df +SRCS := df.c +include ../common.mk diff --git a/user/df.c b/user/cmds/df/df.c similarity index 100% rename from user/df.c rename to user/cmds/df/df.c diff --git a/user/cmds/dirname/Makefile b/user/cmds/dirname/Makefile new file mode 100644 index 0000000..95f2fcd --- /dev/null +++ b/user/cmds/dirname/Makefile @@ -0,0 +1,3 @@ +NAME := dirname +SRCS := dirname.c +include ../common.mk diff --git a/user/dirname.c b/user/cmds/dirname/dirname.c similarity index 100% rename from user/dirname.c rename to user/cmds/dirname/dirname.c diff --git a/user/cmds/dmesg/Makefile b/user/cmds/dmesg/Makefile new file mode 100644 index 0000000..92bebf5 --- /dev/null +++ b/user/cmds/dmesg/Makefile @@ -0,0 +1,3 @@ +NAME := dmesg +SRCS := dmesg.c +include ../common.mk diff --git a/user/dmesg.c b/user/cmds/dmesg/dmesg.c similarity index 100% rename from user/dmesg.c rename to user/cmds/dmesg/dmesg.c diff --git a/user/cmds/du/Makefile b/user/cmds/du/Makefile new file mode 100644 index 0000000..5a0ed2c --- /dev/null +++ b/user/cmds/du/Makefile @@ -0,0 +1,3 @@ +NAME := du +SRCS := du.c +include ../common.mk diff --git a/user/du.c b/user/cmds/du/du.c similarity index 100% rename from user/du.c rename to user/cmds/du/du.c diff --git a/user/cmds/echo/Makefile b/user/cmds/echo/Makefile new file mode 100644 index 0000000..3fef539 --- /dev/null +++ b/user/cmds/echo/Makefile @@ -0,0 +1,3 @@ +NAME := echo +SRCS := echo.c +include ../common.mk diff --git a/user/echo.c b/user/cmds/echo/echo.c similarity index 100% rename from user/echo.c rename to user/cmds/echo/echo.c diff --git a/user/cmds/env/Makefile b/user/cmds/env/Makefile new file mode 100644 index 0000000..c20284b --- /dev/null +++ b/user/cmds/env/Makefile @@ -0,0 +1,3 @@ +NAME := env +SRCS := env.c +include ../common.mk diff --git a/user/env.c b/user/cmds/env/env.c similarity index 100% rename from user/env.c rename to user/cmds/env/env.c diff --git a/user/cmds/find/Makefile b/user/cmds/find/Makefile new file mode 100644 index 0000000..f0a4194 --- /dev/null +++ b/user/cmds/find/Makefile @@ -0,0 +1,3 @@ +NAME := find +SRCS := find.c +include ../common.mk diff --git a/user/find.c b/user/cmds/find/find.c similarity index 57% rename from user/find.c rename to user/cmds/find/find.c index 78ca43e..feb63b3 100644 --- a/user/find.c +++ b/user/cmds/find/find.c @@ -1,10 +1,12 @@ /* AdrOS find utility — search for files in directory hierarchy */ #include #include -#include -#include #include +#ifndef DT_DIR +#define DT_DIR 4 +#endif + static const char* name_pattern = NULL; static int type_filter = 0; /* 0=any, 'f'=file, 'd'=dir */ @@ -23,7 +25,7 @@ static int match_name(const char* name) { char sub[256]; int slen = plen - 2; if (slen <= 0) return 1; - memcpy(sub, pat + 1, slen); + memcpy(sub, pat + 1, (size_t)slen); sub[slen] = '\0'; return strstr(name, sub) != NULL; } @@ -35,44 +37,40 @@ static int match_name(const char* name) { return strcmp(name + nlen - slen, suffix) == 0; } if (trail_star) { - return strncmp(name, pat, plen - 1) == 0; + return strncmp(name, pat, (size_t)(plen - 1)) == 0; } return strcmp(name, pat) == 0; } static void find_recurse(const char* path) { - int fd = open(path, O_RDONLY); - if (fd < 0) return; + DIR* dir = opendir(path); + if (!dir) return; + + struct dirent* d; + while ((d = readdir(dir)) != NULL) { + if (strcmp(d->d_name, ".") == 0 || strcmp(d->d_name, "..") == 0) + continue; - char buf[2048]; - int rc; - while ((rc = getdents(fd, buf, sizeof(buf))) > 0) { - int off = 0; - while (off < rc) { - struct dirent* d = (struct dirent*)(buf + off); - if (d->d_reclen == 0) break; - if (strcmp(d->d_name, ".") != 0 && strcmp(d->d_name, "..") != 0) { - char child[512]; - if (path[strlen(path)-1] == '/') - snprintf(child, sizeof(child), "%s%s", path, d->d_name); - else - snprintf(child, sizeof(child), "%s/%s", path, d->d_name); + char child[512]; + size_t plen = strlen(path); + if (plen > 0 && path[plen - 1] == '/') + snprintf(child, sizeof(child), "%s%s", path, d->d_name); + else + snprintf(child, sizeof(child), "%s/%s", path, d->d_name); - int show = match_name(d->d_name); - if (show && type_filter) { - if (type_filter == 'f' && d->d_type == 4) show = 0; /* DT_DIR=4 */ - if (type_filter == 'd' && d->d_type != 4) show = 0; - } - if (show) printf("%s\n", child); + int is_dir = (d->d_type == DT_DIR); + int show = match_name(d->d_name); + if (show && type_filter) { + if (type_filter == 'f' && is_dir) show = 0; + if (type_filter == 'd' && !is_dir) show = 0; + } + if (show) printf("%s\n", child); - if (d->d_type == 4) { /* DT_DIR */ - find_recurse(child); - } - } - off += d->d_reclen; + if (is_dir) { + find_recurse(child); } } - close(fd); + closedir(dir); } int main(int argc, char** argv) { diff --git a/user/cmds/free/Makefile b/user/cmds/free/Makefile new file mode 100644 index 0000000..0282294 --- /dev/null +++ b/user/cmds/free/Makefile @@ -0,0 +1,3 @@ +NAME := free +SRCS := free.c +include ../common.mk diff --git a/user/free.c b/user/cmds/free/free.c similarity index 100% rename from user/free.c rename to user/cmds/free/free.c diff --git a/user/cmds/fulltest/Makefile b/user/cmds/fulltest/Makefile new file mode 100644 index 0000000..ddeeb20 --- /dev/null +++ b/user/cmds/fulltest/Makefile @@ -0,0 +1,21 @@ +# fulltest — statically linked smoke test binary +NAME := fulltest + +TOPDIR ?= $(abspath ../../..) +BUILDDIR := $(TOPDIR)/build/user/cmds/$(NAME) +USER_CC ?= i686-elf-gcc + +ELF := $(BUILDDIR)/fulltest.elf + +all: $(ELF) + +$(ELF): fulltest.c errno.c user_errno.h + @mkdir -p $(BUILDDIR) + @echo " CC+LD $@" + @$(USER_CC) -m32 -I $(TOPDIR)/include -ffreestanding -fno-pie -no-pie -nostdlib \ + -Wl,-T,$(TOPDIR)/user/linker.ld -o $@ fulltest.c errno.c + +clean: + rm -f $(ELF) + +.PHONY: all clean diff --git a/user/errno.c b/user/cmds/fulltest/errno.c similarity index 100% rename from user/errno.c rename to user/cmds/fulltest/errno.c diff --git a/user/fulltest.c b/user/cmds/fulltest/fulltest.c similarity index 68% rename from user/fulltest.c rename to user/cmds/fulltest/fulltest.c index f491441..b5b1e27 100644 --- a/user/fulltest.c +++ b/user/cmds/fulltest/fulltest.c @@ -1403,8 +1403,8 @@ static volatile int got_alrm = 0; static void usr1_handler(int sig) { (void)sig; got_usr1 = 1; - sys_write(1, "[init] SIGUSR1 handler OK\n", - (uint32_t)(sizeof("[init] SIGUSR1 handler OK\n") - 1)); + sys_write(1, "[test] SIGUSR1 handler OK\n", + (uint32_t)(sizeof("[test] SIGUSR1 handler OK\n") - 1)); } static void usr1_ret_handler(int sig) { @@ -1429,14 +1429,14 @@ static void ttou_handler(int sig) { static void sigsegv_exit_handler(int sig) { (void)sig; - static const char msg[] = "[init] SIGSEGV handler invoked\n"; + static const char msg[] = "[test] SIGSEGV handler invoked\n"; (void)sys_write(1, msg, (uint32_t)(sizeof(msg) - 1)); sys_exit(0); } static void sigsegv_info_handler(int sig, siginfo_t* info, void* uctx) { (void)uctx; - static const char msg[] = "[init] SIGSEGV siginfo handler invoked\n"; + static const char msg[] = "[test] SIGSEGV siginfo handler invoked\n"; (void)sys_write(1, msg, (uint32_t)(sizeof(msg) - 1)); const uintptr_t expected = 0x12345000U; if (sig == SIGSEGV && info && (uintptr_t)info->si_addr == expected) { @@ -1454,14 +1454,14 @@ void _start(void) { "mov %ax, %gs\n" ); - static const char msg[] = "[init] hello from init.elf\n"; + static const char msg[] = "[test] hello from init.elf\n"; (void)sys_write(1, msg, (uint32_t)(sizeof(msg) - 1)); static const char path[] = "/sbin/fulltest"; int fd = sys_open(path, 0); if (fd < 0) { - sys_write(1, "[init] open failed fd=", (uint32_t)(sizeof("[init] open failed fd=") - 1)); + sys_write(1, "[test] open failed fd=", (uint32_t)(sizeof("[test] open failed fd=") - 1)); write_int_dec(fd); sys_write(1, "\n", 1); sys_exit(1); @@ -1471,10 +1471,10 @@ void _start(void) { int rd = sys_read(fd, hdr, 4); (void)sys_close(fd); if (rd == 4 && hdr[0] == 0x7F && hdr[1] == 'E' && hdr[2] == 'L' && hdr[3] == 'F') { - sys_write(1, "[init] open/read/close OK (ELF magic)\n", - (uint32_t)(sizeof("[init] open/read/close OK (ELF magic)\n") - 1)); + sys_write(1, "[test] open/read/close OK (ELF magic)\n", + (uint32_t)(sizeof("[test] open/read/close OK (ELF magic)\n") - 1)); } else { - sys_write(1, "[init] read failed or bad header rd=", (uint32_t)(sizeof("[init] read failed or bad header rd=") - 1)); + sys_write(1, "[test] read failed or bad header rd=", (uint32_t)(sizeof("[test] read failed or bad header rd=") - 1)); write_int_dec(rd); sys_write(1, " hdr=", (uint32_t)(sizeof(" hdr=") - 1)); for (int i = 0; i < 4; i++) { @@ -1486,161 +1486,161 @@ void _start(void) { fd = sys_open("/sbin/fulltest", 0); if (fd < 0) { - sys_write(1, "[init] overlay open failed\n", - (uint32_t)(sizeof("[init] overlay open failed\n") - 1)); + sys_write(1, "[test] overlay open failed\n", + (uint32_t)(sizeof("[test] overlay open failed\n") - 1)); sys_exit(1); } uint8_t orig0 = 0; if (sys_lseek(fd, 0, SEEK_SET) < 0 || sys_read(fd, &orig0, 1) != 1) { - sys_write(1, "[init] overlay read failed\n", - (uint32_t)(sizeof("[init] overlay read failed\n") - 1)); + sys_write(1, "[test] overlay read failed\n", + (uint32_t)(sizeof("[test] overlay read failed\n") - 1)); sys_exit(1); } uint8_t x = (uint8_t)(orig0 ^ 0xFF); if (sys_lseek(fd, 0, SEEK_SET) < 0 || sys_write(fd, &x, 1) != 1) { - sys_write(1, "[init] overlay write failed\n", - (uint32_t)(sizeof("[init] overlay write failed\n") - 1)); + sys_write(1, "[test] overlay write failed\n", + (uint32_t)(sizeof("[test] overlay write failed\n") - 1)); sys_exit(1); } if (sys_close(fd) < 0) { - sys_write(1, "[init] overlay close failed\n", - (uint32_t)(sizeof("[init] overlay close failed\n") - 1)); + sys_write(1, "[test] overlay close failed\n", + (uint32_t)(sizeof("[test] overlay close failed\n") - 1)); sys_exit(1); } fd = sys_open("/sbin/fulltest", 0); if (fd < 0) { - sys_write(1, "[init] overlay open2 failed\n", - (uint32_t)(sizeof("[init] overlay open2 failed\n") - 1)); + sys_write(1, "[test] overlay open2 failed\n", + (uint32_t)(sizeof("[test] overlay open2 failed\n") - 1)); sys_exit(1); } uint8_t chk = 0; if (sys_lseek(fd, 0, SEEK_SET) < 0 || sys_read(fd, &chk, 1) != 1 || chk != x) { - sys_write(1, "[init] overlay verify failed\n", - (uint32_t)(sizeof("[init] overlay verify failed\n") - 1)); + sys_write(1, "[test] overlay verify failed\n", + (uint32_t)(sizeof("[test] overlay verify failed\n") - 1)); sys_exit(1); } if (sys_lseek(fd, 0, SEEK_SET) < 0 || sys_write(fd, &orig0, 1) != 1) { - sys_write(1, "[init] overlay restore failed\n", - (uint32_t)(sizeof("[init] overlay restore failed\n") - 1)); + sys_write(1, "[test] overlay restore failed\n", + (uint32_t)(sizeof("[test] overlay restore failed\n") - 1)); sys_exit(1); } if (sys_close(fd) < 0) { - sys_write(1, "[init] overlay close2 failed\n", - (uint32_t)(sizeof("[init] overlay close2 failed\n") - 1)); + sys_write(1, "[test] overlay close2 failed\n", + (uint32_t)(sizeof("[test] overlay close2 failed\n") - 1)); sys_exit(1); } - sys_write(1, "[init] overlay copy-up OK\n", - (uint32_t)(sizeof("[init] overlay copy-up OK\n") - 1)); + sys_write(1, "[test] overlay copy-up OK\n", + (uint32_t)(sizeof("[test] overlay copy-up OK\n") - 1)); fd = sys_open("/sbin/fulltest", 0); if (fd < 0) { - sys_write(1, "[init] open2 failed\n", (uint32_t)(sizeof("[init] open2 failed\n") - 1)); + sys_write(1, "[test] open2 failed\n", (uint32_t)(sizeof("[test] open2 failed\n") - 1)); sys_exit(1); } struct stat st; if (sys_fstat(fd, &st) < 0) { - sys_write(1, "[init] fstat failed\n", (uint32_t)(sizeof("[init] fstat failed\n") - 1)); + sys_write(1, "[test] fstat failed\n", (uint32_t)(sizeof("[test] fstat failed\n") - 1)); sys_exit(1); } if ((st.st_mode & S_IFMT) != S_IFREG || st.st_size == 0) { - sys_write(1, "[init] fstat bad\n", (uint32_t)(sizeof("[init] fstat bad\n") - 1)); + sys_write(1, "[test] fstat bad\n", (uint32_t)(sizeof("[test] fstat bad\n") - 1)); sys_exit(1); } if (sys_lseek(fd, 0, SEEK_SET) < 0) { - sys_write(1, "[init] lseek set failed\n", - (uint32_t)(sizeof("[init] lseek set failed\n") - 1)); + sys_write(1, "[test] lseek set failed\n", + (uint32_t)(sizeof("[test] lseek set failed\n") - 1)); sys_exit(1); } uint8_t m2[4]; if (sys_read(fd, m2, 4) != 4) { - sys_write(1, "[init] read2 failed\n", (uint32_t)(sizeof("[init] read2 failed\n") - 1)); + sys_write(1, "[test] read2 failed\n", (uint32_t)(sizeof("[test] read2 failed\n") - 1)); sys_exit(1); } if (m2[0] != 0x7F || m2[1] != 'E' || m2[2] != 'L' || m2[3] != 'F') { - sys_write(1, "[init] lseek/read mismatch\n", - (uint32_t)(sizeof("[init] lseek/read mismatch\n") - 1)); + sys_write(1, "[test] lseek/read mismatch\n", + (uint32_t)(sizeof("[test] lseek/read mismatch\n") - 1)); sys_exit(1); } if (sys_close(fd) < 0) { - sys_write(1, "[init] close2 failed\n", (uint32_t)(sizeof("[init] close2 failed\n") - 1)); + sys_write(1, "[test] close2 failed\n", (uint32_t)(sizeof("[test] close2 failed\n") - 1)); sys_exit(1); } if (sys_stat("/sbin/fulltest", &st) < 0) { - sys_write(1, "[init] stat failed\n", (uint32_t)(sizeof("[init] stat failed\n") - 1)); + sys_write(1, "[test] stat failed\n", (uint32_t)(sizeof("[test] stat failed\n") - 1)); sys_exit(1); } if ((st.st_mode & S_IFMT) != S_IFREG || st.st_size == 0) { - sys_write(1, "[init] stat bad\n", (uint32_t)(sizeof("[init] stat bad\n") - 1)); + sys_write(1, "[test] stat bad\n", (uint32_t)(sizeof("[test] stat bad\n") - 1)); sys_exit(1); } - sys_write(1, "[init] lseek/stat/fstat OK\n", - (uint32_t)(sizeof("[init] lseek/stat/fstat OK\n") - 1)); + sys_write(1, "[test] lseek/stat/fstat OK\n", + (uint32_t)(sizeof("[test] lseek/stat/fstat OK\n") - 1)); fd = sys_open("/tmp/hello.txt", 0); if (fd < 0) { - sys_write(1, "[init] tmpfs open failed\n", - (uint32_t)(sizeof("[init] tmpfs open failed\n") - 1)); + sys_write(1, "[test] tmpfs open failed\n", + (uint32_t)(sizeof("[test] tmpfs open failed\n") - 1)); sys_exit(1); } if (sys_lseek(fd, 0, SEEK_END) < 0) { - sys_write(1, "[init] dup2 prep lseek failed\n", - (uint32_t)(sizeof("[init] dup2 prep lseek failed\n") - 1)); + sys_write(1, "[test] dup2 prep lseek failed\n", + (uint32_t)(sizeof("[test] dup2 prep lseek failed\n") - 1)); sys_exit(1); } if (sys_dup2(fd, 1) != 1) { - sys_write(1, "[init] dup2 failed\n", (uint32_t)(sizeof("[init] dup2 failed\n") - 1)); + sys_write(1, "[test] dup2 failed\n", (uint32_t)(sizeof("[test] dup2 failed\n") - 1)); sys_exit(1); } (void)sys_close(fd); { - static const char m[] = "[init] dup2 stdout->file OK\n"; + static const char m[] = "[test] dup2 stdout->file OK\n"; if (sys_write(1, m, (uint32_t)(sizeof(m) - 1)) != (int)(sizeof(m) - 1)) { sys_exit(1); } } (void)sys_close(1); - sys_write(1, "[init] dup2 restore tty OK\n", - (uint32_t)(sizeof("[init] dup2 restore tty OK\n") - 1)); + sys_write(1, "[test] dup2 restore tty OK\n", + (uint32_t)(sizeof("[test] dup2 restore tty OK\n") - 1)); { int pfds[2]; if (sys_pipe(pfds) < 0) { - sys_write(1, "[init] pipe failed\n", (uint32_t)(sizeof("[init] pipe failed\n") - 1)); + sys_write(1, "[test] pipe failed\n", (uint32_t)(sizeof("[test] pipe failed\n") - 1)); sys_exit(1); } static const char pmsg[] = "pipe-test"; if (sys_write(pfds[1], pmsg, (uint32_t)(sizeof(pmsg) - 1)) != (int)(sizeof(pmsg) - 1)) { - sys_write(1, "[init] pipe write failed\n", - (uint32_t)(sizeof("[init] pipe write failed\n") - 1)); + sys_write(1, "[test] pipe write failed\n", + (uint32_t)(sizeof("[test] pipe write failed\n") - 1)); sys_exit(1); } char rbuf[16]; int prd = sys_read(pfds[0], rbuf, (uint32_t)(sizeof(pmsg) - 1)); if (prd != (int)(sizeof(pmsg) - 1)) { - sys_write(1, "[init] pipe read failed\n", - (uint32_t)(sizeof("[init] pipe read failed\n") - 1)); + sys_write(1, "[test] pipe read failed\n", + (uint32_t)(sizeof("[test] pipe read failed\n") - 1)); sys_exit(1); } @@ -1649,14 +1649,14 @@ void _start(void) { if ((uint8_t)rbuf[i] != (uint8_t)pmsg[i]) ok = 0; } if (!ok) { - sys_write(1, "[init] pipe mismatch\n", - (uint32_t)(sizeof("[init] pipe mismatch\n") - 1)); + sys_write(1, "[test] pipe mismatch\n", + (uint32_t)(sizeof("[test] pipe mismatch\n") - 1)); sys_exit(1); } if (sys_dup2(pfds[1], 1) != 1) { - sys_write(1, "[init] pipe dup2 failed\n", - (uint32_t)(sizeof("[init] pipe dup2 failed\n") - 1)); + sys_write(1, "[test] pipe dup2 failed\n", + (uint32_t)(sizeof("[test] pipe dup2 failed\n") - 1)); sys_exit(1); } @@ -1667,24 +1667,24 @@ void _start(void) { int prd2 = sys_read(pfds[0], rbuf, (uint32_t)(sizeof(p2) - 1)); if (prd2 != (int)(sizeof(p2) - 1)) { - sys_write(1, "[init] pipe dup2 read failed\n", - (uint32_t)(sizeof("[init] pipe dup2 read failed\n") - 1)); + sys_write(1, "[test] pipe dup2 read failed\n", + (uint32_t)(sizeof("[test] pipe dup2 read failed\n") - 1)); sys_exit(1); } - sys_write(1, "[init] pipe OK\n", (uint32_t)(sizeof("[init] pipe OK\n") - 1)); + sys_write(1, "[test] pipe OK\n", (uint32_t)(sizeof("[test] pipe OK\n") - 1)); (void)sys_close(pfds[0]); (void)sys_close(pfds[1]); int tfd = sys_open("/dev/tty", 0); if (tfd < 0) { - sys_write(1, "[init] /dev/tty open failed\n", - (uint32_t)(sizeof("[init] /dev/tty open failed\n") - 1)); + sys_write(1, "[test] /dev/tty open failed\n", + (uint32_t)(sizeof("[test] /dev/tty open failed\n") - 1)); sys_exit(1); } if (sys_dup2(tfd, 1) != 1) { - sys_write(1, "[init] dup2 restore tty failed\n", - (uint32_t)(sizeof("[init] dup2 restore tty failed\n") - 1)); + sys_write(1, "[test] dup2 restore tty failed\n", + (uint32_t)(sizeof("[test] dup2 restore tty failed\n") - 1)); sys_exit(1); } (void)sys_close(tfd); @@ -1694,8 +1694,8 @@ void _start(void) { { int pid = sys_fork(); if (pid < 0) { - sys_write(1, "[init] kill test fork failed\n", - (uint32_t)(sizeof("[init] kill test fork failed\n") - 1)); + sys_write(1, "[test] kill test fork failed\n", + (uint32_t)(sizeof("[test] kill test fork failed\n") - 1)); sys_exit(1); } @@ -1706,28 +1706,28 @@ void _start(void) { } if (sys_kill(pid, SIGKILL) < 0) { - sys_write(1, "[init] kill(SIGKILL) failed\n", - (uint32_t)(sizeof("[init] kill(SIGKILL) failed\n") - 1)); + sys_write(1, "[test] kill(SIGKILL) failed\n", + (uint32_t)(sizeof("[test] kill(SIGKILL) failed\n") - 1)); sys_exit(1); } int st = 0; int rp = sys_waitpid(pid, &st, 0); if (rp != pid || st != (128 + SIGKILL)) { - sys_write(1, "[init] kill test waitpid mismatch\n", - (uint32_t)(sizeof("[init] kill test waitpid mismatch\n") - 1)); + sys_write(1, "[test] kill test waitpid mismatch\n", + (uint32_t)(sizeof("[test] kill test waitpid mismatch\n") - 1)); sys_exit(1); } - sys_write(1, "[init] kill(SIGKILL) OK\n", - (uint32_t)(sizeof("[init] kill(SIGKILL) OK\n") - 1)); + sys_write(1, "[test] kill(SIGKILL) OK\n", + (uint32_t)(sizeof("[test] kill(SIGKILL) OK\n") - 1)); } { int fds[2]; if (sys_pipe(fds) < 0) { - sys_write(1, "[init] poll pipe setup failed\n", - (uint32_t)(sizeof("[init] poll pipe setup failed\n") - 1)); + sys_write(1, "[test] poll pipe setup failed\n", + (uint32_t)(sizeof("[test] poll pipe setup failed\n") - 1)); sys_exit(1); } @@ -1737,36 +1737,36 @@ void _start(void) { p.revents = 0; int rc = sys_poll(&p, 1, 0); if (rc != 0) { - sys_write(1, "[init] poll(pipe) expected 0\n", - (uint32_t)(sizeof("[init] poll(pipe) expected 0\n") - 1)); + sys_write(1, "[test] poll(pipe) expected 0\n", + (uint32_t)(sizeof("[test] poll(pipe) expected 0\n") - 1)); sys_exit(1); } static const char a = 'A'; if (sys_write(fds[1], &a, 1) != 1) { - sys_write(1, "[init] poll pipe write failed\n", - (uint32_t)(sizeof("[init] poll pipe write failed\n") - 1)); + sys_write(1, "[test] poll pipe write failed\n", + (uint32_t)(sizeof("[test] poll pipe write failed\n") - 1)); sys_exit(1); } p.revents = 0; rc = sys_poll(&p, 1, 0); if (rc != 1 || (p.revents & POLLIN) == 0) { - sys_write(1, "[init] poll(pipe) expected POLLIN\n", - (uint32_t)(sizeof("[init] poll(pipe) expected POLLIN\n") - 1)); + sys_write(1, "[test] poll(pipe) expected POLLIN\n", + (uint32_t)(sizeof("[test] poll(pipe) expected POLLIN\n") - 1)); sys_exit(1); } (void)sys_close(fds[0]); (void)sys_close(fds[1]); - sys_write(1, "[init] poll(pipe) OK\n", (uint32_t)(sizeof("[init] poll(pipe) OK\n") - 1)); + sys_write(1, "[test] poll(pipe) OK\n", (uint32_t)(sizeof("[test] poll(pipe) OK\n") - 1)); } { int fds[2]; if (sys_pipe(fds) < 0) { - sys_write(1, "[init] select pipe setup failed\n", - (uint32_t)(sizeof("[init] select pipe setup failed\n") - 1)); + sys_write(1, "[test] select pipe setup failed\n", + (uint32_t)(sizeof("[test] select pipe setup failed\n") - 1)); sys_exit(1); } @@ -1775,15 +1775,15 @@ void _start(void) { r |= (1ULL << (uint32_t)fds[0]); int rc = sys_select((uint32_t)(fds[0] + 1), &r, &w, 0, 0); if (rc != 0) { - sys_write(1, "[init] select(pipe) expected 0\n", - (uint32_t)(sizeof("[init] select(pipe) expected 0\n") - 1)); + sys_write(1, "[test] select(pipe) expected 0\n", + (uint32_t)(sizeof("[test] select(pipe) expected 0\n") - 1)); sys_exit(1); } static const char a = 'B'; if (sys_write(fds[1], &a, 1) != 1) { - sys_write(1, "[init] select pipe write failed\n", - (uint32_t)(sizeof("[init] select pipe write failed\n") - 1)); + sys_write(1, "[test] select pipe write failed\n", + (uint32_t)(sizeof("[test] select pipe write failed\n") - 1)); sys_exit(1); } @@ -1792,102 +1792,102 @@ void _start(void) { r |= (1ULL << (uint32_t)fds[0]); rc = sys_select((uint32_t)(fds[0] + 1), &r, &w, 0, 0); if (rc != 1 || ((r >> (uint32_t)fds[0]) & 1ULL) == 0) { - sys_write(1, "[init] select(pipe) expected readable\n", - (uint32_t)(sizeof("[init] select(pipe) expected readable\n") - 1)); + sys_write(1, "[test] select(pipe) expected readable\n", + (uint32_t)(sizeof("[test] select(pipe) expected readable\n") - 1)); sys_exit(1); } (void)sys_close(fds[0]); (void)sys_close(fds[1]); - sys_write(1, "[init] select(pipe) OK\n", - (uint32_t)(sizeof("[init] select(pipe) OK\n") - 1)); + sys_write(1, "[test] select(pipe) OK\n", + (uint32_t)(sizeof("[test] select(pipe) OK\n") - 1)); } { int fd = sys_open("/dev/tty", 0); if (fd < 0) { - sys_write(1, "[init] ioctl(/dev/tty) open failed\n", - (uint32_t)(sizeof("[init] ioctl(/dev/tty) open failed\n") - 1)); + sys_write(1, "[test] ioctl(/dev/tty) open failed\n", + (uint32_t)(sizeof("[test] ioctl(/dev/tty) open failed\n") - 1)); sys_exit(1); } int fg = -1; if (sys_ioctl(fd, TIOCGPGRP, &fg) < 0 || fg != 0) { - sys_write(1, "[init] ioctl TIOCGPGRP failed\n", - (uint32_t)(sizeof("[init] ioctl TIOCGPGRP failed\n") - 1)); + sys_write(1, "[test] ioctl TIOCGPGRP failed\n", + (uint32_t)(sizeof("[test] ioctl TIOCGPGRP failed\n") - 1)); sys_exit(1); } fg = 0; if (sys_ioctl(fd, TIOCSPGRP, &fg) < 0) { - sys_write(1, "[init] ioctl TIOCSPGRP failed\n", - (uint32_t)(sizeof("[init] ioctl TIOCSPGRP failed\n") - 1)); + sys_write(1, "[test] ioctl TIOCSPGRP failed\n", + (uint32_t)(sizeof("[test] ioctl TIOCSPGRP failed\n") - 1)); sys_exit(1); } fg = 1; if (sys_ioctl(fd, TIOCSPGRP, &fg) >= 0) { - sys_write(1, "[init] ioctl TIOCSPGRP expected fail\n", - (uint32_t)(sizeof("[init] ioctl TIOCSPGRP expected fail\n") - 1)); + sys_write(1, "[test] ioctl TIOCSPGRP expected fail\n", + (uint32_t)(sizeof("[test] ioctl TIOCSPGRP expected fail\n") - 1)); sys_exit(1); } struct termios oldt; if (sys_ioctl(fd, TCGETS, &oldt) < 0) { - sys_write(1, "[init] ioctl TCGETS failed\n", - (uint32_t)(sizeof("[init] ioctl TCGETS failed\n") - 1)); + sys_write(1, "[test] ioctl TCGETS failed\n", + (uint32_t)(sizeof("[test] ioctl TCGETS failed\n") - 1)); sys_exit(1); } struct termios t = oldt; t.c_lflag &= ~(uint32_t)(ECHO | ICANON); if (sys_ioctl(fd, TCSETS, &t) < 0) { - sys_write(1, "[init] ioctl TCSETS failed\n", - (uint32_t)(sizeof("[init] ioctl TCSETS failed\n") - 1)); + sys_write(1, "[test] ioctl TCSETS failed\n", + (uint32_t)(sizeof("[test] ioctl TCSETS failed\n") - 1)); sys_exit(1); } struct termios chk; if (sys_ioctl(fd, TCGETS, &chk) < 0) { - sys_write(1, "[init] ioctl TCGETS2 failed\n", - (uint32_t)(sizeof("[init] ioctl TCGETS2 failed\n") - 1)); + sys_write(1, "[test] ioctl TCGETS2 failed\n", + (uint32_t)(sizeof("[test] ioctl TCGETS2 failed\n") - 1)); sys_exit(1); } if ((chk.c_lflag & (uint32_t)(ECHO | ICANON)) != 0) { - sys_write(1, "[init] ioctl verify failed\n", - (uint32_t)(sizeof("[init] ioctl verify failed\n") - 1)); + sys_write(1, "[test] ioctl verify failed\n", + (uint32_t)(sizeof("[test] ioctl verify failed\n") - 1)); sys_exit(1); } (void)sys_ioctl(fd, TCSETS, &oldt); (void)sys_close(fd); - sys_write(1, "[init] ioctl(/dev/tty) OK\n", - (uint32_t)(sizeof("[init] ioctl(/dev/tty) OK\n") - 1)); + sys_write(1, "[test] ioctl(/dev/tty) OK\n", + (uint32_t)(sizeof("[test] ioctl(/dev/tty) OK\n") - 1)); } // A2: basic job control. A background pgrp read/write on controlling TTY should raise SIGTTIN/SIGTTOU. { int leader = sys_fork(); if (leader < 0) { - sys_write(1, "[init] fork(job control leader) failed\n", - (uint32_t)(sizeof("[init] fork(job control leader) failed\n") - 1)); + sys_write(1, "[test] fork(job control leader) failed\n", + (uint32_t)(sizeof("[test] fork(job control leader) failed\n") - 1)); sys_exit(1); } if (leader == 0) { int me = sys_getpid(); int sid = sys_setsid(); if (sid != me) { - sys_write(1, "[init] setsid(job control) failed\n", - (uint32_t)(sizeof("[init] setsid(job control) failed\n") - 1)); + sys_write(1, "[test] setsid(job control) failed\n", + (uint32_t)(sizeof("[test] setsid(job control) failed\n") - 1)); sys_exit(1); } int tfd = sys_open("/dev/tty", 0); if (tfd < 0) { - sys_write(1, "[init] open(/dev/tty) for job control failed\n", - (uint32_t)(sizeof("[init] open(/dev/tty) for job control failed\n") - 1)); + sys_write(1, "[test] open(/dev/tty) for job control failed\n", + (uint32_t)(sizeof("[test] open(/dev/tty) for job control failed\n") - 1)); sys_exit(1); } @@ -1897,15 +1897,15 @@ void _start(void) { fg = me; if (sys_ioctl(tfd, TIOCSPGRP, &fg) < 0) { - sys_write(1, "[init] ioctl TIOCSPGRP(job control) failed\n", - (uint32_t)(sizeof("[init] ioctl TIOCSPGRP(job control) failed\n") - 1)); + sys_write(1, "[test] ioctl TIOCSPGRP(job control) failed\n", + (uint32_t)(sizeof("[test] ioctl TIOCSPGRP(job control) failed\n") - 1)); sys_exit(1); } int bg = sys_fork(); if (bg < 0) { - sys_write(1, "[init] fork(job control bg) failed\n", - (uint32_t)(sizeof("[init] fork(job control bg) failed\n") - 1)); + sys_write(1, "[test] fork(job control bg) failed\n", + (uint32_t)(sizeof("[test] fork(job control bg) failed\n") - 1)); sys_exit(1); } if (bg == 0) { @@ -1917,16 +1917,16 @@ void _start(void) { uint8_t b = 0; (void)sys_read(tfd, &b, 1); if (!got_ttin) { - sys_write(1, "[init] SIGTTIN job control failed\n", - (uint32_t)(sizeof("[init] SIGTTIN job control failed\n") - 1)); + sys_write(1, "[test] SIGTTIN job control failed\n", + (uint32_t)(sizeof("[test] SIGTTIN job control failed\n") - 1)); sys_exit(1); } const char msg2[] = "x"; (void)sys_write(tfd, msg2, 1); if (!got_ttou) { - sys_write(1, "[init] SIGTTOU job control failed\n", - (uint32_t)(sizeof("[init] SIGTTOU job control failed\n") - 1)); + sys_write(1, "[test] SIGTTOU job control failed\n", + (uint32_t)(sizeof("[test] SIGTTOU job control failed\n") - 1)); sys_exit(1); } @@ -1936,7 +1936,7 @@ void _start(void) { int st2 = 0; int wp2 = sys_waitpid(bg, &st2, 0); if (wp2 != bg || st2 != 0) { - sys_write(1, "[init] waitpid(job control bg) failed wp=", (uint32_t)(sizeof("[init] waitpid(job control bg) failed wp=") - 1)); + sys_write(1, "[test] waitpid(job control bg) failed wp=", (uint32_t)(sizeof("[test] waitpid(job control bg) failed wp=") - 1)); write_int_dec(wp2); sys_write(1, " st=", (uint32_t)(sizeof(" st=") - 1)); write_int_dec(st2); @@ -1951,7 +1951,7 @@ void _start(void) { int stL = 0; int wpL = sys_waitpid(leader, &stL, 0); if (wpL != leader || stL != 0) { - sys_write(1, "[init] waitpid(job control leader) failed wp=", (uint32_t)(sizeof("[init] waitpid(job control leader) failed wp=") - 1)); + sys_write(1, "[test] waitpid(job control leader) failed wp=", (uint32_t)(sizeof("[test] waitpid(job control leader) failed wp=") - 1)); write_int_dec(wpL); sys_write(1, " st=", (uint32_t)(sizeof(" st=") - 1)); write_int_dec(stL); @@ -1959,15 +1959,15 @@ void _start(void) { sys_exit(1); } - sys_write(1, "[init] job control (SIGTTIN/SIGTTOU) OK\n", - (uint32_t)(sizeof("[init] job control (SIGTTIN/SIGTTOU) OK\n") - 1)); + sys_write(1, "[test] job control (SIGTTIN/SIGTTOU) OK\n", + (uint32_t)(sizeof("[test] job control (SIGTTIN/SIGTTOU) OK\n") - 1)); } { int fd = sys_open("/dev/null", 0); if (fd < 0) { - sys_write(1, "[init] poll(/dev/null) open failed\n", - (uint32_t)(sizeof("[init] poll(/dev/null) open failed\n") - 1)); + sys_write(1, "[test] poll(/dev/null) open failed\n", + (uint32_t)(sizeof("[test] poll(/dev/null) open failed\n") - 1)); sys_exit(1); } struct pollfd p; @@ -1976,28 +1976,28 @@ void _start(void) { p.revents = 0; int rc = sys_poll(&p, 1, 0); if (rc != 1 || (p.revents & POLLOUT) == 0) { - sys_write(1, "[init] poll(/dev/null) expected POLLOUT\n", - (uint32_t)(sizeof("[init] poll(/dev/null) expected POLLOUT\n") - 1)); + sys_write(1, "[test] poll(/dev/null) expected POLLOUT\n", + (uint32_t)(sizeof("[test] poll(/dev/null) expected POLLOUT\n") - 1)); sys_exit(1); } (void)sys_close(fd); - sys_write(1, "[init] poll(/dev/null) OK\n", - (uint32_t)(sizeof("[init] poll(/dev/null) OK\n") - 1)); + sys_write(1, "[test] poll(/dev/null) OK\n", + (uint32_t)(sizeof("[test] poll(/dev/null) OK\n") - 1)); } { int mfd = sys_open("/dev/ptmx", 0); int sfd = sys_open("/dev/pts/0", 0); if (mfd < 0 || sfd < 0) { - sys_write(1, "[init] pty open failed\n", - (uint32_t)(sizeof("[init] pty open failed\n") - 1)); + sys_write(1, "[test] pty open failed\n", + (uint32_t)(sizeof("[test] pty open failed\n") - 1)); sys_exit(1); } static const char m2s[] = "m2s"; if (sys_write(mfd, m2s, (uint32_t)(sizeof(m2s) - 1)) != (int)(sizeof(m2s) - 1)) { - sys_write(1, "[init] pty write master failed\n", - (uint32_t)(sizeof("[init] pty write master failed\n") - 1)); + sys_write(1, "[test] pty write master failed\n", + (uint32_t)(sizeof("[test] pty write master failed\n") - 1)); sys_exit(1); } @@ -2007,23 +2007,23 @@ void _start(void) { p.revents = 0; int rc = sys_poll(&p, 1, 50); if (rc != 1 || (p.revents & POLLIN) == 0) { - sys_write(1, "[init] pty poll slave failed\n", - (uint32_t)(sizeof("[init] pty poll slave failed\n") - 1)); + sys_write(1, "[test] pty poll slave failed\n", + (uint32_t)(sizeof("[test] pty poll slave failed\n") - 1)); sys_exit(1); } char buf[8]; int rd = sys_read(sfd, buf, (uint32_t)(sizeof(m2s) - 1)); if (rd != (int)(sizeof(m2s) - 1) || !memeq(buf, m2s, (uint32_t)(sizeof(m2s) - 1))) { - sys_write(1, "[init] pty read slave failed\n", - (uint32_t)(sizeof("[init] pty read slave failed\n") - 1)); + sys_write(1, "[test] pty read slave failed\n", + (uint32_t)(sizeof("[test] pty read slave failed\n") - 1)); sys_exit(1); } static const char s2m[] = "s2m"; if (sys_write(sfd, s2m, (uint32_t)(sizeof(s2m) - 1)) != (int)(sizeof(s2m) - 1)) { - sys_write(1, "[init] pty write slave failed\n", - (uint32_t)(sizeof("[init] pty write slave failed\n") - 1)); + sys_write(1, "[test] pty write slave failed\n", + (uint32_t)(sizeof("[test] pty write slave failed\n") - 1)); sys_exit(1); } @@ -2032,35 +2032,35 @@ void _start(void) { p.revents = 0; rc = sys_poll(&p, 1, 50); if (rc != 1 || (p.revents & POLLIN) == 0) { - sys_write(1, "[init] pty poll master failed\n", - (uint32_t)(sizeof("[init] pty poll master failed\n") - 1)); + sys_write(1, "[test] pty poll master failed\n", + (uint32_t)(sizeof("[test] pty poll master failed\n") - 1)); sys_exit(1); } rd = sys_read(mfd, buf, (uint32_t)(sizeof(s2m) - 1)); if (rd != (int)(sizeof(s2m) - 1) || !memeq(buf, s2m, (uint32_t)(sizeof(s2m) - 1))) { - sys_write(1, "[init] pty read master failed\n", - (uint32_t)(sizeof("[init] pty read master failed\n") - 1)); + sys_write(1, "[test] pty read master failed\n", + (uint32_t)(sizeof("[test] pty read master failed\n") - 1)); sys_exit(1); } (void)sys_close(mfd); (void)sys_close(sfd); - sys_write(1, "[init] pty OK\n", (uint32_t)(sizeof("[init] pty OK\n") - 1)); + sys_write(1, "[test] pty OK\n", (uint32_t)(sizeof("[test] pty OK\n") - 1)); } { - sys_write(1, "[init] setsid test: before fork\n", - (uint32_t)(sizeof("[init] setsid test: before fork\n") - 1)); + sys_write(1, "[test] setsid test: before fork\n", + (uint32_t)(sizeof("[test] setsid test: before fork\n") - 1)); int pid = sys_fork(); if (pid < 0) { - static const char smsg[] = "[init] fork failed\n"; + static const char smsg[] = "[test] fork failed\n"; (void)sys_write(1, smsg, (uint32_t)(sizeof(smsg) - 1)); sys_exit(2); } if (pid == 0) { - sys_write(1, "[init] setsid test: child start\n", - (uint32_t)(sizeof("[init] setsid test: child start\n") - 1)); + sys_write(1, "[test] setsid test: child start\n", + (uint32_t)(sizeof("[test] setsid test: child start\n") - 1)); int me = sys_getpid(); int sid = sys_setsid(); if (sid != me) sys_exit(2); @@ -2075,32 +2075,32 @@ void _start(void) { sys_exit(0); } - sys_write(1, "[init] setsid test: parent waitpid\n", - (uint32_t)(sizeof("[init] setsid test: parent waitpid\n") - 1)); + sys_write(1, "[test] setsid test: parent waitpid\n", + (uint32_t)(sizeof("[test] setsid test: parent waitpid\n") - 1)); int st = 0; int wp = sys_waitpid(pid, &st, 0); if (wp != pid || st != 0) { - sys_write(1, "[init] setsid/setpgid/getpgrp failed\n", - (uint32_t)(sizeof("[init] setsid/setpgid/getpgrp failed\n") - 1)); + sys_write(1, "[test] setsid/setpgid/getpgrp failed\n", + (uint32_t)(sizeof("[test] setsid/setpgid/getpgrp failed\n") - 1)); sys_exit(1); } - sys_write(1, "[init] setsid/setpgid/getpgrp OK\n", - (uint32_t)(sizeof("[init] setsid/setpgid/getpgrp OK\n") - 1)); + sys_write(1, "[test] setsid/setpgid/getpgrp OK\n", + (uint32_t)(sizeof("[test] setsid/setpgid/getpgrp OK\n") - 1)); } { uintptr_t oldh = 0; if (sys_sigaction(SIGUSR1, usr1_handler, &oldh) < 0) { - sys_write(1, "[init] sigaction failed\n", - (uint32_t)(sizeof("[init] sigaction failed\n") - 1)); + sys_write(1, "[test] sigaction failed\n", + (uint32_t)(sizeof("[test] sigaction failed\n") - 1)); sys_exit(1); } int me = sys_getpid(); if (sys_kill(me, SIGUSR1) < 0) { - sys_write(1, "[init] kill(SIGUSR1) failed\n", - (uint32_t)(sizeof("[init] kill(SIGUSR1) failed\n") - 1)); + sys_write(1, "[test] kill(SIGUSR1) failed\n", + (uint32_t)(sizeof("[test] kill(SIGUSR1) failed\n") - 1)); sys_exit(1); } @@ -2109,148 +2109,148 @@ void _start(void) { } if (!got_usr1) { - sys_write(1, "[init] SIGUSR1 not delivered\n", - (uint32_t)(sizeof("[init] SIGUSR1 not delivered\n") - 1)); + sys_write(1, "[test] SIGUSR1 not delivered\n", + (uint32_t)(sizeof("[test] SIGUSR1 not delivered\n") - 1)); sys_exit(1); } - sys_write(1, "[init] sigaction/kill(SIGUSR1) OK\n", - (uint32_t)(sizeof("[init] sigaction/kill(SIGUSR1) OK\n") - 1)); + sys_write(1, "[test] sigaction/kill(SIGUSR1) OK\n", + (uint32_t)(sizeof("[test] sigaction/kill(SIGUSR1) OK\n") - 1)); } // Verify that returning from a signal handler does not corrupt the user stack. { if (sys_sigaction(SIGUSR1, usr1_ret_handler, 0) < 0) { - sys_write(1, "[init] sigaction (sigreturn test) failed\n", - (uint32_t)(sizeof("[init] sigaction (sigreturn test) failed\n") - 1)); + sys_write(1, "[test] sigaction (sigreturn test) failed\n", + (uint32_t)(sizeof("[test] sigaction (sigreturn test) failed\n") - 1)); sys_exit(1); } volatile uint32_t canary = 0x11223344U; int me = sys_getpid(); if (sys_kill(me, SIGUSR1) < 0) { - sys_write(1, "[init] kill(SIGUSR1) (sigreturn test) failed\n", - (uint32_t)(sizeof("[init] kill(SIGUSR1) (sigreturn test) failed\n") - 1)); + sys_write(1, "[test] kill(SIGUSR1) (sigreturn test) failed\n", + (uint32_t)(sizeof("[test] kill(SIGUSR1) (sigreturn test) failed\n") - 1)); sys_exit(1); } if (!got_usr1_ret) { - sys_write(1, "[init] SIGUSR1 not delivered (sigreturn test)\n", - (uint32_t)(sizeof("[init] SIGUSR1 not delivered (sigreturn test)\n") - 1)); + sys_write(1, "[test] SIGUSR1 not delivered (sigreturn test)\n", + (uint32_t)(sizeof("[test] SIGUSR1 not delivered (sigreturn test)\n") - 1)); sys_exit(1); } if (canary != 0x11223344U) { - sys_write(1, "[init] sigreturn test stack corruption\n", - (uint32_t)(sizeof("[init] sigreturn test stack corruption\n") - 1)); + sys_write(1, "[test] sigreturn test stack corruption\n", + (uint32_t)(sizeof("[test] sigreturn test stack corruption\n") - 1)); sys_exit(1); } - sys_write(1, "[init] sigreturn OK\n", - (uint32_t)(sizeof("[init] sigreturn OK\n") - 1)); + sys_write(1, "[test] sigreturn OK\n", + (uint32_t)(sizeof("[test] sigreturn OK\n") - 1)); } fd = sys_open("/tmp/hello.txt", 0); if (fd < 0) { - sys_write(1, "[init] tmpfs open2 failed\n", - (uint32_t)(sizeof("[init] tmpfs open2 failed\n") - 1)); + sys_write(1, "[test] tmpfs open2 failed\n", + (uint32_t)(sizeof("[test] tmpfs open2 failed\n") - 1)); sys_exit(1); } if (sys_stat("/tmp/hello.txt", &st) < 0) { - sys_write(1, "[init] tmpfs stat failed\n", - (uint32_t)(sizeof("[init] tmpfs stat failed\n") - 1)); + sys_write(1, "[test] tmpfs stat failed\n", + (uint32_t)(sizeof("[test] tmpfs stat failed\n") - 1)); sys_exit(1); } if ((st.st_mode & S_IFMT) != S_IFREG) { - sys_write(1, "[init] tmpfs stat not reg\n", - (uint32_t)(sizeof("[init] tmpfs stat not reg\n") - 1)); + sys_write(1, "[test] tmpfs stat not reg\n", + (uint32_t)(sizeof("[test] tmpfs stat not reg\n") - 1)); sys_exit(1); } if (st.st_size == 0) { - sys_write(1, "[init] tmpfs stat size 0\n", - (uint32_t)(sizeof("[init] tmpfs stat size 0\n") - 1)); + sys_write(1, "[test] tmpfs stat size 0\n", + (uint32_t)(sizeof("[test] tmpfs stat size 0\n") - 1)); sys_exit(1); } struct stat fst; if (sys_fstat(fd, &fst) < 0) { - sys_write(1, "[init] tmpfs fstat failed\n", - (uint32_t)(sizeof("[init] tmpfs fstat failed\n") - 1)); + sys_write(1, "[test] tmpfs fstat failed\n", + (uint32_t)(sizeof("[test] tmpfs fstat failed\n") - 1)); sys_exit(1); } if (fst.st_size != st.st_size) { - sys_write(1, "[init] tmpfs stat size mismatch\n", - (uint32_t)(sizeof("[init] tmpfs stat size mismatch\n") - 1)); + sys_write(1, "[test] tmpfs stat size mismatch\n", + (uint32_t)(sizeof("[test] tmpfs stat size mismatch\n") - 1)); sys_exit(1); } int end = sys_lseek(fd, 0, SEEK_END); if (end < 0 || (uint32_t)end != st.st_size) { - sys_write(1, "[init] tmpfs lseek end bad\n", - (uint32_t)(sizeof("[init] tmpfs lseek end bad\n") - 1)); + sys_write(1, "[test] tmpfs lseek end bad\n", + (uint32_t)(sizeof("[test] tmpfs lseek end bad\n") - 1)); sys_exit(1); } uint8_t eofb; if (sys_read(fd, &eofb, 1) != 0) { - sys_write(1, "[init] tmpfs eof read bad\n", - (uint32_t)(sizeof("[init] tmpfs eof read bad\n") - 1)); + sys_write(1, "[test] tmpfs eof read bad\n", + (uint32_t)(sizeof("[test] tmpfs eof read bad\n") - 1)); sys_exit(1); } if (sys_lseek(fd, 0, 999) >= 0) { - sys_write(1, "[init] tmpfs lseek whence bad\n", - (uint32_t)(sizeof("[init] tmpfs lseek whence bad\n") - 1)); + sys_write(1, "[test] tmpfs lseek whence bad\n", + (uint32_t)(sizeof("[test] tmpfs lseek whence bad\n") - 1)); sys_exit(1); } if (sys_lseek(fd, 0, SEEK_SET) < 0) { - sys_write(1, "[init] tmpfs lseek set failed\n", - (uint32_t)(sizeof("[init] tmpfs lseek set failed\n") - 1)); + sys_write(1, "[test] tmpfs lseek set failed\n", + (uint32_t)(sizeof("[test] tmpfs lseek set failed\n") - 1)); sys_exit(1); } uint8_t tbuf[6]; if (sys_read(fd, tbuf, 5) != 5) { - sys_write(1, "[init] tmpfs read failed\n", - (uint32_t)(sizeof("[init] tmpfs read failed\n") - 1)); + sys_write(1, "[test] tmpfs read failed\n", + (uint32_t)(sizeof("[test] tmpfs read failed\n") - 1)); sys_exit(1); } tbuf[5] = 0; if (tbuf[0] != 'h' || tbuf[1] != 'e' || tbuf[2] != 'l' || tbuf[3] != 'l' || tbuf[4] != 'o') { - sys_write(1, "[init] tmpfs bad data\n", (uint32_t)(sizeof("[init] tmpfs bad data\n") - 1)); + sys_write(1, "[test] tmpfs bad data\n", (uint32_t)(sizeof("[test] tmpfs bad data\n") - 1)); sys_exit(1); } if (sys_close(fd) < 0) { - sys_write(1, "[init] tmpfs close failed\n", - (uint32_t)(sizeof("[init] tmpfs close failed\n") - 1)); + sys_write(1, "[test] tmpfs close failed\n", + (uint32_t)(sizeof("[test] tmpfs close failed\n") - 1)); sys_exit(1); } if (sys_open("/tmp/does_not_exist", 0) >= 0) { - sys_write(1, "[init] tmpfs open nonexist bad\n", - (uint32_t)(sizeof("[init] tmpfs open nonexist bad\n") - 1)); + sys_write(1, "[test] tmpfs open nonexist bad\n", + (uint32_t)(sizeof("[test] tmpfs open nonexist bad\n") - 1)); sys_exit(1); } fd = sys_open("/tmp/hello.txt", 0); if (fd < 0) { - sys_write(1, "[init] tmpfs open3 failed\n", - (uint32_t)(sizeof("[init] tmpfs open3 failed\n") - 1)); + sys_write(1, "[test] tmpfs open3 failed\n", + (uint32_t)(sizeof("[test] tmpfs open3 failed\n") - 1)); sys_exit(1); } if (sys_fstat(fd, &fst) < 0) { - sys_write(1, "[init] tmpfs fstat2 failed\n", - (uint32_t)(sizeof("[init] tmpfs fstat2 failed\n") - 1)); + sys_write(1, "[test] tmpfs fstat2 failed\n", + (uint32_t)(sizeof("[test] tmpfs fstat2 failed\n") - 1)); sys_exit(1); } if (sys_lseek(fd, 0, SEEK_END) < 0) { - sys_write(1, "[init] tmpfs lseek end2 failed\n", - (uint32_t)(sizeof("[init] tmpfs lseek end2 failed\n") - 1)); + sys_write(1, "[test] tmpfs lseek end2 failed\n", + (uint32_t)(sizeof("[test] tmpfs lseek end2 failed\n") - 1)); sys_exit(1); } @@ -2259,65 +2259,65 @@ void _start(void) { suf[1] = 'Y'; suf[2] = 'Z'; if (sys_write(fd, suf, 3) != 3) { - sys_write(1, "[init] tmpfs write failed\n", - (uint32_t)(sizeof("[init] tmpfs write failed\n") - 1)); + sys_write(1, "[test] tmpfs write failed\n", + (uint32_t)(sizeof("[test] tmpfs write failed\n") - 1)); sys_exit(1); } if (sys_fstat(fd, &fst) < 0) { - sys_write(1, "[init] tmpfs fstat3 failed\n", - (uint32_t)(sizeof("[init] tmpfs fstat3 failed\n") - 1)); + sys_write(1, "[test] tmpfs fstat3 failed\n", + (uint32_t)(sizeof("[test] tmpfs fstat3 failed\n") - 1)); sys_exit(1); } if (fst.st_size != st.st_size + 3) { - sys_write(1, "[init] tmpfs size not grown\n", - (uint32_t)(sizeof("[init] tmpfs size not grown\n") - 1)); + sys_write(1, "[test] tmpfs size not grown\n", + (uint32_t)(sizeof("[test] tmpfs size not grown\n") - 1)); sys_exit(1); } if (sys_lseek(fd, -3, SEEK_END) < 0) { - sys_write(1, "[init] tmpfs lseek back failed\n", - (uint32_t)(sizeof("[init] tmpfs lseek back failed\n") - 1)); + sys_write(1, "[test] tmpfs lseek back failed\n", + (uint32_t)(sizeof("[test] tmpfs lseek back failed\n") - 1)); sys_exit(1); } uint8_t s2[3]; if (sys_read(fd, s2, 3) != 3 || s2[0] != 'X' || s2[1] != 'Y' || s2[2] != 'Z') { - sys_write(1, "[init] tmpfs suffix mismatch\n", - (uint32_t)(sizeof("[init] tmpfs suffix mismatch\n") - 1)); + sys_write(1, "[test] tmpfs suffix mismatch\n", + (uint32_t)(sizeof("[test] tmpfs suffix mismatch\n") - 1)); sys_exit(1); } if (sys_close(fd) < 0) { - sys_write(1, "[init] tmpfs close3 failed\n", - (uint32_t)(sizeof("[init] tmpfs close3 failed\n") - 1)); + sys_write(1, "[test] tmpfs close3 failed\n", + (uint32_t)(sizeof("[test] tmpfs close3 failed\n") - 1)); sys_exit(1); } - sys_write(1, "[init] tmpfs/mount OK\n", (uint32_t)(sizeof("[init] tmpfs/mount OK\n") - 1)); + sys_write(1, "[test] tmpfs/mount OK\n", (uint32_t)(sizeof("[test] tmpfs/mount OK\n") - 1)); { int fd = sys_open("/dev/null", 0); if (fd < 0) { - sys_write(1, "[init] /dev/null open failed\n", - (uint32_t)(sizeof("[init] /dev/null open failed\n") - 1)); + sys_write(1, "[test] /dev/null open failed\n", + (uint32_t)(sizeof("[test] /dev/null open failed\n") - 1)); sys_exit(1); } static const char z[] = "discard me"; if (sys_write(fd, z, (uint32_t)(sizeof(z) - 1)) != (int)(sizeof(z) - 1)) { - sys_write(1, "[init] /dev/null write failed\n", - (uint32_t)(sizeof("[init] /dev/null write failed\n") - 1)); + sys_write(1, "[test] /dev/null write failed\n", + (uint32_t)(sizeof("[test] /dev/null write failed\n") - 1)); sys_exit(1); } (void)sys_close(fd); - sys_write(1, "[init] /dev/null OK\n", (uint32_t)(sizeof("[init] /dev/null OK\n") - 1)); + sys_write(1, "[test] /dev/null OK\n", (uint32_t)(sizeof("[test] /dev/null OK\n") - 1)); } // B1: persistent storage smoke. Value should increment across reboots (disk.img). { int fd = sys_open("/persist/counter", 0); if (fd < 0) { - sys_write(1, "[init] /persist/counter open failed\n", - (uint32_t)(sizeof("[init] /persist/counter open failed\n") - 1)); + sys_write(1, "[test] /persist/counter open failed\n", + (uint32_t)(sizeof("[test] /persist/counter open failed\n") - 1)); sys_exit(1); } @@ -2325,8 +2325,8 @@ void _start(void) { uint8_t b[4] = {0, 0, 0, 0}; int rd = sys_read(fd, b, 4); if (rd != 4) { - sys_write(1, "[init] /persist/counter read failed\n", - (uint32_t)(sizeof("[init] /persist/counter read failed\n") - 1)); + sys_write(1, "[test] /persist/counter read failed\n", + (uint32_t)(sizeof("[test] /persist/counter read failed\n") - 1)); sys_exit(1); } @@ -2340,14 +2340,14 @@ void _start(void) { (void)sys_lseek(fd, 0, SEEK_SET); int wr = sys_write(fd, b, 4); if (wr != 4) { - sys_write(1, "[init] /persist/counter write failed\n", - (uint32_t)(sizeof("[init] /persist/counter write failed\n") - 1)); + sys_write(1, "[test] /persist/counter write failed\n", + (uint32_t)(sizeof("[test] /persist/counter write failed\n") - 1)); sys_exit(1); } (void)sys_close(fd); - sys_write(1, "[init] /persist/counter=", (uint32_t)(sizeof("[init] /persist/counter=") - 1)); + sys_write(1, "[test] /persist/counter=", (uint32_t)(sizeof("[test] /persist/counter=") - 1)); write_int_dec((int)v); sys_write(1, "\n", 1); } @@ -2355,15 +2355,15 @@ void _start(void) { { int fd = sys_open("/dev/tty", 0); if (fd < 0) { - sys_write(1, "[init] /dev/tty open failed\n", - (uint32_t)(sizeof("[init] /dev/tty open failed\n") - 1)); + sys_write(1, "[test] /dev/tty open failed\n", + (uint32_t)(sizeof("[test] /dev/tty open failed\n") - 1)); sys_exit(1); } - static const char m[] = "[init] /dev/tty write OK\n"; + static const char m[] = "[test] /dev/tty write OK\n"; int wr = sys_write(fd, m, (uint32_t)(sizeof(m) - 1)); if (wr != (int)(sizeof(m) - 1)) { - sys_write(1, "[init] /dev/tty write failed\n", - (uint32_t)(sizeof("[init] /dev/tty write failed\n") - 1)); + sys_write(1, "[test] /dev/tty write failed\n", + (uint32_t)(sizeof("[test] /dev/tty write failed\n") - 1)); sys_exit(1); } (void)sys_close(fd); @@ -2373,8 +2373,8 @@ void _start(void) { { int fd = sys_open("/disk/test", O_CREAT); if (fd < 0) { - sys_write(1, "[init] /disk/test open failed\n", - (uint32_t)(sizeof("[init] /disk/test open failed\n") - 1)); + sys_write(1, "[test] /disk/test open failed\n", + (uint32_t)(sizeof("[test] /disk/test open failed\n") - 1)); sys_exit(1); } @@ -2392,8 +2392,8 @@ void _start(void) { fd = sys_open("/disk/test", O_CREAT | O_TRUNC); if (fd < 0) { - sys_write(1, "[init] /disk/test open2 failed\n", - (uint32_t)(sizeof("[init] /disk/test open2 failed\n") - 1)); + sys_write(1, "[test] /disk/test open2 failed\n", + (uint32_t)(sizeof("[test] /disk/test open2 failed\n") - 1)); sys_exit(1); } @@ -2416,28 +2416,28 @@ void _start(void) { } if (sys_write(fd, out, (uint32_t)n) != n) { - sys_write(1, "[init] /disk/test write failed\n", - (uint32_t)(sizeof("[init] /disk/test write failed\n") - 1)); + sys_write(1, "[test] /disk/test write failed\n", + (uint32_t)(sizeof("[test] /disk/test write failed\n") - 1)); sys_exit(1); } (void)sys_close(fd); fd = sys_open("/disk/test", 0); if (fd < 0) { - sys_write(1, "[init] /disk/test open3 failed\n", - (uint32_t)(sizeof("[init] /disk/test open3 failed\n") - 1)); + sys_write(1, "[test] /disk/test open3 failed\n", + (uint32_t)(sizeof("[test] /disk/test open3 failed\n") - 1)); sys_exit(1); } for (uint32_t i = 0; i < (uint32_t)sizeof(buf); i++) buf[i] = 0; rd = sys_read(fd, buf, sizeof(buf)); (void)sys_close(fd); if (rd != n || !memeq(buf, out, (uint32_t)n)) { - sys_write(1, "[init] /disk/test verify failed\n", - (uint32_t)(sizeof("[init] /disk/test verify failed\n") - 1)); + sys_write(1, "[test] /disk/test verify failed\n", + (uint32_t)(sizeof("[test] /disk/test verify failed\n") - 1)); sys_exit(1); } - sys_write(1, "[init] /disk/test prev=", (uint32_t)(sizeof("[init] /disk/test prev=") - 1)); + sys_write(1, "[test] /disk/test prev=", (uint32_t)(sizeof("[test] /disk/test prev=") - 1)); write_int_dec(prev); sys_write(1, " next=", (uint32_t)(sizeof(" next=") - 1)); write_int_dec(next); @@ -2448,7 +2448,7 @@ void _start(void) { { int r = sys_mkdir("/disk/dir"); if (r < 0 && errno != 17) { - sys_write(1, "[init] mkdir /disk/dir failed errno=", (uint32_t)(sizeof("[init] mkdir /disk/dir failed errno=") - 1)); + sys_write(1, "[test] mkdir /disk/dir failed errno=", (uint32_t)(sizeof("[test] mkdir /disk/dir failed errno=") - 1)); write_int_dec(errno); sys_write(1, "\n", 1); sys_exit(1); @@ -2456,41 +2456,41 @@ void _start(void) { int fd = sys_open("/disk/dir/file", O_CREAT | O_TRUNC); if (fd < 0) { - sys_write(1, "[init] open /disk/dir/file failed\n", - (uint32_t)(sizeof("[init] open /disk/dir/file failed\n") - 1)); + sys_write(1, "[test] open /disk/dir/file failed\n", + (uint32_t)(sizeof("[test] open /disk/dir/file failed\n") - 1)); sys_exit(1); } static const char msg2[] = "ok"; if (sys_write(fd, msg2, 2) != 2) { - sys_write(1, "[init] write /disk/dir/file failed\n", - (uint32_t)(sizeof("[init] write /disk/dir/file failed\n") - 1)); + sys_write(1, "[test] write /disk/dir/file failed\n", + (uint32_t)(sizeof("[test] write /disk/dir/file failed\n") - 1)); sys_exit(1); } (void)sys_close(fd); r = sys_unlink("/disk/dir/file"); if (r < 0) { - sys_write(1, "[init] unlink /disk/dir/file failed\n", - (uint32_t)(sizeof("[init] unlink /disk/dir/file failed\n") - 1)); + sys_write(1, "[test] unlink /disk/dir/file failed\n", + (uint32_t)(sizeof("[test] unlink /disk/dir/file failed\n") - 1)); sys_exit(1); } fd = sys_open("/disk/dir/file", 0); if (fd >= 0) { - sys_write(1, "[init] unlink did not remove file\n", - (uint32_t)(sizeof("[init] unlink did not remove file\n") - 1)); + sys_write(1, "[test] unlink did not remove file\n", + (uint32_t)(sizeof("[test] unlink did not remove file\n") - 1)); sys_exit(1); } - sys_write(1, "[init] diskfs mkdir/unlink OK\n", - (uint32_t)(sizeof("[init] diskfs mkdir/unlink OK\n") - 1)); + sys_write(1, "[test] diskfs mkdir/unlink OK\n", + (uint32_t)(sizeof("[test] diskfs mkdir/unlink OK\n") - 1)); } // B4: diskfs getdents smoke { int r = sys_mkdir("/disk/ls"); if (r < 0 && errno != 17) { - sys_write(1, "[init] mkdir /disk/ls failed errno=", (uint32_t)(sizeof("[init] mkdir /disk/ls failed errno=") - 1)); + sys_write(1, "[test] mkdir /disk/ls failed errno=", (uint32_t)(sizeof("[test] mkdir /disk/ls failed errno=") - 1)); write_int_dec(errno); sys_write(1, "\n", 1); sys_exit(1); @@ -2498,24 +2498,24 @@ void _start(void) { int fd = sys_open("/disk/ls/file1", O_CREAT | O_TRUNC); if (fd < 0) { - sys_write(1, "[init] create /disk/ls/file1 failed\n", - (uint32_t)(sizeof("[init] create /disk/ls/file1 failed\n") - 1)); + sys_write(1, "[test] create /disk/ls/file1 failed\n", + (uint32_t)(sizeof("[test] create /disk/ls/file1 failed\n") - 1)); sys_exit(1); } (void)sys_close(fd); fd = sys_open("/disk/ls/file2", O_CREAT | O_TRUNC); if (fd < 0) { - sys_write(1, "[init] create /disk/ls/file2 failed\n", - (uint32_t)(sizeof("[init] create /disk/ls/file2 failed\n") - 1)); + sys_write(1, "[test] create /disk/ls/file2 failed\n", + (uint32_t)(sizeof("[test] create /disk/ls/file2 failed\n") - 1)); sys_exit(1); } (void)sys_close(fd); int dfd = sys_open("/disk/ls", 0); if (dfd < 0) { - sys_write(1, "[init] open dir /disk/ls failed\n", - (uint32_t)(sizeof("[init] open dir /disk/ls failed\n") - 1)); + sys_write(1, "[test] open dir /disk/ls failed\n", + (uint32_t)(sizeof("[test] open dir /disk/ls failed\n") - 1)); sys_exit(1); } @@ -2529,8 +2529,8 @@ void _start(void) { int n = sys_getdents(dfd, ents, (uint32_t)sizeof(ents)); (void)sys_close(dfd); if (n <= 0) { - sys_write(1, "[init] getdents failed\n", - (uint32_t)(sizeof("[init] getdents failed\n") - 1)); + sys_write(1, "[test] getdents failed\n", + (uint32_t)(sizeof("[test] getdents failed\n") - 1)); sys_exit(1); } @@ -2544,80 +2544,80 @@ void _start(void) { } if (!saw_dot || !saw_dotdot || !saw_f1 || !saw_f2) { - sys_write(1, "[init] getdents verify failed\n", - (uint32_t)(sizeof("[init] getdents verify failed\n") - 1)); + sys_write(1, "[test] getdents verify failed\n", + (uint32_t)(sizeof("[test] getdents verify failed\n") - 1)); sys_exit(1); } - sys_write(1, "[init] diskfs getdents OK\n", - (uint32_t)(sizeof("[init] diskfs getdents OK\n") - 1)); + sys_write(1, "[test] diskfs getdents OK\n", + (uint32_t)(sizeof("[test] diskfs getdents OK\n") - 1)); } // B5: isatty() POSIX-like smoke (via ioctl TCGETS) { int fd = sys_open("/dev/tty", 0); if (fd < 0) { - sys_write(1, "[init] isatty open /dev/tty failed\n", - (uint32_t)(sizeof("[init] isatty open /dev/tty failed\n") - 1)); + sys_write(1, "[test] isatty open /dev/tty failed\n", + (uint32_t)(sizeof("[test] isatty open /dev/tty failed\n") - 1)); sys_exit(1); } int r = isatty_fd(fd); (void)sys_close(fd); if (r != 1) { - sys_write(1, "[init] isatty(/dev/tty) failed\n", - (uint32_t)(sizeof("[init] isatty(/dev/tty) failed\n") - 1)); + sys_write(1, "[test] isatty(/dev/tty) failed\n", + (uint32_t)(sizeof("[test] isatty(/dev/tty) failed\n") - 1)); sys_exit(1); } fd = sys_open("/dev/null", 0); if (fd < 0) { - sys_write(1, "[init] isatty open /dev/null failed\n", - (uint32_t)(sizeof("[init] isatty open /dev/null failed\n") - 1)); + sys_write(1, "[test] isatty open /dev/null failed\n", + (uint32_t)(sizeof("[test] isatty open /dev/null failed\n") - 1)); sys_exit(1); } r = isatty_fd(fd); (void)sys_close(fd); if (r != 0) { - sys_write(1, "[init] isatty(/dev/null) expected 0\n", - (uint32_t)(sizeof("[init] isatty(/dev/null) expected 0\n") - 1)); + sys_write(1, "[test] isatty(/dev/null) expected 0\n", + (uint32_t)(sizeof("[test] isatty(/dev/null) expected 0\n") - 1)); sys_exit(1); } - sys_write(1, "[init] isatty OK\n", (uint32_t)(sizeof("[init] isatty OK\n") - 1)); + sys_write(1, "[test] isatty OK\n", (uint32_t)(sizeof("[test] isatty OK\n") - 1)); } // B6: O_NONBLOCK smoke (pipe + pty) { int fds[2]; if (sys_pipe(fds) < 0) { - sys_write(1, "[init] pipe for nonblock failed\n", - (uint32_t)(sizeof("[init] pipe for nonblock failed\n") - 1)); + sys_write(1, "[test] pipe for nonblock failed\n", + (uint32_t)(sizeof("[test] pipe for nonblock failed\n") - 1)); sys_exit(1); } if (sys_fcntl(fds[0], F_SETFL, O_NONBLOCK) < 0) { - sys_write(1, "[init] fcntl nonblock pipe failed\n", - (uint32_t)(sizeof("[init] fcntl nonblock pipe failed\n") - 1)); + sys_write(1, "[test] fcntl nonblock pipe failed\n", + (uint32_t)(sizeof("[test] fcntl nonblock pipe failed\n") - 1)); sys_exit(1); } char b; int r = sys_read(fds[0], &b, 1); if (r != -1 || errno != EAGAIN) { - sys_write(1, "[init] nonblock pipe read expected EAGAIN\n", - (uint32_t)(sizeof("[init] nonblock pipe read expected EAGAIN\n") - 1)); + sys_write(1, "[test] nonblock pipe read expected EAGAIN\n", + (uint32_t)(sizeof("[test] nonblock pipe read expected EAGAIN\n") - 1)); sys_exit(1); } if (sys_write(fds[1], "x", 1) != 1) { - sys_write(1, "[init] pipe write failed\n", - (uint32_t)(sizeof("[init] pipe write failed\n") - 1)); + sys_write(1, "[test] pipe write failed\n", + (uint32_t)(sizeof("[test] pipe write failed\n") - 1)); sys_exit(1); } r = sys_read(fds[0], &b, 1); if (r != 1 || b != 'x') { - sys_write(1, "[init] nonblock pipe read after write failed\n", - (uint32_t)(sizeof("[init] nonblock pipe read after write failed\n") - 1)); + sys_write(1, "[test] nonblock pipe read after write failed\n", + (uint32_t)(sizeof("[test] nonblock pipe read after write failed\n") - 1)); sys_exit(1); } @@ -2626,87 +2626,87 @@ void _start(void) { int p = sys_open("/dev/ptmx", 0); if (p < 0) { - sys_write(1, "[init] open /dev/ptmx failed\n", - (uint32_t)(sizeof("[init] open /dev/ptmx failed\n") - 1)); + sys_write(1, "[test] open /dev/ptmx failed\n", + (uint32_t)(sizeof("[test] open /dev/ptmx failed\n") - 1)); sys_exit(1); } if (sys_fcntl(p, F_SETFL, O_NONBLOCK) < 0) { - sys_write(1, "[init] fcntl nonblock ptmx failed\n", - (uint32_t)(sizeof("[init] fcntl nonblock ptmx failed\n") - 1)); + sys_write(1, "[test] fcntl nonblock ptmx failed\n", + (uint32_t)(sizeof("[test] fcntl nonblock ptmx failed\n") - 1)); sys_exit(1); } char pch; r = sys_read(p, &pch, 1); if (r != -1 || errno != EAGAIN) { - sys_write(1, "[init] nonblock ptmx read expected EAGAIN\n", - (uint32_t)(sizeof("[init] nonblock ptmx read expected EAGAIN\n") - 1)); + sys_write(1, "[test] nonblock ptmx read expected EAGAIN\n", + (uint32_t)(sizeof("[test] nonblock ptmx read expected EAGAIN\n") - 1)); sys_exit(1); } (void)sys_close(p); - sys_write(1, "[init] O_NONBLOCK OK\n", - (uint32_t)(sizeof("[init] O_NONBLOCK OK\n") - 1)); + sys_write(1, "[test] O_NONBLOCK OK\n", + (uint32_t)(sizeof("[test] O_NONBLOCK OK\n") - 1)); } // B6b: pipe2 + dup3 smoke { int fds[2]; if (sys_pipe2(fds, O_NONBLOCK) < 0) { - sys_write(1, "[init] pipe2 failed\n", - (uint32_t)(sizeof("[init] pipe2 failed\n") - 1)); + sys_write(1, "[test] pipe2 failed\n", + (uint32_t)(sizeof("[test] pipe2 failed\n") - 1)); sys_exit(1); } char b; int r = sys_read(fds[0], &b, 1); if (r != -1 || errno != EAGAIN) { - sys_write(1, "[init] pipe2 nonblock read expected EAGAIN\n", - (uint32_t)(sizeof("[init] pipe2 nonblock read expected EAGAIN\n") - 1)); + sys_write(1, "[test] pipe2 nonblock read expected EAGAIN\n", + (uint32_t)(sizeof("[test] pipe2 nonblock read expected EAGAIN\n") - 1)); sys_exit(1); } int d = sys_dup3(fds[0], fds[0], 0); if (d != -1 || errno != EINVAL) { - sys_write(1, "[init] dup3 samefd expected EINVAL\n", - (uint32_t)(sizeof("[init] dup3 samefd expected EINVAL\n") - 1)); + sys_write(1, "[test] dup3 samefd expected EINVAL\n", + (uint32_t)(sizeof("[test] dup3 samefd expected EINVAL\n") - 1)); sys_exit(1); } (void)sys_close(fds[0]); (void)sys_close(fds[1]); - sys_write(1, "[init] pipe2/dup3 OK\n", - (uint32_t)(sizeof("[init] pipe2/dup3 OK\n") - 1)); + sys_write(1, "[test] pipe2/dup3 OK\n", + (uint32_t)(sizeof("[test] pipe2/dup3 OK\n") - 1)); } // B7: chdir/getcwd smoke + relative paths { int r = sys_mkdir("/disk/cwd"); if (r < 0 && errno != 17) { - sys_write(1, "[init] mkdir /disk/cwd failed\n", - (uint32_t)(sizeof("[init] mkdir /disk/cwd failed\n") - 1)); + sys_write(1, "[test] mkdir /disk/cwd failed\n", + (uint32_t)(sizeof("[test] mkdir /disk/cwd failed\n") - 1)); sys_exit(1); } r = sys_chdir("/disk/cwd"); if (r < 0) { - sys_write(1, "[init] chdir failed\n", - (uint32_t)(sizeof("[init] chdir failed\n") - 1)); + sys_write(1, "[test] chdir failed\n", + (uint32_t)(sizeof("[test] chdir failed\n") - 1)); sys_exit(1); } char cwd[64]; for (uint32_t i = 0; i < (uint32_t)sizeof(cwd); i++) cwd[i] = 0; if (sys_getcwd(cwd, (uint32_t)sizeof(cwd)) < 0) { - sys_write(1, "[init] getcwd failed\n", - (uint32_t)(sizeof("[init] getcwd failed\n") - 1)); + sys_write(1, "[test] getcwd failed\n", + (uint32_t)(sizeof("[test] getcwd failed\n") - 1)); sys_exit(1); } // Create file using relative path. int fd = sys_open("rel", O_CREAT | O_TRUNC); if (fd < 0) { - sys_write(1, "[init] open relative failed\n", - (uint32_t)(sizeof("[init] open relative failed\n") - 1)); + sys_write(1, "[test] open relative failed\n", + (uint32_t)(sizeof("[test] open relative failed\n") - 1)); sys_exit(1); } (void)sys_close(fd); @@ -2714,46 +2714,46 @@ void _start(void) { // Stat with relative path. struct stat st; if (sys_stat("rel", &st) < 0) { - sys_write(1, "[init] stat relative failed\n", - (uint32_t)(sizeof("[init] stat relative failed\n") - 1)); + sys_write(1, "[test] stat relative failed\n", + (uint32_t)(sizeof("[test] stat relative failed\n") - 1)); sys_exit(1); } - sys_write(1, "[init] chdir/getcwd OK\n", - (uint32_t)(sizeof("[init] chdir/getcwd OK\n") - 1)); + sys_write(1, "[test] chdir/getcwd OK\n", + (uint32_t)(sizeof("[test] chdir/getcwd OK\n") - 1)); } // B8: *at() syscalls smoke (AT_FDCWD) { int fd = sys_openat(AT_FDCWD, "atfile", O_CREAT | O_TRUNC, 0); if (fd < 0) { - sys_write(1, "[init] openat failed\n", - (uint32_t)(sizeof("[init] openat failed\n") - 1)); + sys_write(1, "[test] openat failed\n", + (uint32_t)(sizeof("[test] openat failed\n") - 1)); sys_exit(1); } (void)sys_close(fd); struct stat st; if (sys_fstatat(AT_FDCWD, "atfile", &st, 0) < 0) { - sys_write(1, "[init] fstatat failed\n", - (uint32_t)(sizeof("[init] fstatat failed\n") - 1)); + sys_write(1, "[test] fstatat failed\n", + (uint32_t)(sizeof("[test] fstatat failed\n") - 1)); sys_exit(1); } if (sys_unlinkat(AT_FDCWD, "atfile", 0) < 0) { - sys_write(1, "[init] unlinkat failed\n", - (uint32_t)(sizeof("[init] unlinkat failed\n") - 1)); + sys_write(1, "[test] unlinkat failed\n", + (uint32_t)(sizeof("[test] unlinkat failed\n") - 1)); sys_exit(1); } if (sys_stat("atfile", &st) >= 0) { - sys_write(1, "[init] unlinkat did not remove file\n", - (uint32_t)(sizeof("[init] unlinkat did not remove file\n") - 1)); + sys_write(1, "[test] unlinkat did not remove file\n", + (uint32_t)(sizeof("[test] unlinkat did not remove file\n") - 1)); sys_exit(1); } - sys_write(1, "[init] *at OK\n", - (uint32_t)(sizeof("[init] *at OK\n") - 1)); + sys_write(1, "[test] *at OK\n", + (uint32_t)(sizeof("[test] *at OK\n") - 1)); } // B9: rename + rmdir smoke @@ -2761,28 +2761,28 @@ void _start(void) { // Create a file, rename it, verify old gone and new exists. int fd = sys_open("/disk/rnold", O_CREAT | O_TRUNC); if (fd < 0) { - sys_write(1, "[init] rename: create failed\n", - (uint32_t)(sizeof("[init] rename: create failed\n") - 1)); + sys_write(1, "[test] rename: create failed\n", + (uint32_t)(sizeof("[test] rename: create failed\n") - 1)); sys_exit(1); } (void)sys_write(fd, "RN", 2); (void)sys_close(fd); if (sys_rename("/disk/rnold", "/disk/rnnew") < 0) { - sys_write(1, "[init] rename failed\n", - (uint32_t)(sizeof("[init] rename failed\n") - 1)); + sys_write(1, "[test] rename failed\n", + (uint32_t)(sizeof("[test] rename failed\n") - 1)); sys_exit(1); } struct stat st; if (sys_stat("/disk/rnold", &st) >= 0) { - sys_write(1, "[init] rename: old still exists\n", - (uint32_t)(sizeof("[init] rename: old still exists\n") - 1)); + sys_write(1, "[test] rename: old still exists\n", + (uint32_t)(sizeof("[test] rename: old still exists\n") - 1)); sys_exit(1); } if (sys_stat("/disk/rnnew", &st) < 0) { - sys_write(1, "[init] rename: new not found\n", - (uint32_t)(sizeof("[init] rename: new not found\n") - 1)); + sys_write(1, "[test] rename: new not found\n", + (uint32_t)(sizeof("[test] rename: new not found\n") - 1)); sys_exit(1); } @@ -2790,80 +2790,80 @@ void _start(void) { // mkdir, then rmdir if (sys_mkdir("/disk/rmtmp") < 0 && errno != 17) { - sys_write(1, "[init] rmdir: mkdir failed\n", - (uint32_t)(sizeof("[init] rmdir: mkdir failed\n") - 1)); + sys_write(1, "[test] rmdir: mkdir failed\n", + (uint32_t)(sizeof("[test] rmdir: mkdir failed\n") - 1)); sys_exit(1); } if (sys_rmdir("/disk/rmtmp") < 0) { - sys_write(1, "[init] rmdir failed\n", - (uint32_t)(sizeof("[init] rmdir failed\n") - 1)); + sys_write(1, "[test] rmdir failed\n", + (uint32_t)(sizeof("[test] rmdir failed\n") - 1)); sys_exit(1); } if (sys_stat("/disk/rmtmp", &st) >= 0) { - sys_write(1, "[init] rmdir: dir still exists\n", - (uint32_t)(sizeof("[init] rmdir: dir still exists\n") - 1)); + sys_write(1, "[test] rmdir: dir still exists\n", + (uint32_t)(sizeof("[test] rmdir: dir still exists\n") - 1)); sys_exit(1); } - sys_write(1, "[init] rename/rmdir OK\n", - (uint32_t)(sizeof("[init] rename/rmdir OK\n") - 1)); + sys_write(1, "[test] rename/rmdir OK\n", + (uint32_t)(sizeof("[test] rename/rmdir OK\n") - 1)); } // B10: getdents on /dev (devfs) and /tmp (tmpfs) { int devfd = sys_open("/dev", 0); if (devfd < 0) { - sys_write(1, "[init] open /dev failed\n", - (uint32_t)(sizeof("[init] open /dev failed\n") - 1)); + sys_write(1, "[test] open /dev failed\n", + (uint32_t)(sizeof("[test] open /dev failed\n") - 1)); sys_exit(1); } char dbuf[256]; int dr = sys_getdents(devfd, dbuf, (uint32_t)sizeof(dbuf)); (void)sys_close(devfd); if (dr <= 0) { - sys_write(1, "[init] getdents /dev failed\n", - (uint32_t)(sizeof("[init] getdents /dev failed\n") - 1)); + sys_write(1, "[test] getdents /dev failed\n", + (uint32_t)(sizeof("[test] getdents /dev failed\n") - 1)); sys_exit(1); } int tmpfd = sys_open("/tmp", 0); if (tmpfd < 0) { - sys_write(1, "[init] open /tmp failed\n", - (uint32_t)(sizeof("[init] open /tmp failed\n") - 1)); + sys_write(1, "[test] open /tmp failed\n", + (uint32_t)(sizeof("[test] open /tmp failed\n") - 1)); sys_exit(1); } char tbuf[256]; int tr = sys_getdents(tmpfd, tbuf, (uint32_t)sizeof(tbuf)); (void)sys_close(tmpfd); if (tr <= 0) { - sys_write(1, "[init] getdents /tmp failed\n", - (uint32_t)(sizeof("[init] getdents /tmp failed\n") - 1)); + sys_write(1, "[test] getdents /tmp failed\n", + (uint32_t)(sizeof("[test] getdents /tmp failed\n") - 1)); sys_exit(1); } - sys_write(1, "[init] getdents multi-fs OK\n", - (uint32_t)(sizeof("[init] getdents multi-fs OK\n") - 1)); + sys_write(1, "[test] getdents multi-fs OK\n", + (uint32_t)(sizeof("[test] getdents multi-fs OK\n") - 1)); } // C1: brk (user heap growth) { uintptr_t cur = sys_brk(0); if (cur == 0) { - sys_write(1, "[init] brk(0) failed\n", (uint32_t)(sizeof("[init] brk(0) failed\n") - 1)); + sys_write(1, "[test] brk(0) failed\n", (uint32_t)(sizeof("[test] brk(0) failed\n") - 1)); sys_exit(1); } uintptr_t next = sys_brk(cur + 4096); if (next < cur + 4096) { - sys_write(1, "[init] brk grow failed\n", (uint32_t)(sizeof("[init] brk grow failed\n") - 1)); + sys_write(1, "[test] brk grow failed\n", (uint32_t)(sizeof("[test] brk grow failed\n") - 1)); sys_exit(1); } volatile uint32_t* p = (volatile uint32_t*)cur; *p = 0xDEADBEEF; if (*p != 0xDEADBEEF) { - sys_write(1, "[init] brk memory bad\n", (uint32_t)(sizeof("[init] brk memory bad\n") - 1)); + sys_write(1, "[test] brk memory bad\n", (uint32_t)(sizeof("[test] brk memory bad\n") - 1)); sys_exit(1); } - sys_write(1, "[init] brk OK\n", (uint32_t)(sizeof("[init] brk OK\n") - 1)); + sys_write(1, "[test] brk OK\n", (uint32_t)(sizeof("[test] brk OK\n") - 1)); } // C2: mmap/munmap (anonymous) @@ -2871,46 +2871,46 @@ void _start(void) { uintptr_t addr = sys_mmap(0, 4096, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1); if (addr == MAP_FAILED_VAL || addr == 0) { - sys_write(1, "[init] mmap failed\n", (uint32_t)(sizeof("[init] mmap failed\n") - 1)); + sys_write(1, "[test] mmap failed\n", (uint32_t)(sizeof("[test] mmap failed\n") - 1)); sys_exit(1); } volatile uint32_t* p = (volatile uint32_t*)addr; *p = 0xCAFEBABE; if (*p != 0xCAFEBABE) { - sys_write(1, "[init] mmap memory bad\n", (uint32_t)(sizeof("[init] mmap memory bad\n") - 1)); + sys_write(1, "[test] mmap memory bad\n", (uint32_t)(sizeof("[test] mmap memory bad\n") - 1)); sys_exit(1); } if (sys_munmap(addr, 4096) < 0) { - sys_write(1, "[init] munmap failed\n", (uint32_t)(sizeof("[init] munmap failed\n") - 1)); + sys_write(1, "[test] munmap failed\n", (uint32_t)(sizeof("[test] munmap failed\n") - 1)); sys_exit(1); } - sys_write(1, "[init] mmap/munmap OK\n", (uint32_t)(sizeof("[init] mmap/munmap OK\n") - 1)); + sys_write(1, "[test] mmap/munmap OK\n", (uint32_t)(sizeof("[test] mmap/munmap OK\n") - 1)); } // C3: clock_gettime (CLOCK_MONOTONIC) { struct timespec ts1, ts2; if (sys_clock_gettime(CLOCK_MONOTONIC, &ts1) < 0) { - sys_write(1, "[init] clock_gettime failed\n", (uint32_t)(sizeof("[init] clock_gettime failed\n") - 1)); + sys_write(1, "[test] clock_gettime failed\n", (uint32_t)(sizeof("[test] clock_gettime failed\n") - 1)); sys_exit(1); } for (volatile uint32_t i = 0; i < 500000U; i++) { } if (sys_clock_gettime(CLOCK_MONOTONIC, &ts2) < 0) { - sys_write(1, "[init] clock_gettime2 failed\n", (uint32_t)(sizeof("[init] clock_gettime2 failed\n") - 1)); + sys_write(1, "[test] clock_gettime2 failed\n", (uint32_t)(sizeof("[test] clock_gettime2 failed\n") - 1)); sys_exit(1); } if (ts2.tv_sec < ts1.tv_sec || (ts2.tv_sec == ts1.tv_sec && ts2.tv_nsec <= ts1.tv_nsec)) { - sys_write(1, "[init] clock_gettime not monotonic\n", (uint32_t)(sizeof("[init] clock_gettime not monotonic\n") - 1)); + sys_write(1, "[test] clock_gettime not monotonic\n", (uint32_t)(sizeof("[test] clock_gettime not monotonic\n") - 1)); sys_exit(1); } - sys_write(1, "[init] clock_gettime OK\n", (uint32_t)(sizeof("[init] clock_gettime OK\n") - 1)); + sys_write(1, "[test] clock_gettime OK\n", (uint32_t)(sizeof("[test] clock_gettime OK\n") - 1)); } // C4: /dev/zero read { int fd = sys_open("/dev/zero", 0); if (fd < 0) { - sys_write(1, "[init] /dev/zero open failed\n", (uint32_t)(sizeof("[init] /dev/zero open failed\n") - 1)); + sys_write(1, "[test] /dev/zero open failed\n", (uint32_t)(sizeof("[test] /dev/zero open failed\n") - 1)); sys_exit(1); } uint8_t zbuf[8]; @@ -2918,113 +2918,113 @@ void _start(void) { int r = sys_read(fd, zbuf, 8); (void)sys_close(fd); if (r != 8) { - sys_write(1, "[init] /dev/zero read failed\n", (uint32_t)(sizeof("[init] /dev/zero read failed\n") - 1)); + sys_write(1, "[test] /dev/zero read failed\n", (uint32_t)(sizeof("[test] /dev/zero read failed\n") - 1)); sys_exit(1); } int allz = 1; for (int i = 0; i < 8; i++) { if (zbuf[i] != 0) allz = 0; } if (!allz) { - sys_write(1, "[init] /dev/zero not zero\n", (uint32_t)(sizeof("[init] /dev/zero not zero\n") - 1)); + sys_write(1, "[test] /dev/zero not zero\n", (uint32_t)(sizeof("[test] /dev/zero not zero\n") - 1)); sys_exit(1); } - sys_write(1, "[init] /dev/zero OK\n", (uint32_t)(sizeof("[init] /dev/zero OK\n") - 1)); + sys_write(1, "[test] /dev/zero OK\n", (uint32_t)(sizeof("[test] /dev/zero OK\n") - 1)); } // C5: /dev/random read (just verify it returns data) { int fd = sys_open("/dev/random", 0); if (fd < 0) { - sys_write(1, "[init] /dev/random open failed\n", (uint32_t)(sizeof("[init] /dev/random open failed\n") - 1)); + sys_write(1, "[test] /dev/random open failed\n", (uint32_t)(sizeof("[test] /dev/random open failed\n") - 1)); sys_exit(1); } uint8_t rbuf[4]; int r = sys_read(fd, rbuf, 4); (void)sys_close(fd); if (r != 4) { - sys_write(1, "[init] /dev/random read failed\n", (uint32_t)(sizeof("[init] /dev/random read failed\n") - 1)); + sys_write(1, "[test] /dev/random read failed\n", (uint32_t)(sizeof("[test] /dev/random read failed\n") - 1)); sys_exit(1); } - sys_write(1, "[init] /dev/random OK\n", (uint32_t)(sizeof("[init] /dev/random OK\n") - 1)); + sys_write(1, "[test] /dev/random OK\n", (uint32_t)(sizeof("[test] /dev/random OK\n") - 1)); } // C6: procfs (/proc/meminfo) { int fd = sys_open("/proc/meminfo", 0); if (fd < 0) { - sys_write(1, "[init] /proc/meminfo open failed\n", (uint32_t)(sizeof("[init] /proc/meminfo open failed\n") - 1)); + sys_write(1, "[test] /proc/meminfo open failed\n", (uint32_t)(sizeof("[test] /proc/meminfo open failed\n") - 1)); sys_exit(1); } char pbuf[64]; int r = sys_read(fd, pbuf, 63); (void)sys_close(fd); if (r <= 0) { - sys_write(1, "[init] /proc/meminfo read failed\n", (uint32_t)(sizeof("[init] /proc/meminfo read failed\n") - 1)); + sys_write(1, "[test] /proc/meminfo read failed\n", (uint32_t)(sizeof("[test] /proc/meminfo read failed\n") - 1)); sys_exit(1); } - sys_write(1, "[init] procfs OK\n", (uint32_t)(sizeof("[init] procfs OK\n") - 1)); + sys_write(1, "[test] procfs OK\n", (uint32_t)(sizeof("[test] procfs OK\n") - 1)); } // C7: pread/pwrite (positional I/O) { int fd = sys_open("/disk/preadtest", O_CREAT | O_TRUNC); if (fd < 0) { - sys_write(1, "[init] pread test open failed\n", (uint32_t)(sizeof("[init] pread test open failed\n") - 1)); + sys_write(1, "[test] pread test open failed\n", (uint32_t)(sizeof("[test] pread test open failed\n") - 1)); sys_exit(1); } static const char pw[] = "ABCDEFGH"; if (sys_write(fd, pw, 8) != 8) { - sys_write(1, "[init] pread test write failed\n", (uint32_t)(sizeof("[init] pread test write failed\n") - 1)); + sys_write(1, "[test] pread test write failed\n", (uint32_t)(sizeof("[test] pread test write failed\n") - 1)); sys_exit(1); } char pb[4]; int r = sys_pread(fd, pb, 4, 2); if (r != 4 || pb[0] != 'C' || pb[1] != 'D' || pb[2] != 'E' || pb[3] != 'F') { - sys_write(1, "[init] pread data bad\n", (uint32_t)(sizeof("[init] pread data bad\n") - 1)); + sys_write(1, "[test] pread data bad\n", (uint32_t)(sizeof("[test] pread data bad\n") - 1)); sys_exit(1); } if (sys_pwrite(fd, "XY", 2, 1) != 2) { - sys_write(1, "[init] pwrite failed\n", (uint32_t)(sizeof("[init] pwrite failed\n") - 1)); + sys_write(1, "[test] pwrite failed\n", (uint32_t)(sizeof("[test] pwrite failed\n") - 1)); sys_exit(1); } r = sys_pread(fd, pb, 3, 0); if (r != 3 || pb[0] != 'A' || pb[1] != 'X' || pb[2] != 'Y') { - sys_write(1, "[init] pwrite verify bad\n", (uint32_t)(sizeof("[init] pwrite verify bad\n") - 1)); + sys_write(1, "[test] pwrite verify bad\n", (uint32_t)(sizeof("[test] pwrite verify bad\n") - 1)); sys_exit(1); } (void)sys_close(fd); (void)sys_unlink("/disk/preadtest"); - sys_write(1, "[init] pread/pwrite OK\n", (uint32_t)(sizeof("[init] pread/pwrite OK\n") - 1)); + sys_write(1, "[test] pread/pwrite OK\n", (uint32_t)(sizeof("[test] pread/pwrite OK\n") - 1)); } // C8: ftruncate { int fd = sys_open("/disk/trunctest", O_CREAT | O_TRUNC); if (fd < 0) { - sys_write(1, "[init] truncate open failed\n", (uint32_t)(sizeof("[init] truncate open failed\n") - 1)); + sys_write(1, "[test] truncate open failed\n", (uint32_t)(sizeof("[test] truncate open failed\n") - 1)); sys_exit(1); } if (sys_write(fd, "ABCDEFGHIJ", 10) != 10) { - sys_write(1, "[init] truncate write failed\n", (uint32_t)(sizeof("[init] truncate write failed\n") - 1)); + sys_write(1, "[test] truncate write failed\n", (uint32_t)(sizeof("[test] truncate write failed\n") - 1)); sys_exit(1); } if (sys_ftruncate(fd, 5) < 0) { - sys_write(1, "[init] ftruncate failed\n", (uint32_t)(sizeof("[init] ftruncate failed\n") - 1)); + sys_write(1, "[test] ftruncate failed\n", (uint32_t)(sizeof("[test] ftruncate failed\n") - 1)); sys_exit(1); } struct stat tst; if (sys_fstat(fd, &tst) < 0 || tst.st_size != 5) { - sys_write(1, "[init] ftruncate size bad\n", (uint32_t)(sizeof("[init] ftruncate size bad\n") - 1)); + sys_write(1, "[test] ftruncate size bad\n", (uint32_t)(sizeof("[test] ftruncate size bad\n") - 1)); sys_exit(1); } (void)sys_close(fd); (void)sys_unlink("/disk/trunctest"); - sys_write(1, "[init] ftruncate OK\n", (uint32_t)(sizeof("[init] ftruncate OK\n") - 1)); + sys_write(1, "[test] ftruncate OK\n", (uint32_t)(sizeof("[test] ftruncate OK\n") - 1)); } // C9: symlink/readlink (use existing /tmp/hello.txt as target) { if (sys_symlink("/tmp/hello.txt", "/tmp/symlink") < 0) { - sys_write(1, "[init] symlink failed\n", (uint32_t)(sizeof("[init] symlink failed\n") - 1)); + sys_write(1, "[test] symlink failed\n", (uint32_t)(sizeof("[test] symlink failed\n") - 1)); sys_exit(1); } @@ -3032,41 +3032,41 @@ void _start(void) { for (uint32_t i = 0; i < 64; i++) lbuf[i] = 0; int r = sys_readlink("/tmp/symlink", lbuf, 63); if (r <= 0) { - sys_write(1, "[init] readlink failed\n", (uint32_t)(sizeof("[init] readlink failed\n") - 1)); + sys_write(1, "[test] readlink failed\n", (uint32_t)(sizeof("[test] readlink failed\n") - 1)); sys_exit(1); } int fd = sys_open("/tmp/symlink", 0); if (fd < 0) { - sys_write(1, "[init] symlink follow failed\n", (uint32_t)(sizeof("[init] symlink follow failed\n") - 1)); + sys_write(1, "[test] symlink follow failed\n", (uint32_t)(sizeof("[test] symlink follow failed\n") - 1)); sys_exit(1); } char sb[6]; r = sys_read(fd, sb, 5); (void)sys_close(fd); if (r != 5 || sb[0] != 'h' || sb[1] != 'e' || sb[2] != 'l' || sb[3] != 'l' || sb[4] != 'o') { - sys_write(1, "[init] symlink data bad\n", (uint32_t)(sizeof("[init] symlink data bad\n") - 1)); + sys_write(1, "[test] symlink data bad\n", (uint32_t)(sizeof("[test] symlink data bad\n") - 1)); sys_exit(1); } (void)sys_unlink("/tmp/symlink"); - sys_write(1, "[init] symlink/readlink OK\n", (uint32_t)(sizeof("[init] symlink/readlink OK\n") - 1)); + sys_write(1, "[test] symlink/readlink OK\n", (uint32_t)(sizeof("[test] symlink/readlink OK\n") - 1)); } // C10: access { if (sys_access("/sbin/fulltest", F_OK) < 0) { - sys_write(1, "[init] access F_OK failed\n", (uint32_t)(sizeof("[init] access F_OK failed\n") - 1)); + sys_write(1, "[test] access F_OK failed\n", (uint32_t)(sizeof("[test] access F_OK failed\n") - 1)); sys_exit(1); } if (sys_access("/sbin/fulltest", R_OK) < 0) { - sys_write(1, "[init] access R_OK failed\n", (uint32_t)(sizeof("[init] access R_OK failed\n") - 1)); + sys_write(1, "[test] access R_OK failed\n", (uint32_t)(sizeof("[test] access R_OK failed\n") - 1)); sys_exit(1); } if (sys_access("/nonexistent", F_OK) >= 0) { - sys_write(1, "[init] access nonexist expected fail\n", (uint32_t)(sizeof("[init] access nonexist expected fail\n") - 1)); + sys_write(1, "[test] access nonexist expected fail\n", (uint32_t)(sizeof("[test] access nonexist expected fail\n") - 1)); sys_exit(1); } - sys_write(1, "[init] access OK\n", (uint32_t)(sizeof("[init] access OK\n") - 1)); + sys_write(1, "[test] access OK\n", (uint32_t)(sizeof("[test] access OK\n") - 1)); } // C11: sigprocmask/sigpending @@ -3074,7 +3074,7 @@ void _start(void) { uint32_t mask = (1U << SIGUSR1); uint32_t oldmask = 0; if (sys_sigprocmask(SIG_BLOCK, mask, &oldmask) < 0) { - sys_write(1, "[init] sigprocmask block failed\n", (uint32_t)(sizeof("[init] sigprocmask block failed\n") - 1)); + sys_write(1, "[test] sigprocmask block failed\n", (uint32_t)(sizeof("[test] sigprocmask block failed\n") - 1)); sys_exit(1); } int me = sys_getpid(); @@ -3082,18 +3082,18 @@ void _start(void) { uint32_t pending = 0; if (sys_sigpending(&pending) < 0) { - sys_write(1, "[init] sigpending failed\n", (uint32_t)(sizeof("[init] sigpending failed\n") - 1)); + sys_write(1, "[test] sigpending failed\n", (uint32_t)(sizeof("[test] sigpending failed\n") - 1)); sys_exit(1); } if (!(pending & (1U << SIGUSR1))) { - sys_write(1, "[init] sigpending SIGUSR1 not set\n", (uint32_t)(sizeof("[init] sigpending SIGUSR1 not set\n") - 1)); + sys_write(1, "[test] sigpending SIGUSR1 not set\n", (uint32_t)(sizeof("[test] sigpending SIGUSR1 not set\n") - 1)); sys_exit(1); } if (sys_sigprocmask(SIG_UNBLOCK, mask, 0) < 0) { - sys_write(1, "[init] sigprocmask unblock failed\n", (uint32_t)(sizeof("[init] sigprocmask unblock failed\n") - 1)); + sys_write(1, "[test] sigprocmask unblock failed\n", (uint32_t)(sizeof("[test] sigprocmask unblock failed\n") - 1)); sys_exit(1); } - sys_write(1, "[init] sigprocmask/sigpending OK\n", (uint32_t)(sizeof("[init] sigprocmask/sigpending OK\n") - 1)); + sys_write(1, "[test] sigprocmask/sigpending OK\n", (uint32_t)(sizeof("[test] sigprocmask/sigpending OK\n") - 1)); } // C12: alarm/SIGALRM @@ -3109,42 +3109,42 @@ void _start(void) { (void)sys_nanosleep(&_ts, 0); } if (!got_alrm) { - sys_write(1, "[init] alarm/SIGALRM not delivered\n", (uint32_t)(sizeof("[init] alarm/SIGALRM not delivered\n") - 1)); + sys_write(1, "[test] alarm/SIGALRM not delivered\n", (uint32_t)(sizeof("[test] alarm/SIGALRM not delivered\n") - 1)); sys_exit(1); } - sys_write(1, "[init] alarm/SIGALRM OK\n", (uint32_t)(sizeof("[init] alarm/SIGALRM OK\n") - 1)); + sys_write(1, "[test] alarm/SIGALRM OK\n", (uint32_t)(sizeof("[test] alarm/SIGALRM OK\n") - 1)); } // C13: shmget/shmat/shmdt (shared memory) { int shmid = sys_shmget(IPC_PRIVATE, 4096, IPC_CREAT | 0666); if (shmid < 0) { - sys_write(1, "[init] shmget failed\n", (uint32_t)(sizeof("[init] shmget failed\n") - 1)); + sys_write(1, "[test] shmget failed\n", (uint32_t)(sizeof("[test] shmget failed\n") - 1)); sys_exit(1); } uintptr_t addr = sys_shmat(shmid, 0, 0); if (addr == MAP_FAILED_VAL || addr == 0) { - sys_write(1, "[init] shmat failed\n", (uint32_t)(sizeof("[init] shmat failed\n") - 1)); + sys_write(1, "[test] shmat failed\n", (uint32_t)(sizeof("[test] shmat failed\n") - 1)); sys_exit(1); } volatile uint32_t* sp = (volatile uint32_t*)addr; *sp = 0x12345678; if (*sp != 0x12345678) { - sys_write(1, "[init] shm memory bad\n", (uint32_t)(sizeof("[init] shm memory bad\n") - 1)); + sys_write(1, "[test] shm memory bad\n", (uint32_t)(sizeof("[test] shm memory bad\n") - 1)); sys_exit(1); } if (sys_shmdt(addr) < 0) { - sys_write(1, "[init] shmdt failed\n", (uint32_t)(sizeof("[init] shmdt failed\n") - 1)); + sys_write(1, "[test] shmdt failed\n", (uint32_t)(sizeof("[test] shmdt failed\n") - 1)); sys_exit(1); } - sys_write(1, "[init] shmget/shmat/shmdt OK\n", (uint32_t)(sizeof("[init] shmget/shmat/shmdt OK\n") - 1)); + sys_write(1, "[test] shmget/shmat/shmdt OK\n", (uint32_t)(sizeof("[test] shmget/shmat/shmdt OK\n") - 1)); } // C14: O_APPEND { int fd = sys_open("/disk/appendtest", O_CREAT | O_TRUNC); if (fd < 0) { - sys_write(1, "[init] O_APPEND create failed\n", (uint32_t)(sizeof("[init] O_APPEND create failed\n") - 1)); + sys_write(1, "[test] O_APPEND create failed\n", (uint32_t)(sizeof("[test] O_APPEND create failed\n") - 1)); sys_exit(1); } (void)sys_write(fd, "AAA", 3); @@ -3152,7 +3152,7 @@ void _start(void) { fd = sys_open("/disk/appendtest", O_APPEND); if (fd < 0) { - sys_write(1, "[init] O_APPEND open failed\n", (uint32_t)(sizeof("[init] O_APPEND open failed\n") - 1)); + sys_write(1, "[test] O_APPEND open failed\n", (uint32_t)(sizeof("[test] O_APPEND open failed\n") - 1)); sys_exit(1); } (void)sys_write(fd, "BBB", 3); @@ -3160,7 +3160,7 @@ void _start(void) { fd = sys_open("/disk/appendtest", 0); if (fd < 0) { - sys_write(1, "[init] O_APPEND verify open failed\n", (uint32_t)(sizeof("[init] O_APPEND verify open failed\n") - 1)); + sys_write(1, "[test] O_APPEND verify open failed\n", (uint32_t)(sizeof("[test] O_APPEND verify open failed\n") - 1)); sys_exit(1); } char abuf[8]; @@ -3168,10 +3168,10 @@ void _start(void) { (void)sys_close(fd); (void)sys_unlink("/disk/appendtest"); if (r != 6 || abuf[0] != 'A' || abuf[3] != 'B') { - sys_write(1, "[init] O_APPEND data bad\n", (uint32_t)(sizeof("[init] O_APPEND data bad\n") - 1)); + sys_write(1, "[test] O_APPEND data bad\n", (uint32_t)(sizeof("[test] O_APPEND data bad\n") - 1)); sys_exit(1); } - sys_write(1, "[init] O_APPEND OK\n", (uint32_t)(sizeof("[init] O_APPEND OK\n") - 1)); + sys_write(1, "[test] O_APPEND OK\n", (uint32_t)(sizeof("[test] O_APPEND OK\n") - 1)); } // C15b: umask @@ -3179,37 +3179,37 @@ void _start(void) { int old = sys_umask(0077); int cur = sys_umask((uint32_t)old); if (cur != 0077) { - sys_write(1, "[init] umask set/get failed\n", (uint32_t)(sizeof("[init] umask set/get failed\n") - 1)); + sys_write(1, "[test] umask set/get failed\n", (uint32_t)(sizeof("[test] umask set/get failed\n") - 1)); sys_exit(1); } - sys_write(1, "[init] umask OK\n", (uint32_t)(sizeof("[init] umask OK\n") - 1)); + sys_write(1, "[test] umask OK\n", (uint32_t)(sizeof("[test] umask OK\n") - 1)); } // C16: F_GETPIPE_SZ / F_SETPIPE_SZ { int fds[2]; if (sys_pipe(fds) < 0) { - sys_write(1, "[init] pipe for pipesz failed\n", (uint32_t)(sizeof("[init] pipe for pipesz failed\n") - 1)); + sys_write(1, "[test] pipe for pipesz failed\n", (uint32_t)(sizeof("[test] pipe for pipesz failed\n") - 1)); sys_exit(1); } int sz = sys_fcntl(fds[0], F_GETPIPE_SZ, 0); if (sz <= 0) { - sys_write(1, "[init] F_GETPIPE_SZ failed\n", (uint32_t)(sizeof("[init] F_GETPIPE_SZ failed\n") - 1)); + sys_write(1, "[test] F_GETPIPE_SZ failed\n", (uint32_t)(sizeof("[test] F_GETPIPE_SZ failed\n") - 1)); sys_exit(1); } int nsz = sys_fcntl(fds[0], F_SETPIPE_SZ, 8192); if (nsz < 0) { - sys_write(1, "[init] F_SETPIPE_SZ failed\n", (uint32_t)(sizeof("[init] F_SETPIPE_SZ failed\n") - 1)); + sys_write(1, "[test] F_SETPIPE_SZ failed\n", (uint32_t)(sizeof("[test] F_SETPIPE_SZ failed\n") - 1)); sys_exit(1); } int sz2 = sys_fcntl(fds[0], F_GETPIPE_SZ, 0); if (sz2 < 8192) { - sys_write(1, "[init] F_GETPIPE_SZ after set bad\n", (uint32_t)(sizeof("[init] F_GETPIPE_SZ after set bad\n") - 1)); + sys_write(1, "[test] F_GETPIPE_SZ after set bad\n", (uint32_t)(sizeof("[test] F_GETPIPE_SZ after set bad\n") - 1)); sys_exit(1); } (void)sys_close(fds[0]); (void)sys_close(fds[1]); - sys_write(1, "[init] pipe capacity OK\n", (uint32_t)(sizeof("[init] pipe capacity OK\n") - 1)); + sys_write(1, "[test] pipe capacity OK\n", (uint32_t)(sizeof("[test] pipe capacity OK\n") - 1)); } // C17: waitid (P_PID, WEXITED) @@ -3219,17 +3219,17 @@ void _start(void) { sys_exit(99); } if (pid < 0) { - sys_write(1, "[init] waitid fork failed\n", (uint32_t)(sizeof("[init] waitid fork failed\n") - 1)); + sys_write(1, "[test] waitid fork failed\n", (uint32_t)(sizeof("[test] waitid fork failed\n") - 1)); sys_exit(1); } uint8_t infobuf[128]; for (uint32_t i = 0; i < 128; i++) infobuf[i] = 0; int r = sys_waitid(P_PID, (uint32_t)pid, infobuf, WEXITED); if (r < 0) { - sys_write(1, "[init] waitid failed\n", (uint32_t)(sizeof("[init] waitid failed\n") - 1)); + sys_write(1, "[test] waitid failed\n", (uint32_t)(sizeof("[test] waitid failed\n") - 1)); sys_exit(1); } - sys_write(1, "[init] waitid OK\n", (uint32_t)(sizeof("[init] waitid OK\n") - 1)); + sys_write(1, "[test] waitid OK\n", (uint32_t)(sizeof("[test] waitid OK\n") - 1)); } // C18: setitimer/getitimer (ITIMER_REAL) @@ -3241,12 +3241,12 @@ void _start(void) { itv.it_interval.tv_usec = 0; struct itimerval old; if (sys_setitimer(ITIMER_REAL, &itv, &old) < 0) { - sys_write(1, "[init] setitimer failed\n", (uint32_t)(sizeof("[init] setitimer failed\n") - 1)); + sys_write(1, "[test] setitimer failed\n", (uint32_t)(sizeof("[test] setitimer failed\n") - 1)); sys_exit(1); } struct itimerval cur; if (sys_getitimer(ITIMER_REAL, &cur) < 0) { - sys_write(1, "[init] getitimer failed\n", (uint32_t)(sizeof("[init] getitimer failed\n") - 1)); + sys_write(1, "[test] getitimer failed\n", (uint32_t)(sizeof("[test] getitimer failed\n") - 1)); sys_exit(1); } itv.it_value.tv_sec = 0; @@ -3254,31 +3254,31 @@ void _start(void) { itv.it_interval.tv_sec = 0; itv.it_interval.tv_usec = 0; (void)sys_setitimer(ITIMER_REAL, &itv, 0); - sys_write(1, "[init] setitimer/getitimer OK\n", (uint32_t)(sizeof("[init] setitimer/getitimer OK\n") - 1)); + sys_write(1, "[test] setitimer/getitimer OK\n", (uint32_t)(sizeof("[test] setitimer/getitimer OK\n") - 1)); } // C19: select on regular file (should return immediately readable) { int fd = sys_open("/sbin/fulltest", 0); if (fd < 0) { - sys_write(1, "[init] select regfile open failed\n", (uint32_t)(sizeof("[init] select regfile open failed\n") - 1)); + sys_write(1, "[test] select regfile open failed\n", (uint32_t)(sizeof("[test] select regfile open failed\n") - 1)); sys_exit(1); } uint64_t readfds = (1ULL << (uint32_t)fd); int r = sys_select((uint32_t)(fd + 1), &readfds, 0, 0, 0); (void)sys_close(fd); if (r < 0) { - sys_write(1, "[init] select regfile failed\n", (uint32_t)(sizeof("[init] select regfile failed\n") - 1)); + sys_write(1, "[test] select regfile failed\n", (uint32_t)(sizeof("[test] select regfile failed\n") - 1)); sys_exit(1); } - sys_write(1, "[init] select regfile OK\n", (uint32_t)(sizeof("[init] select regfile OK\n") - 1)); + sys_write(1, "[test] select regfile OK\n", (uint32_t)(sizeof("[test] select regfile OK\n") - 1)); } // C20: poll on regular file { int fd = sys_open("/sbin/fulltest", 0); if (fd < 0) { - sys_write(1, "[init] poll regfile open failed\n", (uint32_t)(sizeof("[init] poll regfile open failed\n") - 1)); + sys_write(1, "[test] poll regfile open failed\n", (uint32_t)(sizeof("[test] poll regfile open failed\n") - 1)); sys_exit(1); } struct pollfd pfd; @@ -3288,14 +3288,14 @@ void _start(void) { int r = sys_poll(&pfd, 1, 0); (void)sys_close(fd); if (r < 0) { - sys_write(1, "[init] poll regfile failed\n", (uint32_t)(sizeof("[init] poll regfile failed\n") - 1)); + sys_write(1, "[test] poll regfile failed\n", (uint32_t)(sizeof("[test] poll regfile failed\n") - 1)); sys_exit(1); } if (!(pfd.revents & POLLIN)) { - sys_write(1, "[init] poll regfile no POLLIN\n", (uint32_t)(sizeof("[init] poll regfile no POLLIN\n") - 1)); + sys_write(1, "[test] poll regfile no POLLIN\n", (uint32_t)(sizeof("[test] poll regfile no POLLIN\n") - 1)); sys_exit(1); } - sys_write(1, "[init] poll regfile OK\n", (uint32_t)(sizeof("[init] poll regfile OK\n") - 1)); + sys_write(1, "[test] poll regfile OK\n", (uint32_t)(sizeof("[test] poll regfile OK\n") - 1)); } // C21: hard link (skip gracefully if FS doesn't support it) @@ -3312,20 +3312,20 @@ void _start(void) { int r = sys_read(fd, lbuf2, 3); (void)sys_close(fd); if (r == 3 && lbuf2[0] == 'L' && lbuf2[1] == 'N' && lbuf2[2] == 'K') { - sys_write(1, "[init] hard link OK\n", (uint32_t)(sizeof("[init] hard link OK\n") - 1)); + sys_write(1, "[test] hard link OK\n", (uint32_t)(sizeof("[test] hard link OK\n") - 1)); } else { - sys_write(1, "[init] hard link OK\n", (uint32_t)(sizeof("[init] hard link OK\n") - 1)); + sys_write(1, "[test] hard link OK\n", (uint32_t)(sizeof("[test] hard link OK\n") - 1)); } } else { - sys_write(1, "[init] hard link OK\n", (uint32_t)(sizeof("[init] hard link OK\n") - 1)); + sys_write(1, "[test] hard link OK\n", (uint32_t)(sizeof("[test] hard link OK\n") - 1)); } (void)sys_unlink("/disk/linkhard"); } else { - sys_write(1, "[init] hard link OK\n", (uint32_t)(sizeof("[init] hard link OK\n") - 1)); + sys_write(1, "[test] hard link OK\n", (uint32_t)(sizeof("[test] hard link OK\n") - 1)); } (void)sys_unlink("/disk/linkoriginal"); } else { - sys_write(1, "[init] hard link OK\n", (uint32_t)(sizeof("[init] hard link OK\n") - 1)); + sys_write(1, "[test] hard link OK\n", (uint32_t)(sizeof("[test] hard link OK\n") - 1)); } } @@ -3333,13 +3333,13 @@ void _start(void) { { int epfd = sys_epoll_create(1); if (epfd < 0) { - sys_write(1, "[init] epoll_create failed\n", (uint32_t)(sizeof("[init] epoll_create failed\n") - 1)); + sys_write(1, "[test] epoll_create failed\n", (uint32_t)(sizeof("[test] epoll_create failed\n") - 1)); sys_exit(1); } int fds[2]; if (sys_pipe(fds) < 0) { - sys_write(1, "[init] epoll pipe failed\n", (uint32_t)(sizeof("[init] epoll pipe failed\n") - 1)); + sys_write(1, "[test] epoll pipe failed\n", (uint32_t)(sizeof("[test] epoll pipe failed\n") - 1)); sys_exit(1); } @@ -3347,14 +3347,14 @@ void _start(void) { ev.events = POLLIN; ev.data = (uint32_t)fds[0]; if (sys_epoll_ctl(epfd, 1, fds[0], &ev) < 0) { - sys_write(1, "[init] epoll_ctl ADD failed\n", (uint32_t)(sizeof("[init] epoll_ctl ADD failed\n") - 1)); + sys_write(1, "[test] epoll_ctl ADD failed\n", (uint32_t)(sizeof("[test] epoll_ctl ADD failed\n") - 1)); sys_exit(1); } struct { uint32_t events; uint32_t data; } out; int n = sys_epoll_wait(epfd, &out, 1, 0); if (n != 0) { - sys_write(1, "[init] epoll_wait expected 0\n", (uint32_t)(sizeof("[init] epoll_wait expected 0\n") - 1)); + sys_write(1, "[test] epoll_wait expected 0\n", (uint32_t)(sizeof("[test] epoll_wait expected 0\n") - 1)); sys_exit(1); } @@ -3362,27 +3362,27 @@ void _start(void) { n = sys_epoll_wait(epfd, &out, 1, 0); if (n != 1 || !(out.events & POLLIN)) { - sys_write(1, "[init] epoll_wait expected POLLIN\n", (uint32_t)(sizeof("[init] epoll_wait expected POLLIN\n") - 1)); + sys_write(1, "[test] epoll_wait expected POLLIN\n", (uint32_t)(sizeof("[test] epoll_wait expected POLLIN\n") - 1)); sys_exit(1); } (void)sys_close(fds[0]); (void)sys_close(fds[1]); (void)sys_close(epfd); - sys_write(1, "[init] epoll OK\n", (uint32_t)(sizeof("[init] epoll OK\n") - 1)); + sys_write(1, "[test] epoll OK\n", (uint32_t)(sizeof("[test] epoll OK\n") - 1)); } // C22b: EPOLLET edge-triggered mode { int epfd = sys_epoll_create(1); if (epfd < 0) { - sys_write(1, "[init] epollet create failed\n", (uint32_t)(sizeof("[init] epollet create failed\n") - 1)); + sys_write(1, "[test] epollet create failed\n", (uint32_t)(sizeof("[test] epollet create failed\n") - 1)); sys_exit(1); } int fds[2]; if (sys_pipe(fds) < 0) { - sys_write(1, "[init] epollet pipe failed\n", (uint32_t)(sizeof("[init] epollet pipe failed\n") - 1)); + sys_write(1, "[test] epollet pipe failed\n", (uint32_t)(sizeof("[test] epollet pipe failed\n") - 1)); sys_exit(1); } @@ -3390,7 +3390,7 @@ void _start(void) { ev.events = POLLIN | EPOLLET; ev.data = 42; if (sys_epoll_ctl(epfd, 1, fds[0], &ev) < 0) { - sys_write(1, "[init] epollet ctl failed\n", (uint32_t)(sizeof("[init] epollet ctl failed\n") - 1)); + sys_write(1, "[test] epollet ctl failed\n", (uint32_t)(sizeof("[test] epollet ctl failed\n") - 1)); sys_exit(1); } @@ -3399,13 +3399,13 @@ void _start(void) { struct { uint32_t events; uint32_t data; } out; int n = sys_epoll_wait(epfd, &out, 1, 0); if (n != 1 || !(out.events & POLLIN)) { - sys_write(1, "[init] epollet first wait failed\n", (uint32_t)(sizeof("[init] epollet first wait failed\n") - 1)); + sys_write(1, "[test] epollet first wait failed\n", (uint32_t)(sizeof("[test] epollet first wait failed\n") - 1)); sys_exit(1); } n = sys_epoll_wait(epfd, &out, 1, 0); if (n != 0) { - sys_write(1, "[init] epollet second wait should be 0\n", (uint32_t)(sizeof("[init] epollet second wait should be 0\n") - 1)); + sys_write(1, "[test] epollet second wait should be 0\n", (uint32_t)(sizeof("[test] epollet second wait should be 0\n") - 1)); sys_exit(1); } @@ -3414,7 +3414,7 @@ void _start(void) { n = sys_epoll_wait(epfd, &out, 1, 0); if (n != 0) { - sys_write(1, "[init] epollet post-drain should be 0\n", (uint32_t)(sizeof("[init] epollet post-drain should be 0\n") - 1)); + sys_write(1, "[test] epollet post-drain should be 0\n", (uint32_t)(sizeof("[test] epollet post-drain should be 0\n") - 1)); sys_exit(1); } @@ -3422,44 +3422,44 @@ void _start(void) { n = sys_epoll_wait(epfd, &out, 1, 0); if (n != 1 || !(out.events & POLLIN)) { - sys_write(1, "[init] epollet re-arm failed\n", (uint32_t)(sizeof("[init] epollet re-arm failed\n") - 1)); + sys_write(1, "[test] epollet re-arm failed\n", (uint32_t)(sizeof("[test] epollet re-arm failed\n") - 1)); sys_exit(1); } (void)sys_close(fds[0]); (void)sys_close(fds[1]); (void)sys_close(epfd); - sys_write(1, "[init] epollet OK\n", (uint32_t)(sizeof("[init] epollet OK\n") - 1)); + sys_write(1, "[test] epollet OK\n", (uint32_t)(sizeof("[test] epollet OK\n") - 1)); } // C23: inotify_init/add_watch/rm_watch smoke { int ifd = sys_inotify_init(); if (ifd < 0) { - sys_write(1, "[init] inotify_init failed\n", (uint32_t)(sizeof("[init] inotify_init failed\n") - 1)); + sys_write(1, "[test] inotify_init failed\n", (uint32_t)(sizeof("[test] inotify_init failed\n") - 1)); sys_exit(1); } int wd = sys_inotify_add_watch(ifd, "/tmp", 0x100); if (wd < 0) { - sys_write(1, "[init] inotify_add_watch failed\n", (uint32_t)(sizeof("[init] inotify_add_watch failed\n") - 1)); + sys_write(1, "[test] inotify_add_watch failed\n", (uint32_t)(sizeof("[test] inotify_add_watch failed\n") - 1)); sys_exit(1); } if (sys_inotify_rm_watch(ifd, wd) < 0) { - sys_write(1, "[init] inotify_rm_watch failed\n", (uint32_t)(sizeof("[init] inotify_rm_watch failed\n") - 1)); + sys_write(1, "[test] inotify_rm_watch failed\n", (uint32_t)(sizeof("[test] inotify_rm_watch failed\n") - 1)); sys_exit(1); } (void)sys_close(ifd); - sys_write(1, "[init] inotify OK\n", (uint32_t)(sizeof("[init] inotify OK\n") - 1)); + sys_write(1, "[test] inotify OK\n", (uint32_t)(sizeof("[test] inotify OK\n") - 1)); } // C24: aio_read/aio_write smoke { int fd = sys_open("/disk/aiotest", O_CREAT | O_TRUNC); if (fd < 0) { - sys_write(1, "[init] aio open failed\n", (uint32_t)(sizeof("[init] aio open failed\n") - 1)); + sys_write(1, "[test] aio open failed\n", (uint32_t)(sizeof("[test] aio open failed\n") - 1)); sys_exit(1); } @@ -3472,15 +3472,15 @@ void _start(void) { wcb.aio_error = -1; wcb.aio_return = -1; if (sys_aio_write(&wcb) < 0) { - sys_write(1, "[init] aio_write failed\n", (uint32_t)(sizeof("[init] aio_write failed\n") - 1)); + sys_write(1, "[test] aio_write failed\n", (uint32_t)(sizeof("[test] aio_write failed\n") - 1)); sys_exit(1); } if (sys_aio_error(&wcb) != 0) { - sys_write(1, "[init] aio_error after write bad\n", (uint32_t)(sizeof("[init] aio_error after write bad\n") - 1)); + sys_write(1, "[test] aio_error after write bad\n", (uint32_t)(sizeof("[test] aio_error after write bad\n") - 1)); sys_exit(1); } if (sys_aio_return(&wcb) != 4) { - sys_write(1, "[init] aio_return after write bad\n", (uint32_t)(sizeof("[init] aio_return after write bad\n") - 1)); + sys_write(1, "[test] aio_return after write bad\n", (uint32_t)(sizeof("[test] aio_return after write bad\n") - 1)); sys_exit(1); } @@ -3493,21 +3493,21 @@ void _start(void) { rcb.aio_error = -1; rcb.aio_return = -1; if (sys_aio_read(&rcb) < 0) { - sys_write(1, "[init] aio_read failed\n", (uint32_t)(sizeof("[init] aio_read failed\n") - 1)); + sys_write(1, "[test] aio_read failed\n", (uint32_t)(sizeof("[test] aio_read failed\n") - 1)); sys_exit(1); } if (sys_aio_error(&rcb) != 0 || sys_aio_return(&rcb) != 4) { - sys_write(1, "[init] aio_read result bad\n", (uint32_t)(sizeof("[init] aio_read result bad\n") - 1)); + sys_write(1, "[test] aio_read result bad\n", (uint32_t)(sizeof("[test] aio_read result bad\n") - 1)); sys_exit(1); } if (rbuf[0] != 'A' || rbuf[1] != 'I' || rbuf[2] != 'O' || rbuf[3] != '!') { - sys_write(1, "[init] aio_read data bad\n", (uint32_t)(sizeof("[init] aio_read data bad\n") - 1)); + sys_write(1, "[test] aio_read data bad\n", (uint32_t)(sizeof("[test] aio_read data bad\n") - 1)); sys_exit(1); } (void)sys_close(fd); (void)sys_unlink("/disk/aiotest"); - sys_write(1, "[init] aio OK\n", (uint32_t)(sizeof("[init] aio OK\n") - 1)); + sys_write(1, "[test] aio OK\n", (uint32_t)(sizeof("[test] aio OK\n") - 1)); } // D1: nanosleep @@ -3520,64 +3520,64 @@ void _start(void) { int r = sys_nanosleep(&req, 0); (void)sys_clock_gettime(CLOCK_MONOTONIC, &ts2); if (r < 0) { - sys_write(1, "[init] nanosleep failed\n", (uint32_t)(sizeof("[init] nanosleep failed\n") - 1)); + sys_write(1, "[test] nanosleep failed\n", (uint32_t)(sizeof("[test] nanosleep failed\n") - 1)); sys_exit(1); } uint32_t elapsed_ms = (ts2.tv_sec - ts1.tv_sec) * 1000 + (ts2.tv_nsec / 1000000) - (ts1.tv_nsec / 1000000); if (elapsed_ms < 10) { - sys_write(1, "[init] nanosleep too short\n", (uint32_t)(sizeof("[init] nanosleep too short\n") - 1)); + sys_write(1, "[test] nanosleep too short\n", (uint32_t)(sizeof("[test] nanosleep too short\n") - 1)); sys_exit(1); } - sys_write(1, "[init] nanosleep OK\n", (uint32_t)(sizeof("[init] nanosleep OK\n") - 1)); + sys_write(1, "[test] nanosleep OK\n", (uint32_t)(sizeof("[test] nanosleep OK\n") - 1)); } // D2: CLOCK_REALTIME (should return nonzero epoch timestamp) { struct timespec rt; if (sys_clock_gettime(CLOCK_REALTIME, &rt) < 0) { - sys_write(1, "[init] CLOCK_REALTIME failed\n", (uint32_t)(sizeof("[init] CLOCK_REALTIME failed\n") - 1)); + sys_write(1, "[test] CLOCK_REALTIME failed\n", (uint32_t)(sizeof("[test] CLOCK_REALTIME failed\n") - 1)); sys_exit(1); } if (rt.tv_sec == 0) { - sys_write(1, "[init] CLOCK_REALTIME sec=0\n", (uint32_t)(sizeof("[init] CLOCK_REALTIME sec=0\n") - 1)); + sys_write(1, "[test] CLOCK_REALTIME sec=0\n", (uint32_t)(sizeof("[test] CLOCK_REALTIME sec=0\n") - 1)); sys_exit(1); } - sys_write(1, "[init] CLOCK_REALTIME OK\n", (uint32_t)(sizeof("[init] CLOCK_REALTIME OK\n") - 1)); + sys_write(1, "[test] CLOCK_REALTIME OK\n", (uint32_t)(sizeof("[test] CLOCK_REALTIME OK\n") - 1)); } // D3: /dev/urandom read { int fd = sys_open("/dev/urandom", 0); if (fd < 0) { - sys_write(1, "[init] /dev/urandom open failed\n", (uint32_t)(sizeof("[init] /dev/urandom open failed\n") - 1)); + sys_write(1, "[test] /dev/urandom open failed\n", (uint32_t)(sizeof("[test] /dev/urandom open failed\n") - 1)); sys_exit(1); } uint8_t ubuf[4]; int r = sys_read(fd, ubuf, 4); (void)sys_close(fd); if (r != 4) { - sys_write(1, "[init] /dev/urandom read failed\n", (uint32_t)(sizeof("[init] /dev/urandom read failed\n") - 1)); + sys_write(1, "[test] /dev/urandom read failed\n", (uint32_t)(sizeof("[test] /dev/urandom read failed\n") - 1)); sys_exit(1); } - sys_write(1, "[init] /dev/urandom OK\n", (uint32_t)(sizeof("[init] /dev/urandom OK\n") - 1)); + sys_write(1, "[test] /dev/urandom OK\n", (uint32_t)(sizeof("[test] /dev/urandom OK\n") - 1)); } // D4: /proc/cmdline read { int fd = sys_open("/proc/cmdline", 0); if (fd < 0) { - sys_write(1, "[init] /proc/cmdline open failed\n", (uint32_t)(sizeof("[init] /proc/cmdline open failed\n") - 1)); + sys_write(1, "[test] /proc/cmdline open failed\n", (uint32_t)(sizeof("[test] /proc/cmdline open failed\n") - 1)); sys_exit(1); } char cbuf[64]; int r = sys_read(fd, cbuf, 63); (void)sys_close(fd); if (r <= 0) { - sys_write(1, "[init] /proc/cmdline read failed\n", (uint32_t)(sizeof("[init] /proc/cmdline read failed\n") - 1)); + sys_write(1, "[test] /proc/cmdline read failed\n", (uint32_t)(sizeof("[test] /proc/cmdline read failed\n") - 1)); sys_exit(1); } - sys_write(1, "[init] /proc/cmdline OK\n", (uint32_t)(sizeof("[init] /proc/cmdline OK\n") - 1)); + sys_write(1, "[test] /proc/cmdline OK\n", (uint32_t)(sizeof("[test] /proc/cmdline OK\n") - 1)); } // D5: CoW fork (child writes to page, parent sees original) @@ -3585,7 +3585,7 @@ void _start(void) { volatile uint32_t cow_val = 0xAAAAAAAAU; int pid = sys_fork(); if (pid < 0) { - sys_write(1, "[init] CoW fork failed\n", (uint32_t)(sizeof("[init] CoW fork failed\n") - 1)); + sys_write(1, "[test] CoW fork failed\n", (uint32_t)(sizeof("[test] CoW fork failed\n") - 1)); sys_exit(1); } if (pid == 0) { @@ -3596,17 +3596,17 @@ void _start(void) { int st = 0; (void)sys_waitpid(pid, &st, 0); if (st != 0 || cow_val != 0xAAAAAAAAU) { - sys_write(1, "[init] CoW fork data corrupted\n", (uint32_t)(sizeof("[init] CoW fork data corrupted\n") - 1)); + sys_write(1, "[test] CoW fork data corrupted\n", (uint32_t)(sizeof("[test] CoW fork data corrupted\n") - 1)); sys_exit(1); } - sys_write(1, "[init] CoW fork OK\n", (uint32_t)(sizeof("[init] CoW fork OK\n") - 1)); + sys_write(1, "[test] CoW fork OK\n", (uint32_t)(sizeof("[test] CoW fork OK\n") - 1)); } // D6: readv/writev { int fds[2]; if (sys_pipe(fds) < 0) { - sys_write(1, "[init] readv/writev pipe failed\n", (uint32_t)(sizeof("[init] readv/writev pipe failed\n") - 1)); + sys_write(1, "[test] readv/writev pipe failed\n", (uint32_t)(sizeof("[test] readv/writev pipe failed\n") - 1)); sys_exit(1); } char a[] = "HE"; @@ -3618,7 +3618,7 @@ void _start(void) { wv[1].iov_len = 3; int w = sys_writev(fds[1], wv, 2); if (w != 5) { - sys_write(1, "[init] writev failed\n", (uint32_t)(sizeof("[init] writev failed\n") - 1)); + sys_write(1, "[test] writev failed\n", (uint32_t)(sizeof("[test] writev failed\n") - 1)); sys_exit(1); } char r1[3], r2[2]; @@ -3631,34 +3631,34 @@ void _start(void) { (void)sys_close(fds[0]); (void)sys_close(fds[1]); if (r != 5 || r1[0] != 'H' || r1[1] != 'E' || r1[2] != 'L' || r2[0] != 'L' || r2[1] != 'O') { - sys_write(1, "[init] readv data bad\n", (uint32_t)(sizeof("[init] readv data bad\n") - 1)); + sys_write(1, "[test] readv data bad\n", (uint32_t)(sizeof("[test] readv data bad\n") - 1)); sys_exit(1); } - sys_write(1, "[init] readv/writev OK\n", (uint32_t)(sizeof("[init] readv/writev OK\n") - 1)); + sys_write(1, "[test] readv/writev OK\n", (uint32_t)(sizeof("[test] readv/writev OK\n") - 1)); } // D7: fsync { int fd = sys_open("/disk/fsynctest", O_CREAT | O_TRUNC); if (fd < 0) { - sys_write(1, "[init] fsync open failed\n", (uint32_t)(sizeof("[init] fsync open failed\n") - 1)); + sys_write(1, "[test] fsync open failed\n", (uint32_t)(sizeof("[test] fsync open failed\n") - 1)); sys_exit(1); } (void)sys_write(fd, "FS", 2); if (sys_fsync(fd) < 0) { - sys_write(1, "[init] fsync failed\n", (uint32_t)(sizeof("[init] fsync failed\n") - 1)); + sys_write(1, "[test] fsync failed\n", (uint32_t)(sizeof("[test] fsync failed\n") - 1)); sys_exit(1); } (void)sys_close(fd); (void)sys_unlink("/disk/fsynctest"); - sys_write(1, "[init] fsync OK\n", (uint32_t)(sizeof("[init] fsync OK\n") - 1)); + sys_write(1, "[test] fsync OK\n", (uint32_t)(sizeof("[test] fsync OK\n") - 1)); } // D8: truncate (path-based) { int fd = sys_open("/disk/truncpath", O_CREAT | O_TRUNC); if (fd < 0) { - sys_write(1, "[init] truncate open failed\n", (uint32_t)(sizeof("[init] truncate open failed\n") - 1)); + sys_write(1, "[test] truncate open failed\n", (uint32_t)(sizeof("[test] truncate open failed\n") - 1)); sys_exit(1); } (void)sys_write(fd, "1234567890", 10); @@ -3666,10 +3666,10 @@ void _start(void) { int r = sys_truncate("/disk/truncpath", 3); (void)sys_unlink("/disk/truncpath"); if (r < 0) { - sys_write(1, "[init] truncate failed\n", (uint32_t)(sizeof("[init] truncate failed\n") - 1)); + sys_write(1, "[test] truncate failed\n", (uint32_t)(sizeof("[test] truncate failed\n") - 1)); sys_exit(1); } - sys_write(1, "[init] truncate OK\n", (uint32_t)(sizeof("[init] truncate OK\n") - 1)); + sys_write(1, "[test] truncate OK\n", (uint32_t)(sizeof("[test] truncate OK\n") - 1)); } // D9: getuid/getgid/geteuid/getegid @@ -3679,10 +3679,10 @@ void _start(void) { uint32_t euid = sys_geteuid(); uint32_t egid = sys_getegid(); if (uid != euid || gid != egid) { - sys_write(1, "[init] uid/euid mismatch\n", (uint32_t)(sizeof("[init] uid/euid mismatch\n") - 1)); + sys_write(1, "[test] uid/euid mismatch\n", (uint32_t)(sizeof("[test] uid/euid mismatch\n") - 1)); sys_exit(1); } - sys_write(1, "[init] getuid/getgid OK\n", (uint32_t)(sizeof("[init] getuid/getgid OK\n") - 1)); + sys_write(1, "[test] getuid/getgid OK\n", (uint32_t)(sizeof("[test] getuid/getgid OK\n") - 1)); } // D10: chmod @@ -3693,31 +3693,31 @@ void _start(void) { int r = sys_chmod("/disk/chmodtest", 0755); (void)sys_unlink("/disk/chmodtest"); if (r < 0) { - sys_write(1, "[init] chmod failed\n", (uint32_t)(sizeof("[init] chmod failed\n") - 1)); + sys_write(1, "[test] chmod failed\n", (uint32_t)(sizeof("[test] chmod failed\n") - 1)); sys_exit(1); } } - sys_write(1, "[init] chmod OK\n", (uint32_t)(sizeof("[init] chmod OK\n") - 1)); + sys_write(1, "[test] chmod OK\n", (uint32_t)(sizeof("[test] chmod OK\n") - 1)); } // D11: flock (LOCK_EX=2, LOCK_UN=8) { int fd = sys_open("/disk/flocktest", O_CREAT | O_TRUNC); if (fd < 0) { - sys_write(1, "[init] flock open failed\n", (uint32_t)(sizeof("[init] flock open failed\n") - 1)); + sys_write(1, "[test] flock open failed\n", (uint32_t)(sizeof("[test] flock open failed\n") - 1)); sys_exit(1); } if (sys_flock(fd, 2) < 0) { - sys_write(1, "[init] flock LOCK_EX failed\n", (uint32_t)(sizeof("[init] flock LOCK_EX failed\n") - 1)); + sys_write(1, "[test] flock LOCK_EX failed\n", (uint32_t)(sizeof("[test] flock LOCK_EX failed\n") - 1)); sys_exit(1); } if (sys_flock(fd, 8) < 0) { - sys_write(1, "[init] flock LOCK_UN failed\n", (uint32_t)(sizeof("[init] flock LOCK_UN failed\n") - 1)); + sys_write(1, "[test] flock LOCK_UN failed\n", (uint32_t)(sizeof("[test] flock LOCK_UN failed\n") - 1)); sys_exit(1); } (void)sys_close(fd); (void)sys_unlink("/disk/flocktest"); - sys_write(1, "[init] flock OK\n", (uint32_t)(sizeof("[init] flock OK\n") - 1)); + sys_write(1, "[test] flock OK\n", (uint32_t)(sizeof("[test] flock OK\n") - 1)); } // D12: times @@ -3725,10 +3725,10 @@ void _start(void) { struct { uint32_t utime; uint32_t stime; uint32_t cutime; uint32_t cstime; } tms; uint32_t clk = sys_times(&tms); if (clk == 0) { - sys_write(1, "[init] times returned 0\n", (uint32_t)(sizeof("[init] times returned 0\n") - 1)); + sys_write(1, "[test] times returned 0\n", (uint32_t)(sizeof("[test] times returned 0\n") - 1)); sys_exit(1); } - sys_write(1, "[init] times OK\n", (uint32_t)(sizeof("[init] times OK\n") - 1)); + sys_write(1, "[test] times OK\n", (uint32_t)(sizeof("[test] times OK\n") - 1)); } // D13: gettid (should equal getpid for main thread) @@ -3736,10 +3736,10 @@ void _start(void) { int pid = sys_getpid(); int tid = sys_gettid(); if (tid != pid) { - sys_write(1, "[init] gettid != getpid\n", (uint32_t)(sizeof("[init] gettid != getpid\n") - 1)); + sys_write(1, "[test] gettid != getpid\n", (uint32_t)(sizeof("[test] gettid != getpid\n") - 1)); sys_exit(1); } - sys_write(1, "[init] gettid OK\n", (uint32_t)(sizeof("[init] gettid OK\n") - 1)); + sys_write(1, "[test] gettid OK\n", (uint32_t)(sizeof("[test] gettid OK\n") - 1)); } // D14: posix_spawn (spawn echo.elf and wait for it) @@ -3756,11 +3756,11 @@ void _start(void) { sys_exit(0); /* we are the un-exec'd child, exit silently */ } if (r < 0 || child_pid == 0) { - sys_write(1, "[init] posix_spawn OK\n", (uint32_t)(sizeof("[init] posix_spawn OK\n") - 1)); + sys_write(1, "[test] posix_spawn OK\n", (uint32_t)(sizeof("[test] posix_spawn OK\n") - 1)); } else { int st = 0; (void)sys_waitpid((int)child_pid, &st, 0); - sys_write(1, "[init] posix_spawn OK\n", (uint32_t)(sizeof("[init] posix_spawn OK\n") - 1)); + sys_write(1, "[test] posix_spawn OK\n", (uint32_t)(sizeof("[test] posix_spawn OK\n") - 1)); } } @@ -3777,9 +3777,9 @@ void _start(void) { dns = (1000000000U - ta.tv_nsec) + tb.tv_nsec; } if (dns > 0 && dns < 10000000) { - sys_write(1, "[init] clock_ns precision OK\n", (uint32_t)(sizeof("[init] clock_ns precision OK\n") - 1)); + sys_write(1, "[test] clock_ns precision OK\n", (uint32_t)(sizeof("[test] clock_ns precision OK\n") - 1)); } else { - sys_write(1, "[init] clock_ns precision OK\n", (uint32_t)(sizeof("[init] clock_ns precision OK\n") - 1)); + sys_write(1, "[test] clock_ns precision OK\n", (uint32_t)(sizeof("[test] clock_ns precision OK\n") - 1)); } } @@ -3807,17 +3807,17 @@ void _start(void) { int st = 0; (void)sys_waitpid(pid, &st, 0); if (st == 0) { - static const char m[] = "[init] setuid/setgid OK\n"; + static const char m[] = "[test] setuid/setgid OK\n"; (void)sys_write(1, m, (uint32_t)(sizeof(m) - 1)); } else { - sys_write(1, "[init] setuid/setgid failed st=", (uint32_t)(sizeof("[init] setuid/setgid failed st=") - 1)); + sys_write(1, "[test] setuid/setgid failed st=", (uint32_t)(sizeof("[test] setuid/setgid failed st=") - 1)); write_int_dec(st); sys_write(1, "\n", 1); sys_exit(1); } } } else { - static const char m[] = "[init] setuid/setgid OK\n"; + static const char m[] = "[test] setuid/setgid OK\n"; (void)sys_write(1, m, (uint32_t)(sizeof(m) - 1)); } (void)orig_gid; @@ -3827,27 +3827,27 @@ void _start(void) { { int pfds[2]; if (sys_pipe(pfds) < 0) { - sys_write(1, "[init] fcntl pipe failed\n", (uint32_t)(sizeof("[init] fcntl pipe failed\n") - 1)); + sys_write(1, "[test] fcntl pipe failed\n", (uint32_t)(sizeof("[test] fcntl pipe failed\n") - 1)); sys_exit(1); } int fl = sys_fcntl(pfds[0], F_GETFL, 0); if (fl < 0) { - sys_write(1, "[init] fcntl F_GETFL failed\n", (uint32_t)(sizeof("[init] fcntl F_GETFL failed\n") - 1)); + sys_write(1, "[test] fcntl F_GETFL failed\n", (uint32_t)(sizeof("[test] fcntl F_GETFL failed\n") - 1)); sys_exit(1); } // Set O_NONBLOCK if (sys_fcntl(pfds[0], F_SETFL, (uint32_t)fl | O_NONBLOCK) < 0) { - sys_write(1, "[init] fcntl F_SETFL failed\n", (uint32_t)(sizeof("[init] fcntl F_SETFL failed\n") - 1)); + sys_write(1, "[test] fcntl F_SETFL failed\n", (uint32_t)(sizeof("[test] fcntl F_SETFL failed\n") - 1)); sys_exit(1); } int fl2 = sys_fcntl(pfds[0], F_GETFL, 0); if (!(fl2 & (int)O_NONBLOCK)) { - sys_write(1, "[init] fcntl NONBLOCK not set\n", (uint32_t)(sizeof("[init] fcntl NONBLOCK not set\n") - 1)); + sys_write(1, "[test] fcntl NONBLOCK not set\n", (uint32_t)(sizeof("[test] fcntl NONBLOCK not set\n") - 1)); sys_exit(1); } (void)sys_close(pfds[0]); (void)sys_close(pfds[1]); - static const char m[] = "[init] fcntl F_GETFL/F_SETFL OK\n"; + static const char m[] = "[test] fcntl F_GETFL/F_SETFL OK\n"; (void)sys_write(1, m, (uint32_t)(sizeof(m) - 1)); } @@ -3855,25 +3855,25 @@ void _start(void) { { int fd = sys_open("/sbin/fulltest", 0); if (fd < 0) { - sys_write(1, "[init] fcntl cloexec open failed\n", (uint32_t)(sizeof("[init] fcntl cloexec open failed\n") - 1)); + sys_write(1, "[test] fcntl cloexec open failed\n", (uint32_t)(sizeof("[test] fcntl cloexec open failed\n") - 1)); sys_exit(1); } int cloexec = sys_fcntl(fd, F_GETFD, 0); if (cloexec < 0) { - sys_write(1, "[init] fcntl F_GETFD failed\n", (uint32_t)(sizeof("[init] fcntl F_GETFD failed\n") - 1)); + sys_write(1, "[test] fcntl F_GETFD failed\n", (uint32_t)(sizeof("[test] fcntl F_GETFD failed\n") - 1)); sys_exit(1); } if (sys_fcntl(fd, F_SETFD, FD_CLOEXEC) < 0) { - sys_write(1, "[init] fcntl F_SETFD failed\n", (uint32_t)(sizeof("[init] fcntl F_SETFD failed\n") - 1)); + sys_write(1, "[test] fcntl F_SETFD failed\n", (uint32_t)(sizeof("[test] fcntl F_SETFD failed\n") - 1)); sys_exit(1); } int cloexec2 = sys_fcntl(fd, F_GETFD, 0); if (!(cloexec2 & FD_CLOEXEC)) { - sys_write(1, "[init] fcntl CLOEXEC not set\n", (uint32_t)(sizeof("[init] fcntl CLOEXEC not set\n") - 1)); + sys_write(1, "[test] fcntl CLOEXEC not set\n", (uint32_t)(sizeof("[test] fcntl CLOEXEC not set\n") - 1)); sys_exit(1); } (void)sys_close(fd); - static const char m[] = "[init] fcntl FD_CLOEXEC OK\n"; + static const char m[] = "[test] fcntl FD_CLOEXEC OK\n"; (void)sys_write(1, m, (uint32_t)(sizeof(m) - 1)); } @@ -3908,10 +3908,10 @@ void _start(void) { int st = 0; (void)sys_waitpid(pid, &st, 0); if (st == 0) { - static const char m[] = "[init] sigsuspend OK\n"; + static const char m[] = "[test] sigsuspend OK\n"; (void)sys_write(1, m, (uint32_t)(sizeof(m) - 1)); } else { - sys_write(1, "[init] sigsuspend failed\n", (uint32_t)(sizeof("[init] sigsuspend failed\n") - 1)); + sys_write(1, "[test] sigsuspend failed\n", (uint32_t)(sizeof("[test] sigsuspend failed\n") - 1)); sys_exit(1); } } @@ -3951,11 +3951,11 @@ void _start(void) { (void)sys_nanosleep(&ts, 0); } if (found) { - static const char m[] = "[init] orphan reparent OK\n"; + static const char m[] = "[test] orphan reparent OK\n"; (void)sys_write(1, m, (uint32_t)(sizeof(m) - 1)); } else { - sys_write(1, "[init] orphan reparent failed\n", - (uint32_t)(sizeof("[init] orphan reparent failed\n") - 1)); + sys_write(1, "[test] orphan reparent failed\n", + (uint32_t)(sizeof("[test] orphan reparent failed\n") - 1)); } } @@ -3984,20 +3984,20 @@ void _start(void) { int fd = sys_open(ppath, 0); if (fd < 0) { - sys_write(1, "[init] /proc/PID/cmdline open failed\n", - (uint32_t)(sizeof("[init] /proc/PID/cmdline open failed\n") - 1)); + sys_write(1, "[test] /proc/PID/cmdline open failed\n", + (uint32_t)(sizeof("[test] /proc/PID/cmdline open failed\n") - 1)); sys_exit(1); } char clbuf[64]; int r = sys_read(fd, clbuf, 63); (void)sys_close(fd); if (r <= 0) { - sys_write(1, "[init] /proc/PID/cmdline read failed\n", - (uint32_t)(sizeof("[init] /proc/PID/cmdline read failed\n") - 1)); + sys_write(1, "[test] /proc/PID/cmdline read failed\n", + (uint32_t)(sizeof("[test] /proc/PID/cmdline read failed\n") - 1)); sys_exit(1); } - sys_write(1, "[init] /proc/PID/cmdline OK\n", - (uint32_t)(sizeof("[init] /proc/PID/cmdline OK\n") - 1)); + sys_write(1, "[test] /proc/PID/cmdline OK\n", + (uint32_t)(sizeof("[test] /proc/PID/cmdline OK\n") - 1)); } // F2: /proc/self/status (verify PID-specific procfs status) @@ -4022,40 +4022,40 @@ void _start(void) { int fd = sys_open(ppath, 0); if (fd < 0) { - sys_write(1, "[init] /proc/PID/status open failed\n", - (uint32_t)(sizeof("[init] /proc/PID/status open failed\n") - 1)); + sys_write(1, "[test] /proc/PID/status open failed\n", + (uint32_t)(sizeof("[test] /proc/PID/status open failed\n") - 1)); sys_exit(1); } char sbuf[128]; int r = sys_read(fd, sbuf, 127); (void)sys_close(fd); if (r <= 0) { - sys_write(1, "[init] /proc/PID/status read failed\n", - (uint32_t)(sizeof("[init] /proc/PID/status read failed\n") - 1)); + sys_write(1, "[test] /proc/PID/status read failed\n", + (uint32_t)(sizeof("[test] /proc/PID/status read failed\n") - 1)); sys_exit(1); } - sys_write(1, "[init] /proc/PID/status OK\n", - (uint32_t)(sizeof("[init] /proc/PID/status OK\n") - 1)); + sys_write(1, "[test] /proc/PID/status OK\n", + (uint32_t)(sizeof("[test] /proc/PID/status OK\n") - 1)); } // F3: /dev/console write test { int fd = sys_open("/dev/console", O_RDWR); if (fd >= 0) { - static const char cm[] = "[init] console test\n"; + static const char cm[] = "[test] console test\n"; int w = sys_write(fd, cm, (uint32_t)(sizeof(cm) - 1)); (void)sys_close(fd); if (w > 0) { - sys_write(1, "[init] /dev/console OK\n", - (uint32_t)(sizeof("[init] /dev/console OK\n") - 1)); + sys_write(1, "[test] /dev/console OK\n", + (uint32_t)(sizeof("[test] /dev/console OK\n") - 1)); } else { - sys_write(1, "[init] /dev/console OK\n", - (uint32_t)(sizeof("[init] /dev/console OK\n") - 1)); + sys_write(1, "[test] /dev/console OK\n", + (uint32_t)(sizeof("[test] /dev/console OK\n") - 1)); } } else { /* /dev/console may not exist on serial-only boot — skip gracefully */ - sys_write(1, "[init] /dev/console OK\n", - (uint32_t)(sizeof("[init] /dev/console OK\n") - 1)); + sys_write(1, "[test] /dev/console OK\n", + (uint32_t)(sizeof("[test] /dev/console OK\n") - 1)); } } @@ -4071,8 +4071,8 @@ void _start(void) { if (s1 >= 0) (void)sys_close(s1); if (m2 >= 0) (void)sys_close(m2); if (s2 >= 0) (void)sys_close(s2); - sys_write(1, "[init] multi-pty OK\n", - (uint32_t)(sizeof("[init] multi-pty OK\n") - 1)); + sys_write(1, "[test] multi-pty OK\n", + (uint32_t)(sizeof("[test] multi-pty OK\n") - 1)); } else { /* Write through pair 1 */ (void)sys_write(m1, "P1", 2); @@ -4090,11 +4090,11 @@ void _start(void) { (void)sys_close(s2); if (r1 == 2 && r2 == 2 && b1[0] == 'P' && b1[1] == '1' && b2[0] == 'P' && b2[1] == '2') { - sys_write(1, "[init] multi-pty OK\n", - (uint32_t)(sizeof("[init] multi-pty OK\n") - 1)); + sys_write(1, "[test] multi-pty OK\n", + (uint32_t)(sizeof("[test] multi-pty OK\n") - 1)); } else { - sys_write(1, "[init] multi-pty data mismatch\n", - (uint32_t)(sizeof("[init] multi-pty data mismatch\n") - 1)); + sys_write(1, "[test] multi-pty data mismatch\n", + (uint32_t)(sizeof("[test] multi-pty data mismatch\n") - 1)); sys_exit(1); } } @@ -4104,14 +4104,14 @@ void _start(void) { { int fds[2]; if (sys_pipe(fds) < 0) { - sys_write(1, "[init] dup pipe failed\n", - (uint32_t)(sizeof("[init] dup pipe failed\n") - 1)); + sys_write(1, "[test] dup pipe failed\n", + (uint32_t)(sizeof("[test] dup pipe failed\n") - 1)); sys_exit(1); } int d = sys_dup(fds[1]); if (d < 0) { - sys_write(1, "[init] dup failed\n", - (uint32_t)(sizeof("[init] dup failed\n") - 1)); + sys_write(1, "[test] dup failed\n", + (uint32_t)(sizeof("[test] dup failed\n") - 1)); sys_exit(1); } /* Write through dup'd fd, read from original */ @@ -4122,20 +4122,20 @@ void _start(void) { (void)sys_close(fds[0]); (void)sys_close(fds[1]); if (r != 1 || db != 'D') { - sys_write(1, "[init] dup data bad\n", - (uint32_t)(sizeof("[init] dup data bad\n") - 1)); + sys_write(1, "[test] dup data bad\n", + (uint32_t)(sizeof("[test] dup data bad\n") - 1)); sys_exit(1); } - sys_write(1, "[init] dup OK\n", - (uint32_t)(sizeof("[init] dup OK\n") - 1)); + sys_write(1, "[test] dup OK\n", + (uint32_t)(sizeof("[test] dup OK\n") - 1)); } // F6: pipe EOF — close write end, read should return 0 { int fds[2]; if (sys_pipe(fds) < 0) { - sys_write(1, "[init] pipe-eof pipe failed\n", - (uint32_t)(sizeof("[init] pipe-eof pipe failed\n") - 1)); + sys_write(1, "[test] pipe-eof pipe failed\n", + (uint32_t)(sizeof("[test] pipe-eof pipe failed\n") - 1)); sys_exit(1); } (void)sys_close(fds[1]); /* close write end */ @@ -4143,52 +4143,52 @@ void _start(void) { int r = sys_read(fds[0], &eb, 1); (void)sys_close(fds[0]); if (r != 0) { - sys_write(1, "[init] pipe EOF expected 0\n", - (uint32_t)(sizeof("[init] pipe EOF expected 0\n") - 1)); + sys_write(1, "[test] pipe EOF expected 0\n", + (uint32_t)(sizeof("[test] pipe EOF expected 0\n") - 1)); sys_exit(1); } - sys_write(1, "[init] pipe EOF OK\n", - (uint32_t)(sizeof("[init] pipe EOF OK\n") - 1)); + sys_write(1, "[test] pipe EOF OK\n", + (uint32_t)(sizeof("[test] pipe EOF OK\n") - 1)); } // F7: getdents /proc (readdir on procfs root) { int fd = sys_open("/proc", 0); if (fd < 0) { - sys_write(1, "[init] readdir /proc open failed\n", - (uint32_t)(sizeof("[init] readdir /proc open failed\n") - 1)); + sys_write(1, "[test] readdir /proc open failed\n", + (uint32_t)(sizeof("[test] readdir /proc open failed\n") - 1)); sys_exit(1); } char dbuf[512]; int r = sys_getdents(fd, dbuf, 512); (void)sys_close(fd); if (r <= 0) { - sys_write(1, "[init] readdir /proc empty\n", - (uint32_t)(sizeof("[init] readdir /proc empty\n") - 1)); + sys_write(1, "[test] readdir /proc empty\n", + (uint32_t)(sizeof("[test] readdir /proc empty\n") - 1)); sys_exit(1); } - sys_write(1, "[init] readdir /proc OK\n", - (uint32_t)(sizeof("[init] readdir /proc OK\n") - 1)); + sys_write(1, "[test] readdir /proc OK\n", + (uint32_t)(sizeof("[test] readdir /proc OK\n") - 1)); } // F8: getdents /bin (readdir on initrd — tests initrd_readdir fix) { int fd = sys_open("/bin", 0); if (fd < 0) { - sys_write(1, "[init] readdir /bin open failed\n", - (uint32_t)(sizeof("[init] readdir /bin open failed\n") - 1)); + sys_write(1, "[test] readdir /bin open failed\n", + (uint32_t)(sizeof("[test] readdir /bin open failed\n") - 1)); sys_exit(1); } char dbuf[1024]; int r = sys_getdents(fd, dbuf, 1024); (void)sys_close(fd); if (r <= 0) { - sys_write(1, "[init] readdir /bin empty\n", - (uint32_t)(sizeof("[init] readdir /bin empty\n") - 1)); + sys_write(1, "[test] readdir /bin empty\n", + (uint32_t)(sizeof("[test] readdir /bin empty\n") - 1)); sys_exit(1); } - sys_write(1, "[init] readdir /bin OK\n", - (uint32_t)(sizeof("[init] readdir /bin OK\n") - 1)); + sys_write(1, "[test] readdir /bin OK\n", + (uint32_t)(sizeof("[test] readdir /bin OK\n") - 1)); } enum { NCHILD = 100 }; @@ -4196,7 +4196,7 @@ void _start(void) { for (int i = 0; i < NCHILD; i++) { int pid = sys_fork(); if (pid < 0) { - static const char smsg[] = "[init] fork failed\n"; + static const char smsg[] = "[test] fork failed\n"; (void)sys_write(1, smsg, (uint32_t)(sizeof(smsg) - 1)); sys_exit(2); } @@ -4212,11 +4212,11 @@ void _start(void) { if (pid == 0) { int ppid = sys_getppid(); if (ppid == parent_pid) { - static const char msg[] = "[init] getppid OK\n"; + static const char msg[] = "[test] getppid OK\n"; (void)sys_write(1, msg, (uint32_t)(sizeof(msg) - 1)); sys_exit(0); } - static const char msg[] = "[init] getppid failed\n"; + static const char msg[] = "[test] getppid failed\n"; (void)sys_write(1, msg, (uint32_t)(sizeof(msg) - 1)); sys_exit(1); } @@ -4234,10 +4234,10 @@ void _start(void) { int st = 0; int wp = sys_waitpid(pid, &st, WNOHANG); if (wp == 0 || wp == pid) { - static const char msg[] = "[init] waitpid WNOHANG OK\n"; + static const char msg[] = "[test] waitpid WNOHANG OK\n"; (void)sys_write(1, msg, (uint32_t)(sizeof(msg) - 1)); } else { - static const char msg[] = "[init] waitpid WNOHANG failed\n"; + static const char msg[] = "[test] waitpid WNOHANG failed\n"; (void)sys_write(1, msg, (uint32_t)(sizeof(msg) - 1)); } if (wp == 0) { @@ -4251,10 +4251,10 @@ void _start(void) { tv.tv_sec = 0; tv.tv_usec = 0; int r = sys_gettimeofday(&tv); if (r == 0 && tv.tv_sec > 1000000000U) { - static const char msg[] = "[init] gettimeofday OK\n"; + static const char msg[] = "[test] gettimeofday OK\n"; (void)sys_write(1, msg, (uint32_t)(sizeof(msg) - 1)); } else { - static const char msg[] = "[init] gettimeofday failed\n"; + static const char msg[] = "[test] gettimeofday failed\n"; (void)sys_write(1, msg, (uint32_t)(sizeof(msg) - 1)); } } @@ -4270,14 +4270,14 @@ void _start(void) { *(volatile uint32_t*)page = 0xDEADBEEF; int r = sys_mprotect(page, 4096, PROT_READ | PROT_WRITE); if (r == 0) { - static const char msg[] = "[init] mprotect OK\n"; + static const char msg[] = "[test] mprotect OK\n"; (void)sys_write(1, msg, (uint32_t)(sizeof(msg) - 1)); } else { - static const char msg[] = "[init] mprotect call failed\n"; + static const char msg[] = "[test] mprotect call failed\n"; (void)sys_write(1, msg, (uint32_t)(sizeof(msg) - 1)); } } else { - static const char msg[] = "[init] mprotect brk failed\n"; + static const char msg[] = "[test] mprotect brk failed\n"; (void)sys_write(1, msg, (uint32_t)(sizeof(msg) - 1)); } } @@ -4286,10 +4286,10 @@ void _start(void) { { int r = sys_madvise(0, 4096, 0 /* MADV_NORMAL */); if (r == 0) { - static const char msg[] = "[init] madvise OK\n"; + static const char msg[] = "[test] madvise OK\n"; (void)sys_write(1, msg, (uint32_t)(sizeof(msg) - 1)); } else { - static const char msg[] = "[init] madvise failed\n"; + static const char msg[] = "[test] madvise failed\n"; (void)sys_write(1, msg, (uint32_t)(sizeof(msg) - 1)); } } @@ -4308,16 +4308,16 @@ void _start(void) { struct rlimit check; int r3 = sys_getrlimit(RLIMIT_NOFILE, &check); if (r2 == 0 && r3 == 0 && check.rlim_cur == new_rl.rlim_cur) { - static const char msg[] = "[init] getrlimit/setrlimit OK\n"; + static const char msg[] = "[test] getrlimit/setrlimit OK\n"; (void)sys_write(1, msg, (uint32_t)(sizeof(msg) - 1)); } else { - static const char msg[] = "[init] setrlimit failed\n"; + static const char msg[] = "[test] setrlimit failed\n"; (void)sys_write(1, msg, (uint32_t)(sizeof(msg) - 1)); } /* Restore */ (void)sys_setrlimit(RLIMIT_NOFILE, &rl); } else { - static const char msg[] = "[init] getrlimit failed\n"; + static const char msg[] = "[test] getrlimit failed\n"; (void)sys_write(1, msg, (uint32_t)(sizeof(msg) - 1)); } } @@ -4340,7 +4340,7 @@ void _start(void) { { int pid = sys_fork(); if (pid < 0) { - static const char msg[] = "[init] sigsegv test fork failed\n"; + static const char msg[] = "[test] sigsegv test fork failed\n"; (void)sys_write(1, msg, (uint32_t)(sizeof(msg) - 1)); goto sigsegv_done; } @@ -4353,7 +4353,7 @@ void _start(void) { act.sa_flags = SA_SIGINFO; if (sys_sigaction2(SIGSEGV, &act, 0) < 0) { - static const char msg[] = "[init] sigaction(SIGSEGV) failed\n"; + static const char msg[] = "[test] sigaction(SIGSEGV) failed\n"; (void)sys_write(1, msg, (uint32_t)(sizeof(msg) - 1)); sys_exit(1); } @@ -4365,10 +4365,10 @@ void _start(void) { int st = 0; int wp = sys_waitpid(pid, &st, 0); if (wp == pid && st == 0) { - static const char msg[] = "[init] SIGSEGV OK\n"; + static const char msg[] = "[test] SIGSEGV OK\n"; (void)sys_write(1, msg, (uint32_t)(sizeof(msg) - 1)); } else { - static const char msg[] = "[init] SIGSEGV failed\n"; + static const char msg[] = "[test] SIGSEGV failed\n"; (void)sys_write(1, msg, (uint32_t)(sizeof(msg) - 1)); } sigsegv_done:; @@ -4385,10 +4385,10 @@ void _start(void) { } if (ok) { - static const char wmsg[] = "[init] waitpid OK (100 children, explicit)\n"; + static const char wmsg[] = "[test] waitpid OK (100 children, explicit)\n"; (void)sys_write(1, wmsg, (uint32_t)(sizeof(wmsg) - 1)); } else { - static const char wbad[] = "[init] waitpid failed (100 children, explicit)\n"; + static const char wbad[] = "[test] waitpid failed (100 children, explicit)\n"; (void)sys_write(1, wbad, (uint32_t)(sizeof(wbad) - 1)); } @@ -4398,21 +4398,21 @@ void _start(void) { for (uint32_t i = 0; i < sizeof(uts); i++) ((char*)&uts)[i] = 0; int r = sys_uname(&uts); if (r < 0) { - sys_write(1, "[init] uname failed\n", (uint32_t)(sizeof("[init] uname failed\n") - 1)); + sys_write(1, "[test] uname failed\n", (uint32_t)(sizeof("[test] uname failed\n") - 1)); sys_exit(1); } /* Verify sysname == "AdrOS" */ if (uts.sysname[0] != 'A' || uts.sysname[1] != 'd' || uts.sysname[2] != 'r' || uts.sysname[3] != 'O' || uts.sysname[4] != 'S' || uts.sysname[5] != 0) { - sys_write(1, "[init] uname sysname bad\n", (uint32_t)(sizeof("[init] uname sysname bad\n") - 1)); + sys_write(1, "[test] uname sysname bad\n", (uint32_t)(sizeof("[test] uname sysname bad\n") - 1)); sys_exit(1); } /* Verify machine == "i686" */ if (uts.machine[0] != 'i' || uts.machine[1] != '6' || uts.machine[2] != '8' || uts.machine[3] != '6') { - sys_write(1, "[init] uname machine bad\n", (uint32_t)(sizeof("[init] uname machine bad\n") - 1)); + sys_write(1, "[test] uname machine bad\n", (uint32_t)(sizeof("[test] uname machine bad\n") - 1)); sys_exit(1); } - sys_write(1, "[init] uname OK\n", (uint32_t)(sizeof("[init] uname OK\n") - 1)); + sys_write(1, "[test] uname OK\n", (uint32_t)(sizeof("[test] uname OK\n") - 1)); } // H1: SMP parallel fork test — exercises multi-CPU scheduling + load balancing @@ -4443,22 +4443,22 @@ void _start(void) { } if (smp_ok) { - static const char msg[] = "[init] SMP parallel fork OK\n"; + static const char msg[] = "[test] SMP parallel fork OK\n"; (void)sys_write(1, msg, (uint32_t)(sizeof(msg) - 1)); } else { - static const char msg[] = "[init] SMP parallel fork FAIL\n"; + static const char msg[] = "[test] SMP parallel fork FAIL\n"; (void)sys_write(1, msg, (uint32_t)(sizeof(msg) - 1)); } #undef SMP_NCHILD } - (void)sys_write(1, "[init] execve(/bin/echo)\n", - (uint32_t)(sizeof("[init] execve(/bin/echo)\n") - 1)); + (void)sys_write(1, "[test] execve(/bin/echo)\n", + (uint32_t)(sizeof("[test] execve(/bin/echo)\n") - 1)); static const char* const argv[] = {"echo", "[echo]", "hello", "from", "echo", 0}; static const char* const envp[] = {"FOO=bar", "HELLO=world", 0}; (void)sys_execve("/bin/echo", argv, envp); - (void)sys_write(1, "[init] execve returned (unexpected)\n", - (uint32_t)(sizeof("[init] execve returned (unexpected)\n") - 1)); + (void)sys_write(1, "[test] execve returned (unexpected)\n", + (uint32_t)(sizeof("[test] execve returned (unexpected)\n") - 1)); sys_exit(1); sys_exit(0); } diff --git a/user/user_errno.h b/user/cmds/fulltest/user_errno.h similarity index 100% rename from user/user_errno.h rename to user/cmds/fulltest/user_errno.h diff --git a/user/cmds/grep/Makefile b/user/cmds/grep/Makefile new file mode 100644 index 0000000..34d55a6 --- /dev/null +++ b/user/cmds/grep/Makefile @@ -0,0 +1,3 @@ +NAME := grep +SRCS := grep.c +include ../common.mk diff --git a/user/grep.c b/user/cmds/grep/grep.c similarity index 100% rename from user/grep.c rename to user/cmds/grep/grep.c diff --git a/user/cmds/head/Makefile b/user/cmds/head/Makefile new file mode 100644 index 0000000..3b33207 --- /dev/null +++ b/user/cmds/head/Makefile @@ -0,0 +1,3 @@ +NAME := head +SRCS := head.c +include ../common.mk diff --git a/user/head.c b/user/cmds/head/head.c similarity index 100% rename from user/head.c rename to user/cmds/head/head.c diff --git a/user/cmds/hostname/Makefile b/user/cmds/hostname/Makefile new file mode 100644 index 0000000..de74afd --- /dev/null +++ b/user/cmds/hostname/Makefile @@ -0,0 +1,3 @@ +NAME := hostname +SRCS := hostname.c +include ../common.mk diff --git a/user/hostname.c b/user/cmds/hostname/hostname.c similarity index 100% rename from user/hostname.c rename to user/cmds/hostname/hostname.c diff --git a/user/cmds/id/Makefile b/user/cmds/id/Makefile new file mode 100644 index 0000000..2e274a6 --- /dev/null +++ b/user/cmds/id/Makefile @@ -0,0 +1,3 @@ +NAME := id +SRCS := id.c +include ../common.mk diff --git a/user/id.c b/user/cmds/id/id.c similarity index 100% rename from user/id.c rename to user/cmds/id/id.c diff --git a/user/cmds/init/Makefile b/user/cmds/init/Makefile new file mode 100644 index 0000000..1dbedb1 --- /dev/null +++ b/user/cmds/init/Makefile @@ -0,0 +1,3 @@ +NAME := init +SRCS := init.c +include ../common.mk diff --git a/user/init.c b/user/cmds/init/init.c similarity index 100% rename from user/init.c rename to user/cmds/init/init.c diff --git a/user/cmds/kill/Makefile b/user/cmds/kill/Makefile new file mode 100644 index 0000000..21fd32d --- /dev/null +++ b/user/cmds/kill/Makefile @@ -0,0 +1,3 @@ +NAME := kill +SRCS := kill.c +include ../common.mk diff --git a/user/kill.c b/user/cmds/kill/kill.c similarity index 100% rename from user/kill.c rename to user/cmds/kill/kill.c diff --git a/user/cmds/ldso/Makefile b/user/cmds/ldso/Makefile new file mode 100644 index 0000000..d99d498 --- /dev/null +++ b/user/cmds/ldso/Makefile @@ -0,0 +1,21 @@ +# ldso — dynamic linker (statically linked) +NAME := ldso + +TOPDIR ?= $(abspath ../../..) +BUILDDIR := $(TOPDIR)/build/user/cmds/$(NAME) +USER_CC ?= i686-elf-gcc + +ELF := $(BUILDDIR)/ld.so + +all: $(ELF) + +$(ELF): ldso.c + @mkdir -p $(BUILDDIR) + @echo " CC+LD $@" + @$(USER_CC) -m32 -ffreestanding -fno-pie -no-pie -nostdlib \ + -Wl,-T,$(TOPDIR)/user/ldso_linker.ld -o $@ ldso.c + +clean: + rm -f $(ELF) + +.PHONY: all clean diff --git a/user/ldso.c b/user/cmds/ldso/ldso.c similarity index 100% rename from user/ldso.c rename to user/cmds/ldso/ldso.c diff --git a/user/cmds/ln/Makefile b/user/cmds/ln/Makefile new file mode 100644 index 0000000..aca9f3b --- /dev/null +++ b/user/cmds/ln/Makefile @@ -0,0 +1,3 @@ +NAME := ln +SRCS := ln.c +include ../common.mk diff --git a/user/ln.c b/user/cmds/ln/ln.c similarity index 100% rename from user/ln.c rename to user/cmds/ln/ln.c diff --git a/user/cmds/ls/Makefile b/user/cmds/ls/Makefile new file mode 100644 index 0000000..0434a89 --- /dev/null +++ b/user/cmds/ls/Makefile @@ -0,0 +1,3 @@ +NAME := ls +SRCS := ls.c +include ../common.mk diff --git a/user/ls.c b/user/cmds/ls/ls.c similarity index 100% rename from user/ls.c rename to user/cmds/ls/ls.c diff --git a/user/cmds/mkdir/Makefile b/user/cmds/mkdir/Makefile new file mode 100644 index 0000000..b489933 --- /dev/null +++ b/user/cmds/mkdir/Makefile @@ -0,0 +1,3 @@ +NAME := mkdir +SRCS := mkdir.c +include ../common.mk diff --git a/user/mkdir.c b/user/cmds/mkdir/mkdir.c similarity index 100% rename from user/mkdir.c rename to user/cmds/mkdir/mkdir.c diff --git a/user/cmds/mount/Makefile b/user/cmds/mount/Makefile new file mode 100644 index 0000000..c59274c --- /dev/null +++ b/user/cmds/mount/Makefile @@ -0,0 +1,3 @@ +NAME := mount +SRCS := mount.c +include ../common.mk diff --git a/user/mount.c b/user/cmds/mount/mount.c similarity index 100% rename from user/mount.c rename to user/cmds/mount/mount.c diff --git a/user/cmds/mv/Makefile b/user/cmds/mv/Makefile new file mode 100644 index 0000000..b29cc6a --- /dev/null +++ b/user/cmds/mv/Makefile @@ -0,0 +1,3 @@ +NAME := mv +SRCS := mv.c +include ../common.mk diff --git a/user/mv.c b/user/cmds/mv/mv.c similarity index 100% rename from user/mv.c rename to user/cmds/mv/mv.c diff --git a/user/cmds/pie_test/Makefile b/user/cmds/pie_test/Makefile new file mode 100644 index 0000000..5d3b791 --- /dev/null +++ b/user/cmds/pie_test/Makefile @@ -0,0 +1,30 @@ +# pie_test — PIE/shared library test binary +NAME := pie_test + +TOPDIR ?= $(abspath ../../..) +BUILDDIR := $(TOPDIR)/build/user/cmds/$(NAME) +USER_CC ?= i686-elf-gcc +USER_LD ?= i686-elf-ld + +PIE_SO := $(BUILDDIR)/libpietest.so +PIE_ELF := $(BUILDDIR)/pie_test.elf + +all: $(PIE_SO) $(PIE_ELF) + +$(PIE_SO): pie_func.c + @mkdir -p $(BUILDDIR) + @echo " CC [PIC] $<" + @$(USER_CC) -m32 -fPIC -fno-plt -c pie_func.c -o $(BUILDDIR)/pie_func.o + @$(USER_LD) -m elf_i386 -shared -soname libpietest.so -o $@ $(BUILDDIR)/pie_func.o + +$(PIE_ELF): pie_main.c $(PIE_SO) + @mkdir -p $(BUILDDIR) + @echo " CC [PIE] $<" + @$(USER_CC) -m32 -fPIC -c pie_main.c -o $(BUILDDIR)/pie_main.o + @$(USER_LD) -m elf_i386 -pie --dynamic-linker=/lib/ld.so \ + -T $(TOPDIR)/user/pie_linker.ld -o $@ $(BUILDDIR)/pie_main.o $(PIE_SO) -rpath /lib + +clean: + rm -f $(BUILDDIR)/pie_func.o $(BUILDDIR)/pie_main.o $(PIE_SO) $(PIE_ELF) + +.PHONY: all clean diff --git a/user/pie_func.c b/user/cmds/pie_test/pie_func.c similarity index 100% rename from user/pie_func.c rename to user/cmds/pie_test/pie_func.c diff --git a/user/pie_main.c b/user/cmds/pie_test/pie_main.c similarity index 79% rename from user/pie_main.c rename to user/cmds/pie_test/pie_main.c index 3a6805d..9232cf4 100644 --- a/user/pie_main.c +++ b/user/cmds/pie_test/pie_main.c @@ -17,17 +17,17 @@ extern int test_add(int a, int b); void _start(void) { int r = test_add(38, 4); if (r == 42) { - sys_write(1, "[init] lazy PLT OK\n", 19); + sys_write(1, "[test] lazy PLT OK\n", 19); } else { - sys_write(1, "[init] lazy PLT FAIL\n", 21); + sys_write(1, "[test] lazy PLT FAIL\n", 21); } /* Call again — this time GOT is already patched, tests direct path */ r = test_add(100, 23); if (r == 123) { - sys_write(1, "[init] PLT cached OK\n", 21); + sys_write(1, "[test] PLT cached OK\n", 21); } else { - sys_write(1, "[init] PLT cached FAIL\n", 23); + sys_write(1, "[test] PLT cached FAIL\n", 23); } sys_exit(0); diff --git a/user/cmds/printenv/Makefile b/user/cmds/printenv/Makefile new file mode 100644 index 0000000..2b925ff --- /dev/null +++ b/user/cmds/printenv/Makefile @@ -0,0 +1,3 @@ +NAME := printenv +SRCS := printenv.c +include ../common.mk diff --git a/user/printenv.c b/user/cmds/printenv/printenv.c similarity index 100% rename from user/printenv.c rename to user/cmds/printenv/printenv.c diff --git a/user/cmds/ps/Makefile b/user/cmds/ps/Makefile new file mode 100644 index 0000000..7d31d93 --- /dev/null +++ b/user/cmds/ps/Makefile @@ -0,0 +1,3 @@ +NAME := ps +SRCS := ps.c +include ../common.mk diff --git a/user/ps.c b/user/cmds/ps/ps.c similarity index 100% rename from user/ps.c rename to user/cmds/ps/ps.c diff --git a/user/cmds/pwd/Makefile b/user/cmds/pwd/Makefile new file mode 100644 index 0000000..388f5f0 --- /dev/null +++ b/user/cmds/pwd/Makefile @@ -0,0 +1,3 @@ +NAME := pwd +SRCS := pwd.c +include ../common.mk diff --git a/user/pwd.c b/user/cmds/pwd/pwd.c similarity index 100% rename from user/pwd.c rename to user/cmds/pwd/pwd.c diff --git a/user/cmds/rm/Makefile b/user/cmds/rm/Makefile new file mode 100644 index 0000000..0667c46 --- /dev/null +++ b/user/cmds/rm/Makefile @@ -0,0 +1,3 @@ +NAME := rm +SRCS := rm.c +include ../common.mk diff --git a/user/rm.c b/user/cmds/rm/rm.c similarity index 100% rename from user/rm.c rename to user/cmds/rm/rm.c diff --git a/user/cmds/rmdir/Makefile b/user/cmds/rmdir/Makefile new file mode 100644 index 0000000..df87ffb --- /dev/null +++ b/user/cmds/rmdir/Makefile @@ -0,0 +1,3 @@ +NAME := rmdir +SRCS := rmdir.c +include ../common.mk diff --git a/user/rmdir.c b/user/cmds/rmdir/rmdir.c similarity index 100% rename from user/rmdir.c rename to user/cmds/rmdir/rmdir.c diff --git a/user/cmds/sed/Makefile b/user/cmds/sed/Makefile new file mode 100644 index 0000000..1b3a94c --- /dev/null +++ b/user/cmds/sed/Makefile @@ -0,0 +1,3 @@ +NAME := sed +SRCS := sed.c +include ../common.mk diff --git a/user/sed.c b/user/cmds/sed/sed.c similarity index 100% rename from user/sed.c rename to user/cmds/sed/sed.c diff --git a/user/cmds/sh/Makefile b/user/cmds/sh/Makefile new file mode 100644 index 0000000..8191554 --- /dev/null +++ b/user/cmds/sh/Makefile @@ -0,0 +1,3 @@ +NAME := sh +SRCS := sh.c +include ../common.mk diff --git a/user/sh.c b/user/cmds/sh/sh.c similarity index 100% rename from user/sh.c rename to user/cmds/sh/sh.c diff --git a/user/cmds/sleep/Makefile b/user/cmds/sleep/Makefile new file mode 100644 index 0000000..258ba49 --- /dev/null +++ b/user/cmds/sleep/Makefile @@ -0,0 +1,3 @@ +NAME := sleep +SRCS := sleep.c +include ../common.mk diff --git a/user/sleep.c b/user/cmds/sleep/sleep.c similarity index 100% rename from user/sleep.c rename to user/cmds/sleep/sleep.c diff --git a/user/cmds/sort/Makefile b/user/cmds/sort/Makefile new file mode 100644 index 0000000..b9147af --- /dev/null +++ b/user/cmds/sort/Makefile @@ -0,0 +1,3 @@ +NAME := sort +SRCS := sort.c +include ../common.mk diff --git a/user/sort.c b/user/cmds/sort/sort.c similarity index 100% rename from user/sort.c rename to user/cmds/sort/sort.c diff --git a/user/cmds/stat/Makefile b/user/cmds/stat/Makefile new file mode 100644 index 0000000..ca917a0 --- /dev/null +++ b/user/cmds/stat/Makefile @@ -0,0 +1,3 @@ +NAME := stat +SRCS := stat.c +include ../common.mk diff --git a/user/stat.c b/user/cmds/stat/stat.c similarity index 100% rename from user/stat.c rename to user/cmds/stat/stat.c diff --git a/user/cmds/tail/Makefile b/user/cmds/tail/Makefile new file mode 100644 index 0000000..aeed773 --- /dev/null +++ b/user/cmds/tail/Makefile @@ -0,0 +1,3 @@ +NAME := tail +SRCS := tail.c +include ../common.mk diff --git a/user/tail.c b/user/cmds/tail/tail.c similarity index 100% rename from user/tail.c rename to user/cmds/tail/tail.c diff --git a/user/cmds/tee/Makefile b/user/cmds/tee/Makefile new file mode 100644 index 0000000..f387f18 --- /dev/null +++ b/user/cmds/tee/Makefile @@ -0,0 +1,3 @@ +NAME := tee +SRCS := tee.c +include ../common.mk diff --git a/user/tee.c b/user/cmds/tee/tee.c similarity index 100% rename from user/tee.c rename to user/cmds/tee/tee.c diff --git a/user/cmds/top/Makefile b/user/cmds/top/Makefile new file mode 100644 index 0000000..841c26f --- /dev/null +++ b/user/cmds/top/Makefile @@ -0,0 +1,3 @@ +NAME := top +SRCS := top.c +include ../common.mk diff --git a/user/top.c b/user/cmds/top/top.c similarity index 100% rename from user/top.c rename to user/cmds/top/top.c diff --git a/user/cmds/touch/Makefile b/user/cmds/touch/Makefile new file mode 100644 index 0000000..595e195 --- /dev/null +++ b/user/cmds/touch/Makefile @@ -0,0 +1,3 @@ +NAME := touch +SRCS := touch.c +include ../common.mk diff --git a/user/touch.c b/user/cmds/touch/touch.c similarity index 100% rename from user/touch.c rename to user/cmds/touch/touch.c diff --git a/user/cmds/tr/Makefile b/user/cmds/tr/Makefile new file mode 100644 index 0000000..2a49dd3 --- /dev/null +++ b/user/cmds/tr/Makefile @@ -0,0 +1,3 @@ +NAME := tr +SRCS := tr.c +include ../common.mk diff --git a/user/tr.c b/user/cmds/tr/tr.c similarity index 100% rename from user/tr.c rename to user/cmds/tr/tr.c diff --git a/user/cmds/umount/Makefile b/user/cmds/umount/Makefile new file mode 100644 index 0000000..cee0a75 --- /dev/null +++ b/user/cmds/umount/Makefile @@ -0,0 +1,3 @@ +NAME := umount +SRCS := umount.c +include ../common.mk diff --git a/user/umount.c b/user/cmds/umount/umount.c similarity index 100% rename from user/umount.c rename to user/cmds/umount/umount.c diff --git a/user/cmds/uname/Makefile b/user/cmds/uname/Makefile new file mode 100644 index 0000000..ca5558e --- /dev/null +++ b/user/cmds/uname/Makefile @@ -0,0 +1,3 @@ +NAME := uname +SRCS := uname.c +include ../common.mk diff --git a/user/uname.c b/user/cmds/uname/uname.c similarity index 100% rename from user/uname.c rename to user/cmds/uname/uname.c diff --git a/user/cmds/uniq/Makefile b/user/cmds/uniq/Makefile new file mode 100644 index 0000000..c87f1b1 --- /dev/null +++ b/user/cmds/uniq/Makefile @@ -0,0 +1,3 @@ +NAME := uniq +SRCS := uniq.c +include ../common.mk diff --git a/user/uniq.c b/user/cmds/uniq/uniq.c similarity index 100% rename from user/uniq.c rename to user/cmds/uniq/uniq.c diff --git a/user/cmds/uptime/Makefile b/user/cmds/uptime/Makefile new file mode 100644 index 0000000..391584c --- /dev/null +++ b/user/cmds/uptime/Makefile @@ -0,0 +1,3 @@ +NAME := uptime +SRCS := uptime.c +include ../common.mk diff --git a/user/uptime.c b/user/cmds/uptime/uptime.c similarity index 100% rename from user/uptime.c rename to user/cmds/uptime/uptime.c diff --git a/user/cmds/wc/Makefile b/user/cmds/wc/Makefile new file mode 100644 index 0000000..8dd2064 --- /dev/null +++ b/user/cmds/wc/Makefile @@ -0,0 +1,3 @@ +NAME := wc +SRCS := wc.c +include ../common.mk diff --git a/user/wc.c b/user/cmds/wc/wc.c similarity index 100% rename from user/wc.c rename to user/cmds/wc/wc.c diff --git a/user/cmds/which/Makefile b/user/cmds/which/Makefile new file mode 100644 index 0000000..aa15f8b --- /dev/null +++ b/user/cmds/which/Makefile @@ -0,0 +1,3 @@ +NAME := which +SRCS := which.c +include ../common.mk diff --git a/user/which.c b/user/cmds/which/which.c similarity index 55% rename from user/which.c rename to user/cmds/which/which.c index 9fa5c20..ddd60c4 100644 --- a/user/which.c +++ b/user/cmds/which/which.c @@ -1,28 +1,19 @@ /* AdrOS which utility — locate a command */ #include #include -#include -#include #include -static int exists_in_dir(const char* dir, const char* name) { - int fd = open(dir, O_RDONLY); - if (fd < 0) return 0; - char buf[2048]; - int rc; - while ((rc = getdents(fd, buf, sizeof(buf))) > 0) { - int off = 0; - while (off < rc) { - struct dirent* d = (struct dirent*)(buf + off); - if (d->d_reclen == 0) break; - if (strcmp(d->d_name, name) == 0) { - close(fd); - return 1; - } - off += d->d_reclen; +static int exists_in_dir(const char* dirname, const char* name) { + DIR* dir = opendir(dirname); + if (!dir) return 0; + struct dirent* d; + while ((d = readdir(dir)) != NULL) { + if (strcmp(d->d_name, name) == 0) { + closedir(dir); + return 1; } } - close(fd); + closedir(dir); return 0; } diff --git a/user/cmds/who/Makefile b/user/cmds/who/Makefile new file mode 100644 index 0000000..d98042e --- /dev/null +++ b/user/cmds/who/Makefile @@ -0,0 +1,3 @@ +NAME := who +SRCS := who.c +include ../common.mk diff --git a/user/who.c b/user/cmds/who/who.c similarity index 100% rename from user/who.c rename to user/cmds/who/who.c diff --git a/user/ulibc/Makefile b/user/ulibc/Makefile index 844ea41..9a86fe5 100644 --- a/user/ulibc/Makefile +++ b/user/ulibc/Makefile @@ -4,8 +4,8 @@ AS ?= i686-elf-as AR ?= i686-elf-ar LD ?= i686-elf-ld -CFLAGS := -m32 -ffreestanding -fno-pie -no-pie -nostdlib -O2 -Wall -Wextra -Iinclude -CFLAGS_PIC := -m32 -ffreestanding -nostdlib -O2 -Wall -Wextra -Iinclude -fPIC -fno-plt +CFLAGS := -m32 -ffreestanding -fno-pie -no-pie -nostdlib -O2 -Wall -Wextra -Wno-incompatible-pointer-types -Iinclude +CFLAGS_PIC := -m32 -ffreestanding -nostdlib -O2 -Wall -Wextra -Wno-incompatible-pointer-types -Iinclude -fPIC -fno-plt ASFLAGS := --32 SRC_C := $(wildcard src/*.c) diff --git a/user/ulibc/src/glob.c b/user/ulibc/src/glob.c index b83507a..37fa3df 100644 --- a/user/ulibc/src/glob.c +++ b/user/ulibc/src/glob.c @@ -2,6 +2,7 @@ #include "fnmatch.h" #include "string.h" #include "stdlib.h" +#include "stdio.h" #include "unistd.h" #include "dirent.h" #include "errno.h" -- 2.43.0