/[pcsx2_0.9.7]/trunk/3rdparty/SDL-1.3.0-5387/test/testplatform.c
ViewVC logotype

Contents of /trunk/3rdparty/SDL-1.3.0-5387/test/testplatform.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 401 - (show annotations) (download)
Fri Feb 25 17:31:09 2011 UTC (9 years, 9 months ago) by william
File MIME type: text/plain
File size: 5014 byte(s)
Auto Commited Import of: pcsx2-0.9.7-DEBUG (upstream: v0.9.7.4358 local: v0.9.7.313-latest) in ./trunk
1
2 #include <stdio.h>
3
4 #include "SDL.h"
5 #include "SDL_endian.h"
6 #include "SDL_cpuinfo.h"
7 #include "SDL_assert.h"
8
9 /*
10 * Watcom C flags these as Warning 201: "Unreachable code" if you just
11 * compare them directly, so we push it through a function to keep the
12 * compiler quiet. --ryan.
13 */
14 static int
15 badsize(size_t sizeoftype, size_t hardcodetype)
16 {
17 return sizeoftype != hardcodetype;
18 }
19
20 int
21 TestTypes(SDL_bool verbose)
22 {
23 int error = 0;
24
25 if (badsize(sizeof(Uint8), 1)) {
26 if (verbose)
27 printf("sizeof(Uint8) != 1, instead = %u\n",
28 (unsigned int)sizeof(Uint8));
29 ++error;
30 }
31 if (badsize(sizeof(Uint16), 2)) {
32 if (verbose)
33 printf("sizeof(Uint16) != 2, instead = %u\n",
34 (unsigned int)sizeof(Uint16));
35 ++error;
36 }
37 if (badsize(sizeof(Uint32), 4)) {
38 if (verbose)
39 printf("sizeof(Uint32) != 4, instead = %u\n",
40 (unsigned int)sizeof(Uint32));
41 ++error;
42 }
43 #ifdef SDL_HAS_64BIT_TYPE
44 if (badsize(sizeof(Uint64), 8)) {
45 if (verbose)
46 printf("sizeof(Uint64) != 8, instead = %u\n",
47 (unsigned int)sizeof(Uint64));
48 ++error;
49 }
50 #else
51 if (verbose) {
52 printf("WARNING: No 64-bit datatype on this platform\n");
53 }
54 #endif
55 if (verbose && !error)
56 printf("All data types are the expected size.\n");
57
58 return (error ? 1 : 0);
59 }
60
61 int
62 TestEndian(SDL_bool verbose)
63 {
64 int error = 0;
65 Uint16 value = 0x1234;
66 int real_byteorder;
67 Uint16 value16 = 0xCDAB;
68 Uint16 swapped16 = 0xABCD;
69 Uint32 value32 = 0xEFBEADDE;
70 Uint32 swapped32 = 0xDEADBEEF;
71 #ifdef SDL_HAS_64BIT_TYPE
72 Uint64 value64, swapped64;
73 value64 = 0xEFBEADDE;
74 value64 <<= 32;
75 value64 |= 0xCDAB3412;
76 swapped64 = 0x1234ABCD;
77 swapped64 <<= 32;
78 swapped64 |= 0xDEADBEEF;
79 #endif
80
81 if (verbose) {
82 printf("Detected a %s endian machine.\n",
83 (SDL_BYTEORDER == SDL_LIL_ENDIAN) ? "little" : "big");
84 }
85 if ((*((char *) &value) >> 4) == 0x1) {
86 real_byteorder = SDL_BIG_ENDIAN;
87 } else {
88 real_byteorder = SDL_LIL_ENDIAN;
89 }
90 if (real_byteorder != SDL_BYTEORDER) {
91 if (verbose) {
92 printf("Actually a %s endian machine!\n",
93 (real_byteorder == SDL_LIL_ENDIAN) ? "little" : "big");
94 }
95 ++error;
96 }
97 if (verbose) {
98 printf("Value 16 = 0x%X, swapped = 0x%X\n", value16,
99 SDL_Swap16(value16));
100 }
101 if (SDL_Swap16(value16) != swapped16) {
102 if (verbose) {
103 printf("16 bit value swapped incorrectly!\n");
104 }
105 ++error;
106 }
107 if (verbose) {
108 printf("Value 32 = 0x%X, swapped = 0x%X\n", value32,
109 SDL_Swap32(value32));
110 }
111 if (SDL_Swap32(value32) != swapped32) {
112 if (verbose) {
113 printf("32 bit value swapped incorrectly!\n");
114 }
115 ++error;
116 }
117 #ifdef SDL_HAS_64BIT_TYPE
118 if (verbose) {
119 #ifdef _MSC_VER
120 printf("Value 64 = 0x%I64X, swapped = 0x%I64X\n", value64,
121 SDL_Swap64(value64));
122 #else
123 printf("Value 64 = 0x%llX, swapped = 0x%llX\n", value64,
124 SDL_Swap64(value64));
125 #endif
126 }
127 if (SDL_Swap64(value64) != swapped64) {
128 if (verbose) {
129 printf("64 bit value swapped incorrectly!\n");
130 }
131 ++error;
132 }
133 #endif
134 return (error ? 1 : 0);
135 }
136
137
138 int
139 TestCPUInfo(SDL_bool verbose)
140 {
141 if (verbose) {
142 printf("CPU count: %d\n", SDL_GetCPUCount());
143 printf("CPU cache line size: %d\n", SDL_GetCPUCacheLineSize());
144 printf("RDTSC %s\n", SDL_HasRDTSC()? "detected" : "not detected");
145 printf("MMX %s\n", SDL_HasMMX()? "detected" : "not detected");
146 printf("SSE %s\n", SDL_HasSSE()? "detected" : "not detected");
147 printf("SSE2 %s\n", SDL_HasSSE2()? "detected" : "not detected");
148 printf("SSE3 %s\n", SDL_HasSSE3()? "detected" : "not detected");
149 printf("SSE4.1 %s\n", SDL_HasSSE41()? "detected" : "not detected");
150 printf("SSE4.2 %s\n", SDL_HasSSE42()? "detected" : "not detected");
151 }
152 return (0);
153 }
154
155 int
156 TestAssertions(SDL_bool verbose)
157 {
158 SDL_assert(1);
159 SDL_assert_release(1);
160 SDL_assert_paranoid(1);
161 SDL_assert(0 || 1);
162 SDL_assert_release(0 || 1);
163 SDL_assert_paranoid(0 || 1);
164
165 #if 0 /* enable this to test assertion failures. */
166 SDL_assert_release(1 == 2);
167 SDL_assert_release(5 < 4);
168 SDL_assert_release(0 && "This is a test");
169 #endif
170
171 return (0);
172 }
173
174 int
175 main(int argc, char *argv[])
176 {
177 SDL_bool verbose = SDL_TRUE;
178 int status = 0;
179
180 if (argv[1] && (SDL_strcmp(argv[1], "-q") == 0)) {
181 verbose = SDL_FALSE;
182 }
183 if (verbose) {
184 printf("This system is running %s\n", SDL_GetPlatform());
185 }
186
187 status += TestTypes(verbose);
188 status += TestEndian(verbose);
189 status += TestCPUInfo(verbose);
190 status += TestAssertions(verbose);
191
192 return status;
193 }

  ViewVC Help
Powered by ViewVC 1.1.22