xref: /illumos-gate/usr/src/test/util-tests/tests/ctf/check-int.c (revision 66582b606a8194f7f3ba5b3a3a6dca5b0d346361)
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  * Check for basic integer types.
18  */
19 
20 #include <stdlib.h>
21 #include <unistd.h>
22 
23 #include "check-common.h"
24 
25 static check_number_t check_ints[] = {
26 	{ "char", CTF_K_INTEGER, CTF_INT_SIGNED | CTF_INT_CHAR, 0, 8 },
27 	{ "short", CTF_K_INTEGER, CTF_INT_SIGNED, 0, 16 },
28 	{ "int", CTF_K_INTEGER, CTF_INT_SIGNED, 0, 32 },
29 #ifdef	TARGET_LP64
30 	{ "long", CTF_K_INTEGER, CTF_INT_SIGNED, 0, 64 },
31 #else
32 	{ "long", CTF_K_INTEGER, CTF_INT_SIGNED, 0, 32 },
33 #endif
34 	{ "long long", CTF_K_INTEGER, CTF_INT_SIGNED, 0, 64 },
35 	{ "unsigned char", CTF_K_INTEGER, CTF_INT_CHAR, 0, 8 },
36 	{ "unsigned short", CTF_K_INTEGER, 0, 0, 16 },
37 	{ "unsigned int", CTF_K_INTEGER, 0, 0, 32 },
38 #ifdef	TARGET_LP64
39 	{ "unsigned long", CTF_K_INTEGER, 0, 0, 64 },
40 #else
41 	{ "unsigned long", CTF_K_INTEGER, 0, 0, 32 },
42 #endif
43 	{ "unsigned long long", CTF_K_INTEGER, 0, 0, 64 },
44 	{ NULL }
45 };
46 
47 static check_symbol_t check_syms[] = {
48 	{ "a", "char" },
49 	{ "b", "unsigned char" },
50 	{ "d", "short" },
51 	{ "e", "unsigned short" },
52 	{ "g", "int" },
53 	{ "h", "unsigned int" },
54 	{ "j", "long" },
55 	{ "k", "unsigned long" },
56 	{ "m", "long long" },
57 	{ "n", "unsigned long long" },
58 	{ NULL },
59 };
60 
61 int
62 main(int argc, char *argv[])
63 {
64 	int i, ret = 0;
65 
66 	if (argc < 2) {
67 		errx(EXIT_FAILURE, "missing test files");
68 	}
69 
70 	for (i = 1; i < argc; i++) {
71 		ctf_file_t *fp;
72 
73 		if ((fp = ctf_open(argv[i], &ret)) == NULL) {
74 			warnx("failed to open %s: %s", argv[i],
75 			    ctf_errmsg(ret));
76 			ret = EXIT_FAILURE;
77 			continue;
78 		}
79 
80 		if (!ctftest_check_numbers(fp, check_ints))
81 			ret = EXIT_FAILURE;
82 		if (!ctftest_check_symbols(fp, check_syms))
83 			ret = EXIT_FAILURE;
84 		ctf_close(fp);
85 	}
86 
87 	return (ret);
88 }
89