Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/psx/octoshock/tests.cpp
2 views
1
// DO NOT REMOVE/DISABLE THESE MATH AND COMPILER SANITY TESTS. THEY EXIST FOR A REASON.
2
3
/* Mednafen - Multi-system Emulator
4
*
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
9
*
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
14
*
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
*/
19
20
// We really don't want NDEBUG defined ;)
21
#ifdef HAVE_CONFIG_H
22
#include <config.h>
23
#endif
24
25
#undef NDEBUG
26
27
#include <stdio.h>
28
#include <exception>
29
#include <vector>
30
#include <algorithm>
31
#include "octoshock.h"
32
#include "math_ops.h"
33
#include "error.h"
34
35
#ifdef WANT_TEST_LEPACKER
36
#include "lepacker.h"
37
#endif
38
39
#ifdef WANT_TEST_HASHES
40
#include <mednafen/hash/sha1.h>
41
#include <mednafen/hash/sha256.h>
42
#endif
43
44
#ifdef WANT_TEST_ZLIB
45
#include <zlib.h>
46
#endif
47
48
#undef NDEBUG
49
#include <assert.h>
50
#include <math.h>
51
52
#include "psx/masmem.h"
53
54
#if defined(HAVE_FENV_H)
55
#include <fenv.h>
56
#endif
57
58
#define FATALME { printf("Math test failed: %s:%d\n", __FILE__, __LINE__); fprintf(stderr, "Math test failed: %s:%d\n", __FILE__, __LINE__); return(0); }
59
60
namespace MDFN_TESTS_CPP
61
{
62
63
// Don't define this static, and don't define it const. We want these tests to be done at run time, not compile time(although maybe we should do both...).
64
typedef struct
65
{
66
int bits;
67
uint32 negative_one;
68
uint32 mostneg;
69
int32 mostnegresult;
70
} MathTestEntry;
71
72
#define ADD_MTE(_bits) { _bits, ((uint32)1 << _bits) - 1, (uint32)1 << (_bits - 1), (int32)(0 - ((uint32)1 << (_bits - 1))) }
73
74
MathTestEntry math_test_vals[] =
75
{
76
{ 9, 0x01FF, 0x0100, -256 },
77
{ 10, 0x03FF, 0x0200, -512 },
78
{ 11, 0x07FF, 0x0400, -1024 },
79
{ 12, 0x0FFF, 0x0800, -2048 },
80
{ 13, 0x1FFF, 0x1000, -4096 },
81
{ 14, 0x3FFF, 0x2000, -8192 },
82
{ 15, 0x7FFF, 0x4000, -16384 },
83
84
ADD_MTE(17),
85
ADD_MTE(18),
86
ADD_MTE(19),
87
ADD_MTE(20),
88
ADD_MTE(21),
89
ADD_MTE(22),
90
ADD_MTE(23),
91
ADD_MTE(24),
92
ADD_MTE(25),
93
ADD_MTE(26),
94
ADD_MTE(27),
95
ADD_MTE(28),
96
ADD_MTE(29),
97
ADD_MTE(30),
98
ADD_MTE(31),
99
100
{ 0, 0, 0, 0 },
101
};
102
103
static bool DoSizeofTests(void)
104
{
105
const int SizePairs[][2] =
106
{
107
{ sizeof(uint8), 1 },
108
{ sizeof(int8), 1 },
109
110
{ sizeof(uint16), 2 },
111
{ sizeof(int16), 2 },
112
113
{ sizeof(uint32), 4 },
114
{ sizeof(int32), 4 },
115
116
{ sizeof(uint64), 8 },
117
{ sizeof(int64), 8 },
118
119
{ 0, 0 },
120
};
121
122
int i = -1;
123
124
while(SizePairs[++i][0])
125
{
126
if(SizePairs[i][0] != SizePairs[i][1])
127
FATALME;
128
}
129
130
assert(sizeof(char) == 1);
131
assert(sizeof(int) == 4);
132
assert(sizeof(long) >= 4);
133
134
assert(sizeof(char) == SIZEOF_CHAR);
135
assert(sizeof(short) == SIZEOF_SHORT);
136
assert(sizeof(int) == SIZEOF_INT);
137
assert(sizeof(long) == SIZEOF_LONG);
138
assert(sizeof(long long) == SIZEOF_LONG_LONG);
139
140
assert(sizeof(off_t) == SIZEOF_OFF_T);
141
142
return(1);
143
}
144
145
static void AntiNSOBugTest_Sub1_a(int *array) NO_INLINE;
146
static void AntiNSOBugTest_Sub1_a(int *array)
147
{
148
for(int value = 0; value < 127; value++)
149
array[value] += (int8)value * 15;
150
}
151
152
static void AntiNSOBugTest_Sub1_b(int *array) NO_INLINE;
153
static void AntiNSOBugTest_Sub1_b(int *array)
154
{
155
for(int value = 127; value < 256; value++)
156
array[value] += (int8)value * 15;
157
}
158
159
static void AntiNSOBugTest_Sub2(int *array) NO_INLINE;
160
static void AntiNSOBugTest_Sub2(int *array)
161
{
162
for(int value = 0; value < 256; value++)
163
array[value] += (int8)value * 15;
164
}
165
166
static void AntiNSOBugTest_Sub3(int *array) NO_INLINE;
167
static void AntiNSOBugTest_Sub3(int *array)
168
{
169
for(int value = 0; value < 256; value++)
170
{
171
if(value >= 128)
172
array[value] = (value - 256) * 15;
173
else
174
array[value] = value * 15;
175
}
176
}
177
178
static bool DoAntiNSOBugTest(void)
179
{
180
int array1[256], array2[256], array3[256];
181
182
memset(array1, 0, sizeof(array1));
183
memset(array2, 0, sizeof(array2));
184
memset(array3, 0, sizeof(array3));
185
186
AntiNSOBugTest_Sub1_a(array1);
187
AntiNSOBugTest_Sub1_b(array1);
188
AntiNSOBugTest_Sub2(array2);
189
AntiNSOBugTest_Sub3(array3);
190
191
for(int i = 0; i < 256; i++)
192
{
193
if((array1[i] != array2[i]) || (array2[i] != array3[i]))
194
{
195
printf("%d %d %d %d\n", i, array1[i], array2[i], array3[i]);
196
FATALME;
197
}
198
}
199
//for(int value = 0; value < 256; value++)
200
// printf("%d, %d\n", (int8)value, ((int8)value) * 15);
201
202
return(1);
203
}
204
205
//
206
// Related: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61741
207
//
208
// Not found to be causing problems in Mednafen(unlike the earlier no-strict-overflow problem and associated test),
209
// but better safe than sorry.
210
//
211
static void DoAntiNSOBugTest2014_SubA(int a) NO_INLINE NO_CLONE;
212
static void DoAntiNSOBugTest2014_SubA(int a)
213
{
214
char c = 0;
215
216
for(; a; a--)
217
{
218
for(; c >= 0; c++)
219
{
220
221
}
222
}
223
224
assert(c == -128);
225
}
226
227
static int ANSOBT_CallCount;
228
static void DoAntiNSOBugTest2014_SubMx_F(void) NO_INLINE NO_CLONE;
229
static void DoAntiNSOBugTest2014_SubMx_F(void)
230
{
231
ANSOBT_CallCount++;
232
233
assert(ANSOBT_CallCount < 1000);
234
}
235
236
static void DoAntiNSOBugTest2014_SubM1(void) NO_INLINE NO_CLONE;
237
static void DoAntiNSOBugTest2014_SubM1(void)
238
{
239
char a;
240
241
for(a = 127 - 1; a >= 0; a++)
242
DoAntiNSOBugTest2014_SubMx_F();
243
}
244
245
static void DoAntiNSOBugTest2014_SubM3(void) NO_INLINE NO_CLONE;
246
static void DoAntiNSOBugTest2014_SubM3(void)
247
{
248
char a;
249
250
for(a = 127 - 3; a >= 0; a++)
251
DoAntiNSOBugTest2014_SubMx_F();
252
}
253
254
255
static void DoAntiNSOBugTest2014(void)
256
{
257
DoAntiNSOBugTest2014_SubA(1);
258
259
ANSOBT_CallCount = 0;
260
DoAntiNSOBugTest2014_SubM1();
261
assert(ANSOBT_CallCount == 2);
262
263
ANSOBT_CallCount = 0;
264
DoAntiNSOBugTest2014_SubM3();
265
assert(ANSOBT_CallCount == 4);
266
}
267
268
269
#ifdef WANT_TEST_LEPACKER
270
bool DoLEPackerTest(void)
271
{
272
MDFN::LEPacker mizer;
273
static const uint8 correct_result[24] = { 0xed, 0xfe, 0xed, 0xde, 0xaa, 0xca, 0xef, 0xbe, 0xbe, 0xba, 0xfe, 0xca, 0xad, 0xde, 0x01, 0x9a, 0x0c, 0xa7, 0xff, 0x00, 0xff, 0xff, 0x55, 0x7f };
274
275
uint64 u64_test = 0xDEADCAFEBABEBEEFULL;
276
uint32 u32_test = 0xDEEDFEED;
277
uint16 u16_test = 0xCAAA;
278
uint8 u8_test = 0x55;
279
int32 s32_test = -5829478;
280
int16 s16_test = -1;
281
int8 s8_test = 127;
282
283
bool bool_test0 = 0;
284
bool bool_test1 = 1;
285
286
mizer ^ u32_test;
287
mizer ^ u16_test;
288
mizer ^ u64_test;
289
mizer ^ bool_test1;
290
mizer ^ s32_test;
291
mizer ^ bool_test0;
292
mizer ^ s16_test;
293
mizer ^ u8_test;
294
mizer ^ s8_test;
295
296
if(mizer.size() != 24)
297
{
298
printf("Test failed: LEPacker data incorrect size.\n");
299
return(FALSE);
300
}
301
302
for(unsigned int i = 0; i < mizer.size(); i++)
303
if(mizer[i] != correct_result[i])
304
{
305
printf("Test failed: LEPacker packed data incorrect.\n");
306
return(FALSE);
307
}
308
309
u64_test = 0;
310
u32_test = 0;
311
u16_test = 0;
312
u8_test = 0;
313
s32_test = 0;
314
s16_test = 0;
315
s8_test = 0;
316
317
bool_test0 = 1;
318
bool_test1 = 0;
319
320
mizer.set_read_mode(TRUE);
321
322
mizer ^ u32_test;
323
mizer ^ u16_test;
324
mizer ^ u64_test;
325
mizer ^ bool_test1;
326
mizer ^ s32_test;
327
mizer ^ bool_test0;
328
mizer ^ s16_test;
329
mizer ^ u8_test;
330
mizer ^ s8_test;
331
332
333
if(u32_test != 0xDEEDFEED)
334
{
335
printf("Test failed: LEPacker u32 unpacking incorrect.\n");
336
return(FALSE);
337
}
338
339
if(u16_test != 0xCAAA)
340
{
341
printf("Test failed: LEPacker u16 unpacking incorrect.\n");
342
return(FALSE);
343
}
344
345
if(u64_test != 0xDEADCAFEBABEBEEFULL)
346
{
347
printf("%16llx\n", (unsigned long long)u64_test);
348
printf("Test failed: LEPacker u64 unpacking incorrect.\n");
349
return(FALSE);
350
}
351
352
if(u8_test != 0x55)
353
{
354
printf("Test failed: LEPacker u8 unpacking incorrect.\n");
355
return(FALSE);
356
}
357
358
if(s32_test != -5829478)
359
{
360
printf("Test failed: LEPacker s32 unpacking incorrect.\n");
361
return(FALSE);
362
}
363
364
if(s16_test != -1)
365
{
366
printf("Test failed: LEPacker s16 unpacking incorrect.\n");
367
return(FALSE);
368
}
369
370
if(s8_test != 127)
371
{
372
printf("Test failed: LEPacker s8 unpacking incorrect.\n");
373
return(FALSE);
374
}
375
376
if(bool_test0 != 0)
377
{
378
printf("Test failed: LEPacker bool unpacking incorrect.\n");
379
return(FALSE);
380
}
381
382
if(bool_test1 != 1)
383
{
384
printf("Test failed: LEPacker bool unpacking incorrect.\n");
385
return(FALSE);
386
}
387
388
return(TRUE);
389
}
390
#endif
391
392
struct MathTestTSOEntry
393
{
394
int32 a;
395
int32 b;
396
};
397
398
// Don't declare as static(though whopr might mess it up anyway)
399
MathTestTSOEntry MathTestTSOTests[] =
400
{
401
{ 0x7FFFFFFF, 2 },
402
{ 0x7FFFFFFE, 0x7FFFFFFF },
403
{ 0x7FFFFFFF, 0x7FFFFFFF },
404
{ 0x7FFFFFFE, 0x7FFFFFFE },
405
};
406
407
volatile int32 MDFNTestsCPP_SLS_Var = (int32)0xDEADBEEF;
408
volatile int8 MDFNTestsCPP_SLS_Var8 = (int8)0xEF;
409
volatile int16 MDFNTestsCPP_SLS_Var16 = (int16)0xBEEF;
410
int32 MDFNTestsCPP_SLS_Var_NT = (int32)0xDEADBEEF;
411
int32 MDFNTestsCPP_SLS_Var_NT2 = (int32)0x7EADBEEF;
412
413
static uint64 NO_INLINE NO_CLONE Mul_U16U16U32U64_Proper(uint16 a, uint16 b) // For reference
414
{
415
return (uint32)a * (uint32)b;
416
}
417
418
static uint64 NO_INLINE NO_CLONE Mul_U16U16U32U64(uint16 a, uint16 b)
419
{
420
return (uint32)(a * b);
421
}
422
423
static void TestSignedOverflow(void)
424
{
425
assert(Mul_U16U16U32U64_Proper(65535, 65535) == 0xfffe0001ULL);
426
assert(Mul_U16U16U32U64(65535, 65535) == 0xfffe0001ULL);
427
428
for(unsigned int i = 0; i < sizeof(MathTestTSOTests) / sizeof(MathTestTSOEntry); i++)
429
{
430
int32 a = MathTestTSOTests[i].a;
431
int32 b = MathTestTSOTests[i].b;
432
433
assert((a + b) < a && (a + b) < b);
434
435
assert((a + 0x7FFFFFFE) < a);
436
assert((b + 0x7FFFFFFE) < b);
437
438
assert((a + 0x7FFFFFFF) < a);
439
assert((b + 0x7FFFFFFF) < b);
440
441
assert((int32)(a + 0x80000000) < a);
442
assert((int32)(b + 0x80000000) < b);
443
444
assert((int32)(a ^ 0x80000000) < a);
445
assert((int32)(b ^ 0x80000000) < b);
446
}
447
448
for(unsigned i = 0; i < 64; i++)
449
{
450
MDFNTestsCPP_SLS_Var = (MDFNTestsCPP_SLS_Var << 1) ^ ((MDFNTestsCPP_SLS_Var << 2) + 0x7FFFFFFF) ^ ((MDFNTestsCPP_SLS_Var >> 31) & 0x3);
451
MDFNTestsCPP_SLS_Var8 = (MDFNTestsCPP_SLS_Var8 << 1) ^ ((MDFNTestsCPP_SLS_Var8 << 2) + 0x7F) ^ ((MDFNTestsCPP_SLS_Var8 >> 7) & 0x3);
452
MDFNTestsCPP_SLS_Var16 = (MDFNTestsCPP_SLS_Var16 << 1) ^ ((MDFNTestsCPP_SLS_Var16 << 2) + 0x7FFF) ^ ((MDFNTestsCPP_SLS_Var16 >> 15) & 0x3);
453
}
454
455
{
456
int8 a = MDFNTestsCPP_SLS_Var8;
457
int16 b = MDFNTestsCPP_SLS_Var16;
458
int32 c = MDFNTestsCPP_SLS_Var;
459
int64 d = (int64)MDFNTestsCPP_SLS_Var * (int64)MDFNTestsCPP_SLS_Var;
460
int32 e = c;
461
int64 f = c;
462
463
for(int i = 0; i < 64; i++)
464
{
465
a += a * i + b;
466
b += b * i + c;
467
c += c * i + d;
468
d += d * i + a;
469
470
e += e * i + c;
471
f += f * i + c;
472
}
473
//printf("%08x %16llx - %02x %04x %08x %16llx\n", (uint32)e, (uint64)f, (uint8)a, (uint16)b, (uint32)c, (uint64)d);
474
assert((uint32)e == (uint32)f && (uint32)e == 0x00c37de2 && (uint64)f == 0x5d17261900c37de2);
475
assert((uint8)a == 0xbf);
476
assert((uint16)b == 0xb77c);
477
assert((uint32)c == 0xb4244622U);
478
assert((uint64)d == 0xa966e02ed95c83fULL);
479
}
480
481
482
//printf("%02x %04x %08x\n", (uint8)MDFNTestsCPP_SLS_Var8, (uint16)MDFNTestsCPP_SLS_Var16, (uint32)MDFNTestsCPP_SLS_Var);
483
assert((uint8)MDFNTestsCPP_SLS_Var8 == 0x04);
484
assert((uint16)MDFNTestsCPP_SLS_Var16 == 0xa7d8);
485
assert((uint32)MDFNTestsCPP_SLS_Var == 0x4ef11a23);
486
487
for(signed i = 1; i != 0; i =~-i); // Not really signed overflow, but meh!
488
for(signed i = -1; i != 0; i <<= 1);
489
for(signed i = 1; i >= 0; i *= 3);
490
491
if(MDFNTestsCPP_SLS_Var_NT < 0)
492
assert((MDFNTestsCPP_SLS_Var_NT << 2) > 0);
493
494
if(MDFNTestsCPP_SLS_Var_NT2 > 0)
495
assert((MDFNTestsCPP_SLS_Var_NT2 << 2) < 0);
496
}
497
498
unsigned MDFNTests_OverShiftAmounts[3] = { 8, 16, 32};
499
uint32 MDFNTests_OverShiftTV = 0xBEEFD00D;
500
static void TestDefinedOverShift(void)
501
{
502
//for(unsigned sa = 0; sa < 4; sa++)
503
{
504
for(unsigned i = 0; i < 2; i++)
505
{
506
uint8 v8 = MDFNTests_OverShiftTV;
507
uint16 v16 = MDFNTests_OverShiftTV;
508
uint32 v32 = MDFNTests_OverShiftTV;
509
510
int8 iv8 = MDFNTests_OverShiftTV;
511
int16 iv16 = MDFNTests_OverShiftTV;
512
int32 iv32 = MDFNTests_OverShiftTV;
513
514
if(i == 1)
515
{
516
v8 >>= MDFNTests_OverShiftAmounts[0];
517
v16 >>= MDFNTests_OverShiftAmounts[1];
518
v32 = (uint64)v32 >> MDFNTests_OverShiftAmounts[2];
519
520
iv8 >>= MDFNTests_OverShiftAmounts[0];
521
iv16 >>= MDFNTests_OverShiftAmounts[1];
522
iv32 = (int64)iv32 >> MDFNTests_OverShiftAmounts[2];
523
}
524
else
525
{
526
v8 <<= MDFNTests_OverShiftAmounts[0];
527
v16 <<= MDFNTests_OverShiftAmounts[1];
528
v32 = (uint64)v32 << MDFNTests_OverShiftAmounts[2];
529
530
iv8 <<= MDFNTests_OverShiftAmounts[0];
531
iv16 <<= MDFNTests_OverShiftAmounts[1];
532
iv32 = (int64)iv32 << MDFNTests_OverShiftAmounts[2];
533
}
534
535
assert(v8 == 0);
536
assert(v16 == 0);
537
assert(v32 == 0);
538
539
assert(iv8 == 0);
540
assert(iv16 == -(int)i);
541
assert(iv32 == -(int)i);
542
}
543
}
544
}
545
546
static uint8 BoolConvSupportFunc(void) MDFN_COLD NO_INLINE;
547
static uint8 BoolConvSupportFunc(void)
548
{
549
return 0xFF;
550
}
551
552
static bool BoolConv0(void) MDFN_COLD NO_INLINE;
553
static bool BoolConv0(void)
554
{
555
return BoolConvSupportFunc() & 1;
556
}
557
558
static void BoolTestThing(unsigned val) MDFN_COLD NO_INLINE;
559
static void BoolTestThing(unsigned val)
560
{
561
if(val != 1)
562
printf("%u\n", val);
563
564
assert(val == 1);
565
}
566
567
static void TestBoolConv(void)
568
{
569
BoolTestThing(BoolConv0());
570
}
571
572
static void TestNarrowConstFold(void) NO_INLINE MDFN_COLD;
573
static void TestNarrowConstFold(void)
574
{
575
unsigned sa = 8;
576
uint8 za[1] = { 0 };
577
int a;
578
579
a = za[0] < (uint8)(1 << sa);
580
581
assert(a == 0);
582
}
583
584
585
unsigned MDFNTests_ModTern_a = 2;
586
unsigned MDFNTests_ModTern_b = 0;
587
static void ModTernTestEval(unsigned v) NO_INLINE MDFN_COLD;
588
static void ModTernTestEval(unsigned v)
589
{
590
assert(v == 0);
591
}
592
593
static void TestModTern(void) NO_INLINE MDFN_COLD;
594
static void TestModTern(void)
595
{
596
if(!MDFNTests_ModTern_b)
597
{
598
MDFNTests_ModTern_b = MDFNTests_ModTern_a;
599
600
if(1 % (MDFNTests_ModTern_a ? MDFNTests_ModTern_a : 2))
601
MDFNTests_ModTern_b = 0;
602
}
603
ModTernTestEval(MDFNTests_ModTern_b);
604
}
605
606
static int TestBWNotMask31GTZ_Sub(int a) NO_INLINE NO_CLONE;
607
static int TestBWNotMask31GTZ_Sub(int a)
608
{
609
a = (((~a) & 0x80000000LL) > 0) + 1;
610
return a;
611
}
612
613
static void TestBWNotMask31GTZ(void)
614
{
615
assert(TestBWNotMask31GTZ_Sub(0) == 2);
616
}
617
618
int MDFN_tests_TestTernary_val = 0;
619
static void NO_INLINE NO_CLONE TestTernary_Sub(void)
620
{
621
MDFN_tests_TestTernary_val++;
622
}
623
624
static void TestTernary(void)
625
{
626
int a = ((MDFN_tests_TestTernary_val++) ? (MDFN_tests_TestTernary_val = 20) : (TestTernary_Sub(), MDFN_tests_TestTernary_val));
627
628
assert(a == 2);
629
}
630
631
size_t TestLLVM15470_Counter;
632
void NO_INLINE NO_CLONE TestLLVM15470_Sub2(size_t x)
633
{
634
assert(x == TestLLVM15470_Counter);
635
TestLLVM15470_Counter++;
636
}
637
638
void NO_INLINE NO_CLONE TestLLVM15470_Sub(size_t m)
639
{
640
size_t m2 = ~(size_t)0;
641
642
for(size_t i = 1; i <= 4; i *= m)
643
m2++;
644
645
for(size_t a = 0; a < 2; a++)
646
{
647
for(size_t b = 1; b <= 2; b++)
648
{
649
TestLLVM15470_Sub2(a * m2 + b);
650
}
651
}
652
}
653
654
void NO_INLINE NO_CLONE TestLLVM15470(void)
655
{
656
TestLLVM15470_Counter = 1;
657
TestLLVM15470_Sub(2);
658
}
659
660
int NO_INLINE NO_CLONE TestGCC60196_Sub(const int16* data, int count)
661
{
662
int ret = 0;
663
664
for(int i = 0; i < count; i++)
665
ret += i * data[i];
666
667
return ret;
668
}
669
670
void NO_INLINE NO_CLONE TestGCC60196(void)
671
{
672
int16 ta[16];
673
674
for(unsigned i = 0; i < 16; i++)
675
ta[i] = 1;
676
677
assert(TestGCC60196_Sub(ta, sizeof(ta) / sizeof(ta[0])) == 120);
678
}
679
680
template<typename A, typename B>
681
void NO_INLINE NO_CLONE TestSUCompare_Sub(A a, B b)
682
{
683
assert(a < b);
684
}
685
686
int16 TestSUCompare_x0 = 256;
687
688
void NO_INLINE NO_CLONE TestSUCompare(void)
689
{
690
int8 a = 1;
691
uint8 b = 255;
692
int16 c = 1;
693
uint16 d = 65535;
694
int32 e = 1;
695
uint32 f = ~0U;
696
int64 g = ~(uint32)0;
697
uint64 h = ~(uint64)0;
698
699
assert(a < b);
700
assert(c < d);
701
assert((uint32)e < f);
702
assert((uint64)g < h);
703
704
TestSUCompare_Sub<int8, uint8>(1, 255);
705
TestSUCompare_Sub<int16, uint16>(1, 65535);
706
707
TestSUCompare_Sub<int8, uint8>(TestSUCompare_x0, 255);
708
}
709
710
static void DoAlignmentChecks(void)
711
{
712
uint8 padding0[3];
713
alignas(16) uint8 aligned0[7];
714
alignas(4) uint8 aligned1[2];
715
alignas(16) uint32 aligned2[2];
716
uint8 padding1[3];
717
718
static uint8 g_padding0[3];
719
alignas(16) static uint8 g_aligned0[7];
720
alignas(4) static uint8 g_aligned1[2];
721
alignas(16) static uint32 g_aligned2[2];
722
static uint8 g_padding1[3];
723
724
// Make sure compiler doesn't removing padding vars
725
assert((&padding0[1] - &padding0[0]) == 1);
726
assert((&padding1[1] - &padding1[0]) == 1);
727
assert((&g_padding0[1] - &g_padding0[0]) == 1);
728
assert((&g_padding1[1] - &g_padding1[0]) == 1);
729
730
731
assert( (((unsigned long long)&aligned0[0]) & 0xF) == 0);
732
assert( (((unsigned long long)&aligned1[0]) & 0x3) == 0);
733
assert( (((unsigned long long)&aligned2[0]) & 0xF) == 0);
734
735
assert(((uint8 *)&aligned0[1] - (uint8 *)&aligned0[0]) == 1);
736
assert(((uint8 *)&aligned1[1] - (uint8 *)&aligned1[0]) == 1);
737
assert(((uint8 *)&aligned2[1] - (uint8 *)&aligned2[0]) == 4);
738
739
740
assert( (((unsigned long long)&g_aligned0[0]) & 0xF) == 0);
741
assert( (((unsigned long long)&g_aligned1[0]) & 0x3) == 0);
742
assert( (((unsigned long long)&g_aligned2[0]) & 0xF) == 0);
743
744
assert(((uint8 *)&g_aligned0[1] - (uint8 *)&g_aligned0[0]) == 1);
745
assert(((uint8 *)&g_aligned1[1] - (uint8 *)&g_aligned1[0]) == 1);
746
assert(((uint8 *)&g_aligned2[1] - (uint8 *)&g_aligned2[0]) == 4);
747
}
748
749
static uint32 NO_INLINE NO_CLONE RunMASMemTests_DoomAndGloom(uint32 offset)
750
{
751
MultiAccessSizeMem<4, false> mt0;
752
753
mt0.WriteU32(offset, 4);
754
mt0.WriteU16(offset, 0);
755
mt0.WriteU32(offset, mt0.ReadU32(offset) + 1);
756
757
return mt0.ReadU32(offset);
758
}
759
760
static void RunMASMemTests(void)
761
{
762
// Little endian:
763
{
764
MultiAccessSizeMem<4, false> mt0;
765
766
mt0.WriteU16(0, 0xDEAD);
767
mt0.WriteU32(0, 0xCAFEBEEF);
768
mt0.WriteU16(2, mt0.ReadU16(0));
769
mt0.WriteU8(1, mt0.ReadU8(0));
770
mt0.WriteU16(2, mt0.ReadU16(0));
771
mt0.WriteU32(0, mt0.ReadU32(0) + 0x13121111);
772
773
assert(mt0.ReadU16(0) == 0x0100 && mt0.ReadU16(2) == 0x0302);
774
assert(mt0.ReadU32(0) == 0x03020100);
775
776
mt0.WriteU32(0, 0xB0B0AA55);
777
mt0.WriteU24(0, 0xDEADBEEF);
778
assert(mt0.ReadU32(0) == 0xB0ADBEEF);
779
assert(mt0.ReadU24(1) == 0x00B0ADBE);
780
}
781
782
// Big endian:
783
{
784
MultiAccessSizeMem<4, true> mt0;
785
786
mt0.WriteU16(2, 0xDEAD);
787
mt0.WriteU32(0, 0xCAFEBEEF);
788
mt0.WriteU16(0, mt0.ReadU16(2));
789
mt0.WriteU8(2, mt0.ReadU8(3));
790
mt0.WriteU16(0, mt0.ReadU16(2));
791
mt0.WriteU32(0, mt0.ReadU32(0) + 0x13121111);
792
793
assert(mt0.ReadU16(2) == 0x0100 && mt0.ReadU16(0) == 0x0302);
794
assert(mt0.ReadU32(0) == 0x03020100);
795
796
mt0.WriteU32(0, 0xB0B0AA55);
797
mt0.WriteU24(1, 0xDEADBEEF);
798
assert(mt0.ReadU32(0) == 0xB0ADBEEF);
799
assert(mt0.ReadU24(0) == 0x00B0ADBE);
800
}
801
802
assert(RunMASMemTests_DoomAndGloom(0) == 1);
803
}
804
805
#ifdef WANT_TEST_EXCEPTION
806
static void NO_INLINE NO_CLONE ExceptionTestSub(int v, int n, int* y)
807
{
808
if(n)
809
{
810
if(n & 1)
811
{
812
try
813
{
814
ExceptionTestSub(v + n, n - 1, y);
815
}
816
catch(const std::exception &e)
817
{
818
(*y)++;
819
throw;
820
}
821
}
822
else
823
ExceptionTestSub(v + n, n - 1, y);
824
}
825
else
826
throw MDFN_Error(v, "%d", v);
827
}
828
829
static void RunExceptionTests(void)
830
{
831
int y = 0;
832
int z = 0;
833
834
for(int x = -8; x < 8; x++)
835
{
836
try
837
{
838
ExceptionTestSub(x, x & 3, &y);
839
}
840
catch(const MDFN_Error &e)
841
{
842
int epv = x;
843
844
for(unsigned i = x & 3; i; i--)
845
epv += i;
846
847
z += epv;
848
849
assert(e.GetErrno() == epv);
850
assert(atoi(e.what()) == epv);
851
continue;
852
}
853
catch(...)
854
{
855
abort();
856
}
857
abort();
858
}
859
860
assert(y == 16);
861
assert(z == 32);
862
}
863
#endif
864
865
std::vector<int> stltests_vec[2];
866
867
static void NO_INLINE NO_CLONE RunSTLTests_Sub0(int v)
868
{
869
stltests_vec[0].assign(v, v);
870
}
871
872
static void RunSTLTests(void)
873
{
874
assert(stltests_vec[0] == stltests_vec[1]);
875
RunSTLTests_Sub0(0);
876
assert(stltests_vec[0] == stltests_vec[1]);
877
RunSTLTests_Sub0(1);
878
RunSTLTests_Sub0(0);
879
assert(stltests_vec[0] == stltests_vec[1]);
880
}
881
882
static void LZCount_Test(void)
883
{
884
for(uint32 i = 0, x = 0; i < 33; i++, x = (x << 1) + 1)
885
{
886
assert(MDFN_lzcount32(x) == 32 - i);
887
}
888
889
for(uint32 i = 0, x = 0; i < 33; i++, x = (x ? (x << 1) : 1))
890
{
891
assert(MDFN_lzcount32(x) == 32 - i);
892
}
893
894
for(uint64 i = 0, x = 0; i < 65; i++, x = (x << 1) + 1)
895
{
896
assert(MDFN_lzcount64(x) == 64 - i);
897
}
898
899
for(uint64 i = 0, x = 0; i < 65; i++, x = (x ? (x << 1) : 1))
900
{
901
assert(MDFN_lzcount64(x) == 64 - i);
902
}
903
904
uint32 tv = 0;
905
for(uint32 i = 0, x = 1; i < 200; i++, x = (x * 9) + MDFN_lzcount32(x) + MDFN_lzcount32(x >> (x & 31)))
906
{
907
tv += x;
908
}
909
assert(tv == 0x397d920f);
910
911
uint64 tv64 = 0;
912
for(uint64 i = 0, x = 1; i < 200; i++, x = (x * 9) + MDFN_lzcount64(x) + MDFN_lzcount64(x >> (x & 63)))
913
{
914
tv64 += x;
915
}
916
assert(tv64 == 0x7b8263de01922c29);
917
}
918
919
920
// don't make this static, and don't make it local scope. Whole-program optimization might defeat the purpose of this, though...
921
unsigned int mdfn_shifty_test[4] =
922
{
923
0, 8, 16, 32
924
};
925
926
927
// Don't make static.
928
double mdfn_fptest0_sub(double x, double n) MDFN_COLD NO_INLINE;
929
double mdfn_fptest0_sub(double x, double n)
930
{
931
double u = x / (n * n);
932
933
return(u);
934
}
935
936
static void fptest0(void)
937
{
938
assert(mdfn_fptest0_sub(36, 2) == 9);
939
}
940
941
volatile double mdfn_fptest1_v;
942
static void fptest1(void)
943
{
944
mdfn_fptest1_v = 1.0;
945
946
for(int i = 0; i < 128; i++)
947
mdfn_fptest1_v *= 2;
948
949
assert(mdfn_fptest1_v == 340282366920938463463374607431768211456.0);
950
}
951
952
#if defined(HAVE_FENV_H) && defined(HAVE_NEARBYINTF)
953
// For advisory/debug purposes, don't error out on failure.
954
static void libc_rounding_test(void)
955
{
956
unsigned old_rm = fegetround();
957
float tv = 4118966.75;
958
float goodres = 4118967.0;
959
float res;
960
961
fesetround(FE_TONEAREST);
962
963
if((res = nearbyintf(tv)) != goodres)
964
fprintf(stderr, "\n***** Buggy libc nearbyintf() detected(%f != %f). *****\n\n", res, goodres);
965
966
fesetround(old_rm);
967
}
968
#else
969
static void libc_rounding_test(void)
970
{
971
972
}
973
#endif
974
975
static int pow_test_sub_a(int y, double z) NO_INLINE NO_CLONE;
976
static int pow_test_sub_a(int y, double z)
977
{
978
return std::min<int>(floor(pow(10, z)), std::min<int>(floor(pow(10, y)), (int)pow(10, y)));
979
}
980
981
static int pow_test_sub_b(int y) NO_INLINE NO_CLONE;
982
static int pow_test_sub_b(int y)
983
{
984
return std::min<int>(floor(pow(2, y)), (int)pow(2, y));
985
}
986
987
static void pow_test(void)
988
{
989
unsigned muller10 = 1;
990
unsigned muller2 = 1;
991
992
for(int y = 0; y < 10; y++, muller10 *= 10, muller2 <<= 1)
993
{
994
unsigned res10 = pow_test_sub_a(y, y);
995
unsigned res2 = pow_test_sub_b(y);
996
997
//printf("%u %u\n", res10, res2);
998
999
assert(res10 == muller10);
1000
assert(res2 == muller2);
1001
}
1002
}
1003
1004
static void RunFPTests(void)
1005
{
1006
fptest0();
1007
fptest1();
1008
1009
libc_rounding_test();
1010
pow_test();
1011
}
1012
1013
#if 0
1014
static void NO_CLONE NO_INLINE ThreadSub(int tv)
1015
{
1016
throw MDFN_Error(tv, "%d\n", tv);
1017
}
1018
1019
1020
static int ThreadTestEntry(void* data)
1021
{
1022
const uint32 st = *(uint32*)data;
1023
1024
while(MDFND_GetTime() < st)
1025
{
1026
try
1027
{
1028
ThreadSub(rand());
1029
}
1030
catch(MDFN_Error &e)
1031
{
1032
assert(e.GetErrno() == atoi(e.what()));
1033
}
1034
}
1035
1036
return 0;
1037
}
1038
1039
1040
static void RunThreadTests(void)
1041
{
1042
MDFN_Thread *a, *b, *c, *d;
1043
uint32 t = MDFND_GetTime() + 5000;
1044
1045
a = MDFND_CreateThread(ThreadTestEntry, &t);
1046
b = MDFND_CreateThread(ThreadTestEntry, &t);
1047
c = MDFND_CreateThread(ThreadTestEntry, &t);
1048
d = MDFND_CreateThread(ThreadTestEntry, &t);
1049
1050
MDFND_WaitThread(a, NULL);
1051
MDFND_WaitThread(b, NULL);
1052
MDFND_WaitThread(c, NULL);
1053
MDFND_WaitThread(d, NULL);
1054
}
1055
#endif
1056
1057
#ifdef WANT_TEST_ZLIB
1058
static void zlib_test(void)
1059
{
1060
auto cfl = zlibCompileFlags();
1061
1062
assert((2 << ((cfl >> 0) & 0x3)) == sizeof(uInt));
1063
assert((2 << ((cfl >> 2) & 0x3)) == sizeof(uLong));
1064
assert((2 << ((cfl >> 4) & 0x3)) == sizeof(voidpf));
1065
1066
#ifdef Z_LARGE64
1067
if((2 << ((cfl >> 6) & 0x3)) != sizeof(z_off_t))
1068
{
1069
assert(sizeof(z_off64_t) == 8);
1070
assert(&gztell == &gztell64);
1071
}
1072
#else
1073
assert((2 << ((cfl >> 6) & 0x3)) == sizeof(z_off_t));
1074
#endif
1075
}
1076
#endif
1077
1078
const char* MDFN_tests_stringA = "AB\0C";
1079
const char* MDFN_tests_stringB = "AB\0CD";
1080
const char* MDFN_tests_stringC = "AB\0X";
1081
1082
}
1083
1084
using namespace MDFN_TESTS_CPP;
1085
1086
bool MDFN_RunMathTests(void)
1087
{
1088
MathTestEntry *itoo = math_test_vals;
1089
1090
if(!DoSizeofTests())
1091
return(0);
1092
1093
assert(MDFN_tests_stringA != MDFN_tests_stringB && MDFN_tests_stringA[3] == 'C' && MDFN_tests_stringB[4] == 'D');
1094
assert(MDFN_tests_stringA != MDFN_tests_stringC && MDFN_tests_stringB != MDFN_tests_stringC && MDFN_tests_stringC[3] == 'X');
1095
1096
// Make sure the "char" type is signed(pass -fsigned-char to gcc). New code in Mednafen shouldn't be written with the
1097
// assumption that "char" is signed, but there likely is at least some code that does.
1098
{
1099
char tmp = 255;
1100
assert(tmp < 0);
1101
}
1102
1103
#if 0
1104
// TODO(except for 32-bit >> 32 test)
1105
{
1106
uint8 test_cow8 = (uint8)0xFF >> mdfn_shifty_test[1];
1107
uint16 test_cow16 = (uint16)0xFFFF >> mdfn_shifty_test[2];
1108
uint32 test_cow32 = (uint32)0xFFFFFFFF >> mdfn_shifty_test[3];
1109
uint32 test_cow32_2 = (uint32)0xFFFFFFFF >> mdfn_shifty_test[0];
1110
1111
printf("%08x\n", test_cow32);
1112
1113
assert(test_cow8 == 0);
1114
assert(test_cow16 == 0);
1115
assert(test_cow32 == 0);
1116
assert(test_cow32_2 == 0xFFFFFFFF);
1117
}
1118
#endif
1119
1120
{
1121
int32 meow;
1122
1123
meow = 1;
1124
meow >>= 1;
1125
assert(meow == 0);
1126
1127
meow = 5;
1128
meow >>= 1;
1129
assert(meow == 2);
1130
1131
meow = -1;
1132
meow >>= 1;
1133
assert(meow == -1);
1134
1135
meow = -5;
1136
meow >>= 1;
1137
assert(meow == -3);
1138
1139
meow = 1;
1140
meow /= 2;
1141
assert(meow == 0);
1142
1143
meow = 5;
1144
meow /= 2;
1145
assert(meow == 2);
1146
1147
meow = -1;
1148
meow /= 2;
1149
assert(meow == 0);
1150
1151
meow = -5;
1152
meow /= 2;
1153
assert(meow == -2);
1154
1155
meow = -5;
1156
meow = (int32)(meow + ((uint32)meow >> 31)) >> 1;
1157
assert(meow == -2);
1158
1159
#if 0
1160
meow = 1 << 30;
1161
meow <<= 1;
1162
assert(meow == -2147483648);
1163
1164
meow = 1 << 31;
1165
meow <<= 1;
1166
assert(meow == 0);
1167
#endif
1168
}
1169
1170
1171
// New tests added May 22, 2010 to detect MSVC compiler(and possibly other compilers) bad code generation.
1172
{
1173
uint32 test_tab[4] = { 0x2000 | 0x1000, 0x2000, 0x1000, 0x0000 };
1174
const uint32 result_tab[4][2] = { { 0xE, 0x7 }, { 0xE, 0x0 }, { 0x0, 0x7 }, { 0x0, 0x0 } };
1175
1176
for(int i = 0; i < 4; i++)
1177
{
1178
uint32 hflip_xor;
1179
uint32 vflip_xor;
1180
uint32 bgsc;
1181
1182
bgsc = test_tab[i];
1183
1184
hflip_xor = ((int32)(bgsc << 18) >> 30) & 0xE;
1185
vflip_xor = ((int32)(bgsc << 19) >> 31) & 0x7;
1186
1187
assert(hflip_xor == result_tab[i][0]);
1188
assert(vflip_xor == result_tab[i][1]);
1189
1190
//printf("%d %d\n", hflip_xor, result_tab[i][0]);
1191
//printf("%d %d\n", vflip_xor, result_tab[i][1]);
1192
}
1193
1194
uint32 lfsr = 1;
1195
1196
// quick and dirty RNG(to also test non-constant-expression evaluation, at least until compilers are extremely advanced :b)
1197
for(int i = 0; i < 256; i++)
1198
{
1199
int feedback = ((lfsr >> 7) & 1) ^ ((lfsr >> 14) & 1);
1200
lfsr = ((lfsr << 1) & 0x7FFF) | feedback;
1201
1202
uint32 hflip_xor;
1203
uint32 vflip_xor;
1204
uint32 hflip_xor_alt;
1205
uint32 vflip_xor_alt;
1206
uint32 bgsc;
1207
1208
bgsc = lfsr;
1209
1210
hflip_xor = ((int32)(bgsc << 18) >> 30) & 0xE;
1211
vflip_xor = ((int32)(bgsc << 19) >> 31) & 0x7;
1212
1213
hflip_xor_alt = bgsc & 0x2000 ? 0xE : 0;
1214
vflip_xor_alt = bgsc & 0x1000 ? 0x7 : 0;
1215
1216
assert(hflip_xor == hflip_xor_alt);
1217
assert(vflip_xor == vflip_xor_alt);
1218
}
1219
1220
}
1221
1222
DoAlignmentChecks();
1223
TestSignedOverflow();
1224
TestDefinedOverShift();
1225
TestBoolConv();
1226
TestNarrowConstFold();
1227
1228
TestGCC60196();
1229
1230
TestModTern();
1231
TestBWNotMask31GTZ();
1232
TestTernary();
1233
TestLLVM15470();
1234
1235
TestSUCompare();
1236
1237
if(sign_9_to_s16(itoo->negative_one) != -1 || sign_9_to_s16(itoo->mostneg) != itoo->mostnegresult)
1238
FATALME;
1239
itoo++;
1240
1241
if(sign_10_to_s16(itoo->negative_one) != -1 || sign_10_to_s16(itoo->mostneg) != itoo->mostnegresult)
1242
FATALME;
1243
itoo++;
1244
1245
if(sign_11_to_s16(itoo->negative_one) != -1 || sign_11_to_s16(itoo->mostneg) != itoo->mostnegresult)
1246
FATALME;
1247
itoo++;
1248
1249
if(sign_12_to_s16(itoo->negative_one) != -1 || sign_12_to_s16(itoo->mostneg) != itoo->mostnegresult)
1250
FATALME;
1251
itoo++;
1252
1253
if(sign_13_to_s16(itoo->negative_one) != -1 || sign_13_to_s16(itoo->mostneg) != itoo->mostnegresult)
1254
FATALME;
1255
itoo++;
1256
1257
if(sign_14_to_s16(itoo->negative_one) != -1 || sign_14_to_s16(itoo->mostneg) != itoo->mostnegresult)
1258
FATALME;
1259
itoo++;
1260
1261
if(sign_15_to_s16(itoo->negative_one) != -1 || sign_15_to_s16(itoo->mostneg) != itoo->mostnegresult)
1262
FATALME;
1263
itoo++;
1264
1265
if(sign_x_to_s32(17, itoo->negative_one) != -1 || sign_x_to_s32(17, itoo->mostneg) != itoo->mostnegresult)
1266
FATALME;
1267
itoo++;
1268
1269
if(sign_x_to_s32(18, itoo->negative_one) != -1 || sign_x_to_s32(18, itoo->mostneg) != itoo->mostnegresult)
1270
FATALME;
1271
itoo++;
1272
1273
if(sign_x_to_s32(19, itoo->negative_one) != -1 || sign_x_to_s32(19, itoo->mostneg) != itoo->mostnegresult)
1274
FATALME;
1275
itoo++;
1276
1277
if(sign_x_to_s32(20, itoo->negative_one) != -1 || sign_x_to_s32(20, itoo->mostneg) != itoo->mostnegresult)
1278
FATALME;
1279
itoo++;
1280
1281
if(sign_x_to_s32(21, itoo->negative_one) != -1 || sign_x_to_s32(21, itoo->mostneg) != itoo->mostnegresult)
1282
FATALME;
1283
itoo++;
1284
1285
if(sign_x_to_s32(22, itoo->negative_one) != -1 || sign_x_to_s32(22, itoo->mostneg) != itoo->mostnegresult)
1286
FATALME;
1287
itoo++;
1288
1289
if(sign_x_to_s32(23, itoo->negative_one) != -1 || sign_x_to_s32(23, itoo->mostneg) != itoo->mostnegresult)
1290
FATALME;
1291
itoo++;
1292
1293
if(sign_x_to_s32(24, itoo->negative_one) != -1 || sign_x_to_s32(24, itoo->mostneg) != itoo->mostnegresult)
1294
FATALME;
1295
itoo++;
1296
1297
if(sign_x_to_s32(25, itoo->negative_one) != -1 || sign_x_to_s32(25, itoo->mostneg) != itoo->mostnegresult)
1298
FATALME;
1299
itoo++;
1300
1301
if(sign_x_to_s32(26, itoo->negative_one) != -1 || sign_x_to_s32(26, itoo->mostneg) != itoo->mostnegresult)
1302
FATALME;
1303
itoo++;
1304
1305
if(sign_x_to_s32(27, itoo->negative_one) != -1 || sign_x_to_s32(27, itoo->mostneg) != itoo->mostnegresult)
1306
FATALME;
1307
itoo++;
1308
1309
if(sign_x_to_s32(28, itoo->negative_one) != -1 || sign_x_to_s32(28, itoo->mostneg) != itoo->mostnegresult)
1310
FATALME;
1311
itoo++;
1312
1313
if(sign_x_to_s32(29, itoo->negative_one) != -1 || sign_x_to_s32(29, itoo->mostneg) != itoo->mostnegresult)
1314
FATALME;
1315
itoo++;
1316
1317
if(sign_x_to_s32(30, itoo->negative_one) != -1 || sign_x_to_s32(30, itoo->mostneg) != itoo->mostnegresult)
1318
FATALME;
1319
itoo++;
1320
1321
if(sign_x_to_s32(31, itoo->negative_one) != -1 || sign_x_to_s32(31, itoo->mostneg) != itoo->mostnegresult)
1322
FATALME;
1323
itoo++;
1324
1325
if(sizeof(int8) != 1 || sizeof(uint8) != 1)
1326
FATALME;
1327
1328
1329
if(!DoAntiNSOBugTest())
1330
return(0);
1331
1332
DoAntiNSOBugTest2014();
1333
1334
#ifdef WANT_TEST_LEPACKER
1335
if(!DoLEPackerTest())
1336
return(0);
1337
#endif
1338
1339
assert(uilog2(0) == 0);
1340
assert(uilog2(1) == 0);
1341
assert(uilog2(3) == 1);
1342
assert(uilog2(4095) == 11);
1343
assert(uilog2(0xFFFFFFFF) == 31);
1344
1345
RunFPTests();
1346
1347
RunMASMemTests();
1348
1349
#ifdef WANT_TEST_EXCEPTION
1350
RunExceptionTests();
1351
#endif
1352
1353
//RunThreadTests();
1354
1355
RunSTLTests();
1356
1357
LZCount_Test();
1358
1359
#ifdef WANT_TEST_HASHES
1360
sha1_test();
1361
sha256_test();
1362
#endif
1363
1364
#ifdef WANT_TEST_ZLIB
1365
zlib_test();
1366
#endif
1367
1368
#if 0
1369
// Not really a math test.
1370
const char *test_paths[] = { "/meow", "/meow/cow", "\\meow", "\\meow\\cow", "\\\\meow", "\\\\meow\\cow",
1371
"/meow.", "/me.ow/cow.", "\\meow.", "\\me.ow\\cow.", "\\\\meow.", "\\\\meow\\cow.",
1372
"/meow.txt", "/me.ow/cow.txt", "\\meow.txt", "\\me.ow\\cow.txt", "\\\\meow.txt", "\\\\meow\\cow.txt"
1373
1374
"/meow", "/meow\\cow", "\\meow", "\\meow/cow", "\\\\meow", "\\\\meow/cow",
1375
"/meow.", "\\me.ow/cow.", "\\meow.", "/me.ow\\cow.", "\\\\meow.", "\\\\meow/cow.",
1376
"/meow.txt", "/me.ow\\cow.txt", "\\meow.txt", "\\me.ow/cow.txt", "\\\\meow.txt", "\\\\meow/cow.txt",
1377
"/bark///dog", "\\bark\\\\\\dog" };
1378
1379
for(unsigned i = 0; i < sizeof(test_paths) / sizeof(const char *); i++)
1380
{
1381
std::string file_path = std::string(test_paths[i]);
1382
std::string dir_path;
1383
std::string file_base;
1384
std::string file_ext;
1385
1386
MDFN_GetFilePathComponents(file_path, &dir_path, &file_base, &file_ext);
1387
1388
printf("%s ------ dir=%s --- base=%s --- ext=%s\n", file_path.c_str(), dir_path.c_str(), file_base.c_str(), file_ext.c_str());
1389
1390
}
1391
#endif
1392
1393
1394
return(1);
1395
}
1396
1397