Mercurial > flash_v2
annotate packages/infra/current/include/testcase.h @ 210:d2c90368aeef
Merge from eCos master repository on 2002-05-23-21:39:14-BST
| author | jlarmour |
|---|---|
| date | Thu, 23 May 2002 22:59:51 +0000 |
| parents | e0c0827131d1 |
| children |
| 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 //========================================================================== | |
|
208
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
diff
changeset
|
10 //####ECOSGPLCOPYRIGHTBEGIN#### |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
diff
changeset
|
11 // ------------------------------------------- |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
diff
changeset
|
12 // This file is part of eCos, the Embedded Configurable Operating System. |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
diff
changeset
|
13 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc. |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
diff
changeset
|
14 // |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
diff
changeset
|
15 // eCos is free software; you can redistribute it and/or modify it under |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
diff
changeset
|
16 // the terms of the GNU General Public License as published by the Free |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
diff
changeset
|
17 // Software Foundation; either version 2 or (at your option) any later version. |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
diff
changeset
|
18 // |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
diff
changeset
|
19 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
diff
changeset
|
20 // WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
diff
changeset
|
21 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
diff
changeset
|
22 // for more details. |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
diff
changeset
|
23 // |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
diff
changeset
|
24 // You should have received a copy of the GNU General Public License along |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
diff
changeset
|
25 // with eCos; if not, write to the Free Software Foundation, Inc., |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
diff
changeset
|
26 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
diff
changeset
|
27 // |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
diff
changeset
|
28 // As a special exception, if other files instantiate templates or use macros |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
diff
changeset
|
29 // or inline functions from this file, or you compile this file and link it |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
diff
changeset
|
30 // with other works to produce a work based on this file, this file does not |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
diff
changeset
|
31 // by itself cause the resulting work to be covered by the GNU General Public |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
diff
changeset
|
32 // License. However the source code for this file must still be made available |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
diff
changeset
|
33 // in accordance with section (3) of the GNU General Public License. |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
diff
changeset
|
34 // |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
diff
changeset
|
35 // This exception does not invalidate any other reasons why a work based on |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
diff
changeset
|
36 // this file might be covered by the GNU General Public License. |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
diff
changeset
|
37 // |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
diff
changeset
|
38 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc. |
|
210
d2c90368aeef
Merge from eCos master repository on 2002-05-23-21:39:14-BST
jlarmour
parents:
208
diff
changeset
|
39 // at http://sources.redhat.com/ecos/ecos-license/ |
|
208
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
diff
changeset
|
40 // ------------------------------------------- |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
diff
changeset
|
41 //####ECOSGPLCOPYRIGHTEND#### |
| 0 | 42 //========================================================================== |
| 43 //#####DESCRIPTIONBEGIN#### | |
| 44 // | |
| 2 | 45 // Author(s): ctarpy |
| 46 // Contributors: ctarpy, jlarmour | |
| 47 // Date: 1999-02-16 | |
| 0 | 48 // |
| 49 // | |
| 50 //####DESCRIPTIONEND#### | |
| 51 | |
| 52 #include <cyg/infra/cyg_type.h> // Common type definitions and support | |
| 53 | |
| 54 | |
| 2 | 55 // CONSTANTS |
| 56 | |
| 57 // Status codes | |
| 58 | |
| 59 typedef enum { | |
| 60 CYGNUM_TEST_FAIL, | |
| 61 CYGNUM_TEST_PASS, | |
| 62 CYGNUM_TEST_EXIT, | |
| 63 CYGNUM_TEST_INFO, | |
| 64 CYGNUM_TEST_GDBCMD, | |
| 65 CYGNUM_TEST_NA | |
| 66 } Cyg_test_code; | |
| 67 | |
| 68 // FUNCTION PROTOTYPES | |
| 69 | |
| 0 | 70 externC void |
| 2 | 71 cyg_test_output(Cyg_test_code _status_, const char* _msg_, int _line_number_, |
| 72 const char* _file_); | |
| 0 | 73 |
| 74 // This should be called at the start of each test file | |
| 75 externC void | |
| 76 cyg_test_init(void); | |
| 77 | |
| 78 // This causes the test to exit | |
| 79 externC void | |
| 2 | 80 cyg_test_exit(void) CYGBLD_ATTRIB_NORET; |
| 81 | |
| 82 // GLOBALS | |
| 0 | 83 |
| 2 | 84 externC int cyg_test_is_simulator; // infrastructure changes as necessary |
| 85 | |
| 86 // MACROS | |
| 0 | 87 |
| 88 // ----------- Info ----------- | |
| 89 // | |
| 90 // Any macro with EXIT in it should only be used in a panic situation. It | |
| 91 // is synonymous with assert. If the test behaves as expected, it | |
| 92 // should call one of the FINISH macros. | |
| 93 // | |
| 94 // - Compound testcases | |
| 95 // If a testcase is capable of being part of a compound, then the following | |
| 96 // rules apply: | |
| 97 // - The testcase must only ever call one of the EXIT macros if it decides | |
| 98 // the state of the system is such that further testing is meaningless; | |
| 99 // such a call would prevent subsequent tests in the compound from being | |
| 100 // run. | |
| 101 // - In order to terminate the test, the testcase should call one of the | |
| 102 // FINISH macros. This must be done from within main(). | |
| 103 | |
| 104 | |
| 105 | |
| 106 | |
| 107 // The following is the testcase API to be used by testcases. | |
| 108 | |
| 109 #define CYG_TEST_INIT() cyg_test_init() | |
| 110 | |
| 111 #define CYG_TEST_INFO( _msg_ ) \ | |
| 2 | 112 cyg_test_output(CYGNUM_TEST_INFO, _msg_, __LINE__, __FILE__) |
| 0 | 113 |
| 114 #define CYG_TEST_PASS( _msg_ ) \ | |
| 2 | 115 cyg_test_output(CYGNUM_TEST_PASS, _msg_, __LINE__, __FILE__) |
| 0 | 116 |
| 117 #define CYG_TEST_FAIL( _msg_ ) \ | |
| 2 | 118 cyg_test_output(CYGNUM_TEST_FAIL, _msg_, __LINE__, __FILE__) |
| 0 | 119 |
| 120 #define CYG_TEST_EXIT( _msg_ ) \ | |
| 2 | 121 (cyg_test_output(CYGNUM_TEST_EXIT, _msg_, __LINE__, __FILE__), \ |
| 0 | 122 cyg_test_exit()) |
| 123 | |
| 2 | 124 // Use the following macro to instruct GDB to run a command when using |
| 125 // the automatic testing infrastructure. This must be used *before* | |
| 126 // CYG_TEST_INIT() is called | |
| 127 | |
| 128 #define CYG_TEST_GDBCMD( _command_ ) \ | |
| 129 CYG_MACRO_START \ | |
| 130 cyg_test_output(CYGNUM_TEST_GDBCMD, _command_, __LINE__, __FILE__); \ | |
| 131 CYG_MACRO_END | |
| 132 | |
| 133 // Use the following macro to declare that a test is not applicable for | |
| 134 // some reason - perhaps not appropriate due to chosen hardware, | |
| 135 // configuration options governing the presence of a tested feature, or | |
| 136 // even configuration options governing the presence of a feature the | |
| 137 // test relies on _in_order_ to test the feature (despite being | |
| 138 // unrelated!) | |
| 139 | |
| 140 #define CYG_TEST_NA( _msg_ ) \ | |
| 141 CYG_MACRO_START \ | |
| 142 cyg_test_output(CYGNUM_TEST_NA, _msg_, __LINE__, __FILE__); \ | |
| 143 cyg_test_exit(); \ | |
| 144 CYG_MACRO_END | |
| 145 | |
| 0 | 146 #ifdef CYG_COMPOUND_TEST |
| 2 | 147 # define CYG_TEST_FINISH( _msg_ ) \ |
| 148 CYG_MACRO_START \ | |
| 149 cyg_test_output(CYGNUM_TEST_EXIT, _msg_, __LINE__, __FILE__); \ | |
| 150 return 0; \ | |
| 151 CYG_MACRO_END | |
| 0 | 152 #else |
| 2 | 153 # define CYG_TEST_FINISH( _msg_ ) CYG_TEST_EXIT( _msg_ ) |
| 0 | 154 #endif |
| 155 | |
| 156 #define CYG_TEST_STILL_ALIVE( _ctr_ , _msg_ ) CYG_TEST_INFO( _msg_ ) | |
| 157 | |
| 158 | |
| 159 // ----- The following are convenience functions | |
| 160 | |
| 161 #define CYG_TEST_PASS_FINISH( _msg_ ) \ | |
| 2 | 162 CYG_MACRO_START \ |
| 163 CYG_TEST_PASS( _msg_ ); \ | |
| 164 CYG_TEST_FINISH("done"); \ | |
| 165 CYG_MACRO_END | |
| 0 | 166 |
| 167 #define CYG_TEST_FAIL_FINISH( _msg_ ) \ | |
| 2 | 168 CYG_MACRO_START \ |
| 169 CYG_TEST_FAIL( _msg_ ); \ | |
| 170 CYG_TEST_FINISH("done"); \ | |
| 171 CYG_MACRO_END | |
| 0 | 172 |
| 173 | |
| 2 | 174 #define CYG_TEST_CHECK( _chk_ , _msg_) \ |
| 175 CYG_MACRO_START \ | |
| 176 (void)(( _chk_ ) || ( CYG_TEST_FAIL( _msg_ ) , cyg_test_exit(), 1)); \ | |
| 177 CYG_MACRO_END | |
| 0 | 178 |
| 2 | 179 #define CYG_TEST_PASS_FAIL( _cdn_, _msg_ ) \ |
| 180 CYG_MACRO_START \ | |
| 181 if ( _cdn_ ) CYG_TEST_PASS( _msg_ ); else CYG_TEST_FAIL( _msg_ ); \ | |
| 182 CYG_MACRO_END | |
| 0 | 183 |
| 184 | |
| 185 // CYG_TEST_PASS_EXIT and CYG_TEST_FAIL_EXIT are now obscelete, | |
| 186 // but are here for now | |
| 187 // to avoid breaking testcases which still use them. They will | |
| 188 // soon go away. | |
| 2 | 189 #define CYG_TEST_PASS_EXIT( _msg_ ) \ |
| 190 (cyg_test_output(CYGNUM_TEST_PASS, _msg_, __LINE__, __FILE__), \ | |
| 0 | 191 CYG_TEST_EXIT("done")) |
| 192 | |
| 2 | 193 #define CYG_TEST_FAIL_EXIT( _msg_ ) \ |
| 194 (cyg_test_output(CYGNUM_TEST_FAIL, _msg_, __LINE__, __FILE__), \ | |
| 0 | 195 CYG_TEST_EXIT("done")) |
| 196 | |
| 197 | |
| 198 #endif // CYGONCE_INFRA_TESTCASE_H | |
| 199 // EOF testcase.h |
