1 //==========================================================================
5 // Infrastructure diag test harness.
7 //==========================================================================
8 //####ECOSGPLCOPYRIGHTBEGIN####
9 // -------------------------------------------
10 // This file is part of eCos, the Embedded Configurable Operating System.
11 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
13 // eCos is free software; you can redistribute it and/or modify it under
14 // the terms of the GNU General Public License as published by the Free
15 // Software Foundation; either version 2 or (at your option) any later version.
17 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
18 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 // You should have received a copy of the GNU General Public License along
23 // with eCos; if not, write to the Free Software Foundation, Inc.,
24 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
26 // As a special exception, if other files instantiate templates or use macros
27 // or inline functions from this file, or you compile this file and link it
28 // with other works to produce a work based on this file, this file does not
29 // by itself cause the resulting work to be covered by the GNU General Public
30 // License. However the source code for this file must still be made available
31 // in accordance with section (3) of the GNU General Public License.
33 // This exception does not invalidate any other reasons why a work based on
34 // this file might be covered by the GNU General Public License.
36 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
37 // at http://sources.redhat.com/ecos/ecos-license/
38 // -------------------------------------------
39 //####ECOSGPLCOPYRIGHTEND####
40 //==========================================================================
41 //#####DESCRIPTIONBEGIN####
44 // Contributors: dsm, jlarmour
46 // Description: Test harness implementation that uses the infrastructure
47 // diag channel. This is intended for manual testing.
49 //####DESCRIPTIONEND####
51 #include <pkgconf/infra.h>
52 #include <pkgconf/system.h>
53 #include CYGBLD_HAL_TARGET_H // get initialization for
54 #include CYGBLD_HAL_PLATFORM_H // cyg_test_is_simulator
56 #include <cyg/infra/cyg_type.h> // base types
57 #include <cyg/hal/hal_arch.h> // any architecture specific stuff
58 #include <cyg/infra/diag.h> // HAL polled output
59 #include <cyg/infra/testcase.h> // what we implement
61 #include <cyg/hal/hal_intr.h> // exit macro, if defined
63 #ifdef CYGHWR_TARGET_SIMULATOR_NO_GDB_WORKING
64 int cyg_test_is_simulator = 1; // set this anyway
66 int cyg_test_is_simulator = 0; // infrastructure changes as necessary
69 //----------------------------------------------------------------------------
70 // Functions ensuring we get pretty printed assertion messages in the
71 // farm - regardless of configuration and GDB capabilities.
74 # include <pkgconf/kernel.h>
75 # include <cyg/kernel/thread.hxx> // thread id to print
76 # include <cyg/kernel/thread.inl> // ancillaries for above
79 #ifdef CYGSEM_HAL_VIRTUAL_VECTOR_SUPPORT
80 #include <cyg/hal/hal_if.h>
83 static inline const char *trim_file(const char *file)
92 while( *f != '/' && f != file ) f--;
94 return f==file?f:(f+1);
97 static inline const char *trim_func(const char *func)
99 static char fbuf[100];
105 for( i = 0; func[i] && func[i] != '(' ; i++ )
116 void write_lnum( cyg_uint32 lnum)
118 diag_write_char('[');
119 diag_write_dec(lnum);
120 diag_write_char(']');
124 void write_thread_id()
127 Cyg_Thread *t = Cyg_Thread::self();
128 cyg_uint16 tid = 0xFFFF;
130 if( t != NULL ) tid = t->get_unique_id();
132 diag_write_char('<');
134 diag_write_char('>');
138 // Called from the CYG_ASSERT_DOCALL macro
140 cyg_assert_msg( const char *psz_func, const char *psz_file,
141 cyg_uint32 linenum, const char *psz_msg ) __THROW
145 HAL_DISABLE_INTERRUPTS(old_ints);
146 DIAG_DEVICE_START_SYNC();
148 #ifdef CYG_HAL_DIAG_LOCK
152 #ifdef CYGSEM_HAL_VIRTUAL_VECTOR_SUPPORT
156 struct cyg_fconfig fc;
158 cur_console = CYGACC_CALL_IF_SET_CONSOLE_COMM(CYGNUM_CALL_IF_SET_COMM_ID_QUERY_CURRENT);
159 fc.key = (char *)"info_console_force";
160 fc.type = CYGNUM_FLASH_CFG_TYPE_CONFIG_BOOL;
162 if (CYGACC_CALL_IF_FLASH_CFG_OP2(CYGNUM_CALL_IF_FLASH_CFG_GET, &fc)) {
164 fc.key = (char *)"info_console_number";
165 fc.type = CYGNUM_FLASH_CFG_TYPE_CONFIG_INT;
166 if (CYGACC_CALL_IF_FLASH_CFG_OP2(CYGNUM_CALL_IF_FLASH_CFG_GET, &fc)) {
167 // Then i is the console to force it to:
168 CYGACC_CALL_IF_SET_CONSOLE_COMM(i);
173 diag_write_string("ASSERT FAIL: ");
175 diag_write_string(trim_file(psz_file));
177 diag_write_string(trim_func(psz_func));
178 diag_write_char(' ');
179 diag_write_string(psz_msg);
180 diag_write_char('\n');
182 #ifdef CYGSEM_HAL_VIRTUAL_VECTOR_SUPPORT
183 CYGACC_CALL_IF_SET_CONSOLE_COMM(cur_console);
186 #ifdef CYG_HAL_DIAG_UNLOCK
187 CYG_HAL_DIAG_UNLOCK();
190 DIAG_DEVICE_END_SYNC();
191 HAL_RESTORE_INTERRUPTS(old_ints);
201 cyg_test_output(Cyg_test_code status, const char *msg, int line,
207 case CYGNUM_TEST_FAIL:
208 st = (char *)"FAIL:";
210 case CYGNUM_TEST_PASS:
211 st = (char *)"PASS:";
213 case CYGNUM_TEST_EXIT:
214 st = (char *)"EXIT:";
216 case CYGNUM_TEST_INFO:
217 st = (char *)"INFO:";
219 case CYGNUM_TEST_GDBCMD:
223 st = (char *)"NOTAPPLICABLE:";
226 st = (char *)"UNKNOWN STATUS:";
230 #ifdef CYG_HAL_DIAG_LOCK
234 diag_write_string(st);
235 diag_write_char('<');
236 diag_write_string(msg);
237 diag_write_char('>');
238 if( CYGNUM_TEST_FAIL == status ) {
239 diag_write_string(" Line: ");
240 diag_write_dec(line);
241 diag_write_string(", File: ");
242 diag_write_string(file);
244 diag_write_char('\n');
246 #ifdef CYG_HAL_DIAG_UNLOCK
247 CYG_HAL_DIAG_UNLOCK();
253 // This is an appropriate function to set a breakpoint on
257 // workaround SH dwarf2 gen problem
258 #if defined(CYGPKG_HAL_SH) && (__GNUC__ >= 3)
259 static volatile int i;
262 #ifdef CYGHWR_TEST_PROGRAM_EXIT
263 CYGHWR_TEST_PROGRAM_EXIT();
265 #ifdef CYGSEM_INFRA_RESET_ON_TEST_EXIT
266 #ifdef HAL_PLATFORM_RESET
267 HAL_PLATFORM_RESET();
269 #warning "Reset selected for test case exit, but none defined"
272 // Default behaviour - simply hang in a loop