diff --git a/CMakeLists.txt b/CMakeLists.txt index 921f31578e7..bdd35e67449 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1512,6 +1512,7 @@ set(TESTS_WITH_PROGRAM # check_session_leaks checkpoint_dying_threads checkpoint_mixed_mode + checkpoint_persistent_shmem checksum_sanity check_lost_interrupts clone_file_range diff --git a/src/test/checkpoint_persistent_shmem.c b/src/test/checkpoint_persistent_shmem.c new file mode 100644 index 00000000000..f9eae5ca6b7 --- /dev/null +++ b/src/test/checkpoint_persistent_shmem.c @@ -0,0 +1,57 @@ +/* -*- Mode: C; tab-width: 8; c-basic-offset: 2; indent-tabs-mode: nil; -*- */ + +#include "util.h" + +#include +#include +#include +#include +#include + +#define SHM_NAME "/my_shared_memory" +#define SHM_SIZE 4096 + +static void breakpoint(void) {} + +int main(void) { + // Create shared memory + int shm_fd = shm_open(SHM_NAME, O_CREAT | O_RDWR, 0666); + if (shm_fd == -1) { + perror("shm_open"); + return 1; + } + ftruncate(shm_fd, SHM_SIZE); + + // Map shared memory + const char* ptr = + (char*)mmap(0, SHM_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, shm_fd, 0); + if (ptr == MAP_FAILED) { + perror("mmap"); + return 1; + } + + pid_t pid = fork(); + if (pid < 0) { + perror("fork"); + return 1; + } + + const char* parent_msg = "hello parent"; + const char* child_msg = "hello child\0"; + if (pid == 0) { + sleep(1); + memcpy((void*)ptr, parent_msg, strlen(parent_msg)); + return 1; + } else { + wait(NULL); + memcpy((void*)(ptr + strlen(parent_msg)), child_msg, strlen(child_msg)); + breakpoint(); + } + + // Cleanup + munmap((void*)ptr, SHM_SIZE); + shm_unlink(SHM_NAME); + + atomic_puts("EXIT-SUCCESS"); + return 0; +} \ No newline at end of file diff --git a/src/test/checkpoint_persistent_shmem.py b/src/test/checkpoint_persistent_shmem.py new file mode 100644 index 00000000000..bb8eaca34ee --- /dev/null +++ b/src/test/checkpoint_persistent_shmem.py @@ -0,0 +1,22 @@ +from util import * + +send_gdb('break 48') +expect_gdb('Breakpoint 1') +send_gdb('c') +expect_gdb('Breakpoint 1') + +send_gdb('checkpoint') +send_gdb('write-checkpoints') +send_gdb('delete checkpoint 1') +send_gdb('c') + +expect_rr('EXIT-SUCCESS') + +send_gdb('load-checkpoints') +send_gdb('restart 2') +expect_gdb('Program stopped') + +send_gdb('print ptr') +expect_gdb('"hello parenthello child"') + +ok() \ No newline at end of file diff --git a/src/test/checkpoint_persistent_shmem.run b/src/test/checkpoint_persistent_shmem.run new file mode 100644 index 00000000000..235ffcd1372 --- /dev/null +++ b/src/test/checkpoint_persistent_shmem.run @@ -0,0 +1,2 @@ +source `dirname $0`/util.sh +debug_test_gdb_only \ No newline at end of file