1 #ifndef CYGONCE_INFRA_TESTCASE_H
2 #define CYGONCE_INFRA_TESTCASE_H
3 //==========================================================================
7 // Target side interface for tests
9 //==========================================================================
10 //####COPYRIGHTBEGIN####
12 // ----------------------------------------------------------------------------
13 // Copyright (C) 1998, 1999, 2000 Red Hat, Inc.
15 // This file is part of the eCos host tools.
17 // This program is free software; you can redistribute it and/or modify it
18 // under the terms of the GNU General Public License as published by the Free
19 // Software Foundation; either version 2 of the License, or (at your option)
22 // This program is distributed in the hope that it will be useful, but WITHOUT
23 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
24 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
27 // You should have received a copy of the GNU General Public License along with
28 // this program; if not, write to the Free Software Foundation, Inc.,
29 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
31 // ----------------------------------------------------------------------------
33 //####COPYRIGHTEND####
34 //==========================================================================
35 //#####DESCRIPTIONBEGIN####
38 // Contributors: ctarpy, jlarmour
42 //####DESCRIPTIONEND####
44 #include <cyg/infra/cyg_type.h> // Common type definitions and support
60 // FUNCTION PROTOTYPES
63 cyg_test_output(Cyg_test_code _status_, const char* _msg_, int _line_number_,
66 // This should be called at the start of each test file
70 // This causes the test to exit
72 cyg_test_exit(void) CYGBLD_ATTRIB_NORET;
76 externC int cyg_test_is_simulator; // infrastructure changes as necessary
80 // ----------- Info -----------
82 // Any macro with EXIT in it should only be used in a panic situation. It
83 // is synonymous with assert. If the test behaves as expected, it
84 // should call one of the FINISH macros.
86 // - Compound testcases
87 // If a testcase is capable of being part of a compound, then the following
89 // - The testcase must only ever call one of the EXIT macros if it decides
90 // the state of the system is such that further testing is meaningless;
91 // such a call would prevent subsequent tests in the compound from being
93 // - In order to terminate the test, the testcase should call one of the
94 // FINISH macros. This must be done from within main().
99 // The following is the testcase API to be used by testcases.
101 #define CYG_TEST_INIT() cyg_test_init()
103 #define CYG_TEST_INFO( _msg_ ) \
104 cyg_test_output(CYGNUM_TEST_INFO, _msg_, __LINE__, __FILE__)
106 #define CYG_TEST_PASS( _msg_ ) \
107 cyg_test_output(CYGNUM_TEST_PASS, _msg_, __LINE__, __FILE__)
109 #define CYG_TEST_FAIL( _msg_ ) \
110 cyg_test_output(CYGNUM_TEST_FAIL, _msg_, __LINE__, __FILE__)
112 #define CYG_TEST_EXIT( _msg_ ) \
113 (cyg_test_output(CYGNUM_TEST_EXIT, _msg_, __LINE__, __FILE__), \
116 // Use the following macro to instruct GDB to run a command when using
117 // the automatic testing infrastructure. This must be used *before*
118 // CYG_TEST_INIT() is called
120 #define CYG_TEST_GDBCMD( _command_ ) \
122 cyg_test_output(CYGNUM_TEST_GDBCMD, _command_, __LINE__, __FILE__); \
125 // Use the following macro to declare that a test is not applicable for
126 // some reason - perhaps not appropriate due to chosen hardware,
127 // configuration options governing the presence of a tested feature, or
128 // even configuration options governing the presence of a feature the
129 // test relies on _in_order_ to test the feature (despite being
132 #define CYG_TEST_NA( _msg_ ) \
134 cyg_test_output(CYGNUM_TEST_NA, _msg_, __LINE__, __FILE__); \
138 #ifdef CYG_COMPOUND_TEST
139 # define CYG_TEST_FINISH( _msg_ ) \
141 cyg_test_output(CYGNUM_TEST_EXIT, _msg_, __LINE__, __FILE__); \
145 # define CYG_TEST_FINISH( _msg_ ) CYG_TEST_EXIT( _msg_ )
148 #define CYG_TEST_STILL_ALIVE( _ctr_ , _msg_ ) CYG_TEST_INFO( _msg_ )
151 // ----- The following are convenience functions
153 #define CYG_TEST_PASS_FINISH( _msg_ ) \
155 CYG_TEST_PASS( _msg_ ); \
156 CYG_TEST_FINISH("done"); \
159 #define CYG_TEST_FAIL_FINISH( _msg_ ) \
161 CYG_TEST_FAIL( _msg_ ); \
162 CYG_TEST_FINISH("done"); \
166 #define CYG_TEST_CHECK( _chk_ , _msg_) \
168 (void)(( _chk_ ) || ( CYG_TEST_FAIL( _msg_ ) , cyg_test_exit(), 1)); \
171 #define CYG_TEST_PASS_FAIL( _cdn_, _msg_ ) \
173 if ( _cdn_ ) CYG_TEST_PASS( _msg_ ); else CYG_TEST_FAIL( _msg_ ); \
177 // CYG_TEST_PASS_EXIT and CYG_TEST_FAIL_EXIT are now obscelete,
178 // but are here for now
179 // to avoid breaking testcases which still use them. They will
181 #define CYG_TEST_PASS_EXIT( _msg_ ) \
182 (cyg_test_output(CYGNUM_TEST_PASS, _msg_, __LINE__, __FILE__), \
183 CYG_TEST_EXIT("done"))
185 #define CYG_TEST_FAIL_EXIT( _msg_ ) \
186 (cyg_test_output(CYGNUM_TEST_FAIL, _msg_, __LINE__, __FILE__), \
187 CYG_TEST_EXIT("done"))
190 #endif // CYGONCE_INFRA_TESTCASE_H