summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2017-12-15 09:28:42 +0100
committerThomas Haller <thaller@redhat.com>2017-12-15 09:30:20 +0100
commitbb7fcdf21e4ddfb2c8b636ee71ef5a99ff58ce5d (patch)
treec79182875057e5ffd0f575d6cf1d21f8dd2cec7b
parentc04f4febfe97fb728eea850b35771c64da1be92f (diff)
downloadNetworkManager-bb7fcdf21e4ddfb2c8b636ee71ef5a99ff58ce5d.tar.gz
src/tests: fix test_nm_utils_kill_child() under meson
meson spawns the tests in a way that the test process is a session leader. Since the test wants to create a new process group to kill a group of processes that it starts, it failed. $ meson test -C build test-general-with-expect The test would have succeed when wrapping the test for example by strace: $ meson test -C build --wrap='strace' test-general-with-expect Fix that, by forking once more.
-rw-r--r--src/tests/test-general-with-expect.c41
1 files changed, 29 insertions, 12 deletions
diff --git a/src/tests/test-general-with-expect.c b/src/tests/test-general-with-expect.c
index 3e6881ee26..649cd984f0 100644
--- a/src/tests/test-general-with-expect.c
+++ b/src/tests/test-general-with-expect.c
@@ -167,7 +167,7 @@ test_nm_utils_kill_child_spawn (char **argv, gboolean do_not_reap_child)
}
static pid_t
-test_nm_utils_kill_child_create_and_join_pgroup (void)
+do_test_nm_utils_kill_child_create_and_join_pgroup (void)
{
int err, tmp = 0;
int pipefd[2];
@@ -177,10 +177,7 @@ test_nm_utils_kill_child_create_and_join_pgroup (void)
g_assert (err == 0);
pgid = fork();
- if (pgid < 0) {
- g_assert_not_reached ();
- return pgid;
- }
+ g_assert (pgid >= 0);
if (pgid == 0) {
/* child process... */
@@ -206,7 +203,6 @@ test_nm_utils_kill_child_create_and_join_pgroup (void)
err = setpgid (0, pgid);
g_assert (err == 0);
-
do {
err = waitpid (pgid, &tmp, 0);
} while (err == -1 && errno == EINTR);
@@ -280,7 +276,6 @@ do_test_nm_utils_kill_child (void)
/* give processes time to start (and potentially block signals) ... */
g_usleep (G_USEC_PER_SEC / 10);
-
fatal_mask = g_log_set_always_fatal (G_LOG_FATAL_MASK);
g_test_expect_message ("NetworkManager", G_LOG_LEVEL_DEBUG, "*kill child process 'test-s-1-1' (*): waiting up to 3000 milliseconds for process to terminate normally after sending SIGTERM (15)...");
@@ -365,16 +360,38 @@ static void
test_nm_utils_kill_child (void)
{
int err;
+ int exit_status;
pid_t gpid;
+ pid_t child_pid;
- gpid = test_nm_utils_kill_child_create_and_join_pgroup ();
+ /* the tests spawns several processes, we want to clean them up
+ * by sending a SIGKILL to the process group.
+ *
+ * The current process might be a session leader, which prevents it from
+ * creating a new process group. Hence, first fork and let the child
+ * create a new process group, run the tests, and kill all pending
+ * processes. */
+ child_pid = fork ();
+ g_assert (child_pid >= 0);
- do_test_nm_utils_kill_child ();
+ if (child_pid == 0) {
+ gpid = do_test_nm_utils_kill_child_create_and_join_pgroup ();
- err = setpgid (0, 0);
- g_assert (err == 0);
+ do_test_nm_utils_kill_child ();
+
+ err = setpgid (0, 0);
+ g_assert (err == 0);
- kill (-gpid, SIGKILL);
+ kill (-gpid, SIGKILL);
+
+ exit (0);
+ };
+
+ do {
+ err = waitpid (child_pid, &exit_status, 0);
+ } while (err == -1 && errno == EINTR);
+ g_assert (err == child_pid);
+ g_assert (WIFEXITED (exit_status) && WEXITSTATUS(exit_status) == 0);
}
/*****************************************************************************/