test/testplatform.c
author David Ludwig <dludwig@pobox.com>
Wed, 25 Dec 2013 21:39:48 -0500
changeset 8563 c0e68f3b6bbb
parent 7823 4ab3a5ee041d
child 8148 56ba41ac64fe
permissions -rw-r--r--
WinRT: compiled the d3d11 renderer's shaders into SDL itself

Previously, the shaders would get compiled separately, the output of which would need to be packaged into the app. This change should make SDL's dll be the only binary needed to include SDL in a WinRT app.
slouken@5535
     1
/*
slouken@7517
     2
  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
slouken@5535
     3
slouken@5535
     4
  This software is provided 'as-is', without any express or implied
slouken@5535
     5
  warranty.  In no event will the authors be held liable for any damages
slouken@5535
     6
  arising from the use of this software.
slouken@5535
     7
slouken@5535
     8
  Permission is granted to anyone to use this software for any purpose,
slouken@5535
     9
  including commercial applications, and to alter it and redistribute it
slouken@5535
    10
  freely.
slouken@5535
    11
*/
slouken@1421
    12
slouken@1421
    13
#include <stdio.h>
slouken@1421
    14
slouken@1421
    15
#include "SDL.h"
slouken@1421
    16
#include "SDL_endian.h"
slouken@1421
    17
#include "SDL_cpuinfo.h"
slouken@3663
    18
#include "SDL_assert.h"
slouken@1421
    19
slouken@1421
    20
/*
slouken@1421
    21
 * Watcom C flags these as Warning 201: "Unreachable code" if you just
slouken@1421
    22
 *  compare them directly, so we push it through a function to keep the
slouken@1421
    23
 *  compiler quiet.  --ryan.
slouken@1421
    24
 */
slouken@1895
    25
static int
slouken@1895
    26
badsize(size_t sizeoftype, size_t hardcodetype)
slouken@1421
    27
{
slouken@1421
    28
    return sizeoftype != hardcodetype;
slouken@1421
    29
}
slouken@1421
    30
slouken@1895
    31
int
slouken@1895
    32
TestTypes(SDL_bool verbose)
slouken@1421
    33
{
slouken@1895
    34
    int error = 0;
slouken@1421
    35
slouken@1895
    36
    if (badsize(sizeof(Uint8), 1)) {
slouken@1895
    37
        if (verbose)
aschiffler@7639
    38
            SDL_Log("sizeof(Uint8) != 1, instead = %u\n",
slouken@3687
    39
                   (unsigned int)sizeof(Uint8));
slouken@1895
    40
        ++error;
slouken@1895
    41
    }
slouken@1895
    42
    if (badsize(sizeof(Uint16), 2)) {
slouken@1895
    43
        if (verbose)
aschiffler@7639
    44
            SDL_Log("sizeof(Uint16) != 2, instead = %u\n",
slouken@3687
    45
                   (unsigned int)sizeof(Uint16));
slouken@1895
    46
        ++error;
slouken@1895
    47
    }
slouken@1895
    48
    if (badsize(sizeof(Uint32), 4)) {
slouken@1895
    49
        if (verbose)
aschiffler@7639
    50
            SDL_Log("sizeof(Uint32) != 4, instead = %u\n",
slouken@3687
    51
                   (unsigned int)sizeof(Uint32));
slouken@1895
    52
        ++error;
slouken@1895
    53
    }
slouken@1895
    54
    if (badsize(sizeof(Uint64), 8)) {
slouken@1895
    55
        if (verbose)
aschiffler@7639
    56
            SDL_Log("sizeof(Uint64) != 8, instead = %u\n",
slouken@3687
    57
                   (unsigned int)sizeof(Uint64));
slouken@1895
    58
        ++error;
slouken@1895
    59
    }
slouken@1895
    60
    if (verbose && !error)
aschiffler@7639
    61
        SDL_Log("All data types are the expected size.\n");
slouken@1421
    62
slouken@1895
    63
    return (error ? 1 : 0);
slouken@1421
    64
}
slouken@1421
    65
slouken@1895
    66
int
slouken@1895
    67
