File: main.c

package info (click to toggle)
criu 4.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 11,500 kB
  • sloc: ansic: 139,280; python: 7,484; sh: 3,824; java: 2,799; makefile: 2,659; asm: 1,137; perl: 206; xml: 117; exp: 45
file content (57 lines) | stat: -rw-r--r-- 1,348 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
 * 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);

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;
}