test/testplatform.c
author Holmes Futrell <hfutrell@umail.ucsb.edu>
Fri, 15 Aug 2008 00:59:44 +0000
branchgsoc2008_iphone
changeset 2434 12d3b55ebbfc
parent 2062 c9aa6bcb26f3
permissions -rw-r--r--
Added string for iPhone OS platform to the list
slouken@1421
     1
slouken@1421
     2
#include <stdio.h>
slouken@1421
     3
slouken@1421
     4
#include "SDL.h"
slouken@1421
     5
#include "SDL_endian.h"
slouken@1421
     6
#include "SDL_cpuinfo.h"
slouken@1421
     7
slouken@1421
     8
/*
slouken@1421
     9
 * Watcom C flags these as Warning 201: "Unreachable code" if you just
slouken@1421
    10
 *  compare them directly, so we push it through a function to keep the
slouken@1421
    11
 *  compiler quiet.  --ryan.
slouken@1421
    12
 */
slouken@1895
    13
static int
slouken@1895
    14
badsize(size_t sizeoftype, size_t hardcodetype)
slouken@1421
    15
{
slouken@1421
    16
    return sizeoftype != hardcodetype;
slouken@1421
    17
}
slouken@1421
    18
slouken@1895
    19
int
slouken@1895
    20
TestTypes(SDL_bool verbose)
slouken@1421
    21
{
slouken@1895
    22
    int error = 0;
slouken@1421
    23
slouken@1895
    24
    if (badsize(sizeof(Uint8), 1)) {
slouken@1895
    25
        if (verbose)
slouken@1895
    26
            printf("sizeof(Uint8) != 1, instead = %ul\n", sizeof(Uint8));
slouken@1895
    27
        ++error;
slouken@1895
    28
    }
slouken@1895
    29
    if (badsize(sizeof(Uint16), 2)) {
slouken@1895
    30
        if (verbose)
slouken@1895
    31
            printf("sizeof(Uint16) != 2, instead = %ul\n", sizeof(Uint16));
slouken@1895
    32
        ++error;
slouken@1895
    33
    }
slouken@1895
    34
    if (badsize(sizeof(Uint32), 4)) {
slouken@1895
    35
        if (verbose)
slouken@1895
    36
            printf("sizeof(Uint32) != 4, instead = %ul\n", sizeof(Uint32));
slouken@1895
    37
        ++error;
slouken@1895
    38
    }
slouken@1421
    39
#ifdef SDL_HAS_64BIT_TYPE
slouken@1895
    40
    if (badsize(sizeof(Uint64), 8)) {
slouken@1895
    41
        if (verbose)
slouken@1895
    42
            printf("sizeof(Uint64) != 8, instead = %ul\n", sizeof(Uint64));
slouken@1895
    43
        ++error;
slouken@1895
    44
    }
slouken@1421
    45
#else
slouken@1895
    46
    if (verbose) {
slouken@1895
    47
        printf("WARNING: No 64-bit datatype on this platform\n");
slouken@1895
    48
    }
slouken@1421
    49
#endif
slouken@1895
    50
    if (verbose && !error)
slouken@1895
    51
        printf("All data types are the expected size.\n");
slouken@1421
    52
slouken@1895
    53
    return (error ? 1 : 0);
slouken@1421
    54
}
slouken@1421
    55
slouken@1895
    56
int
slouken@1895
    57
