From 82b0e298922a0d51cca2cd7c231b4ed9fd222171 Mon Sep 17 00:00:00 2001 From: Tulio A M Mendes Date: Fri, 17 Apr 2026 14:01:34 -0300 Subject: [PATCH] Fix fulltest TIOCGPGRP failure when run from shell When fulltest runs from /bin/sh (rather than as init directly), the shell has already claimed the controlling TTY via setsid(), setting tty_fg_pgrp to a non-zero value. The test assumed fg == 0, which only holds when running as PID 1 (session_id=0, pgrp_id=0). Fix: compare TIOCGPGRP result against sys_getpgrp() instead of hardcoded 0, use our own pgrp for TIOCSPGRP success test, and use fg=-1 (EINVAL) instead of fg=1 for the expected-failure case. Also rename 'hello from init.elf' to 'hello from fulltest.elf' in both the test binary and the smoke test expectations. --- tests/smoke_test.exp | 2 +- user/cmds/fulltest/fulltest.c | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/tests/smoke_test.exp b/tests/smoke_test.exp index 33f11919..baa95010 100755 --- a/tests/smoke_test.exp +++ b/tests/smoke_test.exp @@ -49,7 +49,7 @@ 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" "\\[test\\] hello from init.elf"} + {"fulltest.elf hello" "\\[test\\] hello from fulltest.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"} diff --git a/user/cmds/fulltest/fulltest.c b/user/cmds/fulltest/fulltest.c index a9e41110..b9adacdc 100644 --- a/user/cmds/fulltest/fulltest.c +++ b/user/cmds/fulltest/fulltest.c @@ -1463,7 +1463,7 @@ void _start(void) { "mov %ax, %gs\n" ); - static const char msg[] = "[test] hello from init.elf\n"; + static const char msg[] = "[test] hello from fulltest.elf\n"; (void)sys_write(1, msg, (uint32_t)(sizeof(msg) - 1)); static const char path[] = "/sbin/fulltest"; @@ -1820,21 +1820,23 @@ void _start(void) { sys_exit(1); } + int my_pgrp = sys_getpgrp(); + int fg = -1; - if (sys_ioctl(fd, TIOCGPGRP, &fg) < 0 || fg != 0) { + if (sys_ioctl(fd, TIOCGPGRP, &fg) < 0 || fg != my_pgrp) { sys_write(1, "[test] ioctl TIOCGPGRP failed\n", (uint32_t)(sizeof("[test] ioctl TIOCGPGRP failed\n") - 1)); sys_exit(1); } - fg = 0; + fg = my_pgrp; if (sys_ioctl(fd, TIOCSPGRP, &fg) < 0) { sys_write(1, "[test] ioctl TIOCSPGRP failed\n", (uint32_t)(sizeof("[test] ioctl TIOCSPGRP failed\n") - 1)); sys_exit(1); } - fg = 1; + fg = -1; if (sys_ioctl(fd, TIOCSPGRP, &fg) >= 0) { sys_write(1, "[test] ioctl TIOCSPGRP expected fail\n", (uint32_t)(sizeof("[test] ioctl TIOCSPGRP expected fail\n") - 1)); -- 2.43.0