comparison test/automated/platform/platform.c @ 3259:22ac66da0765

Merged Edgar's code changes from Google Summer of Code 2009
author Sam Lantinga <slouken@libsdl.org>
date Mon, 07 Sep 2009 05:06:34 +0000
parents
children 245a7d79577c
comparison
equal deleted inserted replaced
3258:e786366ea23b 3259:22ac66da0765
1 /**
2 * Automated SDL platform test.
3 *
4 * Based off of testplatform.c.
5 *
6 * Written by Edgar Simo "bobbens"
7 *
8 * Released under Public Domain.
9 */
10
11
12
13
14 #include "SDL.h"
15 #include "SDL_at.h"
16 #include "SDL_endian.h"
17 #include "SDL_cpuinfo.h"
18
19
20 /*
21 * Prototypes.
22 */
23 static int plat_testSize( size_t sizeoftype, size_t hardcodetype );
24 static void plat_testTypes (void);
25
26
27 /**
28 * @brief Test size.
29 *
30 * @note Watcom C flags these as Warning 201: "Unreachable code" if you just
31 * compare them directly, so we push it through a function to keep the
32 * compiler quiet. --ryan.
33 */
34 static int plat_testSize( size_t sizeoftype, size_t hardcodetype )
35 {
36 return sizeoftype != hardcodetype;
37 }
38
39
40 /**
41 * @brief Tests type size.
42 */
43 static void plat_testTypes (void)
44 {
45 int ret;
46
47 SDL_ATbegin( "Type size" );
48
49 ret = plat_testSize( sizeof(Uint8), 1 );
50 if (SDL_ATvassert( ret == 0, "sizeof(Uint8) = %ul instead of 1", sizeof(Uint8) ))
51 return;
52
53 ret = plat_testSize( sizeof(Uint16), 2 );
54 if (SDL_ATvassert( ret == 0, "sizeof(Uint16) = %ul instead of 2", sizeof(Uint16) ))
55 return;
56
57 ret = plat_testSize( sizeof(Uint32), 4 );
58 if (SDL_ATvassert( ret == 0, "sizeof(Uint32) = %ul instead of 4", sizeof(Uint32) ))
59 return;
60
61 #ifdef SDL_HAS_64BIT_TYPE
62 ret = plat_testSize( sizeof(Uint64), 8 );
63 if (SDL_ATvassert( ret == 0, "sizeof(Uint64) = %ul instead of 8", sizeof(Uint64) ))
64 return;
65 #endif /* SDL_HAS_64BIT_TYPE */
66
67 SDL_ATend();
68 }
69
70
71 /**
72 * @brief Tests platform endianness.
73 */
74 static void plat_testEndian (void)
75 {
76 Uint16 value = 0x1234;
77 int real_byteorder;
78 Uint16 value16 = 0xCDAB;
79 Uint16 swapped16 = 0xABCD;
80 Uint32 value32 = 0xEFBEADDE;
81 Uint32 swapped32 = 0xDEADBEEF;
82 #ifdef SDL_HAS_64BIT_TYPE
83 Uint64 value64, swapped64;
84 value64 = 0xEFBEADDE;
85 value64 <<= 32;
86 value64 |= 0xCDAB3412;
87 swapped64 = 0x1234ABCD;
88 swapped64 <<= 32;
89 swapped64 |= 0xDEADBEEF;
90 #endif
91
92 SDL_ATbegin( "Endianness" );
93
94 /* Test endianness. */
95 if ((*((char *) &value) >> 4) == 0x1) {
96 real_byteorder = SDL_BIG_ENDIAN;
97 } else {
98 real_byteorder = SDL_LIL_ENDIAN;
99 }
100 if (SDL_ATvassert( real_byteorder == SDL_BYTEORDER,
101 "Machine detected as %s endian but appears to be %s endian.",
102 (SDL_BYTEORDER == SDL_LIL_ENDIAN) ? "little" : "big",
103 (real_byteorder == SDL_LIL_ENDIAN) ? "little" : "big" ))
104 return;
105
106 /* Test 16 swap. */
107 if (SDL_ATvassert( SDL_Swap16(value16) == swapped16,
108 "16 bit swapped incorrectly: 0x%X => 0x%X",
109 value16, SDL_Swap16(value16) ))
110 return;
111
112 /* Test 32 swap. */
113 if (SDL_ATvassert( SDL_Swap32(value32) == swapped32,
114 "32 bit swapped incorrectly: 0x%X => 0x%X",
115 value32, SDL_Swap32(value32) ))
116 return;
117
118 #ifdef SDL_HAS_64BIT_TYPE
119 /* Test 64 swap. */
120 if (SDL_ATvassert( SDL_Swap64(value64) == swapped64,
121 #ifdef _MSC_VER
122 "64 bit swapped incorrectly: 0x%I64X => 0x%I64X",
123 #else
124 "64 bit swapped incorrectly: 0x%llX => 0x%llX",
125 #endif
126 value64, SDL_Swap64(value64) ))
127 return;
128 #endif
129
130 SDL_ATend();
131 }
132
133
134 /**
135 * @brief Gets the name of the platform.
136 */
137 const char *platform_getPlatform (void)
138 {
139 return
140 #if __AIX__
141 "AIX"
142 #elif __BEOS__
143 "BeOS"
144 #elif __BSDI__
145 "BSDI"
146 #elif __DREAMCAST__
147 "Dreamcast"
148 #elif __FREEBSD__
149
150 "FreeBSD"
151 #elif __HPUX__
152 "HP-UX"
153 #elif __IRIX__
154 "Irix"
155 #elif __LINUX__
156 "Linux"
157 #elif __MINT__
158 "Atari MiNT"
159 #elif __MACOS__
160 "MacOS Classic"
161 #elif __MACOSX__
162 "Mac OS X"
163 #elif __NETBSD__
164 "NetBSD"
165 #elif __OPENBSD__
166 "OpenBSD"
167 #elif __OS2__
168 "OS/2"
169 #elif __OSF__
170 "OSF/1"
171 #elif __QNXNTO__
172 "QNX Neutrino"
173 #elif __RISCOS__
174 "RISC OS"
175 #elif __SOLARIS__
176 "Solaris"
177 #elif __WIN32__
178 #ifdef _WIN32_WCE
179 "Windows CE"
180 #else
181 "Windows"
182 #endif
183 #elif __IPHONEOS__
184 "iPhone OS"
185 #else
186 "an unknown operating system! (see SDL_platform.h)"
187 #endif
188 ;
189 }
190
191
192 /**
193 * @brief Platform test entrypoint.
194 */
195 #ifdef TEST_STANDALONE
196 int main( int argc, const char *argv[] )
197 {
198 (void) argc;
199 (void) argv;
200 #else /* TEST_STANDALONE */
201 int test_platform (void)
202 {
203 #endif /* TEST_STANDALONE */
204
205 SDL_ATinit( "Platform" );
206
207 /* Debug information. */
208 SDL_ATprintVerbose( 1, "%s System detected\n", platform_getPlatform() );
209 SDL_ATprintVerbose( 1, "System is %s endian\n",
210 #ifdef SDL_LIL_ENDIAN
211 "little"
212 #else
213 "big"
214 #endif
215 );
216 SDL_ATprintVerbose( 1, "Available extensions:\n" );
217 SDL_ATprintVerbose( 1, " RDTSC %s\n", SDL_HasRDTSC()? "detected" : "not detected" );
218 SDL_ATprintVerbose( 1, " MMX %s\n", SDL_HasMMX()? "detected" : "not detected" );
219 SDL_ATprintVerbose( 1, " MMX Ext %s\n", SDL_HasMMXExt()? "detected" : "not detected" );
220 SDL_ATprintVerbose( 1, " 3DNow %s\n", SDL_Has3DNow()? "detected" : "not detected" );
221 SDL_ATprintVerbose( 1, " 3DNow Ext %s\n",
222 SDL_Has3DNowExt()? "detected" : "not detected" );
223 SDL_ATprintVerbose( 1, " SSE %s\n", SDL_HasSSE()? "detected" : "not detected" );
224 SDL_ATprintVerbose( 1, " SSE2 %s\n", SDL_HasSSE2()? "detected" : "not detected" );
225 SDL_ATprintVerbose( 1, " AltiVec %s\n", SDL_HasAltiVec()? "detected" : "not detected" );
226
227 plat_testTypes();
228 plat_testEndian();
229
230 return SDL_ATfinish();
231 }