Skip to content

Commit

Permalink
Added the first test for persistent checkpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
theIDinside committed Feb 10, 2025
1 parent 1434803 commit d103a64
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 0 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
57 changes: 57 additions & 0 deletions src/test/checkpoint_persistent_shmem.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/* -*- Mode: C; tab-width: 8; c-basic-offset: 2; indent-tabs-mode: nil; -*- */

#include "util.h"

#include <fcntl.h>
#include <string.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <unistd.h>

#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;
}
22 changes: 22 additions & 0 deletions src/test/checkpoint_persistent_shmem.py
Original file line number Diff line number Diff line change
@@ -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()
2 changes: 2 additions & 0 deletions src/test/checkpoint_persistent_shmem.run
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
source `dirname $0`/util.sh
debug_test_gdb_only

0 comments on commit d103a64

Please sign in to comment.