use oxpcie only if enabled to avoid baud bottleneck of uart.
[minix.git] / test / test49.c
blob290e5033ec7f6957aa7cbcff7e7d3c1b639ad460
1 #include <assert.h>
2 #include <inttypes.h>
3 #include <stdint.h>
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <string.h>
7 #include <unistd.h>
9 #if defined(__LONG_LONG_SUPPORTED) || (_WORD_SIZE > 2 && __L64)
10 #define TEST_64_BIT
11 #endif
13 #define ERR err(__LINE__)
15 #define MAX_ERROR 4
16 static int errct;
18 static void quit(void)
20 if (errct == 0)
22 printf("ok\n");
23 exit(0);
25 else
27 printf("%d errors\n", errct);
28 exit(1);
32 static void err(int line)
34 printf("error at line %d\n", line);
35 if (++errct >= MAX_ERROR)
36 quit();
39 #define TEST_PRINTF(type, macro, value, result) \
40 { \
41 char buffer[256]; \
42 snprintf(buffer, sizeof(buffer), "%" macro, (type) value); \
43 if (strcmp(buffer, result) != 0) err(__LINE__); \
46 int main(void)
48 #ifdef __LONG_LONG_SUPPORTED
49 printf("Test 49 (GCC) ");
50 #else
51 printf("Test 49 (ACK) ");
52 #endif
53 fflush(stdout);
55 /* test integer sizes */
56 if (sizeof(int8_t) != 1) ERR;
57 if (sizeof(uint8_t) != 1) ERR;
58 if (sizeof(int_fast8_t) < 1) ERR;
59 if (sizeof(uint_fast8_t) < 1) ERR;
60 if (sizeof(int_least8_t) < 1) ERR;
61 if (sizeof(uint_least8_t) < 1) ERR;
62 if (sizeof(int16_t) != 2) ERR;
63 if (sizeof(uint16_t) != 2) ERR;
64 if (sizeof(int_fast16_t) < 2) ERR;
65 if (sizeof(uint_fast16_t) < 2) ERR;
66 if (sizeof(int_least16_t) < 2) ERR;
67 if (sizeof(uint_least16_t) < 2) ERR;
68 if (sizeof(int32_t) != 4) ERR;
69 if (sizeof(uint32_t) != 4) ERR;
70 if (sizeof(int_fast32_t) < 4) ERR;
71 if (sizeof(uint_fast32_t) < 4) ERR;
72 if (sizeof(int_least32_t) < 4) ERR;
73 if (sizeof(uint_least32_t) < 4) ERR;
74 #ifdef TEST_64_BIT
75 if (sizeof(int64_t) != 8) ERR;
76 if (sizeof(uint64_t) != 8) ERR;
77 if (sizeof(int_fast64_t) < 8) ERR;
78 if (sizeof(uint_fast64_t) < 8) ERR;
79 if (sizeof(int_least64_t) < 8) ERR;
80 if (sizeof(uint_least64_t) < 8) ERR;
81 #endif
82 if (sizeof(intptr_t) != sizeof(void *)) ERR;
83 if (sizeof(uintptr_t) != sizeof(void *)) ERR;
84 #ifdef TEST_64_BIT
85 if (sizeof(intmax_t) < 8) ERR;
86 if (sizeof(uintmax_t) < 8) ERR;
87 #else
88 if (sizeof(intmax_t) < 4) ERR;
89 if (sizeof(uintmax_t) < 4) ERR;
90 #endif
92 /* test integer signedness */
93 if ((int8_t) (-1) >= 0) ERR;
94 if ((uint8_t) (-1) <= 0) ERR;
95 if ((int_fast8_t) (-1) >= 0) ERR;
96 if ((uint_fast8_t) (-1) <= 0) ERR;
97 if ((int_least8_t) (-1) >= 0) ERR;
98 if ((uint_least8_t) (-1) <= 0) ERR;
99 if ((int16_t) (-1) >= 0) ERR;
100 if ((uint16_t) (-1) <= 0) ERR;
101 if ((int_fast16_t) (-1) >= 0) ERR;
102 if ((uint_fast16_t) (-1) <= 0) ERR;
103 if ((int_least16_t) (-1) >= 0) ERR;
104 if ((uint_least16_t) (-1) <= 0) ERR;
105 if ((int32_t) (-1) >= 0) ERR;
106 if ((uint32_t) (-1) <= 0) ERR;
107 if ((int_fast32_t) (-1) >= 0) ERR;
108 if ((uint_fast32_t) (-1) <= 0) ERR;
109 if ((int_least32_t) (-1) >= 0) ERR;
110 if ((uint_least32_t) (-1) <= 0) ERR;
111 #ifdef TEST_64_BIT
112 if ((int64_t) (-1) >= 0) ERR;
113 if ((uint64_t) (-1) <= 0) ERR;
114 if ((int_fast64_t) (-1) >= 0) ERR;
115 if ((uint_fast64_t) (-1) <= 0) ERR;
116 if ((int_least64_t) (-1) >= 0) ERR;
117 if ((uint_least64_t) (-1) <= 0) ERR;
118 #endif
119 if ((intptr_t) (-1) >= 0) ERR;
120 if ((uintptr_t) (-1) <= 0) ERR;
121 if ((intptr_t) (-1) >= 0) ERR;
122 if ((uintptr_t) (-1) <= 0) ERR;
124 /* test printf */
125 TEST_PRINTF(int32_t, PRId32, INT32_MIN, "-2147483648");
126 TEST_PRINTF(int32_t, PRId32, INT32_MAX, "2147483647");
127 TEST_PRINTF(int32_t, PRIi32, INT32_MIN, "-2147483648");
128 TEST_PRINTF(int32_t, PRIi32, INT32_MAX, "2147483647");
129 TEST_PRINTF(uint32_t, PRIu32, UINT32_MAX, "4294967295");
130 TEST_PRINTF(uint32_t, PRIX32, UINT32_MAX, "FFFFFFFF");
131 TEST_PRINTF(uint32_t, PRIx32, UINT32_MAX, "ffffffff");
132 TEST_PRINTF(uint32_t, PRIo32, UINT32_MAX, "37777777777");
134 TEST_PRINTF(int_fast32_t, PRIdFAST32, INT32_MIN, "-2147483648");
135 TEST_PRINTF(int_fast32_t, PRIdFAST32, INT32_MAX, "2147483647");
136 TEST_PRINTF(int_fast32_t, PRIiFAST32, INT32_MIN, "-2147483648");
137 TEST_PRINTF(int_fast32_t, PRIiFAST32, INT32_MAX, "2147483647");
138 TEST_PRINTF(uint_fast32_t, PRIuFAST32, UINT32_MAX, "4294967295");
139 TEST_PRINTF(uint_fast32_t, PRIXFAST32, UINT32_MAX, "FFFFFFFF");
140 TEST_PRINTF(uint_fast32_t, PRIxFAST32, UINT32_MAX, "ffffffff");
141 TEST_PRINTF(uint_fast32_t, PRIoFAST32, UINT32_MAX, "37777777777");
143 TEST_PRINTF(int_least32_t, PRIdLEAST32, INT32_MIN, "-2147483648");
144 TEST_PRINTF(int_least32_t, PRIdLEAST32, INT32_MAX, "2147483647");
145 TEST_PRINTF(int_least32_t, PRIiLEAST32, INT32_MIN, "-2147483648");
146 TEST_PRINTF(int_least32_t, PRIiLEAST32, INT32_MAX, "2147483647");
147 TEST_PRINTF(uint_least32_t, PRIuLEAST32, UINT32_MAX, "4294967295");
148 TEST_PRINTF(uint_least32_t, PRIXLEAST32, UINT32_MAX, "FFFFFFFF");
149 TEST_PRINTF(uint_least32_t, PRIxLEAST32, UINT32_MAX, "ffffffff");
150 TEST_PRINTF(uint_least32_t, PRIoLEAST32, UINT32_MAX, "37777777777");
152 #ifdef TEST_64_BIT
153 TEST_PRINTF(int64_t, PRId64, INT64_MIN, "-9223372036854775808");
154 TEST_PRINTF(int64_t, PRId64, INT64_MAX, "9223372036854775807");
155 TEST_PRINTF(int64_t, PRIi64, INT64_MIN, "-9223372036854775808");
156 TEST_PRINTF(int64_t, PRIi64, INT64_MAX, "9223372036854775807");
157 TEST_PRINTF(uint64_t, PRIu64, UINT64_MAX, "18446744073709551615");
158 TEST_PRINTF(uint64_t, PRIX64, UINT64_MAX, "FFFFFFFFFFFFFFFF");
159 TEST_PRINTF(uint64_t, PRIx64, UINT64_MAX, "ffffffffffffffff");
160 TEST_PRINTF(uint64_t, PRIo64, UINT64_MAX, "1777777777777777777777");
162 TEST_PRINTF(int_fast64_t, PRIdFAST64, INT64_MIN, "-9223372036854775808");
163 TEST_PRINTF(int_fast64_t, PRIdFAST64, INT64_MAX, "9223372036854775807");
164 TEST_PRINTF(int_fast64_t, PRIiFAST64, INT64_MIN, "-9223372036854775808");
165 TEST_PRINTF(int_fast64_t, PRIiFAST64, INT64_MAX, "9223372036854775807");
166 TEST_PRINTF(uint_fast64_t, PRIuFAST64, UINT64_MAX, "18446744073709551615");
167 TEST_PRINTF(uint_fast64_t, PRIXFAST64, UINT64_MAX, "FFFFFFFFFFFFFFFF");
168 TEST_PRINTF(uint_fast64_t, PRIxFAST64, UINT64_MAX, "ffffffffffffffff");
169 TEST_PRINTF(uint_fast64_t, PRIoFAST64, UINT64_MAX, "1777777777777777777777");
171 TEST_PRINTF(int_least64_t, PRIdLEAST64, INT64_MIN, "-9223372036854775808");
172 TEST_PRINTF(int_least64_t, PRIdLEAST64, INT64_MAX, "9223372036854775807");
173 TEST_PRINTF(int_least64_t, PRIiLEAST64, INT64_MIN, "-9223372036854775808");
174 TEST_PRINTF(int_least64_t, PRIiLEAST64, INT64_MAX, "9223372036854775807");
175 TEST_PRINTF(uint_least64_t, PRIuLEAST64, UINT64_MAX, "18446744073709551615");
176 TEST_PRINTF(uint_least64_t, PRIXLEAST64, UINT64_MAX, "FFFFFFFFFFFFFFFF");
177 TEST_PRINTF(uint_least64_t, PRIxLEAST64, UINT64_MAX, "ffffffffffffffff");
178 TEST_PRINTF(uint_least64_t, PRIoLEAST64, UINT64_MAX, "1777777777777777777777");
180 TEST_PRINTF(intmax_t, PRIdMAX, INT64_MIN, "-9223372036854775808");
181 TEST_PRINTF(intmax_t, PRIdMAX, INT64_MAX, "9223372036854775807");
182 TEST_PRINTF(intmax_t, PRIiMAX, INT64_MIN, "-9223372036854775808");
183 TEST_PRINTF(intmax_t, PRIiMAX, INT64_MAX, "9223372036854775807");
184 TEST_PRINTF(uintmax_t, PRIuMAX, UINT64_MAX, "18446744073709551615");
185 TEST_PRINTF(uintmax_t, PRIXMAX, UINT64_MAX, "FFFFFFFFFFFFFFFF");
186 TEST_PRINTF(uintmax_t, PRIxMAX, UINT64_MAX, "ffffffffffffffff");
187 TEST_PRINTF(uintmax_t, PRIoMAX, UINT64_MAX, "1777777777777777777777");
188 #else
189 TEST_PRINTF(intmax_t, PRIdMAX, INT32_MIN, "-2147483648");
190 TEST_PRINTF(intmax_t, PRIdMAX, INT32_MAX, "2147483647");
191 TEST_PRINTF(intmax_t, PRIiMAX, INT32_MIN, "-2147483648");
192 TEST_PRINTF(intmax_t, PRIiMAX, INT32_MAX, "2147483647");
193 TEST_PRINTF(uintmax_t, PRIuMAX, UINT32_MAX, "4294967295");
194 TEST_PRINTF(uintmax_t, PRIXMAX, UINT32_MAX, "FFFFFFFF");
195 TEST_PRINTF(uintmax_t, PRIxMAX, UINT32_MAX, "ffffffff");
196 TEST_PRINTF(uintmax_t, PRIoMAX, UINT32_MAX, "37777777777");
197 #endif
199 TEST_PRINTF(intptr_t, PRIdPTR, INT32_MIN, "-2147483648");
200 TEST_PRINTF(intptr_t, PRIdPTR, INT32_MAX, "2147483647");
201 TEST_PRINTF(intptr_t, PRIiPTR, INT32_MIN, "-2147483648");
202 TEST_PRINTF(intptr_t, PRIiPTR, INT32_MAX, "2147483647");
203 TEST_PRINTF(uintptr_t, PRIuPTR, UINT32_MAX, "4294967295");
204 TEST_PRINTF(uintptr_t, PRIXPTR, UINT32_MAX, "FFFFFFFF");
205 TEST_PRINTF(uintptr_t, PRIxPTR, UINT32_MAX, "ffffffff");
206 TEST_PRINTF(uintptr_t, PRIoPTR, UINT32_MAX, "37777777777");
208 /* done */
209 quit();
210 assert(0);
211 return -1;