mempool: Tests mempool destroy in child process
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 19 Mar 2024 21:19:57 +0000 (17:19 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 19 Mar 2024 21:23:36 +0000 (17:23 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: I8615436deaf089ba0f560145d604251307b307b9

tests/mempool_test.c

index 6e1fe6df5961302457572cf95d6b5eeee9cf2ec8..281683151333adb9fe58dd89bf28c75bdd07aa66 100644 (file)
@@ -331,6 +331,44 @@ static void run_robust_tests(enum rseq_mempool_populate_policy policy)
                "robust-free-list-corruption");
 }
 
+static void fork_child(struct rseq_mempool *pool,
+               enum rseq_mempool_populate_policy policy __attribute__((unused)))
+{
+       rseq_mempool_destroy(pool);
+}
+
+/*
+ * Test that destroying a mempool works in child after fork.
+ */
+static int run_fork_destroy_pool_test(void (*test)(struct rseq_mempool *, enum rseq_mempool_populate_policy),
+                       enum rseq_mempool_populate_policy policy)
+{
+       pid_t cpid;
+       int status;
+       struct rseq_mempool *pool;
+
+       pool = make_test_pool(policy);
+       if (!pool)
+               _exit(EXIT_FAILURE);
+
+       cpid = fork();
+
+       switch (cpid) {
+       case -1:
+               return 0;
+       case 0:
+               test(pool, policy);
+               _exit(EXIT_SUCCESS);
+       default:
+               waitpid(cpid, &status, 0);
+       }
+
+       if (WIFSIGNALED(status))
+               return 0;
+
+       return 1;
+}
+
 int main(void)
 {
        size_t len;
@@ -357,6 +395,10 @@ int main(void)
 
        run_robust_tests(RSEQ_MEMPOOL_POPULATE_PRIVATE_ALL);
        run_robust_tests(RSEQ_MEMPOOL_POPULATE_PRIVATE_NONE);
+       ok(run_fork_destroy_pool_test(fork_child, RSEQ_MEMPOOL_POPULATE_PRIVATE_ALL),
+               "fork destroy pool test populate private all");
+       ok(run_fork_destroy_pool_test(fork_child, RSEQ_MEMPOOL_POPULATE_PRIVATE_NONE),
+               "fork destroy pool test populate private none");
 
        exit(exit_status());
 }
This page took 0.032833 seconds and 4 git commands to generate.