Skip to content

Commit d103a64

Browse files
committed
Added the first test for persistent checkpoints
1 parent 1434803 commit d103a64

File tree

4 files changed

+82
-0
lines changed

4 files changed

+82
-0
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1512,6 +1512,7 @@ set(TESTS_WITH_PROGRAM
15121512
# check_session_leaks
15131513
checkpoint_dying_threads
15141514
checkpoint_mixed_mode
1515+
checkpoint_persistent_shmem
15151516
checksum_sanity
15161517
check_lost_interrupts
15171518
clone_file_range
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/* -*- Mode: C; tab-width: 8; c-basic-offset: 2; indent-tabs-mode: nil; -*- */
2+
3+
#include "util.h"
4+
5+
#include <fcntl.h>
6+
#include <string.h>
7+
#include <sys/mman.h>
8+
#include <sys/stat.h>
9+
#include <unistd.h>
10+
11+
#define SHM_NAME "/my_shared_memory"
12+
#define SHM_SIZE 4096
13+
14+
static void breakpoint(void) {}
15+
16+
int main(void) {
17+
// Create shared memory
18+
int shm_fd = shm_open(SHM_NAME, O_CREAT | O_RDWR, 0666);
19+
if (shm_fd == -1) {
20+
perror("shm_open");
21+
return 1;
22+
}
23+
ftruncate(shm_fd, SHM_SIZE);
24+
25+
// Map shared memory
26+
const char* ptr =
27+
(char*)mmap(0, SHM_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, shm_fd, 0);
28+
if (ptr == MAP_FAILED) {
29+
perror("mmap");
30+
return 1;
31+
}
32+
33+
pid_t pid = fork();
34+
if (pid < 0) {
35+
perror("fork");
36+
return 1;
37+
}
38+
39+
const char* parent_msg = "hello parent";
40+
const char* child_msg = "hello child\0";
41+
if (pid == 0) {
42+
sleep(1);
43+
memcpy((void*)ptr, parent_msg, strlen(parent_msg));
44+
return 1;
45+
} else {
46+
wait(NULL);
47+
memcpy((void*)(ptr + strlen(parent_msg)), child_msg, strlen(child_msg));
48+
breakpoint();
49+
}
50+
51+
// Cleanup
52+
munmap((void*)ptr, SHM_SIZE);
53+
shm_unlink(SHM_NAME);
54+
55+
atomic_puts("EXIT-SUCCESS");
56+
return 0;
57+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from util import *
2+
3+
send_gdb('break 48')
4+
expect_gdb('Breakpoint 1')
5+
send_gdb('c')
6+
expect_gdb('Breakpoint 1')
7+
8+
send_gdb('checkpoint')
9+
send_gdb('write-checkpoints')
10+
send_gdb('delete checkpoint 1')
11+
send_gdb('c')
12+
13+
expect_rr('EXIT-SUCCESS')
14+
15+
send_gdb('load-checkpoints')
16+
send_gdb('restart 2')
17+
expect_gdb('Program stopped')
18+
19+
send_gdb('print ptr')
20+
expect_gdb('"hello parenthello child"')
21+
22+
ok()
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
source `dirname $0`/util.sh
2+
debug_test_gdb_only

0 commit comments

Comments
 (0)