-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: generate checkpoint image files for tests
Previously, tests were run against a stats-dump file available in the test directory. Now that we require other checkpoint files to test the functionality added through CRIT, a proper checkpoint is generated with CRIU and used. Signed-off-by: Prajwal S N <[email protected]>
- Loading branch information
Showing
11 changed files
with
145 additions
and
49 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
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 |
---|---|---|
|
@@ -2,3 +2,5 @@ checkpointctl | |
checkpointctl.coverage | ||
.coverage | ||
junit.xml | ||
test/piggie/piggie | ||
test/test-imgs |
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,26 @@ | ||
CRIU ?= criu | ||
CC ?= gcc | ||
|
||
all: test clean | ||
|
||
test: test-imgs | ||
@echo "Running BATS tests..." | ||
bats checkpointctl.bats | ||
|
||
test-junit: test-imgs | ||
@echo "Running BATS tests with JUnit results..." | ||
bats -F junit checkpointctl.bats > junit.xml | ||
|
||
test-imgs: piggie/piggie | ||
$(eval PID := $(shell piggie/piggie)) | ||
mkdir -p $@ | ||
$(CRIU) dump -v4 -o dump.log -D $@ -t $(PID) | ||
|
||
piggie/piggie: piggie/piggie.c | ||
$(CC) $^ -o $@ | ||
|
||
clean: | ||
@echo "Cleaning up test files..." | ||
@rm -rf test-imgs piggie/piggie | ||
|
||
.PHONY: all test test-junit clean |
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,61 @@ | ||
#define _GNU_SOURCE | ||
#include <stdio.h> | ||
#include <signal.h> | ||
#include <unistd.h> | ||
#include <sys/mman.h> | ||
#include <fcntl.h> | ||
#include <sched.h> | ||
|
||
#define STKS (4*4096) | ||
|
||
#ifndef CLONE_NEWPID | ||
#define CLONE_NEWPID 0x20000000 | ||
#endif | ||
|
||
static int do_test(void *logf) | ||
{ | ||
int fd, i = 0; | ||
|
||
setsid(); | ||
|
||
close(0); | ||
close(1); | ||
close(2); | ||
|
||
fd = open("/dev/null", O_RDONLY); | ||
if (fd != 0) { | ||
dup2(fd, 0); | ||
close(fd); | ||
} | ||
|
||
fd = open(logf, O_WRONLY | O_TRUNC | O_CREAT, 0600); | ||
dup2(fd, 1); | ||
dup2(fd, 2); | ||
if (fd != 1 && fd != 2) | ||
close(fd); | ||
|
||
while (1) { | ||
sleep(1); | ||
printf("%d\n", i++); | ||
fflush(stdout); | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
int main(int argc, char **argv) | ||
{ | ||
int pid; | ||
void *stk; | ||
|
||
stk = mmap(NULL, STKS, PROT_READ | PROT_WRITE, | ||
MAP_PRIVATE | MAP_ANON | MAP_GROWSDOWN, 0, 0); | ||
pid = clone(do_test, stk + STKS, SIGCHLD | CLONE_NEWPID, argv[1]); | ||
if (pid < 0) { | ||
fprintf(stderr, "clone() failed: %m\n"); | ||
return 1; | ||
} | ||
printf("%d\n", pid); | ||
|
||
return 0; | ||
} |
Binary file not shown.