-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(crit): add E2E test for crit CLI
The end-to-end test uses a simple C program to generate image files and test all commands provided by the crit CLI. Signed-off-by: Prajwal S N <prajwalnadig21@gmail.com>
- Loading branch information
Showing
6 changed files
with
188 additions
and
2 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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
CC ?= gcc | ||
|
||
all: test clean | ||
|
||
test: loop | ||
@./crit-test.sh | ||
|
||
loop: loop.c | ||
$(CC) $^ -o $@ | ||
|
||
clean: | ||
@rm -f *.img *.log *.json stats-* | ||
|
||
.PHONY: all test 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
#!/bin/bash | ||
|
||
set -x | ||
|
||
CRIT=../../crit/bin/crit | ||
|
||
function gen_imgs { | ||
PID=$(./loop) | ||
if ! criu dump -v4 -o dump.log -D ./ -t "$PID"; then | ||
echo "Failed to checkpoint process $PID" | ||
cat dump.log | ||
kill -9 "$PID" | ||
exit 1 | ||
fi | ||
|
||
images_list=$(ls -1 ./*.img) | ||
if [ -z "$images_list" ]; then | ||
echo "Failed to generate images" | ||
exit 1 | ||
fi | ||
} | ||
|
||
function run_test1 { | ||
for x in $images_list | ||
do | ||
echo "=== $x" | ||
if [[ $x == *pages* ]]; then | ||
echo "skip" | ||
continue | ||
fi | ||
|
||
echo " -- to json" | ||
$CRIT decode -i "$x" -o "$x"".json" --pretty || exit $? | ||
echo " -- to img" | ||
$CRIT encode -i "$x"".json" -o "$x"".json.img" || exit $? | ||
echo " -- cmp" | ||
cmp "$x" "$x"".json.img" || exit $? | ||
|
||
echo "=== done" | ||
done | ||
} | ||
|
||
|
||
function run_test2 { | ||
mapfile -t array <<< "$images_list" | ||
|
||
PROTO_IN=${array[0]} | ||
JSON_IN=$(mktemp -p ./ tmp.XXXXXXXXXX.json) | ||
OUT=$(mktemp -p ./ tmp.XXXXXXXXXX.log) | ||
|
||
# prepare | ||
${CRIT} decode -i "${PROTO_IN}" -o "${JSON_IN}" | ||
|
||
# proto in - json out decode | ||
cat "${PROTO_IN}" | ${CRIT} decode || exit 1 | ||
cat "${PROTO_IN}" | ${CRIT} decode -o "${OUT}" || exit 1 | ||
cat "${PROTO_IN}" | ${CRIT} decode > "${OUT}" || exit 1 | ||
${CRIT} decode -i "${PROTO_IN}" || exit 1 | ||
${CRIT} decode -i "${PROTO_IN}" -o "${OUT}" || exit 1 | ||
${CRIT} decode -i "${PROTO_IN}" > "${OUT}" || exit 1 | ||
${CRIT} decode < "${PROTO_IN}" || exit 1 | ||
${CRIT} decode -o "${OUT}" < "${PROTO_IN}" || exit 1 | ||
${CRIT} decode < "${PROTO_IN}" > "${OUT}" || exit 1 | ||
|
||
# proto in - json out encode -> should fail | ||
cat "${PROTO_IN}" | ${CRIT} encode || true | ||
cat "${PROTO_IN}" | ${CRIT} encode -o "${OUT}" || true | ||
cat "${PROTO_IN}" | ${CRIT} encode > "${OUT}" || true | ||
${CRIT} encode -i "${PROTO_IN}" || true | ||
${CRIT} encode -i "${PROTO_IN}" -o "${OUT}" || true | ||
${CRIT} encode -i "${PROTO_IN}" > "${OUT}" || true | ||
|
||
# json in - proto out encode | ||
cat "${JSON_IN}" | ${CRIT} encode || exit 1 | ||
cat "${JSON_IN}" | ${CRIT} encode -o "${OUT}" || exit 1 | ||
cat "${JSON_IN}" | ${CRIT} encode > "${OUT}" || exit 1 | ||
${CRIT} encode -i "${JSON_IN}" || exit 1 | ||
${CRIT} encode -i "${JSON_IN}" -o "${OUT}" || exit 1 | ||
${CRIT} encode -i "${JSON_IN}" > "${OUT}" || exit 1 | ||
${CRIT} encode < "${JSON_IN}" || exit 1 | ||
${CRIT} encode -o "${OUT}" < "${JSON_IN}" || exit 1 | ||
${CRIT} encode < "${JSON_IN}" > "${OUT}" || exit 1 | ||
|
||
# json in - proto out decode -> should fail | ||
cat "${JSON_IN}" | ${CRIT} decode || true | ||
cat "${JSON_IN}" | ${CRIT} decode -o "${OUT}" || true | ||
cat "${JSON_IN}" | ${CRIT} decode > "${OUT}" || true | ||
${CRIT} decode -i "${JSON_IN}" || true | ||
${CRIT} decode -i "${JSON_IN}" -o "${OUT}" || true | ||
${CRIT} decode -i "${JSON_IN}" > "${OUT}" || true | ||
|
||
# explore image directory | ||
${CRIT} x ./ ps || exit 1 | ||
${CRIT} x ./ fds || exit 1 | ||
${CRIT} x ./ mems || exit 1 | ||
${CRIT} x ./ rss || exit 1 | ||
} | ||
|
||
echo "Generating images..." | ||
gen_imgs | ||
echo "Testing recode..." | ||
run_test1 | ||
echo "Testing commands..." | ||
run_test2 |
Binary file not shown.
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,63 @@ | ||
#include <sys/types.h> | ||
#include <sys/stat.h> | ||
#include <fcntl.h> | ||
#include <unistd.h> | ||
#include <stdlib.h> | ||
#include <stdio.h> | ||
|
||
int main(void) | ||
{ | ||
pid_t pid; | ||
pid_t sid; | ||
int res = EXIT_FAILURE; | ||
int start_pipe[2]; | ||
|
||
if (pipe(start_pipe)) { | ||
perror("pipe failed!"); | ||
goto out; | ||
} | ||
|
||
pid = fork(); | ||
if (pid < 0) { | ||
perror("fork failed!"); | ||
goto out; | ||
} | ||
|
||
if (pid == 0) { | ||
close(start_pipe[0]); | ||
|
||
sid = setsid(); | ||
if (sid < 0) { | ||
perror("setsid failed!"); | ||
res = EXIT_FAILURE; | ||
write(start_pipe[1], &res, sizeof(res)); | ||
close(start_pipe[1]); | ||
exit(1); | ||
} | ||
|
||
// Create a file descriptor for "crit x ./ fds" test | ||
open("/dev/null", O_RDONLY); | ||
|
||
chdir("/"); | ||
close(STDIN_FILENO); | ||
close(STDOUT_FILENO); | ||
close(STDERR_FILENO); | ||
|
||
res = EXIT_SUCCESS; | ||
write(start_pipe[1], &res, sizeof(res)); | ||
close(start_pipe[1]); | ||
|
||
while (1) { | ||
sleep(1); | ||
} | ||
} | ||
|
||
close(start_pipe[1]); | ||
read(start_pipe[0], &res, sizeof(res)); | ||
close(start_pipe[0]); | ||
|
||
out: | ||
if (res == EXIT_SUCCESS) | ||
printf("%d\n", pid); | ||
return res; | ||
} |