xref: /illumos-gate/usr/src/test/util-tests/tests/ctf/check-merge-reduction.c (revision 8a2b682e57a046b828f37bcde1776f131ef4629f)
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  * This tests that a global that has been scoped to local scope through symbol
18  * reduction of a mapfile can still be detected.
19  */
20 
21 #include "check-common.h"
22 
23 static check_symbol_t check_syms[] = {
24 	{ "data", "int" },
25 	{ NULL }
26 };
27 
28 static const char *scoped_args[] = { "uint32_t" };
29 
30 static check_function_test_t functions[] = {
31 	{ "global", "int", 0, 0, NULL },
32 	{ "scoped", "int", 1, 0, scoped_args },
33 	{ NULL }
34 };
35 
36 int
37 main(int argc, char *argv[])
38 {
39 	int i, ret = 0;
40 
41 	if (argc < 2) {
42 		errx(EXIT_FAILURE, "missing test files");
43 	}
44 
45 	for (i = 1; i < argc; i++) {
46 		ctf_file_t *fp;
47 		uint_t j;
48 
49 		if ((fp = ctf_open(argv[i], &ret)) == NULL) {
50 			warnx("failed to open %s: %s", argv[i],
51 			    ctf_errmsg(ret));
52 			ret = EXIT_FAILURE;
53 			continue;
54 		}
55 
56 		if (!ctftest_check_symbols(fp, check_syms))
57 			ret = EXIT_FAILURE;
58 
59 		for (j = 0; functions[j].cft_name != NULL; j++) {
60 			if (!ctftest_check_function(functions[j].cft_name, fp,
61 			    functions[j].cft_rtype, functions[j].cft_nargs,
62 			    functions[j].cft_flags, functions[j].cft_args)) {
63 				ret = EXIT_FAILURE;
64 			}
65 		}
66 
67 
68 		ctf_close(fp);
69 	}
70 
71 	return (ret);
72 }
73