From 1a72feebcc79e5dbf44ed6d2cb7653b1fad901b0 Mon Sep 17 00:00:00 2001 From: Stefan Berger Date: Fri, 13 Oct 2023 14:43:06 -0400 Subject: [PATCH] [LibOS] Add testcase for reproducing checkpoint on sbrk issue Signed-off-by: Stefan Berger --- libos/test/regression/fork_and_sbrk.c | 57 +++++++++++++++++++++++++++ libos/test/regression/meson.build | 1 + libos/test/regression/test_libos.py | 5 +++ libos/test/regression/tests.toml | 1 + libos/test/regression/tests_musl.toml | 1 + 5 files changed, 65 insertions(+) create mode 100644 libos/test/regression/fork_and_sbrk.c diff --git a/libos/test/regression/fork_and_sbrk.c b/libos/test/regression/fork_and_sbrk.c new file mode 100644 index 0000000000..b08281eae3 --- /dev/null +++ b/libos/test/regression/fork_and_sbrk.c @@ -0,0 +1,57 @@ +/* SPDX-License-Identifier: LGPL-3.0-or-later */ +/* Copyright (C) 2023 IBM Corporation + * Stefan Berger + */ + +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include + +int proceed = 0; + +static void* thread_func(void* arg) { + while (__atomic_load_n(&proceed, __ATOMIC_ACQUIRE) == 0) + usleep(1); + proceed = 0; + + usleep(10); + pid_t pid = fork(); + if (pid < 0) { + perror("fork failed\n"); + exit(1); + } + if (pid > 0) { + while (__atomic_load_n(&proceed, __ATOMIC_ACQUIRE) == 0) + usleep(1); + printf("TEST OK\n"); + } else { + printf("Child started\n"); + } + exit(0); +} + +int main(int argc, char** argv) { + pthread_t forker; + if (pthread_create(&forker, NULL, thread_func, NULL) != 0) { + perror("pthread_create failed"); + return 1; + } + + proceed = 1; + while (__atomic_load_n(&proceed, __ATOMIC_ACQUIRE) == 1); + + size_t i; + for (i = 0; i < 1024; i++) { + sbrk(0x10000); + sbrk(-0x10000); + } + + proceed = 1; + sleep(1); + + return 0; +} diff --git a/libos/test/regression/meson.build b/libos/test/regression/meson.build index b46d27e395..956faf8185 100644 --- a/libos/test/regression/meson.build +++ b/libos/test/regression/meson.build @@ -41,6 +41,7 @@ tests = { 'fork_and_mprotect': {}, 'fork_and_munmap': {}, 'fork_and_pthread_create': {}, + 'fork_and_sbrk': {}, 'fp_multithread': { 'c_args': '-fno-builtin', # see comment in the test's source 'link_args': '-lm', diff --git a/libos/test/regression/test_libos.py b/libos/test/regression/test_libos.py index 6acf21588c..2878d22572 100644 --- a/libos/test/regression/test_libos.py +++ b/libos/test/regression/test_libos.py @@ -1018,6 +1018,11 @@ def test_163_fork_and_pthread_create(self): stdout, _ = self.run_binary(['fork_and_pthread_create']) self.assertIn("TEST OK", stdout) + def test_164_fork_and_sbrk(self): + for _ in range(0, 10): + stdout, _ = self.run_binary(['fork_and_sbrk']) + self.assertIn("TEST OK", stdout) + class TC_31_Syscall(RegressionTestCase): def test_000_syscall_redirect(self): stdout, _ = self.run_binary(['syscall']) diff --git a/libos/test/regression/tests.toml b/libos/test/regression/tests.toml index 1a3f2f7efd..8a01fbacc7 100644 --- a/libos/test/regression/tests.toml +++ b/libos/test/regression/tests.toml @@ -44,6 +44,7 @@ manifests = [ "fork_and_mprotect", "fork_and_munmap", "fork_and_pthread_create", + "fork_and_sbrk", "fork_disallowed", "fp_multithread", "fstat_cwd", diff --git a/libos/test/regression/tests_musl.toml b/libos/test/regression/tests_musl.toml index cbdb153beb..837c9846c0 100644 --- a/libos/test/regression/tests_musl.toml +++ b/libos/test/regression/tests_musl.toml @@ -46,6 +46,7 @@ manifests = [ "fork_and_mprotect", "fork_and_munmap", "fork_and_pthread_create", + "fork_and_sbrk", "fork_disallowed", "fp_multithread", "fstat_cwd",