summaryrefslogtreecommitdiff
path: root/usr/src/test/util-tests/tests/ctf/check-function.c
blob: fdb60ce29088ad1a0e52fc5c4fcdf8211b66d2ef (plain)
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
 * This file and its contents are supplied under the terms of the
 * Common Development and Distribution License ("CDDL"), version 1.0.
 * You may only use this file in accordance with the terms of version
 * 1.0 of the CDDL.
 *
 * A full copy of the text of the CDDL should have accompanied this
 * source.  A copy of the CDDL is also available via the Internet at
 * http://www.illumos.org/license/CDDL.
 */

/*
 * Copyright (c) 2019, Joyent, Inc.
 */

/*
 * Check that we properly handle functions and function pointers.
 */

#include "check-common.h"

static const char *one_args[] = { "int" };
static const char *two_args[] = { "int", "const char *" };
static const char *three_args[] = { "int", "const char *", "float" };
static const char *argument_args[] = { "uintptr_t" };
static const char *vararg_args[] = { "const char *" };

static check_function_test_t functions[] = {
	{ "simple_func", "void", 0, 0, NULL },
	{ "one", "void", 1, 0, one_args },
	{ "two", "void", 2, 0, two_args },
	{ "three", "void", 3, 0, three_args },
	{ "noarg", "const char *", 0, 0, NULL },
	{ "argument", "const char *", 1, 0, argument_args },
	{ "vararg", "void", 1, CTF_FUNC_VARARG, vararg_args },
	{ "vararg_ret", "uintptr_t", 1, CTF_FUNC_VARARG, vararg_args },
	{ NULL }
};

static const char *strfunc_args[] = { "const char *", "const char *" };

static check_function_test_t fptrs[] = {
	{ "strfunc_t", "int", 2, 0, strfunc_args },
	{ "vararg_t", "void", 1, CTF_FUNC_VARARG, vararg_args },
	{ NULL }
};

int
main(int argc, char *argv[])
{
	int i, ret = 0;

	if (argc < 2) {
		errx(EXIT_FAILURE, "missing test files");
	}

	for (i = 1; i < argc; i++) {
		ctf_file_t *fp;
		uint_t j;

		if ((fp = ctf_open(argv[i], &ret)) == NULL) {
			warnx("failed to open %s: %s", argv[i],
			    ctf_errmsg(ret));
			ret = EXIT_FAILURE;
			continue;
		}

		for (j = 0; functions[j].cft_name != NULL; j++) {
			if (!ctftest_check_function(functions[j].cft_name, fp,
			    functions[j].cft_rtype, functions[j].cft_nargs,
			    functions[j].cft_flags, functions[j].cft_args)) {
				ret = EXIT_FAILURE;
			}
		}

		for (j = 0; fptrs[j].cft_name != NULL; j++) {
			if (!ctftest_check_fptr(fptrs[j].cft_name, fp,
			    fptrs[j].cft_rtype, fptrs[j].cft_nargs,
			    fptrs[j].cft_flags, fptrs[j].cft_args)) {
				ret = EXIT_FAILURE;
			}
		}

		ctf_close(fp);
	}

	return (ret);
}