-
Notifications
You must be signed in to change notification settings - Fork 202
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[LibOS] Add testcase for reproducing checkpoint on mmap() issue
This test case will occasionally show the following error: > while :; do gramine-direct fork_and_mmap; done ... [P2:T3:fork_and_mmap] error: Sending IPC process-exit notification \ failed: Connection reset by peer (ECONNRESET) Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
- Loading branch information
1 parent
2bfdb84
commit f1b0132
Showing
5 changed files
with
74 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* 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> | ||
#include <sys/mman.h> | ||
|
||
#define NUM_PAGES 1024 | ||
|
||
int proceed = 0; | ||
|
||
static void* thread_func(void* arg) { | ||
while (__atomic_load_n(&proceed, __ATOMIC_ACQUIRE) == 0) | ||
usleep(1); | ||
proceed = 0; | ||
|
||
usleep(1); | ||
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) { | ||
long page_size = sysconf(_SC_PAGESIZE); | ||
if (page_size == -1 && errno) { | ||
err(1, "sysconf"); | ||
} | ||
|
||
|
||
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 < NUM_PAGES; i++) | ||
mmap(NULL, page_size, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); | ||
|
||
proceed = 1; | ||
sleep(1); | ||
|
||
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
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
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