xref: /illumos-gate/usr/src/test/util-tests/tests/ctf/check-float.c (revision 8a2b682e57a046b828f37bcde1776f131ef4629f)
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 float types.
18  */
19 
20 #include <stdlib.h>
21 #include <unistd.h>
22 
23 #include "check-common.h"
24 
25 static check_number_t check_floats[] = {
26 	{ "float", CTF_K_FLOAT, CTF_FP_SINGLE, 0, 32 },
27 	{ "double", CTF_K_FLOAT, CTF_FP_DOUBLE, 0, 64 },
28 #ifdef	TARGET_LP64
29 	{ "long double", CTF_K_FLOAT, CTF_FP_LDOUBLE, 0, 128 },
30 #else
31 	{ "long double", CTF_K_FLOAT, CTF_FP_LDOUBLE, 0, 96 },
32 #endif
33 	{ "complex float", CTF_K_FLOAT, CTF_FP_CPLX, 0, 64 },
34 	{ "complex double", CTF_K_FLOAT, CTF_FP_DCPLX, 0, 128 },
35 #ifdef	TARGET_LP64
36 	{ "complex long double", CTF_K_FLOAT, CTF_FP_LDCPLX, 0, 256 },
37 #else
38 	{ "complex long double", CTF_K_FLOAT, CTF_FP_LDCPLX, 0, 192 },
39 #endif
40 	{ NULL }
41 };
42 
43 static check_symbol_t check_syms[] = {
44 	{ "a", "float" },
45 	{ "b", "double" },
46 	{ "c", "long double" },
47 	{ "d", "complex float" },
48 	{ "e", "complex double" },
49 	{ "f", "complex long double" },
50 	{ NULL }
51 };
52 
53 int
54 main(int argc, char *argv[])
55 {
56 	int i, ret = 0;
57 
58 	if (argc < 2) {
59 		errx(EXIT_FAILURE, "missing test files");
60 	}
61 
62 	for (i = 1; i < argc; i++) {
63 		ctf_file_t *fp;
64 
65 		if ((fp = ctf_open(argv[i], &ret)) == NULL) {
66 			warnx("failed to open %s: %s", argv[i],
67 			    ctf_errmsg(ret));
68 			ret = EXIT_FAILURE;
69 			continue;
70 		}
71 
72 		if (!ctftest_check_numbers(fp, check_floats))
73 			ret = EXIT_FAILURE;
74 		if (!ctftest_check_symbols(fp, check_syms))
75 			ret = EXIT_FAILURE;
76 		ctf_close(fp);
77 	}
78 
79 	return (ret);
80 }
81