2
0
mirror of https://github.com/checkpoint-restore/criu synced 2025-08-26 03:47:35 +00:00
criu/test/compel/main.c
Dmitry Safonov d6cea81047 compel/tests: test binary should return error
To check test's result in travis.

Cc: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Dmitry Safonov <dsafonov@virtuozzo.com>
Reviewed-by: Cyrill Gorcunov <gorcunov@gmail.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-03-14 21:03:30 +03:00

65 lines
1.4 KiB
C

/*
* Test for handle_binary().
* In this test ELF binary file is constructed from
* header up to sections and relocations.
* On each stage it tests non-valid ELF binaries to be parsed.
* For passing test, handle_binary should return errors for all
* non-valid binaries and handle all relocations.
*
* Test author: Dmitry Safonov <dsafonov@virtuozzo.com>
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdarg.h>
#include "piegen.h"
#include "arch_test_handle_binary.h"
/* size of buffer with formed ELF file */
const size_t test_elf_buf_size = 4096;
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_fmt, ...)
{
static unsigned test_nr = 1;
int ret = handle_binary(mem, test_elf_buf_size);
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);
return ret != expected_ret;
}
int main(int argc, char **argv)
{
void *elf_buf = malloc(test_elf_buf_size);
int ret;
ret = arch_run_tests(elf_buf);
free(elf_buf);
return ret;
}