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 2020 Joyent, Inc.
14  */
15 
16 #ifndef _CHECK_COMMON_H
17 #define	_CHECK_COMMON_H
18 
19 /*
20  * Common definitions for the CTF tests
21  */
22 
23 #include <stdlib.h>
24 #include <unistd.h>
25 #include <libctf.h>
26 #include <err.h>
27 #include <strings.h>
28 #include <sys/param.h>
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 /*
35  * A set of bits that can be set on tests to indicate that the test should be
36  * skipped when dealing with a certain compiler. These should be added as
37  * needed. Right now this is here because of the clang bitfield bug that is
38  * triggered by check-sou.c.
39  */
40 typedef enum {
41 	SKIP_CLANG	= 1 << 0
42 } check_skip_t;
43 
44 typedef struct check_number {
45 	const char *cn_tname;
46 	uint_t cn_kind;
47 	uint_t cn_flags;
48 	uint_t cn_offset;
49 	uint_t cn_size;
50 	check_skip_t cn_skips;
51 } check_number_t;
52 
53 typedef struct check_symbol {
54 	const char *cs_symbol;
55 	const char *cs_type;
56 } check_symbol_t;
57 
58 typedef struct check_descent {
59 	const char *cd_tname;
60 	uint_t cd_kind;
61 	const char *cd_contents;
62 	uint_t cd_nents;
63 } check_descent_t;
64 
65 typedef struct check_descent_test {
66 	const char *cdt_sym;
67 	const check_descent_t *cdt_tests;
68 } check_descent_test_t;
69 
70 typedef struct check_enum {
71 	const char *ce_name;
72 	int64_t ce_value;
73 } check_enum_t;
74 
75 typedef struct check_enum_test {
76 	const char *cet_type;
77 	const check_enum_t *cet_tests;
78 } check_enum_test_t;
79 
80 typedef struct check_member {
81 	const char *cm_name;
82 	const char *cm_type;
83 	ulong_t cm_offset;
84 } check_member_t;
85 
86 typedef struct check_member_test {
87 	const char *cmt_type;
88 	int cmt_kind;
89 	size_t cmt_size;
90 	const check_member_t *cmt_members;
91 	check_skip_t cmt_skips;
92 } check_member_test_t;
93 
94 typedef struct check_function_test {
95 	const char *cft_name;
96 	const char *cft_rtype;
97 	uint_t cft_nargs;
98 	uint_t cft_flags;
99 	const char **cft_args;
100 } check_function_test_t;
101 
102 typedef struct check_size_test {
103 	const char *cst_name;
104 	size_t cst_size;
105 } check_size_test_t;
106 
107 /*
108  * Looks up each type and verifies that it matches the expected type.
109  */
110 extern boolean_t ctftest_check_numbers(ctf_file_t *, const check_number_t *);
111 
112 /*
113  * Looks at each symbol specified and verifies that it matches the expected
114  * type.
115  */
116 extern boolean_t ctftest_check_symbols(ctf_file_t *, const check_symbol_t *);
117 
118 /*
119  * Given a symbol name which refers to a type, walks all the references of that
120  * type and checks against it with each subsequent entry.
121  */
122 extern boolean_t ctftest_check_descent(const char *, ctf_file_t *,
123     const check_descent_t *, boolean_t);
124 
125 /*
126  * Checks that all of the listed members of an enum are present and have the
127  * right values.
128  */
129 extern boolean_t ctftest_check_enum(const char *, ctf_file_t *,
130     const check_enum_t *);
131 
132 /*
133  * Checks that all of the members of a structure or union are present and have
134  * the right types and byte offsets. This can be used for either structures or
135  * unions.
136  */
137 extern boolean_t ctftest_check_members(const char *, ctf_file_t *, int, size_t,
138     const check_member_t *);
139 
140 /*
141  * Check that the named function or function pointer has the correct return
142  * type, arguments, and function flags.
143  */
144 extern boolean_t ctftest_check_function(const char *, ctf_file_t *,
145     const char *, uint_t, uint_t, const char **);
146 extern boolean_t ctftest_check_fptr(const char *, ctf_file_t *,
147     const char *, uint_t, uint_t, const char **);
148 
149 /*
150  * Check size of types.
151  */
152 extern boolean_t ctftest_check_size(const char *, ctf_file_t *, size_t);
153 
154 /*
155  * Determine whether or not we have a duplicate type or not based on its name.
156  */
157 extern boolean_t ctftest_duplicates(ctf_file_t *);
158 
159 /*
160  * Determine whether or not we should skip a given test.
161  */
162 extern boolean_t ctftest_skip(check_skip_t);
163 
164 #ifdef __cplusplus
165 }
166 #endif
167 
168 #endif /* _CHECK_COMMON_H */
169