mirror of
https://github.com/checkpoint-restore/criu
synced 2025-08-31 06:15:24 +00:00
test: Add anonymous shared memory test
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
This commit is contained in:
@@ -2,11 +2,18 @@ OBJS += testee.o
|
||||
OBJS += testee-static.o
|
||||
OBJS += testee-threads.o
|
||||
OBJS += testee-unlinked.o
|
||||
OBJS += asmem.o
|
||||
|
||||
PROGS := $(patsubst %.o,%,$(OBJS))
|
||||
|
||||
all: $(PROGS)
|
||||
|
||||
asmem: asmem.c
|
||||
$(E) " CC " $(patsubst %.c,%.o,$<)
|
||||
$(Q) $(CC) -c $(CFLAGS) $< -o $(patsubst %.c,%.o,$<)
|
||||
$(E) " LINK " $@
|
||||
$(Q) $(CC) -o $@ $(patsubst %.c,%.o,$<)
|
||||
|
||||
testee: testee.c
|
||||
$(E) " CC " $(patsubst %.c,%.o,$<)
|
||||
$(Q) $(CC) -c $(CFLAGS) $< -o $(patsubst %.c,%.o,$<)
|
||||
|
BIN
test/asmem
Executable file
BIN
test/asmem
Executable file
Binary file not shown.
53
test/asmem.c
Normal file
53
test/asmem.c
Normal file
@@ -0,0 +1,53 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <sys/wait.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/mman.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include <sched.h>
|
||||
|
||||
static void *map;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
pid_t pid;
|
||||
|
||||
printf("%s pid %d\n", argv[0], getpid());
|
||||
|
||||
map = mmap(NULL, 1024, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_SHARED, -1, 0);
|
||||
if (map == MAP_FAILED) {
|
||||
printf("mmap failed\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
memset(map, '-', 32);
|
||||
((char *)map)[32] = 0;
|
||||
|
||||
printf("%d: shmem '%s'\n", getpid(), (char *)map);
|
||||
|
||||
pid = fork();
|
||||
if (pid == -1) {
|
||||
printf("fork failed\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (pid == 0) {
|
||||
while(1) {
|
||||
printf("%d: shmem '%s'\n", getpid(), (char *)map);
|
||||
sleep(5);
|
||||
}
|
||||
} else {
|
||||
while(1) {
|
||||
printf("%d: shmem '%s'\n", getpid(), (char *)map);
|
||||
sleep(5);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user