TestEndian(SDL_bool verbose)
slouken@1421
    68
{
slouken@1895
    69
    int error = 0;
slouken@1895
    70
    Uint16 value = 0x1234;
slouken@1895
    71
    int real_byteorder;
slouken@1895
    72
    Uint16 value16 = 0xCDAB;
slouken@1895
    73
    Uint16 swapped16 = 0xABCD;
slouken@1895
    74
    Uint32 value32 = 0xEFBEADDE;
slouken@1895
    75
    Uint32 swapped32 = 0xDEADBEEF;
slouken@1895
    76
    Uint64 value64, swapped64;
slouken@5512
    77
slouken@1895
    78
    value64 = 0xEFBEADDE;
slouken@1895
    79
    value64 <<= 32;
slouken@1895
    80
    value64 |= 0xCDAB3412;
slouken@1895
    81
    swapped64 = 0x1234ABCD;
slouken@1895
    82
    swapped64 <<= 32;
slouken@1895
    83
    swapped64 |= 0xDEADBEEF;
slouken@1421
    84
slouken@1895
    85
    if (verbose) {
aschiffler@7639
    86
        SDL_Log("Detected a %s endian machine.\n",
slouken@1895
    87
               (SDL_BYTEORDER == SDL_LIL_ENDIAN) ? "little" : "big");
slouken@1895
    88
    }
slouken@1895
    89
    if ((*((char *) &value) >> 4) == 0x1) {
slouken@1895
    90
        real_byteorder = SDL_BIG_ENDIAN;
slouken@1895
    91
    } else {
slouken@1895
    92
        real_byteorder = SDL_LIL_ENDIAN;
slouken@1895
    93
    }
slouken@1895
    94
    if (real_byteorder != SDL_BYTEORDER) {
slouken@1895
    95
        if (verbose) {
aschiffler@7639
    96
            SDL_Log("Actually a %s endian machine!\n",
slouken@1895
    97
                   (real_byteorder == SDL_LIL_ENDIAN) ? "little" : "big");
slouken@1895
    98
        }
slouken@1895
    99
        ++error;
slouken@1895
   100
    }
slouken@1895
   101
    if (verbose) {
aschiffler@7639
   102
        SDL_Log("Value 16 = 0x%X, swapped = 0x%X\n", value16,
slouken@1895
   103
               SDL_Swap16(value16));
slouken@1895
   104
    }
slouken@1895
   105
    if (SDL_Swap16(value16) != swapped16) {
slouken@1895
   106
        if (verbose) {
aschiffler@7639
   107
            SDL_Log("16 bit value swapped incorrectly!\n");
slouken@1895
   108
        }
slouken@1895
   109
        ++error;
slouken@1895
   110
    }
slouken@1895
   111
    if (verbose) {
aschiffler@7639
   112
        SDL_Log("Value 32 = 0x%X, swapped = 0x%X\n", value32,
slouken@1895
   113
               SDL_Swap32(value32));
slouken@1895
   114
    }
slouken@1895
   115
    if (SDL_Swap32(value32) != swapped32) {
slouken@1895
   116
        if (verbose) {
aschiffler@7639
   117
            SDL_Log("32 bit value swapped incorrectly!\n");
slouken@1895
   118
        }
slouken@1895
   119
        ++error;
slouken@1895
   120
    }
slouken@1895
   121
    if (verbose) {
slouken@1615
   122
#ifdef _MSC_VER
aschiffler@7639
   123
        SDL_Log("Value 64 = 0x%I64X, swapped = 0x%I64X\n", value64,
slouken@1895
   124
               SDL_Swap64(value64));
slouken@1615
   125
#else
aschiffler@7639
   126
        SDL_Log("Value 64 = 0x%llX, swapped = 0x%llX\n",
icculus@5638
   127
               (unsigned long long) value64,
icculus@5638
   128
               (unsigned long long) SDL_Swap64(value64));
slouken@1615
   129
#endif
slouken@1895
   130
    }
slouken@1895
   131
    if (SDL_Swap64(value64) != swapped64) {
slouken@1895
   132
        if (verbose) {
aschiffler@7639
   133
            SDL_Log("64 bit value swapped incorrectly!\n");
slouken@1895
   134
        }
slouken@1895
   135
        ++error;
slouken@1895
   136
    }
slouken@1895
   137
    return (error ? 1 : 0);
slouken@1421
   138
}
slouken@1421
   139
slouken@1421
   140
slouken@1895
   141
int
slouken@1895
   142
