1 /*---------------------------------------------------------------------------*
2 Project: TwlSDK - include - utest
3 File: utest.h
4
5 Copyright 2005-2008 Nintendo. All rights reserved.
6
7 These coded instructions, statements, and computer programs contain
8 proprietary information of Nintendo of America Inc. and/or Nintendo
9 Company Ltd., and are protected by Federal copyright law. They may
10 not be disclosed to third parties or copied or duplicated in any form,
11 in whole or in part, without the prior written consent of Nintendo.
12
13 $Date:: 2008-09-18#$
14 $Rev: 8573 $
15 $Author: okubata_ryoma $
16 *---------------------------------------------------------------------------*/
17 #ifndef NITRO_UTEST_H__
18 #define NITRO_UTEST_H__
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22
23 //---------------------------------------------------------------------------
24 // Library for unit function test
25 //
26 // CAUTION
27 // This library is an alpha version for internal testing. The specifications are currently in review.
28 // Accordingly, the interface could change, and this feature itself could be deleted. Also, the library has not been fully confirmed to operate in all environments.
29 //
30 //
31 //
32 // Related files
33 // $NitroSDK/tools/bin/make_utest_main__
34 // $NitroSDK/build/tools/nitload-gcc
35 //---------------------------------------------------------------------------
36 #ifdef SDK_ARM9
37
38 #include <nitro/os/common/system.h>
39 #include <nitro/os/common/context.h>
40
41 //---------------------------------------------------------------------------
42 // Test module structure
43 //
44 typedef void (*UTiCallback) (void);
45
46 typedef struct UTiModule_
47 {
48 char *filename;
49 char *testname;
50 UTiCallback callback;
51 UTiCallback callback_begin;
52 UTiCallback callback_end;
53 }
54 UTiModule;
55
56 //---------------------------------------------------------------------------
57 // Test result values
58 //
59 typedef enum UTiResult_
60 {
61 UT_RESULT_OK = 1,
62 UT_RESULT_NG = 0,
63 UT_RESULT_UNTESTED = -1
64 }
65 UTiResult;
66
67 extern UTiResult UTi_Result;
68
UTi_SetResult(UTiResult r)69 static inline void UTi_SetResult(UTiResult r)
70 {
71 UTi_Result = r;
72 }
UTi_GetResult(void)73 static inline UTiResult UTi_GetResult(void)
74 {
75 return UTi_Result;
76 }
77
78 //---------------------------------------------------------------------------
79 void UTi_Main(int, UTiModule *);
80 void UTi_Printf(const char *, ...);
81 void UTi_PrintfWithFloat(const char *, ...);
82 void UTi_PutString(const char *str);
83 void UTi_ClearMessage(void);
84 char *UTi_GetMessage(void);
85 void UTi_SetMessage(const char *, int, const char *, ...);
86 void UTi_SetMessageWithFloat(const char *, int, const char *, ...);
87
88 //---------------------------------------------------------------------------
89 #define UT_ASSERTMESSAGE_MAXLEN 1024
90
91 void UTi_Assert(const char *, int, const char *, int);
92 void UTi_AssertEq(const char *, int, const char *, int, const char *, int);
93 void UTi_AssertNe(const char *, int, const char *, int, const char *, int);
94
95 #define UT_Assert(ex) UTi_Assert( __FILE__, __LINE__, #ex, (int)(ex))
96 #define UT_AssertEq(ex1,ex2) UTi_AssertEq(__FILE__, __LINE__, #ex1, (int)(ex1), #ex2, (int)(ex2))
97 #define UT_AssertNe(ex1,ex2) UTi_AssertNe(__FILE__, __LINE__, #ex1, (int)(ex1), #ex2, (int)(ex2))
98
99 void UTi_AssertMemEq(const char *file, int line,
100 const char *exp_str1, const void *exp_ptr1,
101 const char *exp_str2, const void *exp_ptr2, int exp_len);
102 void UTi_AssertMemNe(const char *file, int line,
103 const char *exp_str1, const void *exp_ptr1,
104 const char *exp_str2, const void *exp_ptr2, int exp_len);
105
106 #define UT_AssertMemPtrEq(ex1,ex2,len) \
107 UTi_AssertMemEq(__FILE__, __LINE__, #ex1, (const void*)(ex1), #ex2, (const void*)(ex2), (int)(len))
108 #define UT_AssertMemPtrNe(ex1,ex2,len) \
109 UTi_AssertMemNe(__FILE__, __LINE__, #ex1, (const void*)(ex1), #ex2, (const void*)(ex2), (int)(len))
110 #define UT_AssertMemEq(ex1,ex2) \
111 UTi_AssertMemEq(__FILE__, __LINE__, #ex1, (const void*)&(ex1), #ex2, (const void*)&(ex2), sizeof(ex1))
112 #define UT_AssertMemNe(ex1,ex2) \
113 UTi_AssertMemNe(__FILE__, __LINE__, #ex1, (const void*)&(ex1), #ex2, (const void*)&(ex2), sizeof(ex1))
114
115 void UTi_AssertAsserted(const char *, int, const char *, int);
116 void UTi_AssertNotAsserted(const char *, int, const char *, int);
117
118 int UTi_MemCmp(const void *ptr1, const void *ptr2, int len);
119
120 //---------------------------------------------------------------------------
121 // Context for LONG JUMP / LONG JUMP during ASSERT
122 //
123 #ifdef SDK_DEBUG
124 extern OSContext UTi_AssertContext;
125 extern void (*OSi_FuncTerminate) (void);
126 void UTi_Terminate(void);
127
128 #define UT_AssertAsserted(ex) \
129 { \
130 int __n; \
131 OSi_FuncTerminate = UTi_Terminate; \
132 __n = OS_SaveContext( &UTi_AssertContext ); \
133 if (!__n) (void)(ex); \
134 UTi_AssertAsserted(__FILE__, __LINE__, #ex, __n ); \
135 OSi_FuncTerminate = OS_Terminate; \
136 }
137 #define UT_AssertNotAsserted(ex) \
138 { \
139 int __n; \
140 OSi_FuncTerminate = UTi_Terminate; \
141 __n = OS_SaveContext( &UTi_AssertContext ); \
142 if (!__n) (void)(ex); \
143 UTi_AssertNotAsserted(__FILE__, __LINE__, #ex, __n ); \
144 OSi_FuncTerminate = OS_Terminate; \
145 }
146 #else
147 #define UT_AssertAsserted(ex) ((void)0)
148 #define UT_AssertNotAsserted(ex) ((void)0)
149 #endif
150
151 //---------------------------------------------------------------------------
152 //---------------------------------------------------------------------------
153 #else //SDK_ARM7
154
155 // UnitTest is NOT supported on ARM7 devenv.
156 #define UT_Assert(ex) ((void)0)
157 #define UT_AssertEq(ex1,ex2) ((void)0)
158 #define UT_AssertNe(ex1,ex2) ((void)0)
159 #define UT_AssertMemPtrEq(ex1,ex2,len) ((void)0)
160 #define UT_AssertMemPtrNe(ex1,ex2,len) ((void)0)
161 #define UT_AssertMemEq(ex1,ex2) ((void)0)
162 #define UT_AssertMemNe(ex1,ex2) ((void)0)
163 #define UT_AssertAsserted(ex) ((void)0)
164 #define UT_AssertNotAsserted(ex) ((void)0)
165
166 #endif //SDK_ARM9/SDK_ARM7
167 //---------------------------------------------------------------------------
168 //---------------------------------------------------------------------------
169
170 #ifdef __cplusplus
171 } /* extern "C" */
172 #endif
173 #endif //NITRO_UTEST_H__
174