77#include <ctr/math.h>
88#include <ctr/rng.h>
99#include <ctr/coll.h>
10+ #include <ctr/list.h>
11+ #include <ctr/jitpool.h>
12+ #include <ctr/test_backup.h>
1013
1114extern const char * s_nameTestedFunc ;
1215
1316void TEST_WRAPPER ();
14- void LoadTestPatches ();
17+ void TEST_LoadPatches ();
18+ void TEST_Init ();
19+ bool TEST_Memcmp (const void * expected , const void * actual , u32 n );
1520u32 PatchFunction_Beg (u32 * index , const char * funcName );
1621void PatchFunction_End (u32 index );
17- u32 PrintSVectorDiff (const SVec3 * expected , const SVec3 * ret );
18- u32 PrintMatrixDiff (const Matrix * expected , const Matrix * ret , u32 cmpTrans );
22+ u32 TEST_PrintSVectorDiff (const SVec3 * expected , const SVec3 * ret );
23+ u32 TEST_PrintMatrixDiff (const Matrix * expected , const Matrix * ret , u32 cmpTrans );
1924
2025force_inline void FlushCache ()
2126{
@@ -24,11 +29,31 @@ force_inline void FlushCache()
2429 ((void (* )())0xa0 )();
2530}
2631
27- #define BACKUP_ADDR 0x80400000
32+ #define TEST
2833
34+ #if defined(TEST )
35+ #define DYNAMIC_ASSERT (expected , actual , msg ) \
36+ do { \
37+ if ((expected) != (actual)) { \
38+ printf("DYNAMIC_ASSERT FAILED (expected %d, got %d): %s\n", (u32)(expected), (u32)(actual), msg); \
39+ } \
40+ } while (0)
41+ #else
42+ #define DYNAMIC_ASSERT (expected , actual , msg )
43+ #endif
44+
45+ #if defined(TEST )
46+ #define STATIC_ASSERT (cond , msg ) _Static_assert(cond, msg)
47+ #else
48+ #define STATIC_ASSERT (cond , msg )
49+ #endif
50+
51+ #if defined(TEST )
2952#define TEST_MATH_IMPL
3053#define TEST_RNG_IMPL
3154#define TEST_COLL_IMPL
55+ #define TEST_LIST_IMPL
56+ #endif
3257
3358#ifdef TEST_MATH_IMPL
3459 void TEST_MATH_Sin (u32 angle , s32 ret );
@@ -51,16 +76,30 @@ force_inline void FlushCache()
5176#endif
5277
5378#ifdef TEST_RNG_IMPL
79+ typedef struct BDATA_RNG_Rand
80+ {
81+ u32 e_seed ; //backup of 0x8008d424
82+ } BDATA_RNG_Rand ;
5483 void BACKUP_RNG_Rand ();
84+ void RESTORE_RNG_Rand (BDATA_RNG_Rand * restore );
5585 void TEST_RNG_Rand ();
86+
87+ typedef struct BDATA_RNG_RandInt
88+ {
89+ RNGSeed e_gameTracker_seed ; //backup of e_gameTracker->seed
90+ } BDATA_RNG_RandInt ;
5691 void BACKUP_RNG_RandInt ();
92+ void RESTORE_RNG_RandInt (BDATA_RNG_RandInt * restore );
5793 void TEST_RNG_RandInt (u32 n , s32 ret );
94+
5895 void TEST_RNG_PseudoRand (u16 n , u16 ret );
5996 void TEST_RNG_Random (RNGSeed * seed , const RNGSeed * ret );
6097#else
6198 #define BACKUP_RNG_Rand ()
99+ #define RESTORE_RNG_Rand (restore )
62100 #define TEST_RNG_Rand ()
63101 #define BACKUP_RNG_RandInt ()
102+ #define RESTORE_RNG_RandInt (restore )
64103 #define TEST_RNG_RandInt (n , ret )
65104 #define TEST_RNG_PseudoRand (n , ret )
66105 #define TEST_RNG_Random (seed , ret )
@@ -70,11 +109,40 @@ force_inline void FlushCache()
70109 void TEST_COLL_ProjectPointToEdge (const SVec3 * v1 , const SVec3 * v2 , const SVec3 * point , const SVec3 * ret );
71110 void TEST_COLL_CalculateTrianglePlane (const CollDCache * cache , CollVertex * v1 , const CollVertex * v2 , const CollVertex * v3 , const CollVertex * ret );
72111 void TEST_COLL_LoadVerticeData (CollDCache * cache );
73- void TEST_COLL_LoadQuadblockData_LowLOD (CollDCache * cache , const Quadblock * quadblock , const CollDCache * ret );
74- void TEST_COLL_LoadQuadblockData_HighLOD (CollDCache * cache , const Quadblock * quadblock , const CollDCache * ret );
112+
113+ typedef struct BDATA_COLL_LoadQuadblockData_LowLOD
114+ {
115+ CollDCache cache ; //backup of *cache
116+ } BDATA_COLL_LoadQuadblockData_LowLOD ;
117+ void BACKUP_COLL_LoadQuadblockData_LowLOD (CollDCache * cache );
118+ void RESTORE_COLL_LoadQuadblockData_LowLOD (BDATA_COLL_LoadQuadblockData_LowLOD * restore , CollDCache * cache );
119+ void TEST_COLL_LoadQuadblockData_LowLOD (const Quadblock * quadblock , CollDCache * cache );
120+
121+ typedef struct BDATA_COLL_LoadQuadblockData_HighLOD
122+ {
123+ CollDCache cache ; //backup of *cache
124+ } BDATA_COLL_LoadQuadblockData_HighLOD ;
125+ void BACKUP_COLL_LoadQuadblockData_HighLOD (CollDCache * cache );
126+ void RESTORE_COLL_LoadQuadblockData_HighLOD (BDATA_COLL_LoadQuadblockData_HighLOD * restore , CollDCache * cache );
127+ void TEST_COLL_LoadQuadblockData_HighLOD (const Quadblock * quadblock , CollDCache * cache );
128+
75129 void TEST_COLL_BarycentricTest (TestVertex * t , const CollVertex * v1 , const CollVertex * v2 , const CollVertex * v3 , const SVec3 * pos , s32 ret );
76- void TEST_COLL_TestTriangle (CollDCache * cache , const CollVertex * v1 , const CollVertex * v2 , const CollVertex * v3 , const CollDCache * ret );
77- void TEST_COLL_TestLeaf_Quadblock (const Quadblock * quadblock , CollDCache * cache , const CollDCache * ret );
130+
131+ typedef struct BDATA_COLL_TestTriangle
132+ {
133+ CollDCache cache ; //backup of *cache
134+ } BDATA_COLL_TestTriangle ;
135+ void BACKUP_COLL_TestTriangle (CollDCache * cache );
136+ void RESTORE_COLL_TestTriangle (BDATA_COLL_TestTriangle * restore , CollDCache * cache );
137+ void TEST_COLL_TestTriangle (const CollVertex * v1 , const CollVertex * v2 , const CollVertex * v3 , CollDCache * cache );
138+
139+ typedef struct BDATA_COLL_TestLeaf_Quadblock
140+ {
141+ CollDCache cache ; //backup of *cache
142+ } BDATA_COLL_TestLeaf_Quadblock ;
143+ void BACKUP_COLL_TestLeaf_Quadblock (CollDCache * cache );
144+ void RESTORE_COLL_TestLeaf_Quadblock (BDATA_COLL_TestLeaf_Quadblock * restore , CollDCache * cache );
145+ void TEST_COLL_TestLeaf_Quadblock (const Quadblock * quadblock , CollDCache * cache );
78146#else
79147 #define TEST_COLL_ProjectPointToEdge (out , v1 , v2 , point )
80148 #define TEST_COLL_CalculateTrianglePlane (cache , v1 , v2 , v3 , ret )
@@ -84,4 +152,10 @@ force_inline void FlushCache()
84152 #define TEST_COLL_BarycentricTest (t , v1 , v2 , v3 , pos , ret )
85153 #define TEST_COLL_TestTriangle (cache , v1 , v2 , v3 , ret )
86154 #define TEST_COLL_TestLeaf_Quadblock (quadblock , cache , ret )
155+ #endif
156+
157+ #ifdef TEST_LIST_IMPL
158+
159+ #else
160+
87161#endif
0 commit comments