[CRIU] [PATCH 6/6] test: Add lib.c to libcriu tests

Pavel Emelyanov xemul at parallels.com
Wed Jun 25 04:25:24 PDT 2014


Just some common stuff.

Signed-off-by: Pavel Emelyanov <xemul at parallels.com>
---
 test/libcriu/Makefile    |  7 +++++--
 test/libcriu/lib.c       | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 test/libcriu/lib.h       |  2 ++
 test/libcriu/test_self.c | 45 +--------------------------------------------
 test/libcriu/test_sub.c  | 43 +------------------------------------------
 5 files changed, 56 insertions(+), 88 deletions(-)
 create mode 100644 test/libcriu/lib.c
 create mode 100644 test/libcriu/lib.h

diff --git a/test/libcriu/Makefile b/test/libcriu/Makefile
index 462af64..c6a8697 100644
--- a/test/libcriu/Makefile
+++ b/test/libcriu/Makefile
@@ -4,18 +4,21 @@ all: test_sub test_self
 run: all
 	./run.sh
 
-test_sub: test_sub.o
+test_sub: test_sub.o lib.o
 	gcc $^ -L ../../lib -lcriu -o $@
 
 test_sub.o: test_sub.c
 	gcc -c $^ -I ../../lib -o $@
 
-test_self: test_self.o
+test_self: test_self.o lib.o
 	gcc $^ -L ../../lib -lcriu -o $@
 
 test_self.o: test_self.c
 	gcc -c $^ -I ../../lib -o $@
 
+lib.o: lib.c
+	gcc -c $^ -I ../../lib -o $@
+
 clean:
 	rm -rf test_sub test_sub.o test_self test_sub.o
 .PHONY: clean
diff --git a/test/libcriu/lib.c b/test/libcriu/lib.c
new file mode 100644
index 0000000..33aa409
--- /dev/null
+++ b/test/libcriu/lib.c
@@ -0,0 +1,47 @@
+#include <stdio.h>
+#include <errno.h>
+#include <sys/wait.h>
+
+void what_err_ret_mean(int ret)
+{
+	/* NOTE: errno is set by libcriu */
+	switch (ret) {
+	case -EBADE:
+		perror("RPC has returned fail");
+		break;
+	case -ECONNREFUSED:
+		perror("Unable to connect to CRIU");
+		break;
+	case -ECOMM:
+		perror("Unable to send/recv msg to/from CRIU");
+		break;
+	case -EINVAL:
+		perror("CRIU doesn't support this type of request."
+		       "You should probably update CRIU");
+		break;
+	case -EBADMSG:
+		perror("Unexpected response from CRIU."
+		       "You should probably update CRIU");
+		break;
+	default:
+		perror("Unknown error type code."
+		       "You should probably update CRIU");
+	}
+}
+
+int chk_exit(int status, int want)
+{
+	if (WIFEXITED(status)) {
+		if (WEXITSTATUS(status) == want)
+			return 0;
+
+		printf("   `- FAIL (exit %d)\n", WEXITSTATUS(status));
+	} else if (WIFSIGNALED(status))
+		printf("   `- FAIL (die %d)\n", WTERMSIG(status));
+	else
+		printf("   `- FAIL (%#x)\n", status);
+
+	return 1;
+}
+
+
diff --git a/test/libcriu/lib.h b/test/libcriu/lib.h
new file mode 100644
index 0000000..67b784b
--- /dev/null
+++ b/test/libcriu/lib.h
@@ -0,0 +1,2 @@
+void what_err_ret_mean(int ret);
+int chk_exit(int status, int want);
diff --git a/test/libcriu/test_self.c b/test/libcriu/test_self.c
index c4aa061..592ec5f 100644
--- a/test/libcriu/test_self.c
+++ b/test/libcriu/test_self.c
@@ -6,50 +6,7 @@
 #include <errno.h>
 #include <signal.h>
 #include <sys/wait.h>
-
-static void what_err_ret_mean(ret)
-{
-	/* NOTE: errno is set by libcriu */
-	switch (ret) {
-	case -EBADE:
-		perror("RPC has returned fail");
-		break;
-	case -ECONNREFUSED:
-		perror("Unable to connect to CRIU");
-		break;
-	case -ECOMM:
-		perror("Unable to send/recv msg to/from CRIU");
-		break;
-	case -EINVAL:
-		perror("CRIU doesn't support this type of request."
-		       "You should probably update CRIU");
-		break;
-	case -EBADMSG:
-		perror("Unexpected response from CRIU."
-		       "You should probably update CRIU");
-		break;
-	default:
-		perror("Unknown error type code."
-		       "You should probably update CRIU");
-	}
-}
-
-static inline int chk_exit(int status, int want)
-{
-	if (WIFEXITED(status)) {
-		if (WEXITSTATUS(status) == want) {
-			printf("   `- Success\n");
-			return 0;
-		}
-
-		printf("   `- FAIL (exit %d)\n", WEXITSTATUS(status));
-	} else if (WIFSIGNALED(status))
-		printf("   `- FAIL (die %d)\n", WTERMSIG(status));
-	else
-		printf("   `- FAIL (%#x)\n", status);
-
-	return 1;
-}
+#include "lib.h"
 
 #define SUCC_DUMP_ECODE	41
 #define SUCC_RSTR_ECODE	43
diff --git a/test/libcriu/test_sub.c b/test/libcriu/test_sub.c
index 162c331..161a671 100644
--- a/test/libcriu/test_sub.c
+++ b/test/libcriu/test_sub.c
@@ -4,48 +4,7 @@
 #include <errno.h>
 #include <stdlib.h>
 #include <signal.h>
-
-static void what_err_ret_mean(ret)
-{
-	/* NOTE: errno is set by libcriu */
-	switch (ret) {
-	case -EBADE:
-		perror("RPC has returned fail");
-		break;
-	case -ECONNREFUSED:
-		perror("Unable to connect to CRIU");
-		break;
-	case -ECOMM:
-		perror("Unable to send/recv msg to/from CRIU");
-		break;
-	case -EINVAL:
-		perror("CRIU doesn't support this type of request."
-		       "You should probably update CRIU");
-		break;
-	case -EBADMSG:
-		perror("Unexpected response from CRIU."
-		       "You should probably update CRIU");
-		break;
-	default:
-		perror("Unknown error type code."
-		       "You should probably update CRIU");
-	}
-}
-
-static inline int chk_exit(int status, int want)
-{
-	if (WIFEXITED(status)) {
-		if (WEXITSTATUS(status) == want)
-			return 0;
-
-		printf("   `- FAIL (exit %d)\n", WEXITSTATUS(status));
-	} else if (WIFSIGNALED(status))
-		printf("   `- FAIL (die %d)\n", WTERMSIG(status));
-	else
-		printf("   `- FAIL (%#x)\n", status);
-
-	return 1;
-}
+#include "lib.h"
 
 static int stop = 0;
 static void sh(int sig)
-- 
1.8.4.2




More information about the CRIU mailing list