From 1bb237b695fbabf05fc196748e47b9ecb97e9903 Mon Sep 17 00:00:00 2001 From: Max Filippov Date: Fri, 10 May 2024 11:42:12 -0700 Subject: test-skeleton: don't force -d on noMMU There's a few tests whose do_test() is supposed to time out or terminate with a signal. Tests communicate it to the test skeleton by defining EXPECTED_SIGNAL or EXPECTED_STATUS and the skeleton completes with success code when that happens. Running test suite in direct mode by default changes that, as a result test running script reports failures for the tests that actually pass or hangs. Instead of switching to direct test running when building for noMMU use vfork() and exec() the test in the child process in direct mode. This makes the default test process behavior the same on MMU and noMMU targets. Signed-off-by: Max Filippov --- test/test-skeleton.c | 65 ++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 50 insertions(+), 15 deletions(-) (limited to 'test/test-skeleton.c') diff --git a/test/test-skeleton.c b/test/test-skeleton.c index 557996d..323a9c6 100644 --- a/test/test-skeleton.c +++ b/test/test-skeleton.c @@ -222,18 +222,15 @@ handler_killpid(int sig) /* We provide the entry point here. */ int -main (int argc, char *argv[]) +main (int argc, char *argv[], char *envp[]) { -#ifdef __ARCH_USE_MMU__ int direct = 0; /* Directly call the test function? */ -#else - int direct = 1; -#endif int status; int opt; unsigned int timeoutfactor = 1; pid_t termpid; char *envstr_timeoutfactor; + char **argv1; /* Make uses of freed and uninitialized memory known. */ #ifdef __MALLOC_STANDARD__ @@ -303,19 +300,21 @@ main (int argc, char *argv[]) /* make sure temporary files are deleted. */ atexit (delete_temp_files); - /* Correct for the possible parameters. */ - argv[optind - 1] = argv[0]; - argv += optind - 1; - argc -= optind - 1; + /* If we are not expected to fork run the function immediately. */ + if (direct) + { + /* Correct for the possible parameters. */ + argv[optind - 1] = argv[0]; + argv += optind - 1; + argc -= optind - 1; - /* Call the initializing function, if one is available. */ + /* Call the initializing function, if one is available. */ #ifdef PREPARE - PREPARE (argc, argv); + PREPARE (argc, argv); #endif - /* If we are not expected to fork run the function immediately. */ - if (direct) - return TEST_FUNCTION; + return TEST_FUNCTION; + } /* Set up the test environment: - prevent core dumps @@ -340,15 +339,51 @@ main (int argc, char *argv[]) if (setpgid (0, 0) != 0) printf ("Failed to set the process group ID: %m\n"); + /* Correct for the possible parameters. */ + argv[optind - 1] = argv[0]; + argv += optind - 1; + argc -= optind - 1; + + /* Call the initializing function, if one is available. */ +#ifdef PREPARE + PREPARE (argc, argv); +#endif + /* Execute the test function and exit with the return value. */ exit (TEST_FUNCTION); } else if (pid < 0) -#endif { perror ("Cannot fork test program"); exit (1); } +#else + argv1 = malloc ((argc + 2) * sizeof(void *)); + argv1[0] = argv[0]; + argv1[1] = "-d"; + memcpy(argv1 + 2, argv + 1, argc * sizeof(void *)); + + pid = vfork (); + if (pid == 0) + { + /* This is the child. */ + /* We put the test process in its own pgrp so that if it bogusly + generates any job control signals, they won't hit the whole build. */ + if (setpgid (0, 0) != 0) + printf ("Failed to set the process group ID: %m\n"); + + if (execve (argv1[0], argv1, envp) < 0) + { + perror ("Cannot exec test program"); + _exit (1); + } + } + else if (pid < 0) + { + perror ("Cannot vfork test program"); + exit (1); + } +#endif #ifdef __XXX_HANDLE_CTRL_C signal (SIGTERM, handler_killpid); -- cgit v1.2.3