TestCPUInfo(SDL_bool verbose)
slouken@1421
   143
{
slouken@1895
   144
    if (verbose) {
aschiffler@7639
   145
        SDL_Log("CPU count: %d\n", SDL_GetCPUCount());
aschiffler@7639
   146
        SDL_Log("CPU cache line size: %d\n", SDL_GetCPUCacheLineSize());
aschiffler@7639
   147
        SDL_Log("RDTSC %s\n", SDL_HasRDTSC()? "detected" : "not detected");
aschiffler@7639
   148
        SDL_Log("AltiVec %s\n", SDL_HasAltiVec()? "detected" : "not detected");
aschiffler@7639
   149
        SDL_Log("MMX %s\n", SDL_HasMMX()? "detected" : "not detected");
aschiffler@7639
   150
        SDL_Log("3DNow! %s\n", SDL_Has3DNow()? "detected" : "not detected");
aschiffler@7639
   151
        SDL_Log("SSE %s\n", SDL_HasSSE()? "detected" : "not detected");
aschiffler@7639
   152
        SDL_Log("SSE2 %s\n", SDL_HasSSE2()? "detected" : "not detected");
aschiffler@7639
   153
        SDL_Log("SSE3 %s\n", SDL_HasSSE3()? "detected" : "not detected");
aschiffler@7639
   154
        SDL_Log("SSE4.1 %s\n", SDL_HasSSE41()? "detected" : "not detected");
aschiffler@7639
   155
        SDL_Log("SSE4.2 %s\n", SDL_HasSSE42()? "detected" : "not detected");
slouken@7823
   156
        SDL_Log("System RAM %d MB\n", SDL_GetSystemRAM());
slouken@1895
   157
    }
slouken@1895
   158
    return (0);
slouken@1421
   159
}
slouken@1421
   160
slouken@1895
   161
int
slouken@3663
   162
TestAssertions(SDL_bool verbose)
slouken@3663
   163
{
slouken@3663
   164
    SDL_assert(1);
slouken@3663
   165
    SDL_assert_release(1);
slouken@3663
   166
    SDL_assert_paranoid(1);
slouken@3663
   167
    SDL_assert(0 || 1);
slouken@3663
   168
    SDL_assert_release(0 || 1);
slouken@3663
   169
    SDL_assert_paranoid(0 || 1);
slouken@3663
   170
slouken@3663
   171
#if 0   /* enable this to test assertion failures. */
slouken@3663
   172
    SDL_assert_release(1 == 2);
slouken@3663
   173
    SDL_assert_release(5 < 4);
slouken@3663
   174
    SDL_assert_release(0 && "This is a test");
slouken@3663
   175
#endif
slouken@3663
   176
slouken@5542
   177
    {
slouken@5542
   178
        const SDL_assert_data *item = SDL_GetAssertionReport();
slouken@5542
   179
        while (item) {
aschiffler@7639
   180
            SDL_Log("'%s', %s (%s:%d), triggered %u times, always ignore: %s.\n",
slouken@5542
   181
                item->condition, item->function, item->filename,
slouken@5542
   182
                item->linenum, item->trigger_count,
slouken@5542
   183
                item->always_ignore ? "yes" : "no");
slouken@5542
   184
            item = item->next;
slouken@5542
   185
        }
slouken@5542
   186
    }
slouken@3663
   187
    return (0);
slouken@3663
   188
}
slouken@3663
   189
slouken@3663
   190
int
slouken@1895
   191
main(int argc, char *argv[])
slouken@1421
   192
{
slouken@1895
   193
    SDL_bool verbose = SDL_TRUE;
slouken@1895
   194
    int status = 0;
slouken@1421
   195
aschiffler@7639
   196
    /* Enable standard application logging */
aschiffler@7639
   197
    SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
aschiffler@7639
   198
slouken@1895
   199
    if (argv[1] && (SDL_strcmp(argv[1], "-q") == 0)) {
slouken@1895
   200
        verbose = SDL_FALSE;
slouken@1895
   201
    }
slouken@1895
   202
    if (verbose) {
aschiffler@7639
   203
        SDL_Log("This system is running %s\n", SDL_GetPlatform());
slouken@1895
   204
    }
slouken@1421
   205
slouken@1895
   206
    status += TestTypes(verbose);
slouken@1895
   207
    status += TestEndian(verbose);
slouken@1895
   208
    status += TestCPUInfo(verbose);
slouken@3663
   209
    status += TestAssertions(verbose);
slouken@3663
   210
slouken@1895
   211
    return status;
slouken@1421
   212
}