TestEndian(SDL_bool verbose)
slouken@1421
    58
{
slouken@1895
    59
    int error = 0;
slouken@1895
    60
    Uint16 value = 0x1234;
slouken@1895
    61
    int real_byteorder;
slouken@1895
    62
    Uint16 value16 = 0xCDAB;
slouken@1895
    63
    Uint16 swapped16 = 0xABCD;
slouken@1895
    64
    Uint32 value32 = 0xEFBEADDE;
slouken@1895
    65
    Uint32 swapped32 = 0xDEADBEEF;
slouken@1421
    66
#ifdef SDL_HAS_64BIT_TYPE
slouken@1895
    67
    Uint64 value64, swapped64;
slouken@1895
    68
    value64 = 0xEFBEADDE;
slouken@1895
    69
    value64 <<= 32;
slouken@1895
    70
    value64 |= 0xCDAB3412;
slouken@1895
    71
    swapped64 = 0x1234ABCD;
slouken@1895
    72
    swapped64 <<= 32;
slouken@1895
    73
    swapped64 |= 0xDEADBEEF;
slouken@1421
    74
#endif
slouken@1421
    75
slouken@1895
    76
    if (verbose) {
slouken@1895
    77
        printf("Detected a %s endian machine.\n",
slouken@1895
    78
               (SDL_BYTEORDER == SDL_LIL_ENDIAN) ? "little" : "big");
slouken@1895
    79
    }
slouken@1895
    80
    if ((*((char *) &value) >> 4) == 0x1) {
slouken@1895
    81
        real_byteorder = SDL_BIG_ENDIAN;
slouken@1895
    82
    } else {
slouken@1895
    83
        real_byteorder = SDL_LIL_ENDIAN;
slouken@1895
    84
    }
slouken@1895
    85
    if (real_byteorder != SDL_BYTEORDER) {
slouken@1895
    86
        if (verbose) {
slouken@1895
    87
            printf("Actually a %s endian machine!\n",
slouken@1895
    88
                   (real_byteorder == SDL_LIL_ENDIAN) ? "little" : "big");
slouken@1895
    89
        }
slouken@1895
    90
        ++error;
slouken@1895
    91
    }
slouken@1895
    92
    if (verbose) {
slouken@1895
    93
        printf("Value 16 = 0x%X, swapped = 0x%X\n", value16,
slouken@1895
    94
               SDL_Swap16(value16));
slouken@1895
    95
    }
slouken@1895
    96
    if (SDL_Swap16(value16) != swapped16) {
slouken@1895
    97
        if (verbose) {
slouken@1895
    98
            printf("16 bit value swapped incorrectly!\n");
slouken@1895
    99
        }
slouken@1895
   100
        ++error;
slouken@1895
   101
    }
slouken@1895
   102
    if (verbose) {
slouken@1895
   103
        printf("Value 32 = 0x%X, swapped = 0x%X\n", value32,
slouken@1895
   104
               SDL_Swap32(value32));
slouken@1895
   105
    }
slouken@1895
   106
    if (SDL_Swap32(value32) != swapped32) {
slouken@1895
   107
        if (verbose) {
slouken@1895
   108
            printf("32 bit value swapped incorrectly!\n");
slouken@1895
   109
        }
slouken@1895
   110
        ++error;
slouken@1895
   111
    }
slouken@1421
   112
#ifdef SDL_HAS_64BIT_TYPE
slouken@1895
   113
    if (verbose) {
slouken@1615
   114
#ifdef _MSC_VER
slouken@1895
   115
        printf("Value 64 = 0x%I64X, swapped = 0x%I64X\n", value64,
slouken@1895
   116
               SDL_Swap64(value64));
slouken@1615
   117
#else
slouken@1895
   118
        printf("Value 64 = 0x%llX, swapped = 0x%llX\n", value64,
slouken@1895
   119
               SDL_Swap64(value64));
slouken@1615
   120
#endif
slouken@1895
   121
    }
slouken@1895
   122
    if (SDL_Swap64(value64) != swapped64) {
slouken@1895
   123
        if (verbose) {
slouken@1895
   124
            printf("64 bit value swapped incorrectly!\n");
slouken@1895
   125
        }
slouken@1895
   126
        ++error;
slouken@1895
   127
    }
slouken@1421
   128
#endif
slouken@1895
   129
    return (error ? 1 : 0);
slouken@1421
   130
}
slouken@1421
   131
slouken@1421
   132
slouken@1895
   133
int
slouken@1895
   134
