Remove building with NOCRYPTO option
[minix3.git] / tests / include / sys / t_cdefs.c
bloba47300969fc901808ddc933fd8d6bf4127ece887
1 /* $NetBSD: t_cdefs.c,v 1.3 2013/09/05 09:01:27 gsutre Exp $ */
3 /*-
4 * Copyright (c) 2012 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Christos Zoulas.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/cdefs.h>
33 __COPYRIGHT("@(#) Copyright (c) 2008\
34 The NetBSD Foundation, inc. All rights reserved.");
35 __RCSID("$NetBSD: t_cdefs.c,v 1.3 2013/09/05 09:01:27 gsutre Exp $");
37 #include <atf-c.h>
38 #include <sys/types.h>
39 #include <limits.h>
40 #include <stdint.h>
42 static const struct {
43 const char *name;
44 intmax_t min;
45 intmax_t max;
46 } s[] = {
47 { "signed char", SCHAR_MIN, SCHAR_MAX },
48 { "signed short", SHRT_MIN, SHRT_MAX },
49 { "signed int", INT_MIN, INT_MAX },
50 { "signed long", LONG_MIN, LONG_MAX },
51 { "signed long long", LLONG_MIN, LLONG_MAX },
54 static const struct {
55 const char *name;
56 uintmax_t min;
57 uintmax_t max;
58 } u[] = {
59 { "unsigned char", 0, UCHAR_MAX },
60 { "unsigned short", 0, USHRT_MAX },
61 { "unsigned int", 0, UINT_MAX },
62 { "unsigned long", 0, ULONG_MAX },
63 { "unsigned long long", 0, ULLONG_MAX },
66 ATF_TC(stypeminmax);
67 ATF_TC_HEAD(stypeminmax, tc)
69 atf_tc_set_md_var(tc, "descr", "Checks signed type min/max macros");
73 ATF_TC_BODY(stypeminmax, tc)
75 #define CHECK(a, b) ATF_REQUIRE(__type_min(a) == s[b].min); \
76 ATF_REQUIRE(__type_max(a) == s[b].max)
78 CHECK(signed char, 0);
79 CHECK(signed short, 1);
80 CHECK(signed int, 2);
81 CHECK(signed long, 3);
82 CHECK(signed long long, 4);
83 #undef CHECK
86 ATF_TC(utypeminmax);
87 ATF_TC_HEAD(utypeminmax, tc)
89 atf_tc_set_md_var(tc, "descr", "Checks unsigned type min/max macros");
92 ATF_TC_BODY(utypeminmax, tc)
94 #define CHECK(a, b) ATF_REQUIRE(__type_min(a) == u[b].min); \
95 ATF_REQUIRE(__type_max(a) == u[b].max)
97 CHECK(unsigned char, 0);
98 CHECK(unsigned short, 1);
99 CHECK(unsigned int, 2);
100 CHECK(unsigned long, 3);
101 CHECK(unsigned long long, 4);
102 #undef CHECK
105 ATF_TC(sissigned);
106 ATF_TC_HEAD(sissigned, tc)
108 atf_tc_set_md_var(tc, "descr", "Checks issigned macro for signed");
111 ATF_TC_BODY(sissigned, tc)
113 #define CHECK(a) ATF_REQUIRE(__type_is_signed(a) == 1)
115 CHECK(signed char);
116 CHECK(signed short);
117 CHECK(signed int);
118 CHECK(signed long);
119 CHECK(signed long long);
120 #undef CHECK
123 ATF_TC(uissigned);
124 ATF_TC_HEAD(uissigned, tc)
126 atf_tc_set_md_var(tc, "descr", "Checks issigned macro for unsigned");
129 ATF_TC_BODY(uissigned, tc)
131 #define CHECK(a) ATF_REQUIRE(__type_is_signed(a) == 0)
133 CHECK(unsigned char);
134 CHECK(unsigned short);
135 CHECK(unsigned int);
136 CHECK(unsigned long);
137 CHECK(unsigned long long);
138 #undef CHECK
141 ATF_TC(utypemask);
142 ATF_TC_HEAD(utypemask, tc)
144 atf_tc_set_md_var(tc, "descr", "Checks type mask macro for unsigned");
147 ATF_TC_BODY(utypemask, tc)
149 #define CHECK(a, b) ATF_REQUIRE(__type_mask(a) == b)
151 CHECK(unsigned char, 0xffffffffffffff00ULL);
152 CHECK(unsigned short, 0xffffffffffff0000ULL);
153 CHECK(unsigned int, 0xffffffff00000000ULL);
154 CHECK(unsigned long long, 0x0000000000000000ULL);
155 #undef CHECK
158 ATF_TC(stypemask);
159 ATF_TC_HEAD(stypemask, tc)
161 atf_tc_set_md_var(tc, "descr", "Checks type mask macro for signed");
164 ATF_TC_BODY(stypemask, tc)
166 #define CHECK(a, b) ATF_REQUIRE(__type_mask(a) == b)
168 CHECK(signed char, 0xffffffffffffff00LL);
169 CHECK(signed short, 0xffffffffffff0000LL);
170 CHECK(signed int, 0xffffffff00000000LL);
171 CHECK(signed long long, 0x0000000000000000LL);
172 #undef CHECK
175 ATF_TC(stypefit);
176 ATF_TC_HEAD(stypefit, tc)
178 atf_tc_set_md_var(tc, "descr", "Checks typefit macro for signed");
181 ATF_TC_BODY(stypefit, tc)
183 #define CHECK(a, b, c) ATF_REQUIRE(!__type_fit(a, b) == c)
185 CHECK(signed char, -1, 0);
186 CHECK(signed char, 1, 0);
187 CHECK(signed char, 0x7f, 0);
188 CHECK(signed char, 0x80, 1);
189 CHECK(signed char, 0xff, 1);
190 CHECK(signed char, 0x1ff, 1);
192 CHECK(signed short, -1, 0);
193 CHECK(signed short, 1, 0);
194 CHECK(signed short, 0x7fff, 0);
195 CHECK(signed short, 0x8000, 1);
196 CHECK(signed short, 0xffff, 1);
197 CHECK(signed short, 0x1ffff, 1);
199 CHECK(signed int, -1, 0);
200 CHECK(signed int, 1, 0);
201 CHECK(signed int, 0x7fffffff, 0);
202 CHECK(signed int, 0x80000000, 1);
203 CHECK(signed int, 0xffffffff, 1);
204 CHECK(signed int, 0x1ffffffffLL, 1);
206 CHECK(signed long long, -1, 0);
207 CHECK(signed long long, 1, 0);
208 CHECK(signed long long, 0x7fffffffffffffffLL, 0);
209 CHECK(signed long long, 0x8000000000000000LL, 1);
210 CHECK(signed long long, 0xffffffffffffffffLL, 1);
212 #undef CHECK
215 ATF_TC(utypefit);
216 ATF_TC_HEAD(utypefit, tc)
218 atf_tc_set_md_var(tc, "descr", "Checks typefit macro for unsigned");
221 ATF_TC_BODY(utypefit, tc)
223 #define CHECK(a, b, c) ATF_REQUIRE(!__type_fit(a, b) == c)
225 CHECK(unsigned char, -1, 1);
226 CHECK(unsigned char, 1, 0);
227 CHECK(unsigned char, 0x7f, 0);
228 CHECK(unsigned char, 0x80, 0);
229 CHECK(unsigned char, 0xff, 0);
230 CHECK(unsigned char, 0x1ff, 1);
232 CHECK(unsigned short, -1, 1);
233 CHECK(unsigned short, 1, 0);
234 CHECK(unsigned short, 0x7fff, 0);
235 CHECK(unsigned short, 0x8000, 0);
236 CHECK(unsigned short, 0xffff, 0);
237 CHECK(unsigned short, 0x1ffff, 1);
239 CHECK(unsigned int, -1, 1);
240 CHECK(unsigned int, 1, 0);
241 CHECK(unsigned int, 0x7fffffff, 0);
242 CHECK(unsigned int, 0x80000000, 0);
243 CHECK(unsigned int, 0xffffffff, 0);
244 CHECK(unsigned int, 0x1ffffffffLL, 1);
246 CHECK(unsigned long long, -1, 1);
247 CHECK(unsigned long long, 1, 0);
248 CHECK(unsigned long long, 0x7fffffffffffffffULL, 0);
249 CHECK(unsigned long long, 0x8000000000000000ULL, 0);
250 CHECK(unsigned long long, 0xffffffffffffffffULL, 0);
252 #undef CHECK
255 ATF_TP_ADD_TCS(tp)
257 ATF_TP_ADD_TC(tp, stypeminmax);
258 ATF_TP_ADD_TC(tp, utypeminmax);
259 ATF_TP_ADD_TC(tp, sissigned);
260 ATF_TP_ADD_TC(tp, uissigned);
261 ATF_TP_ADD_TC(tp, stypemask);
262 ATF_TP_ADD_TC(tp, utypemask);
263 ATF_TP_ADD_TC(tp, stypefit);
264 ATF_TP_ADD_TC(tp, utypefit);
266 return atf_no_error();