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 /*
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 { "empty", "int [0]" },
40 { NULL }
41 };
42
43 static check_descent_t check_array_a[] = {
44 { "int [3]", CTF_K_ARRAY, "int", 3 },
45 { "int", CTF_K_INTEGER },
46 { NULL }
47 };
48
49 static check_descent_t check_array_b[] = {
50 { "double [42]", CTF_K_ARRAY, "double", 42 },
51 { "double", CTF_K_FLOAT },
52 { NULL }
53 };
54
55 static check_descent_t check_array_c[] = {
56 { "const char *[2]", CTF_K_ARRAY, "const char *", 2 },
57 { "const char *", CTF_K_POINTER },
58 { "const char", CTF_K_CONST },
59 { "char", CTF_K_INTEGER },
60 { NULL }
61 };
62
63 static check_descent_t check_array_i[] = {
64 { "int [4][5][6][7][8][9][10]", CTF_K_ARRAY,
65 "int [5][6][7][8][9][10]", 4 },
66 { "int [5][6][7][8][9][10]", CTF_K_ARRAY, "int [6][7][8][9][10]", 5 },
67 { "int [6][7][8][9][10]", CTF_K_ARRAY, "int [7][8][9][10]", 6 },
68 { "int [7][8][9][10]", CTF_K_ARRAY, "int [8][9][10]", 7 },
69 { "int [8][9][10]", CTF_K_ARRAY, "int [9][10]", 8 },
70 { "int [9][10]", CTF_K_ARRAY, "int [10]", 9 },
71 { "int [10]", CTF_K_ARRAY, "int", 10 },
72 { "int", CTF_K_INTEGER },
73 { NULL },
74 };
75
76 static check_descent_t check_array_empty[] = {
77 { "int [0]", CTF_K_ARRAY, "int", 0 },
78 { "int", CTF_K_INTEGER },
79 { NULL }
80 };
81
82 static check_descent_test_t descents[] = {
83 { "a", check_array_a },
84 { "b", check_array_b },
85 { "c", check_array_c },
86 { "i", check_array_i },
87 { "empty", check_array_empty },
88 { NULL }
89 };
90
91 int
main(int argc,char * argv[])92 main(int argc, char *argv[])
93 {
94 int i, ret = 0;
95
96 if (argc < 2) {
97 errx(EXIT_FAILURE, "missing test files");
98 }
99
100 for (i = 1; i < argc; i++) {
101 ctf_file_t *fp;
102 uint_t d;
103
104 if ((fp = ctf_open(argv[i], &ret)) == NULL) {
105 warnx("failed to open %s: %s", argv[i],
106 ctf_errmsg(ret));
107 ret = EXIT_FAILURE;
108 continue;
109 }
110 if (!ctftest_check_numbers(fp, check_base))
111 ret = EXIT_FAILURE;
112 if (!ctftest_check_symbols(fp, check_syms))
113 ret = EXIT_FAILURE;
114 for (d = 0; descents[d].cdt_sym != NULL; d++) {
115 if (!ctftest_check_descent(descents[d].cdt_sym, fp,
116 descents[d].cdt_tests, B_FALSE)) {
117 ret = EXIT_FAILURE;
118 }
119 }
120 ctf_close(fp);
121 }
122
123 return (ret);
124 }
125