1 /*
2 * Copyright (c) 2025 Robert Clausecker <fuz@FreeBSD.org>
3 *
4 * SPDX-License-Identifier: FreeBSD-2-Clause
5 */
6
7 #include <assert.h>
8 #include <limits.h>
9 #include <signal.h>
10 #include <stdint.h>
11 #include <wchar.h>
12
13 #include <atf-c.h>
14
15 /* if this file builds, the unit tests have passed */
16 #define CHECK_STYPE(type, TYPE) \
17 static_assert(sizeof(type) * CHAR_BIT == TYPE ## _WIDTH, \
18 __XSTRING(TYPE) "_WIDTH wrongly defined"); \
19 static_assert((1ULL << (TYPE ## _WIDTH - 1)) - 1 == TYPE ## _MAX, \
20 __XSTRING(TYPE) "_MAX wrongly defined"); \
21 static_assert(TYPE ## _MIN == -TYPE ## _MAX - 1, \
22 __XSTRING(TYPE) "_MIN wrongly defined")
23 #define CHECK_UTYPE(type, TYPE) \
24 static_assert(sizeof(type) * CHAR_BIT == TYPE ## _WIDTH, \
25 __XSTRING(TYPE) "_WIDTH wrongly defined"); \
26 static_assert((type)~0ULL == TYPE ## _MAX, \
27 __XSTRING(TYPE) "_MAX wrongly defined");
28
29 /* primitive types */
30 #ifdef __CHAR_UNSIGNED__
31 CHECK_UTYPE(char, CHAR);
32 #else
33 CHECK_STYPE(char, CHAR);
34 #endif
35
36 CHECK_STYPE(signed char, SCHAR);
37 CHECK_STYPE(short, SHRT);
38 CHECK_STYPE(int, INT);
39 CHECK_STYPE(long, LONG);
40 CHECK_STYPE(long long, LLONG);
41
42 CHECK_UTYPE(unsigned char, UCHAR);
43 CHECK_UTYPE(unsigned short, USHRT);
44 CHECK_UTYPE(unsigned int, UINT);
45 CHECK_UTYPE(unsigned long, ULONG);
46 CHECK_UTYPE(unsigned long long, ULLONG);
47
48 /* fixed-width types */
49 CHECK_STYPE(int8_t, INT8);
50 CHECK_STYPE(int16_t, INT16);
51 CHECK_STYPE(int32_t, INT32);
52 CHECK_STYPE(int64_t, INT64);
53
54 CHECK_UTYPE(uint8_t, UINT8);
55 CHECK_UTYPE(uint16_t, UINT16);
56 CHECK_UTYPE(uint32_t, UINT32);
57 CHECK_UTYPE(uint64_t, UINT64);
58
59 CHECK_STYPE(int_least8_t, INT_LEAST8);
60 CHECK_STYPE(int_least16_t, INT_LEAST16);
61 CHECK_STYPE(int_least32_t, INT_LEAST32);
62 CHECK_STYPE(int_least64_t, INT_LEAST64);
63
64 CHECK_UTYPE(uint_least8_t, UINT_LEAST8);
65 CHECK_UTYPE(uint_least16_t, UINT_LEAST16);
66 CHECK_UTYPE(uint_least32_t, UINT_LEAST32);
67 CHECK_UTYPE(uint_least64_t, UINT_LEAST64);
68
69 CHECK_STYPE(int_fast8_t, INT_FAST8);
70 CHECK_STYPE(int_fast16_t, INT_FAST16);
71 CHECK_STYPE(int_fast32_t, INT_FAST32);
72 CHECK_STYPE(int_fast64_t, INT_FAST64);
73
74 CHECK_UTYPE(uint_fast8_t, UINT_FAST8);
75 CHECK_UTYPE(uint_fast16_t, UINT_FAST16);
76 CHECK_UTYPE(uint_fast32_t, UINT_FAST32);
77 CHECK_UTYPE(uint_fast64_t, UINT_FAST64);
78
79 /* other types */
80 #if WCHAR_MIN == 0
81 CHECK_UTYPE(wchar_t, WCHAR);
82 #else
83 CHECK_STYPE(wchar_t, WCHAR);
84 #endif
85 CHECK_STYPE(intmax_t, INTMAX);
86 CHECK_STYPE(intptr_t, INTPTR);
87 CHECK_STYPE(ptrdiff_t, PTRDIFF);
88 CHECK_STYPE(wint_t, WINT);
89 CHECK_STYPE(sig_atomic_t, SIG_ATOMIC);
90
91 CHECK_UTYPE(uintmax_t, UINTMAX);
92 CHECK_UTYPE(uintptr_t, UINTPTR);
93 CHECK_UTYPE(size_t, SIZE);
94
95 /* dummy */
96 ATF_TC_WITHOUT_HEAD(dummy);
ATF_TC_BODY(dummy,tc)97 ATF_TC_BODY(dummy, tc) {}
98
ATF_TP_ADD_TCS(tp)99 ATF_TP_ADD_TCS(tp)
100 {
101 ATF_TP_ADD_TC(tp, dummy);
102
103 return (atf_no_error());
104 }
105