Skip to content

Commit

Permalink
[LibOS] Add testcase for reproducing checkpoint on sbrk issue
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
  • Loading branch information
stefanberger committed Feb 27, 2024
1 parent 4879980 commit 1a72fee
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 0 deletions.
57 changes: 57 additions & 0 deletions libos/test/regression/fork_and_sbrk.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/* SPDX-License-Identifier: LGPL-3.0-or-later */
/* Copyright (C) 2023 IBM Corporation
* Stefan Berger <stefanb@linux.ibm.com>
*/

#define _GNU_SOURCE
#include <pthread.h>
#include <err.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

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;
}
1 change: 1 addition & 0 deletions libos/test/regression/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
5 changes: 5 additions & 0 deletions libos/test/regression/test_libos.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
Expand Down
1 change: 1 addition & 0 deletions libos/test/regression/tests.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ manifests = [
"fork_and_mprotect",
"fork_and_munmap",
"fork_and_pthread_create",
"fork_and_sbrk",
"fork_disallowed",
"fp_multithread",
"fstat_cwd",
Expand Down
1 change: 1 addition & 0 deletions libos/test/regression/tests_musl.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ manifests = [
"fork_and_mprotect",
"fork_and_munmap",
"fork_and_pthread_create",
"fork_and_sbrk",
"fork_disallowed",
"fp_multithread",
"fstat_cwd",
Expand Down

0 comments on commit 1a72fee

Please sign in to comment.