Commit 80a5f519 authored by Dmitry Safonov's avatar Dmitry Safonov Committed by Andrei Vagin

test/compel: add va_args printing to launch_test()

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@openvz.org>
Signed-off-by: 's avatarDmitry Safonov <dsafonov@virtuozzo.com>
Acked-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@virtuozzo.com>
Signed-off-by: 's avatarAndrei Vagin <avagin@virtuozzo.com>
parent e162c0cd
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
#define __ARCH_TEST_HANDLE_BINARY__ #define __ARCH_TEST_HANDLE_BINARY__
#include "uapi/elf64-types.h" #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) static __maybe_unused void arch_test_set_elf_hdr_ident(void *mem)
{ {
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
#define __ARCH_TEST_HANDLE_BINARY__ #define __ARCH_TEST_HANDLE_BINARY__
#include "uapi/elf32-types.h" #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) static __maybe_unused void arch_test_set_elf_hdr_ident(void *mem)
{ {
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
#define __ARCH_TEST_HANDLE_BINARY__ #define __ARCH_TEST_HANDLE_BINARY__
#include "uapi/elf64-types.h" #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) static __maybe_unused void arch_test_set_elf_hdr_ident(void *mem)
{ {
......
...@@ -34,12 +34,12 @@ static __maybe_unused void arch_test_set_elf_hdr_machine(Ehdr_t *hdr) ...@@ -34,12 +34,12 @@ static __maybe_unused void arch_test_set_elf_hdr_machine(Ehdr_t *hdr)
#endif /* CONFIG_X86_32 */ #endif /* CONFIG_X86_32 */
extern void run_tests_64(void *mem); extern void run_tests_64(void *mem, const char *msg);
extern void run_tests_32(void *mem); extern void run_tests_32(void *mem, const char *msg);
static __maybe_unused void arch_run_tests(void *mem) static __maybe_unused void arch_run_tests(void *mem)
{ {
run_tests_64(mem); run_tests_64(mem, "(64-bit ELF)");
run_tests_32(mem); run_tests_32(mem, "(32-bit ELF)");
} }
#endif /* __ARCH_TEST_HANDLE_BINARY__ */ #endif /* __ARCH_TEST_HANDLE_BINARY__ */
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
#include "arch_test_handle_binary.h" #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) static void set_elf_hdr_relocatable(Ehdr_t *hdr)
{ {
...@@ -13,18 +13,18 @@ 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; 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)); 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; return -1;
arch_test_set_elf_hdr_ident(elf); 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; return -1;
arch_test_set_elf_hdr_machine(elf); 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; return -1;
set_elf_hdr_relocatable(elf); set_elf_hdr_relocatable(elf);
...@@ -32,8 +32,8 @@ static int test_prepare_elf_header(void *elf) ...@@ -32,8 +32,8 @@ static int test_prepare_elf_header(void *elf)
return 0; 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; return;
} }
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
#include <stdarg.h>
#include "piegen.h" #include "piegen.h"
#include "arch_test_handle_binary.h" #include "arch_test_handle_binary.h"
...@@ -22,22 +23,30 @@ ...@@ -22,22 +23,30 @@
extern int handle_binary(void *mem, size_t size); extern int handle_binary(void *mem, size_t size);
extern void run_tests(void *mem); extern void run_tests(void *mem);
/* To shut down error printing on tests for failures */
piegen_opt_t opts = { piegen_opt_t opts = {
.fout = NULL, .fout = NULL,
.ferr = NULL, .ferr = NULL,
.fdebug = 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; static unsigned test_nr = 1;
int ret = handle_binary(mem, ELF_BUF_SIZE); int ret = handle_binary(mem, ELF_BUF_SIZE);
va_list params;
if (ret != expected_ret)
printf("not ok %u - %s, expected %d but ret is %d\n", va_start(params, test_fmt);
test_nr, test_name, expected_ret, ret); if (ret != expected_ret) {
else printf("not ok %u - ", test_nr);
printf("ok %u - %s\n", test_nr, test_name); 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++; test_nr++;
fflush(stdout); fflush(stdout);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment