xref: /illumos-gate/usr/src/test/util-tests/tests/ctf/check-function.c (revision d2f7972d81337947df76c36b8c2a5f290829fa7a)
1 /*
2  * This file and its contents are supplied under the terms of the
3  * Common Development and Distribution License ("CDDL"), version 1.0.
4  * You may only use this file in accordance with the terms of version
5  * 1.0 of the CDDL.
6  *
7  * A full copy of the text of the CDDL should have accompanied this
8  * source.  A copy of the CDDL is also available via the Internet at
9  * http://www.illumos.org/license/CDDL.
10  */
11 
12 /*
13  * Copyright (c) 2019, Joyent, Inc.
14  */
15 
16 /*
17  * Check that we properly handle functions and function pointers.
18  */
19 
20 #include "check-common.h"
21 
22 static const char *one_args[] = { "int" };
23 static const char *two_args[] = { "int", "const char *" };
24 static const char *three_args[] = { "int", "const char *", "float" };
25 static const char *argument_args[] = { "uintptr_t" };
26 static const char *vararg_args[] = { "const char *" };
27 
28 static check_function_test_t functions[] = {
29 	{ "simple_func", "void", 0, 0, NULL },
30 	{ "one", "void", 1, 0, one_args },
31 	{ "two", "void", 2, 0, two_args },
32 	{ "three", "void", 3, 0, three_args },
33 	{ "noarg", "const char *", 0, 0, NULL },
34 	{ "argument", "const char *", 1, 0, argument_args },
35 	{ "vararg", "void", 1, CTF_FUNC_VARARG, vararg_args },
36 	{ "vararg_ret", "uintptr_t", 1, CTF_FUNC_VARARG, vararg_args },
37 	{ NULL }
38 };
39 
40 static const char *strfunc_args[] = { "const char *", "const char *" };
41 
42 static check_function_test_t fptrs[] = {
43 	{ "strfunc_t", "int", 2, 0, strfunc_args },
44 	{ "vararg_t", "void", 1, CTF_FUNC_VARARG, vararg_args },
45 	{ NULL }
46 };
47 
48 int
49 main(int argc, char *argv[])
50 {
51 	int i, ret = 0;
52 
53 	if (argc < 2) {
54 		errx(EXIT_FAILURE, "missing test files");
55 	}
56 
57 	for (i = 1; i < argc; i++) {
58 		ctf_file_t *fp;
59 		uint_t j;
60 
61 		if ((fp = ctf_open(argv[i], &ret)) == NULL) {
62 			warnx("failed to open %s: %s", argv[i],
63 			    ctf_errmsg(ret));
64 			ret = EXIT_FAILURE;
65 			continue;
66 		}
67 
68 		for (j = 0; functions[j].cft_name != NULL; j++) {
69 			if (!ctftest_check_function(functions[j].cft_name, fp,
70 			    functions[j].cft_rtype, functions[j].cft_nargs,
71 			    functions[j].cft_flags, functions[j].cft_args)) {
72 				ret = EXIT_FAILURE;
73 			}
74 		}
75 
76 		for (j = 0; fptrs[j].cft_name != NULL; j++) {
77 			if (!ctftest_check_fptr(fptrs[j].cft_name, fp,
78 			    fptrs[j].cft_rtype, fptrs[j].cft_nargs,
79 			    fptrs[j].cft_flags, fptrs[j].cft_args)) {
80 				ret = EXIT_FAILURE;
81 			}
82 		}
83 
84 		ctf_close(fp);
85 	}
86 
87 	return (ret);
88 }
89