|
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 |
|
|
27 // by Cygnus are Copyright (C) 1998 Cygnus Solutions. All Rights Reserved. |
|
|
28 // ------------------------------------------- |
|
|
29 // |
|
|
30 //####COPYRIGHTEND#### |
|
|
31 //========================================================================== |
|
|
32 //#####DESCRIPTIONBEGIN#### |
|
|
33 // |
|
|
34 // Author(s): ctarpy |
|
|
35 // Contributors: ctarpy |
|
|
36 // Date: 1998/16/3 |
|
|
37 // |
|
|
38 // |
|
|
39 //####DESCRIPTIONEND#### |
|
|
40 |
|
|
41 #include <cyg/infra/cyg_type.h> // Common type definitions and support |
|
|
42 |
|
|
43 |
|
|
44 // The values of status have the following meaning: |
|
|
45 // 0 fail |
|
|
46 // 1 pass |
|
|
47 // 2 exit |
|
|
48 // 3 info |
|
|
49 externC void |
|
|
50 cyg_test_output(int status, char* msg, int line_number, char* file); |
|
|
51 |
|
|
52 // This should be called at the start of each test file |
|
|
53 externC void |
|
|
54 cyg_test_init(void); |
|
|
55 |
|
|
56 // This causes the test to exit |
|
|
57 externC void |
|
|
58 cyg_test_exit(void) __attribute__ ((__noreturn__)); |
|
|
59 |
|
|
60 |
|
|
61 // ----------- Info ----------- |
|
|
62 // |
|
|
63 // Any macro with EXIT in it should only be used in a panic situation. It |
|
|
64 // is synonymous with assert. If the test behaves as expected, it |
|
|
65 // should call one of the FINISH macros. |
|
|
66 // |
|
|
67 // - Compound testcases |
|
|
68 // If a testcase is capable of being part of a compound, then the following |
|
|
69 // rules apply: |
|
|
70 // - The testcase must only ever call one of the EXIT macros if it decides |
|
|
71 // the state of the system is such that further testing is meaningless; |
|
|
72 // such a call would prevent subsequent tests in the compound from being |
|
|
73 // run. |
|
|
74 // - In order to terminate the test, the testcase should call one of the |
|
|
75 // FINISH macros. This must be done from within main(). |
|
|
76 |
|
|
77 |
|
|
78 |
|
|
79 |
|
|
80 // The following is the testcase API to be used by testcases. |
|
|
81 |
|
|
82 #define CYG_TEST_INIT() cyg_test_init() |
|
|
83 |
|
|
84 #define CYG_TEST_INFO( _msg_ ) \ |
|
|
85 cyg_test_output(3, _msg_, __LINE__, __FILE__) |
|
|
86 |
|
|
87 #define CYG_TEST_PASS( _msg_ ) \ |
|
|
88 cyg_test_output(1, _msg_, __LINE__, __FILE__) |
|
|
89 |
|
|
90 #define CYG_TEST_FAIL( _msg_ ) \ |
|
|
91 cyg_test_output(0, _msg_, __LINE__, __FILE__) |
|
|
92 |
|
|
93 #define CYG_TEST_EXIT( _msg_ ) \ |
|
|
94 (cyg_test_output(2, _msg_, __LINE__, __FILE__), \ |
|
|
95 cyg_test_exit()) |
|
|
96 |
|
|
97 #ifdef CYG_COMPOUND_TEST |
|
|
98 # define CYG_TEST_FINISH( _msg_ ) \ |
|
|
99 (cyg_test_output(2, _msg_, __LINE__, __FILE__), \ |
|
|
100 return 0; |
|
|
101 #else |
|
|
102 # define CYG_TEST_FINISH( _msg_ ) \ |
|
|
103 (cyg_test_output(2, _msg_, __LINE__, __FILE__), \ |
|
|
104 cyg_test_exit()) |
|
|
105 #endif |
|
|
106 |
|
|
107 #define CYG_TEST_STILL_ALIVE( _ctr_ , _msg_ ) CYG_TEST_INFO( _msg_ ) |
|
|
108 |
|
|
109 |
|
|
110 |
|
|
111 |
|
|
112 // ----- The following are convenience functions |
|
|
113 |
|
|
114 #define CYG_TEST_PASS_FINISH( _msg_ ) \ |
|
|
115 (cyg_test_output(1, _msg_, __LINE__, __FILE__), \ |
|
|
116 CYG_TEST_FINISH("done")) |
|
|
117 |
|
|
118 #define CYG_TEST_FAIL_FINISH( _msg_ ) \ |
|
|
119 (cyg_test_output(0, _msg_, __LINE__, __FILE__), \ |
|
|
120 CYG_TEST_FINISH("done")) |
|
|
121 |
|
|
122 |
|
|
123 #define CYG_TEST_CHECK( _chk_ , _msg_) \ |
|
|
124 (void)(( _chk_ ) || ( cyg_test_output(0, _msg_, __LINE__, __FILE__), \ |
|
|
125 cyg_test_exit(), 1) ) |
|
|
126 |
|
|
127 #define CYG_TEST_PASS_FAIL( _cdn_, _msg_ ) \ |
|
|
128 if ( _cdn_ ) CYG_TEST_PASS( _msg_ ); else CYG_TEST_FAIL( _msg_ ) |
|
|
129 |
|
|
130 |
|
|
131 // CYG_TEST_PASS_EXIT and CYG_TEST_FAIL_EXIT are now obscelete, |
|
|
132 // but are here for now |
|
|
133 // to avoid breaking testcases which still use them. They will |
|
|
134 // soon go away. |
|
|
135 #define CYG_TEST_PASS_EXIT( _msg_ ) \ |
|
|
136 (cyg_test_output(1, _msg_, __LINE__, __FILE__), \ |
|
|
137 CYG_TEST_EXIT("done")) |
|
|
138 |
|
|
139 #define CYG_TEST_FAIL_EXIT( _msg_ ) \ |
|
|
140 (cyg_test_output(0, _msg_, __LINE__, __FILE__), \ |
|
|
141 CYG_TEST_EXIT("done")) |
|
|
142 |
|
|
143 |
|
|
144 #endif // CYGONCE_INFRA_TESTCASE_H |
|
|
145 // EOF testcase.h |