aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
authorMike Rapoport (Microsoft) <rppt@kernel.org>2026-05-11 19:27:48 +0300
committerAndrew Morton <akpm@linux-foundation.org>2026-05-28 21:31:41 -0700
commit64351b45b5cad61915567de9fca14c55612ac279 (patch)
tree580fcd9d7ed03ce9f520e341e9bf2a777eb955b7 /tools
parentdf610524b21d91f15529f38cdc4c4cd9baeae9f9 (diff)
downloadlinux-next-history-64351b45b5cad61915567de9fca14c55612ac279.tar.gz
selftests/mm: migration: properly cleanup fork()ed processes
Several migration test use fork() to create worker processes. These processes are later killed, but nothing collects their exit status and they remain as zombies in the system. Add a helper function that kills the worker processes, waitpid()s for them and verifies the exit status. Replace the loops that call kill() for each process with a call to that helper. Link: https://lore.kernel.org/20260511162840.375890-5-rppt@kernel.org Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org> Reported-by: Luiz Capitulino <luizcap@redhat.com> Tested-by: Luiz Capitulino <luizcap@redhat.com> Reviewed-by: Luiz Capitulino <luizcap@redhat.com> Cc: Baolin Wang <baolin.wang@linux.alibaba.com> Cc: Barry Song <baohua@kernel.org> Cc: David Hildenbrand <david@kernel.org> Cc: Dev Jain <dev.jain@arm.com> Cc: Donet Tom <donettom@linux.ibm.com> Cc: Jason Gunthorpe <jgg@ziepe.ca> Cc: John Hubbard <jhubbard@nvidia.com> Cc: Lance Yang <lance.yang@linux.dev> Cc: Leon Romanovsky <leon@kernel.org> Cc: Liam Howlett <liam@infradead.org> Cc: Li Wang <li.wang@linux.dev> Cc: Lorenzo Stoakes <ljs@kernel.org> Cc: Mark Brown <broonie@kernel.org> Cc: Michal Hocko <mhocko@suse.com> Cc: Nico Pache <npache@redhat.com> Cc: Peter Xu <peterx@redhat.com> Cc: Ryan Roberts <ryan.roberts@arm.com> Cc: Sarthak Sharma <sarthak.sharma@arm.com> Cc: Shuah Khan <shuah@kernel.org> Cc: Suren Baghdasaryan <surenb@google.com> Cc: Vlastimil Babka <vbabka@kernel.org> Cc: Zi Yan <ziy@nvidia.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Diffstat (limited to 'tools')
-rw-r--r--tools/testing/selftests/mm/migration.c47
1 files changed, 35 insertions, 12 deletions
diff --git a/tools/testing/selftests/mm/migration.c b/tools/testing/selftests/mm/migration.c
index 16ffd3c55ee09..e504829df6b6f 100644
--- a/tools/testing/selftests/mm/migration.c
+++ b/tools/testing/selftests/mm/migration.c
@@ -67,6 +67,29 @@ FIXTURE_TEARDOWN(migration)
free(self->pids);
}
+static bool kill_children(FIXTURE_DATA(migration) * self)
+{
+ bool err = false;
+ pid_t pid;
+ int i;
+
+ for (i = 0; i < self->nthreads; i++) {
+ int status = 0;
+
+ pid = self->pids[i];
+ if (pid < 0)
+ continue;
+ if (kill(pid, SIGTERM))
+ err = true;
+ if (pid != waitpid(pid, &status, 0))
+ err = true;
+ if (!WIFSIGNALED(status) || WTERMSIG(status) != SIGTERM)
+ err = true;
+ }
+
+ return !err;
+}
+
int migrate(uint64_t *ptr, int n1, int n2)
{
int ret, tmp;
@@ -151,7 +174,7 @@ TEST_F_TIMEOUT(migration, shared_anon, 2*RUNTIME)
{
pid_t pid;
uint64_t *ptr;
- int i;
+ int i, err;
ptr = mmap(NULL, TWOMEG, PROT_READ | PROT_WRITE,
MAP_SHARED | MAP_ANONYMOUS, -1, 0);
@@ -171,9 +194,9 @@ TEST_F_TIMEOUT(migration, shared_anon, 2*RUNTIME)
}
}
- ASSERT_EQ(migrate(ptr, self->n1, self->n2), 0);
- for (i = 0; i < self->nthreads; i++)
- ASSERT_EQ(kill(self->pids[i], SIGTERM), 0);
+ err = migrate(ptr, self->n1, self->n2);
+ ASSERT_EQ(kill_children(self), true);
+ ASSERT_EQ(err, 0);
}
/*
@@ -217,7 +240,7 @@ TEST_F_TIMEOUT(migration, shared_anon_thp, 2*RUNTIME)
uint64_t pmdsize;
pid_t pid;
uint64_t *ptr;
- int i;
+ int i, err;
if (!thp_is_enabled())
SKIP(return, "Transparent Hugepages not available");
@@ -247,9 +270,9 @@ TEST_F_TIMEOUT(migration, shared_anon_thp, 2*RUNTIME)
}
}
- ASSERT_EQ(migrate(ptr, self->n1, self->n2), 0);
- for (i = 0; i < self->nthreads; i++)
- ASSERT_EQ(kill(self->pids[i], SIGTERM), 0);
+ err = migrate(ptr, self->n1, self->n2);
+ ASSERT_EQ(kill_children(self), true);
+ ASSERT_EQ(err, 0);
}
/*
@@ -287,7 +310,7 @@ TEST_F_TIMEOUT(migration, shared_anon_htlb, 2*RUNTIME)
unsigned long hugepage_size;
pid_t pid;
uint64_t *ptr;
- int i;
+ int i, err;
hugepage_size = default_huge_page_size();
if (!hugepage_size)
@@ -311,9 +334,9 @@ TEST_F_TIMEOUT(migration, shared_anon_htlb, 2*RUNTIME)
}
}
- ASSERT_EQ(migrate(ptr, self->n1, self->n2), 0);
- for (i = 0; i < self->nthreads; i++)
- ASSERT_EQ(kill(self->pids[i], SIGTERM), 0);
+ err = migrate(ptr, self->n1, self->n2);
+ ASSERT_EQ(kill_children(self), true);
+ ASSERT_EQ(err, 0);
}
TEST_HARNESS_MAIN