[CRIU] [PATCH 3/3] test/compel: add va_args printing to launch_test()

Dmitry Safonov dsafonov at virtuozzo.com
Wed May 25 05:52:59 PDT 2016


Also changed tests messages, before (on x86):
  ok 1 - check zero ELF header
  ok 2 - check non-supported ELF header
  ok 3 - check non-relocatable ELF header
  ok 4 - check zero ELF header
  ok 5 - check non-supported ELF header
  ok 6 - check non-relocatable ELF header
After:
  ok 1 - zero ELF header (64-bit ELF)
  ok 2 - unsupported ELF header (64-bit ELF)
  ok 3 - non-relocatable ELF header (64-bit ELF)
  ok 4 - zero ELF header (32-bit ELF)
  ok 5 - unsupported ELF header (32-bit ELF)
  ok 6 - non-relocatable ELF header (32-bit ELF)

Cc: Cyrill Gorcunov <gorcunov at openvz.org>
Signed-off-by: Dmitry Safonov <dsafonov at virtuozzo.com>
---
 .../arch/aarch64/include/arch_test_handle_binary.h |  2 +-
 .../arch/arm/include/arch_test_handle_binary.h     |  2 +-
 .../arch/ppc64/include/arch_test_handle_binary.h   |  2 +-
 .../arch/x86/include/arch_test_handle_binary.h     |  8 ++++----
 test/compel/handle_binary.c                        | 14 ++++++-------
 test/compel/main.c                                 | 23 +++++++++++++++-------
 6 files changed, 30 insertions(+), 21 deletions(-)

diff --git a/test/compel/arch/aarch64/include/arch_test_handle_binary.h b/test/compel/arch/aarch64/include/arch_test_handle_binary.h
index 9ed25c9f5aed..cbefd6843d6c 100644
--- a/test/compel/arch/aarch64/include/arch_test_handle_binary.h
+++ b/test/compel/arch/aarch64/include/arch_test_handle_binary.h
@@ -2,7 +2,7 @@
 #define __ARCH_TEST_HANDLE_BINARY__
 
 #include "uapi/elf64-types.h"
