testplatform replaces testtypes, testendian, and testcpuinfo
authorSam Lantinga <slouken@libsdl.org>
Fri, 24 Feb 2006 06:49:31 +0000
changeset 1421638da75f9ab8
parent 1420 2405517b5eab
child 1422 d2ee8da60262
testplatform replaces testtypes, testendian, and testcpuinfo
test/Makefile.in
test/testcpuinfo.c
test/testendian.c
test/testplatform.c
test/testtypes.c
     1.1 --- a/test/Makefile.in	Thu Feb 23 21:51:10 2006 +0000
     1.2 +++ b/test/Makefile.in	Fri Feb 24 06:49:31 2006 +0000
     1.3 @@ -7,7 +7,7 @@
     1.4  CFLAGS  = @CFLAGS@
     1.5  LIBS	= @LIBS@
     1.6  
     1.7 -TARGETS = checkkeys$(EXE) graywin$(EXE) loopwave$(EXE) testalpha$(EXE) testbitmap$(EXE) testblitspeed$(EXE) testcdrom$(EXE) testcpuinfo$(EXE) testdyngl$(EXE) testendian$(EXE) testerror$(EXE) testgamma$(EXE) testgl$(EXE) testhread$(EXE) testjoystick$(EXE) testkeys$(EXE) testlock$(EXE) testoverlay2$(EXE) testoverlay$(EXE) testpalette$(EXE) testsem$(EXE) testsprite$(EXE) testtimer$(EXE) testtypes$(EXE) testver$(EXE) testvidinfo$(EXE) testwin$(EXE) testwm$(EXE) threadwin$(EXE) torturethread$(EXE)
     1.8 +TARGETS = checkkeys$(EXE) graywin$(EXE) loopwave$(EXE) testalpha$(EXE) testbitmap$(EXE) testblitspeed$(EXE) testcdrom$(EXE) testdyngl$(EXE) testerror$(EXE) testgamma$(EXE) testgl$(EXE) testhread$(EXE) testjoystick$(EXE) testkeys$(EXE) testlock$(EXE) testoverlay2$(EXE) testoverlay$(EXE) testpalette$(EXE) testplatform$(EXE) testsem$(EXE) testsprite$(EXE) testtimer$(EXE) testver$(EXE) testvidinfo$(EXE) testwin$(EXE) testwm$(EXE) threadwin$(EXE) torturethread$(EXE)
     1.9  
    1.10  all: $(TARGETS)
    1.11  
    1.12 @@ -32,15 +32,9 @@
    1.13  testcdrom$(EXE): $(srcdir)/testcdrom.c
    1.14  	$(CC) -o $@ $? $(CFLAGS) $(LIBS)
    1.15  
    1.16 -testcpuinfo$(EXE): $(srcdir)/testcpuinfo.c
    1.17 -	$(CC) -o $@ $? $(CFLAGS) $(LIBS)
    1.18 -
    1.19  testdyngl$(EXE): $(srcdir)/testdyngl.c
    1.20  	$(CC) -o $@ $? $(CFLAGS) $(LIBS)
    1.21  
    1.22 -testendian$(EXE): $(srcdir)/testendian.c
    1.23 -	$(CC) -o $@ $? $(CFLAGS) $(LIBS)
    1.24 -
    1.25  testerror$(EXE): $(srcdir)/testerror.c
    1.26  	$(CC) -o $@ $? $(CFLAGS) $(LIBS)
    1.27  
    1.28 @@ -71,6 +65,9 @@
    1.29  testpalette$(EXE): $(srcdir)/testpalette.c
    1.30  	$(CC) -o $@ $? $(CFLAGS) $(LIBS) @MATHLIB@
    1.31  
    1.32 +testplatform$(EXE): $(srcdir)/testplatform.c
    1.33 +	$(CC) -o $@ $? $(CFLAGS) $(LIBS)
    1.34 +
    1.35  testsem$(EXE): $(srcdir)/testsem.c
    1.36  	$(CC) -o $@ $? $(CFLAGS) $(LIBS)
    1.37  
    1.38 @@ -80,9 +77,6 @@
    1.39  testtimer$(EXE): $(srcdir)/testtimer.c
    1.40  	$(CC) -o $@ $? $(CFLAGS) $(LIBS)
    1.41  
    1.42 -testtypes$(EXE): $(srcdir)/testtypes.c
    1.43 -	$(CC) -o $@ $? $(CFLAGS) $(LIBS)
    1.44 -
    1.45  testver$(EXE): $(srcdir)/testver.c
    1.46  	$(CC) -o $@ $? $(CFLAGS) $(LIBS)
    1.47  
     2.1 --- a/test/testcpuinfo.c	Thu Feb 23 21:51:10 2006 +0000
     2.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.3 @@ -1,20 +0,0 @@
     2.4 -
     2.5 -/* Test program to check SDL's CPU feature detection */
     2.6 -
     2.7 -#include <stdio.h>
     2.8 -
     2.9 -#include "SDL.h"
    2.10 -#include "SDL_cpuinfo.h"
    2.11 -
    2.12 -int main(int argc, char *argv[])
    2.13 -{
    2.14 -	printf("RDTSC %s\n", SDL_HasRDTSC() ? "detected" : "not detected");
    2.15 -	printf("MMX %s\n", SDL_HasMMX() ? "detected" : "not detected");
    2.16 -	printf("MMX Ext %s\n", SDL_HasMMXExt() ? "detected" : "not detected");
    2.17 -	printf("3DNow %s\n", SDL_Has3DNow() ? "detected" : "not detected");
    2.18 -	printf("3DNow Ext %s\n", SDL_Has3DNowExt() ? "detected" : "not detected");
    2.19 -	printf("SSE %s\n", SDL_HasSSE() ? "detected" : "not detected");
    2.20 -	printf("SSE2 %s\n", SDL_HasSSE2() ? "detected" : "not detected");
    2.21 -	printf("AltiVec %s\n", SDL_HasAltiVec() ? "detected" : "not detected");
    2.22 -	return(0);
    2.23 -}
     3.1 --- a/test/testendian.c	Thu Feb 23 21:51:10 2006 +0000
     3.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.3 @@ -1,73 +0,0 @@
     3.4 -
     3.5 -/* Test program to check SDL's CPU endian detection and byte swapping routines */
     3.6 -
     3.7 -#include <stdio.h>
     3.8 -
     3.9 -#include "SDL.h"
    3.10 -#include "SDL_endian.h"
    3.11 -
    3.12 -int main(int argc, char *argv[])
    3.13 -{
    3.14 -	Uint16 value16 = 0xCDAB;
    3.15 -	Uint32 value32 = 0xEFBEADDE;
    3.16 -#if defined(__GNUC__) && defined(SDL_HAS_64BIT_TYPE)
    3.17 -	Uint64 value64 = 0xEFBEADDECDAB3412LL;
    3.18 -#endif
    3.19 -
    3.20 -	printf("This system is running %s\n",
    3.21 -#if __AIX__
    3.22 -			"AIX"
    3.23 -#elif __AMIGA__
    3.24 -			"AmigaOS"
    3.25 -#elif __BEOS__
    3.26 -			"BeOS"
    3.27 -#elif __BSDI__
    3.28 -			"BSDI"
    3.29 -#elif __DREAMCAST__
    3.30 -			"Dreamcast"
    3.31 -#elif __FREEBSD__
    3.32 -			"FreeBSD"
    3.33 -#elif __HPUX__
    3.34 -			"HP-UX"
    3.35 -#elif __IRIX__
    3.36 -			"Irix"
    3.37 -#elif __LINUX__
    3.38 -			"Linux"
    3.39 -#elif __MACOS__
    3.40 -			"MacOS Classic"
    3.41 -#elif __MACOSX__
    3.42 -			"MacOS X"
    3.43 -#elif __NETBSD__
    3.44 -			"NetBSD"
    3.45 -#elif __OPENBSD__
    3.46 -			"OpenBSD"
    3.47 -#elif __OS2__
    3.48 -			"OS/2"
    3.49 -#elif __OSF__
    3.50 -			"OSF/1"
    3.51 -#elif __QNXNTO__
    3.52 -			"QNX Neutrino"
    3.53 -#elif __RISCOS__
    3.54 -			"RISC OS"
    3.55 -#elif __SOLARIS__
    3.56 -			"Solaris"
    3.57 -#elif __WIN32__
    3.58 -#ifdef _WIN32_WCE
    3.59 -			"Windows CE"
    3.60 -#else
    3.61 -			"Windows"
    3.62 -#endif
    3.63 -#else
    3.64 -			"an unknown operating system!"
    3.65 -#endif
    3.66 -			);
    3.67 -
    3.68 -	printf("This is a %s endian machine.\n",
    3.69 -		(SDL_BYTEORDER == SDL_LIL_ENDIAN) ? "little" : "big");
    3.70 -	printf("Value 16 = 0x%X, swapped = 0x%X\n", value16, SDL_Swap16(value16));
    3.71 -	printf("Value 32 = 0x%X, swapped = 0x%X\n", value32, SDL_Swap32(value32));
    3.72 -#if defined(__GNUC__) && defined(SDL_HAS_64BIT_TYPE)
    3.73 -	printf("Value 64 = 0x%llX, swapped = 0x%llX\n", value64, SDL_Swap64(value64));
    3.74 -#endif
    3.75 -	return(0);
    3.76 -}
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/test/testplatform.c	Fri Feb 24 06:49:31 2006 +0000
     4.3 @@ -0,0 +1,205 @@
     4.4 +
     4.5 +#include <stdio.h>
     4.6 +
     4.7 +#include "SDL.h"
     4.8 +#include "SDL_endian.h"
     4.9 +#include "SDL_cpuinfo.h"
    4.10 +
    4.11 +/*
    4.12 + * Watcom C flags these as Warning 201: "Unreachable code" if you just
    4.13 + *  compare them directly, so we push it through a function to keep the
    4.14 + *  compiler quiet.  --ryan.
    4.15 + */
    4.16 +static int badsize(size_t sizeoftype, size_t hardcodetype)
    4.17 +{
    4.18 +    return sizeoftype != hardcodetype;
    4.19 +}
    4.20 +
    4.21 +int TestTypes(SDL_bool verbose)
    4.22 +{
    4.23 +	int error = 0;
    4.24 +
    4.25 +	if ( badsize(sizeof(Uint8), 1) ) {
    4.26 +		if ( verbose )
    4.27 +			printf("sizeof(Uint8) != 1, instead = %d\n",
    4.28 +								sizeof(Uint8));
    4.29 +		++error;
    4.30 +	}
    4.31 +	if ( badsize(sizeof(Uint16), 2) ) {
    4.32 +		if ( verbose )
    4.33 +			printf("sizeof(Uint16) != 2, instead = %d\n",
    4.34 +								sizeof(Uint16));
    4.35 +		++error;
    4.36 +	}
    4.37 +	if ( badsize(sizeof(Uint32), 4) ) {
    4.38 +		if ( verbose )
    4.39 +			printf("sizeof(Uint32) != 4, instead = %d\n",
    4.40 +								sizeof(Uint32));
    4.41 +		++error;
    4.42 +	}
    4.43 +#ifdef SDL_HAS_64BIT_TYPE
    4.44 +	if ( badsize(sizeof(Uint64), 8) ) {
    4.45 +		if ( verbose )
    4.46 +			printf("sizeof(Uint64) != 8, instead = %d\n",
    4.47 +								sizeof(Uint64));
    4.48 +		++error;
    4.49 +	}
    4.50 +#else
    4.51 +	if ( verbose ) {
    4.52 +		printf("WARNING: No 64-bit datatype on this platform\n");
    4.53 +	}
    4.54 +#endif
    4.55 +	if ( verbose && !error )
    4.56 +		printf("All data types are the expected size.\n");
    4.57 +
    4.58 +	return( error ? 1 : 0 );
    4.59 +}
    4.60 +
    4.61 +int TestEndian(SDL_bool verbose)
    4.62 +{
    4.63 +	int error = 0;
    4.64 +	Uint16 value = 0x1234;
    4.65 +	int real_byteorder;
    4.66 +	Uint16 value16 = 0xCDAB;
    4.67 +	Uint16 swapped16 = 0xABCD;
    4.68 +	Uint32 value32 = 0xEFBEADDE;
    4.69 +	Uint32 swapped32 = 0xDEADBEEF;
    4.70 +#ifdef SDL_HAS_64BIT_TYPE
    4.71 +	Uint64 value64, swapped64;
    4.72 +	value64 = 0xEFBEADDE;
    4.73 +	value64 <<= 32;
    4.74 +	value64 |= 0xCDAB3412;
    4.75 +	swapped64 = 0x1234ABCD;
    4.76 +	swapped64 <<= 32;
    4.77 +	swapped64 |= 0xDEADBEEF;
    4.78 +#endif
    4.79 +
    4.80 +	if ( verbose ) {
    4.81 +		printf("Detected a %s endian machine.\n",
    4.82 +			(SDL_BYTEORDER == SDL_LIL_ENDIAN) ? "little" : "big");
    4.83 +	}
    4.84 +	if ( *((char *)&value) == '1' ) {
    4.85 +		real_byteorder = SDL_BIG_ENDIAN;
    4.86 +	} else {
    4.87 +		real_byteorder = SDL_LIL_ENDIAN;
    4.88 +	}
    4.89 +	if ( real_byteorder != SDL_BYTEORDER ) {
    4.90 +		if ( verbose ) {
    4.91 +			printf("Actually a %s endian machine!\n",
    4.92 +				(real_byteorder == SDL_LIL_ENDIAN) ? "little" : "big");
    4.93 +		}
    4.94 +		++error;
    4.95 +	}
    4.96 +	if ( verbose ) {
    4.97 +		printf("Value 16 = 0x%X, swapped = 0x%X\n", value16, SDL_Swap16(value16));
    4.98 +	}
    4.99 +	if ( SDL_Swap16(value16) != swapped16 ) {
   4.100 +		if ( verbose ) {
   4.101 +			printf("16 bit value swapped incorrectly!\n");
   4.102 +		}
   4.103 +		++error;
   4.104 +	}
   4.105 +	if ( verbose ) {
   4.106 +		printf("Value 32 = 0x%X, swapped = 0x%X\n", value32, SDL_Swap32(value32));
   4.107 +	}
   4.108 +	if ( SDL_Swap32(value32) != swapped32 ) {
   4.109 +		if ( verbose ) {
   4.110 +			printf("32 bit value swapped incorrectly!\n");
   4.111 +		}
   4.112 +		++error;
   4.113 +	}
   4.114 +#ifdef SDL_HAS_64BIT_TYPE
   4.115 +	if ( verbose ) {
   4.116 +		printf("Value 64 = 0x%llX, swapped = 0x%llX\n", value64, SDL_Swap64(value64));
   4.117 +	}
   4.118 +	if ( SDL_Swap64(value64) != swapped64 ) {
   4.119 +		if ( verbose ) {
   4.120 +			printf("64 bit value swapped incorrectly!\n");
   4.121 +		}
   4.122 +		++error;
   4.123 +	}
   4.124 +#endif
   4.125 +	return( error ? 1 : 0 );
   4.126 +}
   4.127 +
   4.128 +
   4.129 +int TestCPUInfo(SDL_bool verbose)
   4.130 +{
   4.131 +	if ( verbose ) {
   4.132 +		printf("RDTSC %s\n", SDL_HasRDTSC() ? "detected" : "not detected");
   4.133 +		printf("MMX %s\n", SDL_HasMMX() ? "detected" : "not detected");
   4.134 +		printf("MMX Ext %s\n", SDL_HasMMXExt() ? "detected" : "not detected");
   4.135 +		printf("3DNow %s\n", SDL_Has3DNow() ? "detected" : "not detected");
   4.136 +		printf("3DNow Ext %s\n", SDL_Has3DNowExt() ? "detected" : "not detected");
   4.137 +		printf("SSE %s\n", SDL_HasSSE() ? "detected" : "not detected");
   4.138 +		printf("SSE2 %s\n", SDL_HasSSE2() ? "detected" : "not detected");
   4.139 +		printf("AltiVec %s\n", SDL_HasAltiVec() ? "detected" : "not detected");
   4.140 +	}
   4.141 +	return(0);
   4.142 +}
   4.143 +
   4.144 +int main(int argc, char *argv[])
   4.145 +{
   4.146 +	SDL_bool verbose = SDL_TRUE;
   4.147 +	int status = 0;
   4.148 +
   4.149 +	if ( argv[1] && (SDL_strcmp(argv[1], "-q") == 0) ) {
   4.150 +		verbose = SDL_FALSE;
   4.151 +	}
   4.152 +	if ( verbose ) {
   4.153 +		printf("This system is running %s\n",
   4.154 +#if __AIX__
   4.155 +			"AIX"
   4.156 +#elif __AMIGA__
   4.157 +			"AmigaOS"
   4.158 +#elif __BEOS__
   4.159 +			"BeOS"
   4.160 +#elif __BSDI__
   4.161 +			"BSDI"
   4.162 +#elif __DREAMCAST__
   4.163 +			"Dreamcast"
   4.164 +#elif __FREEBSD__
   4.165 +			"FreeBSD"
   4.166 +#elif __HPUX__
   4.167 +			"HP-UX"
   4.168 +#elif __IRIX__
   4.169 +			"Irix"
   4.170 +#elif __LINUX__
   4.171 +			"Linux"
   4.172 +#elif __MINT__
   4.173 +			"Atari MiNT"
   4.174 +#elif __MACOS__
   4.175 +			"MacOS Classic"
   4.176 +#elif __MACOSX__
   4.177 +			"MacOS X"
   4.178 +#elif __NETBSD__
   4.179 +			"NetBSD"
   4.180 +#elif __OPENBSD__
   4.181 +			"OpenBSD"
   4.182 +#elif __OS2__
   4.183 +			"OS/2"
   4.184 +#elif __OSF__
   4.185 +			"OSF/1"
   4.186 +#elif __QNXNTO__
   4.187 +			"QNX Neutrino"
   4.188 +#elif __RISCOS__
   4.189 +			"RISC OS"
   4.190 +#elif __SOLARIS__
   4.191 +			"Solaris"
   4.192 +#elif __WIN32__
   4.193 +#ifdef _WIN32_WCE
   4.194 +			"Windows CE"
   4.195 +#else
   4.196 +			"Windows"
   4.197 +#endif
   4.198 +#else
   4.199 +			"an unknown operating system! (see SDL_platform.h)"
   4.200 +#endif
   4.201 +		);
   4.202 +	}
   4.203 +
   4.204 +	status += TestTypes(verbose);
   4.205 +	status += TestEndian(verbose);
   4.206 +	status += TestCPUInfo(verbose);
   4.207 +	return status;
   4.208 +}
     5.1 --- a/test/testtypes.c	Thu Feb 23 21:51:10 2006 +0000
     5.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.3 @@ -1,58 +0,0 @@
     5.4 -
     5.5 -#include <stdio.h>
     5.6 -#include "SDL_main.h"
     5.7 -#include "SDL_stdinc.h"
     5.8 -
     5.9 -/*
    5.10 - * Watcom C flags these as Warning 201: "Unreachable code" if you just
    5.11 - *  compare them directly, so we push it through a function to keep the
    5.12 - *  compiler quiet.  --ryan.
    5.13 - */
    5.14 -static int badsize(size_t sizeoftype, size_t hardcodetype)
    5.15 -{
    5.16 -    return sizeoftype != hardcodetype;
    5.17 -}
    5.18 -
    5.19 -int main(int argc, char *argv[])
    5.20 -{
    5.21 -	int error = 0;
    5.22 -	int verbose = 1;
    5.23 -
    5.24 -	if ( argv[1] && (strcmp(argv[1], "-q") == 0) )
    5.25 -		verbose = 0;
    5.26 -
    5.27 -	if ( badsize(sizeof(Uint8), 1) ) {
    5.28 -		if ( verbose )
    5.29 -			printf("sizeof(Uint8) != 1, instead = %d\n",
    5.30 -								sizeof(Uint8));
    5.31 -		++error;
    5.32 -	}
    5.33 -	if ( badsize(sizeof(Uint16), 2) ) {
    5.34 -		if ( verbose )
    5.35 -			printf("sizeof(Uint16) != 2, instead = %d\n",
    5.36 -								sizeof(Uint16));
    5.37 -		++error;
    5.38 -	}
    5.39 -	if ( badsize(sizeof(Uint32), 4) ) {
    5.40 -		if ( verbose )
    5.41 -			printf("sizeof(Uint32) != 4, instead = %d\n",
    5.42 -								sizeof(Uint32));
    5.43 -		++error;
    5.44 -	}
    5.45 -#ifdef SDL_HAS_64BIT_TYPE
    5.46 -	if ( badsize(sizeof(Uint64), 8) ) {
    5.47 -		if ( verbose )
    5.48 -			printf("sizeof(Uint64) != 8, instead = %d\n",
    5.49 -								sizeof(Uint64));
    5.50 -		++error;
    5.51 -	}
    5.52 -#else
    5.53 -	if ( verbose ) {
    5.54 -		printf("WARNING: No 64-bit datatype on this platform\n");
    5.55 -	}
    5.56 -#endif
    5.57 -	if ( verbose && ! error )
    5.58 -		printf("All data types are the expected size.\n");
    5.59 -
    5.60 -	return( error ? 1 : 0 );
    5.61 -}