xref: /illumos-gate/usr/src/test/util-tests/tests/ctf/check-forward.c (revision 622d9a34dc9e68ddd38b93df5eda1bc20f0d507a)
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 2019, Joyent, Inc.
14  */
15 
16 /*
17  * Verify that we can properly handle forward declarations.
18  */
19 
20 #include "check-common.h"
21 
22 static check_symbol_t check_syms[] = {
23 	{ "forward", "struct forward" },
24 	{ "foop", "struct foo *" },
25 	{ "barp", "union bar *" },
26 	{ "bazp", "enum baz *" },
27 	{ NULL }
28 };
29 
30 static check_member_t check_member_forward[] = {
31 #ifdef	TARGET_LP64
32 	{ "prev", "struct foo *", 0 },
33 	{ "next", "struct foo *", 8 * NBBY },
34 	{ "data", "union bar *", 16 * NBBY },
35 	{ "tag", "enum baz *", 24 * NBBY },
36 #else
37 	{ "prev", "struct foo *", 0 },
38 	{ "next", "struct foo *", 4 * NBBY },
39 	{ "data", "union bar *", 8 * NBBY },
40 	{ "tag", "enum baz *", 12 * NBBY },
41 #endif
42 	{ NULL }
43 };
44 
45 
46 static check_member_test_t members[] = {
47 #ifdef	TARGET_LP64
48 	{ "struct forward", CTF_K_STRUCT, 32, check_member_forward },
49 #else
50 	{ "struct forward", CTF_K_STRUCT, 16, check_member_forward },
51 #endif
52 	{ NULL }
53 };
54 
55 static check_descent_t check_descent_foo[] = {
56 	{ "struct foo *", CTF_K_POINTER },
57 	{ "struct foo", CTF_K_FORWARD },
58 	{ NULL }
59 };
60 
61 static check_descent_t check_descent_bar[] = {
62 	{ "union bar *", CTF_K_POINTER },
63 	{ "union bar", CTF_K_FORWARD },
64 	{ NULL }
65 };
66 
67 static check_descent_t check_descent_baz[] = {
68 	{ "enum baz *", CTF_K_POINTER },
69 	{ "enum baz", CTF_K_ENUM },
70 	{ NULL }
71 };
72 
73 static check_descent_test_t descents[] = {
74 	{ "foop", check_descent_foo },
75 	{ "barp", check_descent_bar },
76 	{ "bazp", check_descent_baz },
77 	{ NULL }
78 };
79 int
80 main(int argc, char *argv[])
81 {
82 	int i, ret = 0;
83 
84 	if (argc < 2) {
85 		errx(EXIT_FAILURE, "missing test files");
86 	}
87 
88 	for (i = 1; i < argc; i++) {
89 		ctf_file_t *fp;
90 		uint_t j;
91 
92 		if ((fp = ctf_open(argv[i], &ret)) == NULL) {
93 			warnx("failed to open %s: %s", argv[i],
94 			    ctf_errmsg(ret));
95 			ret = EXIT_FAILURE;
96 			continue;
97 		}
98 
99 		if (!ctftest_check_symbols(fp, check_syms))
100 			ret = EXIT_FAILURE;
101 
102 		for (j = 0; descents[j].cdt_sym != NULL; j++) {
103 			if (!ctftest_check_descent(descents[j].cdt_sym, fp,
104 			    descents[j].cdt_tests, B_FALSE)) {
105 				ret = EXIT_FAILURE;
106 			}
107 		}
108 
109 
110 		for (j = 0; members[j].cmt_type != NULL; j++) {
111 			if (!ctftest_check_members(members[j].cmt_type, fp,
112 			    members[j].cmt_kind, members[j].cmt_size,
113 			    members[j].cmt_members)) {
114 				ret = EXIT_FAILURE;
115 			}
116 		}
117 
118 		ctf_close(fp);
119 	}
120 
121 	return (ret);
122 }
123