-#define __run_tests	arch_run_tests
+#define arch_run_tests(mem) __run_tests(mem, "")
 
 static __maybe_unused void arch_test_set_elf_hdr_ident(void *mem)
 {
diff --git a/test/compel/arch/arm/include/arch_test_handle_binary.h b/test/compel/arch/arm/include/arch_test_handle_binary.h
index 4b14b2bf682b..d803829119d6 100644
--- a/test/compel/arch/arm/include/arch_test_handle_binary.h
+++ b/test/compel/arch/arm/include/arch_test_handle_binary.h
@@ -2,7 +2,7 @@
 #define __ARCH_TEST_HANDLE_BINARY__
 
 #include "uapi/elf32-types.h"
-#define __run_tests	arch_run_tests
+#define arch_run_tests(mem) __run_tests(mem, "")
 
 static __maybe_unused void arch_test_set_elf_hdr_ident(void *mem)
 {
diff --git a/test/compel/arch/ppc64/include/arch_test_handle_binary.h b/test/compel/arch/ppc64/include/arch_test_handle_binary.h
index 7bf80b25d524..0c70c91db289 100644
--- a/test/compel/arch/ppc64/include/arch_test_handle_binary.h
+++ b/test/compel/arch/ppc64/include/arch_test_handle_binary.h
@@ -2,7 +2,7 @@
 #define __ARCH_TEST_HANDLE_BINARY__
 
 #include "uapi/elf64-types.h"
-#define __run_tests	arch_run_tests
+#define arch_run_tests(mem) __run_tests(mem, "")
 
 static __maybe_unused void arch_test_set_elf_hdr_ident(void *mem)
 {
diff --git a/test/compel/arch/x86/include/arch_test_handle_binary.h b/test/compel/arch/x86/include/arch_test_handle_binary.h
index cbc240e5892a..082c00dfb648 100644
--- a/test/compel/arch/x86/include/arch_test_handle_binary.h
+++ b/test/compel/arch/x86/include/arch_test_handle_binary.h
@@ -34,12 +34,12 @@ static __maybe_unused void arch_test_set_elf_hdr_machine(Ehdr_t *hdr)
 
 #endif /* CONFIG_X86_32 */
 
-extern void run_tests_64(void *mem);
-extern void run_tests_32(void *mem);
+extern void run_tests_64(void *mem, const char *msg);
+extern void run_tests_32(void *mem, const char *msg);
 
 static __maybe_unused void arch_run_tests(void *mem)
 {
-	run_tests_64(mem);
-	run_tests_32(mem);
+	run_tests_64(mem, "(64-bit ELF)");
+	run_tests_32(mem, "(32-bit ELF)");
 }
 #endif /* __ARCH_TEST_HANDLE_BINARY__ */
diff --git a/test/compel/handle_binary.c b/test/compel/handle_binary.c
index a1d0bc0a09d8..09100427f2bb 100644
--- a/test/compel/handle_binary.c
+++ b/test/compel/handle_binary.c
@@ -5,7 +5,7 @@
 
 #include "arch_test_handle_binary.h"
 
-extern int launch_test(void *mem, int expected_ret, const char *test_name);
+extern int launch_test(void *mem, int expected_ret, const char *test_fmt, ...);
 
 static void set_elf_hdr_relocatable(Ehdr_t *hdr)
 {
@@ -13,18 +13,18 @@ static void set_elf_hdr_relocatable(Ehdr_t *hdr)
 	hdr->e_version = EV_CURRENT;
 }
 
-static int test_prepare_elf_header(void *elf)
+static int test_prepare_elf_header(void *elf, const char *msg)
 {
 	memset(elf, 0, sizeof(Ehdr_t));
-	if (launch_test(elf, -E_NOT_ELF, "check zero ELF header"))
+	if (launch_test(elf, -E_NOT_ELF, "zero ELF header %s", msg))
 		return -1;
 
 	arch_test_set_elf_hdr_ident(elf);
-	if (launch_test(elf, -E_NOT_ELF, "check non-supported ELF header"))
+	if (launch_test(elf, -E_NOT_ELF, "unsupported ELF header %s", msg))
 		return -1;
 
 	arch_test_set_elf_hdr_machine(elf);
-	if (launch_test(elf, -E_NOT_ELF, "check non-relocatable ELF header"))
+	if (launch_test(elf, -E_NOT_ELF, "non-relocatable ELF header %s", msg))
 		return -1;
 
 	set_elf_hdr_relocatable(elf);
@@ -32,8 +32,8 @@ static int test_prepare_elf_header(void *elf)
 	return 0;
 }
 
-void __run_tests(void *mem)
+void __run_tests(void *mem, const char *msg)
 {
-	if (test_prepare_elf_header(mem))
+	if (test_prepare_elf_header(mem, msg))
 		return;
 }
diff --git a/test/compel/main.c b/test/compel/main.c
index e272dfb766da..869d5f7a2240 100644
--- a/test/compel/main.c
+++ b/test/compel/main.c
@@ -12,6 +12,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <stdarg.h>
 
 #include "piegen.h"
 #include "arch_test_handle_binary.h"
@@ -22,22 +23,30 @@
 extern int handle_binary(void *mem, size_t size);
 extern void run_tests(void *mem);
 
+/* To shut down error printing on tests for failures */
 piegen_opt_t opts = {
 	.fout		= NULL,
 	.ferr		= NULL,
 	.fdebug		= NULL,
 };
 
-int launch_test(void *mem, int expected_ret, const char *test_name)
+int launch_test(void *mem, int expected_ret, const char *test_fmt, ...)
 {
 	static unsigned test_nr = 1;
 	int ret = handle_binary(mem, ELF_BUF_SIZE);
-
-	if (ret != expected_ret)
-		printf("not ok %u - %s, expected %d but ret is %d\n",
-				test_nr, test_name, expected_ret, ret);
-	else
-		printf("ok %u - %s\n", test_nr, test_name);
+	va_list params;
+
+	va_start(params, test_fmt);
+	if (ret != expected_ret) {
+		printf("not ok %u - ", test_nr);
+		vprintf(test_fmt, params);
+		printf(", expected %d but ret is %d\n", expected_ret, ret);
+	} else {
+		printf("ok %u - ", test_nr);
+		vprintf(test_fmt, params);
+		putchar('\n');
+	}
+	va_end(params);
 	test_nr++;
 	fflush(stdout);
 
-- 
2.8.2



More information about the CRIU mailing list