TestCPUInfo(SDL_bool verbose)
slouken@1421
   135
{
slouken@1895
   136
    if (verbose) {
slouken@1895
   137
        printf("RDTSC %s\n", SDL_HasRDTSC()? "detected" : "not detected");
slouken@1895
   138
        printf("MMX %s\n", SDL_HasMMX()? "detected" : "not detected");
slouken@1895
   139
        printf("MMX Ext %s\n", SDL_HasMMXExt()? "detected" : "not detected");
slouken@1895
   140
        printf("3DNow %s\n", SDL_Has3DNow()? "detected" : "not detected");
slouken@1895
   141
        printf("3DNow Ext %s\n",
slouken@1895
   142
               SDL_Has3DNowExt()? "detected" : "not detected");
slouken@1895
   143
        printf("SSE %s\n", SDL_HasSSE()? "detected" : "not detected");
slouken@1895
   144
        printf("SSE2 %s\n", SDL_HasSSE2()? "detected" : "not detected");
slouken@1895
   145
        printf("AltiVec %s\n", SDL_HasAltiVec()? "detected" : "not detected");
slouken@1895
   146
    }
slouken@1895
   147
    return (0);
slouken@1421
   148
}
slouken@1421
   149
slouken@1895
   150
int
slouken@1895
   151
main(int argc, char *argv[])
slouken@1421
   152
{
slouken@1895
   153
    SDL_bool verbose = SDL_TRUE;
slouken@1895
   154
    int status = 0;
slouken@1421
   155
slouken@1895
   156
    if (argv[1] && (SDL_strcmp(argv[1], "-q") == 0)) {
slouken@1895
   157
        verbose = SDL_FALSE;
slouken@1895
   158
    }
slouken@1895
   159
    if (verbose) {
slouken@1895
   160
        printf("This system is running %s\n",
slouken@1421
   161
#if __AIX__
slouken@1895
   162
               "AIX"
slouken@1421
   163
#elif __BEOS__
slouken@1895
   164
               "BeOS"
slouken@1421
   165
#elif __BSDI__
slouken@1895
   166
               "BSDI"
slouken@1421
   167
#elif __DREAMCAST__
slouken@1895
   168
               "Dreamcast"
slouken@1421
   169
#elif __FREEBSD__
slouken@1895
   170
               "FreeBSD"
slouken@1421
   171
#elif __HPUX__
slouken@1895
   172
               "HP-UX"
slouken@1421
   173
#elif __IRIX__
slouken@1895
   174
               "Irix"
slouken@1421
   175
#elif __LINUX__
slouken@1895
   176
               "Linux"
slouken@1421
   177
#elif __MINT__
slouken@1895
   178
               "Atari MiNT"
slouken@1421
   179
#elif __MACOS__
slouken@1895
   180
               "MacOS Classic"
slouken@1421
   181
#elif __MACOSX__
slouken@1895
   182
               "Mac OS X"
slouken@1421
   183
#elif __NETBSD__
slouken@1895
   184
               "NetBSD"
slouken@1421
   185
#elif __OPENBSD__
slouken@1895
   186
               "OpenBSD"
slouken@1421
   187
#elif __OS2__
slouken@1895
   188
               "OS/2"
slouken@1421
   189
#elif __OSF__
slouken@1895
   190
               "OSF/1"
slouken@1421
   191
#elif __QNXNTO__
slouken@1895
   192
               "QNX Neutrino"
slouken@1421
   193
#elif __RISCOS__
slouken@1895
   194
               "RISC OS"
slouken@1421
   195
#elif __SOLARIS__
slouken@1895
   196
               "Solaris"
slouken@1421
   197
#elif __WIN32__
slouken@1421
   198
#ifdef _WIN32_WCE
slouken@1895
   199
               "Windows CE"
slouken@1421
   200
#else
slouken@1895
   201
               "Windows"
slouken@1421
   202
#endif
hfutrell@2434
   203
#elif __IPHONEOS__
hfutrell@2434
   204
			   "iPhone OS"
slouken@1421
   205
#else
slouken@1895
   206
               "an unknown operating system! (see SDL_platform.h)"
slouken@1421
   207
#endif
slouken@1895
   208
            );
slouken@1895
   209
    }
slouken@1421
   210
slouken@1895
   211
    status += TestTypes(verbose);
slouken@1895
   212
    status += TestEndian(verbose);
slouken@1895
   213
    status += TestCPUInfo(verbose);
slouken@1895
   214
    return status;
slouken@1421
   215
}