diff --git a/test/others/.gitignore b/test/others/.gitignore new file mode 100644 index 000000000..1ef2ddf24 --- /dev/null +++ b/test/others/.gitignore @@ -0,0 +1 @@ +loop diff --git a/test/others/Makefile b/test/others/Makefile new file mode 100644 index 000000000..b84894bfa --- /dev/null +++ b/test/others/Makefile @@ -0,0 +1,2 @@ +loop: + gcc -Wall loop.c -o loop diff --git a/test/others/crit/Makefile b/test/others/crit/Makefile index 75d09b66c..ca296e333 100644 --- a/test/others/crit/Makefile +++ b/test/others/crit/Makefile @@ -1,4 +1,5 @@ run: clean + @make -C .. loop ./test.sh clean: diff --git a/test/others/crit/loop.sh b/test/others/crit/loop.sh deleted file mode 100755 index 0ab34ce96..000000000 --- a/test/others/crit/loop.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash -while :; do - sleep 1 -done diff --git a/test/others/crit/test.sh b/test/others/crit/test.sh index 345f8ce04..0d38043d7 100755 --- a/test/others/crit/test.sh +++ b/test/others/crit/test.sh @@ -8,8 +8,7 @@ source ../env.sh images_list="" function gen_imgs { - setsid ./loop.sh < /dev/null &> /dev/null & - PID=$! + PID=$(../loop) if ! $CRIU dump -v4 -o dump.log -D ./ -t "$PID"; then echo "Failed to checkpoint process $PID" cat dump.log diff --git a/test/others/criu-coredump/Makefile b/test/others/criu-coredump/Makefile index aa684a972..2b0d5e688 100644 --- a/test/others/criu-coredump/Makefile +++ b/test/others/criu-coredump/Makefile @@ -1,4 +1,5 @@ run: clean + @make -C .. loop ./test.sh clean: diff --git a/test/others/criu-coredump/loop.sh b/test/others/criu-coredump/loop.sh deleted file mode 100755 index 0ab34ce96..000000000 --- a/test/others/criu-coredump/loop.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash -while :; do - sleep 1 -done diff --git a/test/others/criu-coredump/test.sh b/test/others/criu-coredump/test.sh index 6a0fbc627..62d9f7edc 100755 --- a/test/others/criu-coredump/test.sh +++ b/test/others/criu-coredump/test.sh @@ -1,8 +1,7 @@ source ../env.sh function gen_imgs { - setsid ./loop.sh < /dev/null &> /dev/null & - PID=$! + PID=$(../loop) if ! $CRIU dump -v4 -o dump.log -D ./ -t "$PID"; then echo "Failed to checkpoint process $PID" cat dump.log diff --git a/test/others/loop.c b/test/others/loop.c new file mode 100644 index 000000000..850c5dedf --- /dev/null +++ b/test/others/loop.c @@ -0,0 +1,63 @@ +#include +#include +#include +#include +#include +#include + +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; +} diff --git a/test/others/rpc/Makefile b/test/others/rpc/Makefile index 08caa0c77..fc64f0c97 100644 --- a/test/others/rpc/Makefile +++ b/test/others/rpc/Makefile @@ -7,6 +7,7 @@ LDLIBS += -lprotobuf-c PYTHON ?= python run: all + @make -C .. loop mkdir -p build chmod a+rwx build rm -f build/status diff --git a/test/others/rpc/loop.sh b/test/others/rpc/loop.sh deleted file mode 100755 index 0ab34ce96..000000000 --- a/test/others/rpc/loop.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash -while :; do - sleep 1 -done diff --git a/test/others/rpc/run.sh b/test/others/rpc/run.sh index d1facd82f..afd4fb5e3 100755 --- a/test/others/rpc/run.sh +++ b/test/others/rpc/run.sh @@ -44,12 +44,11 @@ function test_py { function test_restore_loop { mkdir -p build/imgs_loop - title_print "Run loop.sh" - setsid ./loop.sh < /dev/null &> build/loop.log & - P=${!} + title_print "Run loop process" + P=$(../loop) echo "pid ${P}" - title_print "Dump loop.sh" + title_print "Dump loop process" # So theoretically '-j' (--shell-job) should not be necessary, but on alpine # this test fails without it. ${CRIU} dump -j -v4 -o dump-loop.log -D build/imgs_loop -t ${P}