1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
|
// $Id$
//
// ============================================================================
//
// = LIBRARY
// tests
//
// = FILENAME
// Basic_Types_Test.cpp
//
// = DESCRIPTION
// Checks the #defines in ace/Basic_Types.h, and a few other basics.
//
// = AUTHOR
// David L. Levine <levine@cs.wustl.edu>
//
// ============================================================================
#include "ace/config-all.h"
// Don't use the ACE version accessors in class ACE, so that we can
// support this test cleanly with the OS component, only.
#include "ace/Version.h"
#if defined (ACE_HAS_MINIMAL_ACE_OS)
// Redefine these macros to allow the test to print out useful info.
# undef ACE_DEBUG
# define ACE_DEBUG(x) ACE_OS::fprintf x
# define LM_DEBUG stdout
# undef ACE_ERROR
# define ACE_ERROR(x) ACE_OS::fprintf x
# define LM_ERROR stderr
# define ACE_START_TEST(x) ACE_OS::printf (x ACE_TEXT ("\n"))
# define ACE_END_TEST
#else /* ! ACE_HAS_MINIMAL_ACE_OS */
# include "test_config.h"
#endif /* ! ACE_HAS_MINIMAL_ACE_OS */
#include "ace/Basic_Types.h"
#include "ace/OS_NS_unistd.h"
typedef void* (*a_function_pointer) (void*);
static
u_int
check (const ACE_TCHAR *message, u_int i, u_int j)
{
if (i == j)
{
ACE_DEBUG ((LM_DEBUG, message, j, ACE_TEXT ("\n")));
return 0;
}
else
{
ACE_ERROR ((LM_ERROR, ACE_TEXT ("assertion failed \"%s\": %u != %u\n"),
message, i, j));
return 1;
}
}
// If the platform lacks an unsigned long long, define one.
#if defined (ACE_LACKS_LONGLONG_T) || defined (ACE_LACKS_UNSIGNEDLONGLONG_T)
static
u_int
check_ace_u_longlong (const ACE_TCHAR *const name,
const ACE_U_LongLong ull,
const u_long hi,
const u_long lo)
{
if (ull.hi () == hi && ull.lo () == lo)
return 0;
else
ACE_ERROR_RETURN ((LM_ERROR,
ACE_TEXT ("%s; hi: %x, should be %x; ")
ACE_TEXT ("lo: %x, should be %x.\n"),
name, ull.hi (), hi, ull.lo (), lo),
1);
}
static
u_int
test_ace_u_longlong (void)
{
u_int errors = 0;
ACE_U_LongLong ull1 (0x21,1);
errors += check_ace_u_longlong (ACE_TEXT ("ull1"), ull1, 1, 0x21);
ACE_U_LongLong ull2 (0x20,2);
errors += check_ace_u_longlong (ACE_TEXT ("ull2"), ull2, 2, 0x20);
ull2 -= ull1;
errors += check_ace_u_longlong (ACE_TEXT ("ull2"), ull2, 0, 0xfffffffful);
ull2 += ull1;
errors += check_ace_u_longlong (ACE_TEXT ("ull2"), ull2, 2, 0x20);
ACE_U_LongLong ull3 = ull1 + ull1;
errors += check_ace_u_longlong (ACE_TEXT ("ull3"), ull3, 2, 0x42);
ACE_U_LongLong ull4 = ACE_U_LongLong (0x1111, 0) -
ACE_U_LongLong (0x1112, 0);
errors += check_ace_u_longlong (ACE_TEXT ("ull4"), ull4, 0xfffffffful, 0xfffffffful);
ACE_U_LongLong ull5 = ACE_U_LongLong (0x1111, 1) -
ACE_U_LongLong (0x1112, 0);
errors += check_ace_u_longlong (ACE_TEXT ("ull5"), ull5, 0, 0xfffffffful);
++ull5;
errors += check_ace_u_longlong (ACE_TEXT ("ull5"), ull5, 1, 0);
ACE_U_LongLong ull6 = ull2 + ACE_U_LongLong (0, 1);
errors += check_ace_u_longlong (ACE_TEXT ("ull6"), ull6, 3, 0x20);
ull6 += ACE_U_LongLong (0xffffffff, 0xfff0);
errors += check_ace_u_longlong (ACE_TEXT ("ull6"), ull6, 0xfff4, 0x1f);
++ull6;
errors += check_ace_u_longlong (ACE_TEXT ("ull6"), ull6, 0xfff4, 0x20);
// The hi part of ull6 will be lost in the following, because
// the quotient has only 32 bits.
errors += check_ace_u_longlong (ACE_TEXT ("ull6 / 1"),
(ACE_U_LongLong) (ull6 / 1u),
0, 0x20);
// There's apparently a small loss in precision in
// ACE_U_LongLong::operator/. It calculates
// ull6 / 0xd0000 as 0x13b013b4 instead of 0x13b04ec4.
errors += check_ace_u_longlong (ACE_TEXT ("ull6 / 0x10000 / 0xd"),
(ACE_U_LongLong) (ull6 / 0x10000u / 0xd),
0, 0x13b04ec4);
errors += check_ace_u_longlong (ACE_TEXT ("ull6 % 5"),
(ACE_U_LongLong) (ull6 % 5),
0, 1);
errors += check_ace_u_longlong (ACE_TEXT ("ull6 % 0x20007"),
(ACE_U_LongLong) (ull6 % 0x20007),
0, 0x3f63);
ACE_U_LongLong ull7 (12);
ull7 *= 3125;
errors += check_ace_u_longlong (ACE_TEXT ("12 * 3125"),
ull7,
0, 37500);
ull7 *= 100;
errors += check_ace_u_longlong (ACE_TEXT ("37500 * 100"),
ull7,
0, 3750000);
errors += check_ace_u_longlong (ACE_TEXT ("3750000 << 16"),
ull7 << 16 ,
0x39, 0x38700000);
errors += check_ace_u_longlong (ACE_TEXT ("3750000 >> 16"),
ull7 >> 16,
0, 0x39);
ull7 <<= 32;
errors += check_ace_u_longlong (ACE_TEXT ("3750000 <<= 32"),
ull7,
3750000, 0);
ull7 >>= 12;
errors += check_ace_u_longlong (ACE_TEXT ("3750000 <<= 32 >>= 15"),
ull7,
0x393, 0x87000000);
ACE_U_LongLong ull8 (0x0f0f, 0xf0f0);
ACE_U_LongLong ull9 (0xf0f0, 0xf0f0);
ull8 |= ull9;
errors += check_ace_u_longlong (ACE_TEXT ("ull8 |= ull9"),
ull8,
0xf0f0, 0xffff);
ull9.lo (0x5678);
ull9.hi (0x1234);
ull8 &= ull9;
errors += check_ace_u_longlong (ACE_TEXT ("ull8 &= 0x12345678"),
ull9,
0x1234, 0x5678);
return errors;
}
#else
static u_int
test_ace_u_longlong (void)
{
return 0; /* Platform has native types; no need to test ACE_U_LongLong */
}
#endif /* ACE_LACKS_LONGLONG_T || ACE_LACKS_UNSIGNEDLONGLONG_T */
int
run_main (int, ACE_TCHAR *[])
{
ACE_START_TEST (ACE_TEXT ("Basic_Types_Test"));
ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("This is ACE Version %u.%u.%u\n\n"),
ACE_MAJOR_VERSION,
ACE_MINOR_VERSION,
ACE_BETA_VERSION));
u_int errors = 0;
errors += check (ACE_TEXT ("ACE_SIZEOF_CHAR: %u%s"),
sizeof (char), ACE_SIZEOF_CHAR);
#if defined (ACE_HAS_WCHAR)
errors += check (ACE_TEXT ("ACE_SIZEOF_WCHAR: %u%s"),
sizeof (wchar_t), ACE_SIZEOF_WCHAR);
#endif /* ACE_HAS_WCHAR */
errors += check (ACE_TEXT ("ACE_SIZEOF_SHORT: %u%s"),
sizeof (short), ACE_SIZEOF_SHORT);
errors += check (ACE_TEXT ("ACE_SIZEOF_INT: %u%s"),
sizeof (int), ACE_SIZEOF_INT);
errors += check (ACE_TEXT ("ACE_SIZEOF_LONG: %u%s"),
sizeof (long), ACE_SIZEOF_LONG);
errors += check (ACE_TEXT ("ACE_SIZEOF_LONG_LONG: %u%s"),
#if defined (ACE_LACKS_LONGLONG_T)
sizeof (ACE_U_LongLong),
#elif defined (ACE_WIN32)
sizeof (unsigned __int64),
#else /* ! ACE_WIN32 && ! ACE_LACKS_LONGLONG_T */
sizeof (long long),
#endif /* ! ACE_WIN32 && ! ACE_LACKS_LONGLONG_T */
ACE_SIZEOF_LONG_LONG);
errors += check (ACE_TEXT ("sizeof 64-bit literal: %u%s"),
sizeof ACE_UINT64_LITERAL (1),
8);
errors += check (ACE_TEXT ("ACE_SIZEOF_VOID_P: %u%s"),
sizeof (void *), ACE_SIZEOF_VOID_P);
errors += check (ACE_TEXT ("ACE_SIZEOF_FLOAT: %u%s"),
sizeof (float), ACE_SIZEOF_FLOAT);
errors += check (ACE_TEXT ("ACE_SIZEOF_DOUBLE: %u%s"),
sizeof (double), ACE_SIZEOF_DOUBLE);
errors += check (ACE_TEXT ("ACE_SIZEOF_LONG_DOUBLE: %u%s"),
sizeof (long double), ACE_SIZEOF_LONG_DOUBLE);
// Crays don't have 16-bit quantities, so don't even test for 16-bit values
#if !defined(_UNICOS)
errors += check (ACE_TEXT ("sizeof (ACE_INT16) is %u%s"),
sizeof (ACE_INT16), 2);
errors += check (ACE_TEXT ("sizeof (ACE_UINT16) is %u%s"),
sizeof (ACE_INT16), 2);
#else /* ! _UNICOS */
errors += check (ACE_TEXT ("sizeof (ACE_INT16) is %u%s"),
sizeof (ACE_INT16), 8);
errors += check (ACE_TEXT ("sizeof (ACE_UINT16) is %u%s"),
sizeof (ACE_INT16), 8);
#endif /* ! _UNICOS */
// MPP Crays do have 32-bit quantities (short), though vector Crays don't
#if !defined(_UNICOS) || defined(_CRAYMPP)
errors += check (ACE_TEXT ("sizeof (ACE_INT32) is %u%s"),
sizeof (ACE_INT32), 4);
errors += check (ACE_TEXT ("sizeof (ACE_UINT32) is %u%s"),
sizeof (ACE_INT32), 4);
#else /* ! _UNICOS */
errors += check (ACE_TEXT ("sizeof (ACE_INT32) is %u%s"),
sizeof (ACE_INT32), 8);
errors += check (ACE_TEXT ("sizeof (ACE_UINT32) is %u%s"),
sizeof (ACE_INT32), 8);
#endif /* ! _UNICOS */
errors += check (ACE_TEXT ("sizeof (ACE_UINT64) is %u%s"),
sizeof (ACE_UINT64), 8);
errors += test_ace_u_longlong ();
// ACE assumes sizeof (ptrdiff_t) == sizeof (void*)
if (sizeof (ptrdiff_t) == sizeof (void *))
ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("sizeof (ptrdiff_t) == sizeof (void*)\n")));
else
{
ACE_ERROR ((LM_ERROR,
ACE_TEXT ("sizeof (ptrdiff_t) != sizeof (void*)\n")));
++errors;
}
// ACE assumes sizeof (ptrdiff_t) >= sizeof (a_function_pointer)
if (sizeof (ptrdiff_t) >= sizeof (a_function_pointer))
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("sizeof (ptrdiff_t) >= sizeof (a_function_pointer)\n")));
else
{
ACE_ERROR ((LM_ERROR,
ACE_TEXT ("sizeof (ptrdiff_t) < sizeof (a_function_pointer)\n")));
++errors;
}
ACE_UINT16 test_val = 123;
#if defined (ACE_LITTLE_ENDIAN)
ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("little endian\n")));
if (ACE_HTONS (test_val) == test_val)
ACE_ERROR ((LM_ERROR,
ACE_TEXT ("Endian test: %d == %d but should be different\n"),
ACE_HTONS (test_val), test_val));
#elif defined (ACE_BIG_ENDIAN)
ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("big endian\n")));
if (ACE_HTONS (test_val) != test_val)
ACE_ERROR ((LM_ERROR,
ACE_TEXT ("Endian test: %d != %d but should be equal\n"),
ACE_HTONS (test_val), test_val));
#else
ACE_ERROR ((LM_ERROR,
ACE_TEXT ("assertion failed: no ACE_*_ENDIAN definition!\n")));
++errors;
#endif /* ACE_LITTLE_ENDIAN */
ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("OS page size: %u\n"),
ACE_OS::getpagesize ()));
#if defined (_SC_PAGESIZE)
ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("sysconf page size: %d\n"),
(int) ACE_OS::sysconf (_SC_PAGESIZE)));
#endif /* _SC_PAGESIZE */
#if defined (_SC_CLK_TCK)
ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("clock ticks/sec = %d\n"),
(int) ACE_OS::sysconf (_SC_CLK_TCK)));
#endif /* _SC_CLK_TCK */
ACE_END_TEST;
return errors == 0 ? 0 : 1;
}
|