-
Notifications
You must be signed in to change notification settings - Fork 601
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added the first test for persistent checkpoints
- Loading branch information
1 parent
1434803
commit d103a64
Showing
4 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
source `dirname $0`/util.sh | ||
debug_test_gdb_only |