From bef9db25b5c50d34adc4d1c684f68338ba2d86f6 Mon Sep 17 00:00:00 2001 From: Adam Debek Date: Fri, 6 Feb 2026 22:50:23 +0100 Subject: [PATCH 1/2] libc/exit: enable host testcases that need init system in docker container JIRA: CI-365 --- libc/exit/exit.c | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/libc/exit/exit.c b/libc/exit/exit.c index c05c332cd..a0e7f4869 100644 --- a/libc/exit/exit.c +++ b/libc/exit/exit.c @@ -19,6 +19,7 @@ */ #include +#include #include #include #include @@ -48,6 +49,8 @@ #define TEST_EXIT_STR "test123" #define TEST_EXIT_DUMMY_VAL 12345678 +bool test_hasInitSystem = true; + /* Disable warnings caused by no checking write() return value, since ASSERT cannot be used in child process */ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-result" @@ -595,9 +598,10 @@ TEST(unistd_exit, close_streams) TEST(unistd_exit, orphaned_child) { -#ifndef phoenix - TEST_IGNORE_MESSAGE("Lack of init system in docker container"); -#endif + if (!test_hasInitSystem) { + TEST_IGNORE_MESSAGE("Lack of init system in docker container"); + } + /* Test if parent _exit affect child process */ pid_t pid; int pipefd[2]; @@ -675,9 +679,10 @@ TEST(unistd_exit, orphaned_child) TEST(unistd_exit, new_parent_id) { -#ifndef phoenix - TEST_IGNORE_MESSAGE("Lack of init system in docker container"); -#endif + if (!test_hasInitSystem) { + TEST_IGNORE_MESSAGE("Lack of init system in docker container"); + } + /* Test that child acquire new parent ID */ pid_t pid; int pipefd[2]; @@ -1214,6 +1219,23 @@ void runner(void) int main(int argc, char *argv[]) { + char hostname[128]; + gethostname(hostname, sizeof(hostname)); + + if (strstr(hostname, "docker") != NULL) { + if (getenv("USE_TINI") == NULL) { + if (access("/usr/bin/tini", X_OK) == 0) { + setenv("USE_TINI", "yes", 1); + execl("/usr/bin/tini", "tini", "-s", argv[0], NULL); + perror("execl tini"); + exit(EXIT_FAILURE); + } + else { + test_hasInitSystem = false; + } + } + } + return (UnityMain(argc, (const char **)argv, runner) == 0) ? EXIT_SUCCESS : EXIT_FAILURE; } From dbf63a43fbc969c2ae03e9b914015780c073b842 Mon Sep 17 00:00:00 2001 From: Adam Debek Date: Fri, 6 Feb 2026 23:08:19 +0100 Subject: [PATCH 2/2] libc/exit: add missing sigpipe handler JIRA: CI-365 --- libc/exit/exit.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/libc/exit/exit.c b/libc/exit/exit.c index a0e7f4869..3b7d229ea 100644 --- a/libc/exit/exit.c +++ b/libc/exit/exit.c @@ -110,7 +110,22 @@ static void test_sigchldHandler(int signum) sa.sa_handler = SIG_DFL; // Set the handler to default action sigemptyset(&sa.sa_mask); sa.sa_flags = 0; - TEST_ASSERT_EQUAL_INT(0, sigaction(SIGCHLD, &sa, NULL)); + sigaction(SIGCHLD, &sa, NULL); + + /* Change value of variable to confirm that handler has been invoked */ + test_common.test_handlerFlag = TEST_EXIT_DUMMY_VAL; +} + + +/* SIGPIPE signal handler */ +static void test_sigpipeHandler(int signum) +{ + struct sigaction sa; + + sa.sa_handler = SIG_DFL; // Set the handler to default action + sigemptyset(&sa.sa_mask); + sa.sa_flags = 0; + sigaction(SIGPIPE, &sa, NULL); /* Change value of variable to confirm that handler has been invoked */ test_common.test_handlerFlag = TEST_EXIT_DUMMY_VAL; @@ -581,6 +596,15 @@ TEST(unistd_exit, close_streams) /* parent */ else { int status, ret; + struct sigaction sa; + + sa.sa_handler = test_sigpipeHandler; + TEST_ASSERT_EQUAL_INT(0, sigemptyset(&sa.sa_mask)); + sa.sa_flags = 0; + TEST_ASSERT_EQUAL_INT(0, sigaction(SIGPIPE, &sa, NULL)); + + /* Check handlerFlag has initial value */ + TEST_ASSERT_EQUAL_INT(0, test_common.test_handlerFlag); ret = wait(&status); TEST_ASSERT_EQUAL_INT(pid, ret); @@ -591,6 +615,10 @@ TEST(unistd_exit, close_streams) ret = write(pipefd[1], TEST_EXIT_STR, sizeof(TEST_EXIT_STR)); TEST_ASSERT_EQUAL_INT(-1, ret); TEST_ASSERT_EQUAL_INT(EPIPE, errno); +#ifndef phoenix + // https://github.com/phoenix-rtos/phoenix-rtos-project/issues/733 + TEST_ASSERT_EQUAL_INT(TEST_EXIT_DUMMY_VAL, test_common.test_handlerFlag); +#endif close(pipefd[1]); /* close write pipe end */ } }