[CRIU] [PATCH] test: Add tstexec test-case
Cyrill Gorcunov
gorcunov at openvz.org
Wed Sep 5 12:43:05 EDT 2012
Guys, I believe it worth to have in our tree (we could
tune it up more if needed)
-------------- next part --------------
>From ec0e835618718cd77a0c88ba5c4bb6eafcf91e77 Mon Sep 17 00:00:00 2001
From: Cyrill Gorcunov <gorcunov at openvz.org>
Date: Wed, 5 Sep 2012 20:41:27 +0400
Subject: [PATCH] test: Add tstexec test-case
Provided-by: Daniel Lezcano <daniel.lezcano at linaro.org>
Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
test/app-emu/forking/Makefile | 8 +++++++
test/app-emu/forking/run.sh | 28 +++++++++++++++++++++++++++
test/app-emu/forking/tstexec.c | 41 ++++++++++++++++++++++++++++++++++++++++
3 files changed, 77 insertions(+), 0 deletions(-)
create mode 100644 test/app-emu/forking/Makefile
create mode 100644 test/app-emu/forking/run.sh
create mode 100644 test/app-emu/forking/tstexec.c
diff --git a/test/app-emu/forking/Makefile b/test/app-emu/forking/Makefile
new file mode 100644
index 0000000..6da3fcd
--- /dev/null
+++ b/test/app-emu/forking/Makefile
@@ -0,0 +1,8 @@
+all: tstexec
+ echo "Done"
+
+tstexec: tstexec.c
+ gcc $< -o $@
+
+clean:
+ rm -f *.o
diff --git a/test/app-emu/forking/run.sh b/test/app-emu/forking/run.sh
new file mode 100644
index 0000000..31ef8f7
--- /dev/null
+++ b/test/app-emu/forking/run.sh
@@ -0,0 +1,28 @@
+#!/bin/bash
+
+crtools="../../../crtools"
+
+setsid ./tstexec > /dev/null &
+
+pid=${!}
+
+rm -fr ./dump
+mkdir dump
+
+for i in {1..5}; do
+ echo "Dumping"
+ ${crtools} dump -D ./dump -o dump.log -v 4 -t ${pid} || {
+ echo "Dump failed"
+ exit 1
+ }
+
+ sleep 1
+
+ echo "Dumped, restoring and waiting for completion"
+ ${crtools} restore -d -D ./dump -o restore.log -v 4 -t ${pid} || {
+ echo "Restore failed"
+ exit 1
+ }
+done
+
+echo PASS
diff --git a/test/app-emu/forking/tstexec.c b/test/app-emu/forking/tstexec.c
new file mode 100644
index 0000000..3202902
--- /dev/null
+++ b/test/app-emu/forking/tstexec.c
@@ -0,0 +1,41 @@
+/*
+ * A test case from Daniel Lezcano <daniel.lezcano at linaro.org>
+ *
+ * http://openvz.org/pipermail/criu/2012-September/004381.html
+ */
+#include <stdio.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+
+int main(int argc, char *argv[])
+{
+ pid_t pid;
+ int status;
+
+ while (1) {
+ pid = fork();
+ if (!pid) {
+ execl("/bin/true", "/bin/true", NULL);
+ return 1;
+ } else if (pid > 0) {
+ if (waitpid(pid, &status, 0) < 0) {
+ perror("waitpid\n");
+ break;
+ }
+
+ if (WIFEXITED(status) && !WEXITSTATUS(status)) {
+ fprintf(stderr, ".");
+ continue;
+ }
+
+ printf("child process exited anormally\n");
+ break;
+ }
+
+ perror("fork\n");
+ break;
+ }
+
+ return 0;
+}
--
1.7.7.6
More information about the CRIU
mailing list