1 #ifndef CYGONCE_INFRA_TESTCASE_H
2 #define CYGONCE_INFRA_TESTCASE_H
3 //==========================================================================
7 // Target side interface for tests
9 //==========================================================================
10 //####ECOSGPLCOPYRIGHTBEGIN####
11 // -------------------------------------------
12 // This file is part of eCos, the Embedded Configurable Operating System.
13 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
15 // eCos is free software; you can redistribute it and/or modify it under
16 // the terms of the GNU General Public License as published by the Free
17 // Software Foundation; either version 2 or (at your option) any later version.
19 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
20 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24 // You should have received a copy of the GNU General Public License along
25 // with eCos; if not, write to the Free Software Foundation, Inc.,
26 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
28 // As a special exception, if other files instantiate templates or use macros
29 // or inline functions from this file, or you compile this file and link it
30 // with other works to produce a work based on this file, this file does not
31 // by itself cause the resulting work to be covered by the GNU General Public
32 // License. However the source code for this file must still be made available
33 // in accordance with section (3) of the GNU General Public License.
35 // This exception does not invalidate any other reasons why a work based on
36 // this file might be covered by the GNU General Public License.
38 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
39 // at http://sources.redhat.com/ecos/ecos-license/
40 // -------------------------------------------
41 //####ECOSGPLCOPYRIGHTEND####
42 //==========================================================================
43 //#####DESCRIPTIONBEGIN####
46 // Contributors: ctarpy, jlarmour
50 //####DESCRIPTIONEND####
52 #include <cyg/infra/cyg_type.h> // Common type definitions and support
68 // FUNCTION PROTOTYPES
71 cyg_test_output(Cyg_test_code _status_, const char* _msg_, int _line_number_,
74 // This should be called at the start of each test file
78 // This causes the test to exit
80 cyg_test_exit(void) CYGBLD_ATTRIB_NORET;
84 externC int cyg_test_is_simulator; // infrastructure changes as necessary
88 // ----------- Info -----------
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.
94 // - Compound testcases
95 // If a testcase is capable of being part of a compound, then the following
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
101 // - In order to terminate the test, the testcase should call one of the
102 // FINISH macros. This must be done from within main().
107 // The following is the testcase API to be used by testcases.
109 #define CYG_TEST_INIT() cyg_test_init()
111 #define CYG_TEST_INFO( _msg_ ) \
112 cyg_test_output(CYGNUM_TEST_INFO, _msg_, __LINE__, __FILE__)
114 #define CYG_TEST_PASS( _msg_ ) \
115 cyg_test_output(CYGNUM_TEST_PASS, _msg_, __LINE__, __FILE__)
117 #define CYG_TEST_FAIL( _msg_ ) \
118 cyg_test_output(CYGNUM_TEST_FAIL, _msg_, __LINE__, __FILE__)
120 #define CYG_TEST_EXIT( _msg_ ) \
121 (cyg_test_output(CYGNUM_TEST_EXIT, _msg_, __LINE__, __FILE__), \
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
128 #define CYG_TEST_GDBCMD( _command_ ) \
130 cyg_test_output(CYGNUM_TEST_GDBCMD, _command_, __LINE__, __FILE__); \
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
140 #define CYG_TEST_NA( _msg_ ) \
142 cyg_test_output(CYGNUM_TEST_NA, _msg_, __LINE__, __FILE__); \
146 #ifdef CYG_COMPOUND_TEST
147 # define CYG_TEST_FINISH( _msg_ ) \
149 cyg_test_output(CYGNUM_TEST_EXIT, _msg_, __LINE__, __FILE__); \
153 # define CYG_TEST_FINISH( _msg_ ) CYG_TEST_EXIT( _msg_ )
156 #define CYG_TEST_STILL_ALIVE( _ctr_ , _msg_ ) CYG_TEST_INFO( _msg_ )
159 // ----- The following are convenience functions
161 #define CYG_TEST_PASS_FINISH( _msg_ ) \
163 CYG_TEST_PASS( _msg_ ); \
164 CYG_TEST_FINISH("done"); \
167 #define CYG_TEST_FAIL_FINISH( _msg_ ) \
169 CYG_TEST_FAIL( _msg_ ); \
170 CYG_TEST_FINISH("done"); \
174 #define CYG_TEST_CHECK( _chk_ , _msg_) \
176 (void)(( _chk_ ) || ( CYG_TEST_FAIL( _msg_ ) , cyg_test_exit(), 1)); \
179 #define CYG_TEST_PASS_FAIL( _cdn_, _msg_ ) \
181 if ( _cdn_ ) CYG_TEST_PASS( _msg_ ); else CYG_TEST_FAIL( _msg_ ); \
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
189 #define CYG_TEST_PASS_EXIT( _msg_ ) \
190 (cyg_test_output(CYGNUM_TEST_PASS, _msg_, __LINE__, __FILE__), \
191 CYG_TEST_EXIT("done"))
193 #define CYG_TEST_FAIL_EXIT( _msg_ ) \
194 (cyg_test_output(CYGNUM_TEST_FAIL, _msg_, __LINE__, __FILE__), \
195 CYG_TEST_EXIT("done"))
198 #endif // CYGONCE_INFRA_TESTCASE_H