|
0
|
1 #ifndef CYGONCE_INFRA_TESTCASE_H |
|
|
2 #define CYGONCE_INFRA_TESTCASE_H |
|
|
3 //========================================================================== |
|
|
4 // |
|
|
5 // testcase.h |
|
|
6 // |
|
|
7 // Target side interface for tests |
|
|
8 // |
|
|
9 //========================================================================== |
|
|
10 //####COPYRIGHTBEGIN#### |
|
|
11 // |
|
|
12 // ------------------------------------------- |
|
|
13 // The contents of this file are subject to the Cygnus eCos Public License |
|
|
14 // Version 1.0 (the "License"); you may not use this file except in |
|
|
15 // compliance with the License. You may obtain a copy of the License at |
|
|
16 // http://sourceware.cygnus.com/ecos |
|
|
17 // |
|
|
18 // Software distributed under the License is distributed on an "AS IS" |
|
|
19 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the |
|
|
20 // License for the specific language governing rights and limitations under |
|
|
21 // the License. |
|
|
22 // |
|
|
23 // The Original Code is eCos - Embedded Cygnus Operating System, released |
|
|
24 // September 30, 1998. |
|
|
25 // |
|
|
26 // The Initial Developer of the Original Code is Cygnus. Portions created |
|
2
|
27 // by Cygnus are Copyright (C) 1998,1999 Cygnus Solutions. All Rights Reserved. |
|
0
|
28 // ------------------------------------------- |
|
|
29 // |
|
|
30 //####COPYRIGHTEND#### |
|
|
31 //========================================================================== |
|
|
32 //#####DESCRIPTIONBEGIN#### |
|
|
33 // |
|
2
|
34 // Author(s): ctarpy |
|
|
35 // Contributors: ctarpy, jlarmour |
|
|
36 // Date: 1999-02-16 |
|
0
|
37 // |
|
|
38 // |
|
|
39 //####DESCRIPTIONEND#### |
|
|
40 |
|
|
41 #include <cyg/infra/cyg_type.h> // Common type definitions and support |
|
|
42 |
|
|
43 |
|
2
|
44 // CONSTANTS |
|
|
45 |
|
|
46 // Status codes |
|
|
47 |
|
|
48 typedef enum { |
|
|
49 CYGNUM_TEST_FAIL, |
|
|
50 CYGNUM_TEST_PASS, |
|
|
51 CYGNUM_TEST_EXIT, |
|
|
52 CYGNUM_TEST_INFO, |
|
|
53 CYGNUM_TEST_GDBCMD, |
|
|
54 CYGNUM_TEST_NA |
|
|
55 } Cyg_test_code; |
|
|
56 |
|
|
57 // FUNCTION PROTOTYPES |
|
|
58 |
|
0
|
59 externC void |
|
2
|
60 cyg_test_output(Cyg_test_code _status_, const char* _msg_, int _line_number_, |
|
|
61 const char* _file_); |
|
0
|
62 |
|
|
63 // This should be called at the start of each test file |
|
|
64 externC void |
|
|
65 cyg_test_init(void); |
|
|
66 |
|
|
67 // This causes the test to exit |
|
|
68 externC void |
|
2
|
69 cyg_test_exit(void) CYGBLD_ATTRIB_NORET; |
|
|
70 |
|
|
71 // GLOBALS |
|
0
|
72 |
|
2
|
73 externC int cyg_test_is_simulator; // infrastructure changes as necessary |
|
|
74 |
|
|
75 // MACROS |
|
0
|
76 |
|
|
77 // ----------- Info ----------- |
|
|
78 // |
|
|
79 // Any macro with EXIT in it should only be used in a panic situation. It |
|
|
80 // is synonymous with assert. If the test behaves as expected, it |
|
|
81 // should call one of the FINISH macros. |
|
|
82 // |
|
|
83 // - Compound testcases |
|
|
84 // If a testcase is capable of being part of a compound, then the following |
|
|
85 // rules apply: |
|
|
86 // - The testcase must only ever call one of the EXIT macros if it decides |
|
|
87 // the state of the system is such that further testing is meaningless; |
|
|
88 // such a call would prevent subsequent tests in the compound from being |
|
|
89 // run. |
|
|
90 // - In order to terminate the test, the testcase should call one of the |
|
|
91 // FINISH macros. This must be done from within main(). |
|
|
92 |
|
|
93 |
|
|
94 |
|
|
95 |
|
|
96 // The following is the testcase API to be used by testcases. |
|
|
97 |
|
|
98 #define CYG_TEST_INIT() cyg_test_init() |
|
|
99 |
|
|
100 #define CYG_TEST_INFO( _msg_ ) \ |
|
2
|
101 cyg_test_output(CYGNUM_TEST_INFO, _msg_, __LINE__, __FILE__) |
|
0
|
102 |
|
|
103 #define CYG_TEST_PASS( _msg_ ) \ |
|
2
|
104 cyg_test_output(CYGNUM_TEST_PASS, _msg_, __LINE__, __FILE__) |
|
0
|
105 |
|
|
106 #define CYG_TEST_FAIL( _msg_ ) \ |
|
2
|
107 cyg_test_output(CYGNUM_TEST_FAIL, _msg_, __LINE__, __FILE__) |
|
0
|
108 |
|
|
109 #define CYG_TEST_EXIT( _msg_ ) \ |
|
2
|
110 (cyg_test_output(CYGNUM_TEST_EXIT, _msg_, __LINE__, __FILE__), \ |
|
0
|
111 cyg_test_exit()) |
|
|
112 |
|
2
|
113 // Use the following macro to instruct GDB to run a command when using |
|
|
114 // the automatic testing infrastructure. This must be used *before* |
|
|
115 // CYG_TEST_INIT() is called |
|
|
116 |
|
|
117 #define CYG_TEST_GDBCMD( _command_ ) \ |
|
|
118 CYG_MACRO_START \ |
|
|
119 cyg_test_output(CYGNUM_TEST_GDBCMD, _command_, __LINE__, __FILE__); \ |
|
|
120 CYG_MACRO_END |
|
|
121 |
|
|
122 // Use the following macro to declare that a test is not applicable for |
|
|
123 // some reason - perhaps not appropriate due to chosen hardware, |
|
|
124 // configuration options governing the presence of a tested feature, or |
|
|
125 // even configuration options governing the presence of a feature the |
|
|
126 // test relies on _in_order_ to test the feature (despite being |
|
|
127 // unrelated!) |
|
|
128 |
|
|
129 #define CYG_TEST_NA( _msg_ ) \ |
|
|
130 CYG_MACRO_START \ |
|
|
131 cyg_test_output(CYGNUM_TEST_NA, _msg_, __LINE__, __FILE__); \ |
|
|
132 cyg_test_exit(); \ |
|
|
133 CYG_MACRO_END |
|
|
134 |
|
0
|
135 #ifdef CYG_COMPOUND_TEST |
|
2
|
136 # define CYG_TEST_FINISH( _msg_ ) \ |
|
|
137 CYG_MACRO_START \ |
|
|
138 cyg_test_output(CYGNUM_TEST_EXIT, _msg_, __LINE__, __FILE__); \ |
|
|
139 return 0; \ |
|
|
140 CYG_MACRO_END |
|
0
|
141 #else |
|
2
|
142 # define CYG_TEST_FINISH( _msg_ ) CYG_TEST_EXIT( _msg_ ) |
|
0
|
143 #endif |
|
|
144 |
|
|
145 #define CYG_TEST_STILL_ALIVE( _ctr_ , _msg_ ) CYG_TEST_INFO( _msg_ ) |
|
|
146 |
|
|
147 |
|
|
148 // ----- The following are convenience functions |
|
|
149 |
|
|
150 #define CYG_TEST_PASS_FINISH( _msg_ ) \ |
|
2
|
151 CYG_MACRO_START \ |
|
|
152 CYG_TEST_PASS( _msg_ ); \ |
|
|
153 CYG_TEST_FINISH("done"); \ |
|
|
154 CYG_MACRO_END |
|
0
|
155 |
|
|
156 #define CYG_TEST_FAIL_FINISH( _msg_ ) \ |
|
2
|
157 CYG_MACRO_START \ |
|
|
158 CYG_TEST_FAIL( _msg_ ); \ |
|
|
159 CYG_TEST_FINISH("done"); \ |
|
|
160 CYG_MACRO_END |
|
0
|
161 |
|
|
162 |
|
2
|
163 #define CYG_TEST_CHECK( _chk_ , _msg_) \ |
|
|
164 CYG_MACRO_START \ |
|
|
165 (void)(( _chk_ ) || ( CYG_TEST_FAIL( _msg_ ) , cyg_test_exit(), 1)); \ |
|
|
166 CYG_MACRO_END |
|
0
|
167 |
|
2
|
168 #define CYG_TEST_PASS_FAIL( _cdn_, _msg_ ) \ |
|
|
169 CYG_MACRO_START \ |
|
|
170 if ( _cdn_ ) CYG_TEST_PASS( _msg_ ); else CYG_TEST_FAIL( _msg_ ); \ |
|
|
171 CYG_MACRO_END |
|
0
|
172 |
|
|
173 |
|
|
174 // CYG_TEST_PASS_EXIT and CYG_TEST_FAIL_EXIT are now obscelete, |
|
|
175 // but are here for now |
|
|
176 // to avoid breaking testcases which still use them. They will |
|
|
177 // soon go away. |
|
2
|
178 #define CYG_TEST_PASS_EXIT( _msg_ ) \ |
|
|
179 (cyg_test_output(CYGNUM_TEST_PASS, _msg_, __LINE__, __FILE__), \ |
|
0
|
180 CYG_TEST_EXIT("done")) |
|
|
181 |
|
2
|
182 #define CYG_TEST_FAIL_EXIT( _msg_ ) \ |
|
|
183 (cyg_test_output(CYGNUM_TEST_FAIL, _msg_, __LINE__, __FILE__), \ |
|
0
|
184 CYG_TEST_EXIT("done")) |
|
|
185 |
|
|
186 |
|
|
187 #endif // CYGONCE_INFRA_TESTCASE_H |
|
|
188 // EOF testcase.h |