summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Filippov <jcmvbkbc@gmail.com>2024-05-10 11:42:12 -0700
committerWaldemar Brodkorb <wbx@openadk.org>2024-05-11 07:52:10 +0200
commit1bb237b695fbabf05fc196748e47b9ecb97e9903 (patch)
treeb968db6ce30e98314f7b8ca090935d0d1ba2343c
parent76f1c1797d4df964e61d85fbc8dd0205e3af9013 (diff)
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 <jcmvbkbc@gmail.com>
-rw-r--r--test/test-skeleton.c65
1 files changed, 50 insertions, 15 deletions
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);