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