This is an automated email from the ASF dual-hosted git repository.

acassis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git


The following commit(s) were added to refs/heads/master by this push:
     new 40d1ec9d7 testing/ostest: Take the result of the chroot test tasks 
from memory.
40d1ec9d7 is described below

commit 40d1ec9d7238410c465215ccbd8d2bbfabade05c
Author: Marco Casaroli <[email protected]>
AuthorDate: Fri Nov 6 20:31:35 2026 +0100

    testing/ostest: Take the result of the chroot test tasks from memory.
    
    ostest_main() sets SA_NOCLDWAIT on SIGCHLD for the whole run when
    SCHED_HAVE_PARENT, SCHED_CHILD_STATUS and ENABLE_ALL_SIGNALS are set, so
    waitpid() keeps no exit status: it gives ECHILD when the child or the
    grandchild of the chroot test ended before it.  qemu-armv8a:nsh with
    FS_CHROOT and FS_TMPFS then stopped in the assertion of chroot_test().
    
    waitpid() now only waits for the task, and ECHILD means that the task
    ended, as in fork_test() and vfork_test().  Each task reports its result
    in a variable: the test is not built in a kernel build, so the tasks share
    the memory.
    
    Assisted-by: Claude Code:claude-opus-5-5
    Signed-off-by: Marco Casaroli <[email protected]>
---
 testing/ostest/chroot.c | 46 ++++++++++++++++++++++++++++++++++++++--------
 1 file changed, 38 insertions(+), 8 deletions(-)

diff --git a/testing/ostest/chroot.c b/testing/ostest/chroot.c
index b5fc44465..f6ec61f99 100644
--- a/testing/ostest/chroot.c
+++ b/testing/ostest/chroot.c
@@ -57,10 +57,38 @@
 #define CHROOT_SECRET  CHROOT_TMPDIR "/ostest_secret"
 #define CHROOT_PRIO    100
 
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/* The result of each task.  ostest_main() sets SA_NOCLDWAIT on SIGCHLD for
+ * the whole run, so waitpid() gives no exit status after a task ended.
+ * The test is not built in a kernel build, so the tasks share this memory.
+ */
+
+static volatile int g_childret;
+static volatile int g_grandchildret;
+
 /****************************************************************************
  * Private Functions
  ****************************************************************************/
 
+/* Wait for a task to end.  waitpid() blocks on a task that is alive, and
+ * gives ECHILD when the task ended before it.
+ */
+
+static int chroot_wait(pid_t pid)
+{
+  int status;
+
+  if (waitpid(pid, &status, 0) != pid && errno != ECHILD)
+    {
+      return ERROR;
+    }
+
+  return OK;
+}
+
 static int chroot_fail(FAR const char *msg)
 {
   printf("chroot_test: ERROR %s errno=%d\n", msg, errno);
@@ -81,6 +109,7 @@ static int chroot_grandchild(int argc, FAR char *argv[])
     }
 
   printf("chroot_test: grandchild still sees the jail\n");
+  g_grandchildret = EXIT_SUCCESS;
   return EXIT_SUCCESS;
 }
 
@@ -88,7 +117,6 @@ static int chroot_child(int argc, FAR char *argv[])
 {
   struct stat st;
   pid_t pid;
-  int status;
   int fd;
   int hostfd;
 
@@ -163,6 +191,7 @@ static int chroot_child(int argc, FAR char *argv[])
   printf("chroot_test: pre-opened host fd still usable after chroot\n");
   close(hostfd);
 
+  g_grandchildret = EXIT_FAILURE;
   pid = task_create("chroot_gc", CHROOT_PRIO, STACKSIZE,
                     chroot_grandchild, NULL);
   if (pid < 0)
@@ -170,18 +199,19 @@ static int chroot_child(int argc, FAR char *argv[])
       return chroot_fail("task_create(grandchild) failed");
     }
 
-  if (waitpid(pid, &status, 0) != pid)
+  if (chroot_wait(pid) < 0)
     {
       return chroot_fail("waitpid(grandchild) failed");
     }
 
-  if (!WIFEXITED(status) || WEXITSTATUS(status) != EXIT_SUCCESS)
+  if (g_grandchildret != EXIT_SUCCESS)
     {
-      printf("chroot_test: ERROR grandchild status=%d\n", status);
+      printf("chroot_test: ERROR grandchild failed\n");
       ASSERT(false);
       return EXIT_FAILURE;
     }
 
+  g_childret = EXIT_SUCCESS;
   return EXIT_SUCCESS;
 }
 
@@ -245,7 +275,6 @@ static void chroot_cleanup(void)
 int chroot_test(void)
 {
   pid_t pid;
-  int status;
 #ifdef CONFIG_DEV_NULL
   int fd;
 #endif
@@ -257,6 +286,7 @@ int chroot_test(void)
       return ERROR;
     }
 
+  g_childret = EXIT_FAILURE;
   pid = task_create("chroot_child", CHROOT_PRIO, STACKSIZE,
                     chroot_child, NULL);
   if (pid < 0)
@@ -267,7 +297,7 @@ int chroot_test(void)
       return ERROR;
     }
 
-  if (waitpid(pid, &status, 0) != pid)
+  if (chroot_wait(pid) < 0)
     {
       printf("chroot_test: ERROR waitpid failed errno=%d\n", errno);
       ASSERT(false);
@@ -277,9 +307,9 @@ int chroot_test(void)
 
   chroot_cleanup();
 
-  if (!WIFEXITED(status) || WEXITSTATUS(status) != EXIT_SUCCESS)
+  if (g_childret != EXIT_SUCCESS)
     {
-      printf("chroot_test: ERROR child status=%d\n", status);
+      printf("chroot_test: ERROR child failed\n");
       ASSERT(false);
       return ERROR;
     }

Reply via email to