xref: /illumos-gate/usr/src/test/util-tests/tests/ctf/check-array.c (revision c12492cf73149aa0aa845af5d59966b0eb5aa910)
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  * Check that we properly generate basic nested arrays.
18  */
19 
20 #include "check-common.h"
21 
22 static check_number_t check_base[] = {
23 	{ "char", CTF_K_INTEGER, CTF_INT_SIGNED | CTF_INT_CHAR, 0, 8 },
24 	{ "int", CTF_K_INTEGER, CTF_INT_SIGNED, 0, 32 },
25 	{ "double", CTF_K_FLOAT, CTF_FP_DOUBLE, 0, 64 },
26 	{ NULL }
27 };
28 
29 static check_symbol_t check_syms[] = {
30 	{ "a", "int [3]" },
31 	{ "b", "double [42]" },
32 	{ "c", "const char *[2]" },
33 	{ "d", "int [4][5]" },
34 	{ "e", "int [4][5][6]" },
35 	{ "f", "int [4][5][6][7]" },
36 	{ "g", "int [4][5][6][7][8]" },
37 	{ "h", "int [4][5][6][7][8][9]" },
38 	{ "i", "int [4][5][6][7][8][9][10]" },
39 	{ NULL }
40 };
41 
42 static check_descent_t check_array_a[] = {
43 	{ "int [3]", CTF_K_ARRAY, "int", 3 },
44 	{ "int", CTF_K_INTEGER },
45 	{ NULL }
46 };
47 
48 static check_descent_t check_array_b[] = {
49 	{ "double [42]", CTF_K_ARRAY, "double", 42 },
50 	{ "double", CTF_K_FLOAT },
51 	{ NULL }
52 };
53 
54 static check_descent_t check_array_c[] = {
55 	{ "const char *[2]", CTF_K_ARRAY, "const char *", 2 },
56 	{ "const char *", CTF_K_POINTER },
57 	{ "const char", CTF_K_CONST },
58 	{ "char", CTF_K_INTEGER },
59 	{ NULL }
60 };
61 
62 static check_descent_t check_array_i[] = {
63 	{ "int [4][5][6][7][8][9][10]", CTF_K_ARRAY,
64 	    "int [5][6][7][8][9][10]", 4 },
65 	{ "int [5][6][7][8][9][10]", CTF_K_ARRAY, "int [6][7][8][9][10]", 5 },
66 	{ "int [6][7][8][9][10]", CTF_K_ARRAY, "int [7][8][9][10]", 6 },
67 	{ "int [7][8][9][10]", CTF_K_ARRAY, "int [8][9][10]", 7 },
68 	{ "int [8][9][10]", CTF_K_ARRAY, "int [9][10]", 8 },
69 	{ "int [9][10]", CTF_K_ARRAY, "int [10]", 9 },
70 	{ "int [10]", CTF_K_ARRAY, "int", 10 },
71 	{ "int", CTF_K_INTEGER },
72 	{ NULL },
73 };
74 
75 static check_descent_test_t descents[] = {
76 	{ "a", check_array_a },
77 	{ "b", check_array_b },
78 	{ "c", check_array_c },
79 	{ "i", check_array_i },
80 	{ NULL }
81 };
82 
83 int
84 main(int argc, char *argv[])
85 {
86 	int i, ret = 0;
87 
88 	if (argc < 2) {
89 		errx(EXIT_FAILURE, "missing test files");
90 	}
91 
92 	for (i = 1; i < argc; i++) {
93 		ctf_file_t *fp;
94 		uint_t d;
95 
96 		if ((fp = ctf_open(argv[i], &ret)) == NULL) {
97 			warnx("failed to open %s: %s", argv[i],
98 			    ctf_errmsg(ret));
99 			ret = EXIT_FAILURE;
100 			continue;
101 		}
102 		if (!ctftest_check_numbers(fp, check_base))
103 			ret = EXIT_FAILURE;
104 		if (!ctftest_check_symbols(fp, check_syms))
105 			ret = EXIT_FAILURE;
106 		for (d = 0; descents[d].cdt_sym != NULL; d++) {
107 			if (!ctftest_check_descent(descents[d].cdt_sym, fp,
108 			    descents[d].cdt_tests, B_FALSE)) {
109 				ret = EXIT_FAILURE;
110 			}
111 		}
112 		ctf_close(fp);
113 	}
114 
115 	return (ret);
116 }
117