]> git.kernelconcepts.de Git - karo-tx-redboot.git/blob - packages/infra/v2_0/src/tcdiag.cxx
unified MX27, MX25, MX37 trees
[karo-tx-redboot.git] / packages / infra / v2_0 / src / tcdiag.cxx
1 //==========================================================================
2 //
3 //        tcdiag.cxx
4 //
5 //        Infrastructure diag test harness.
6 //
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.
12 //
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.
16 //
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
20 // for more details.
21 //
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.
25 //
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.
32 //
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.
35 //
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####
42 //
43 // Author(s):     dsm
44 // Contributors:  dsm, jlarmour
45 // Date:          1999-02-16
46 // Description:   Test harness implementation that uses the infrastructure
47 //                diag channel.  This is intended for manual testing.
48 // 
49 //####DESCRIPTIONEND####
50
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
55
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
60
61 #include <cyg/hal/hal_intr.h>          // exit macro, if defined
62
63 #ifdef CYGHWR_TARGET_SIMULATOR_NO_GDB_WORKING
64 int cyg_test_is_simulator = 1;         // set this anyway
65 #else
66 int cyg_test_is_simulator = 0;         // infrastructure changes as necessary
67 #endif
68
69 //----------------------------------------------------------------------------
70 // Functions ensuring we get pretty printed assertion messages in the
71 // farm - regardless of configuration and GDB capabilities.
72
73 #ifdef CYGPKG_KERNEL
74 # include <pkgconf/kernel.h>
75 # include <cyg/kernel/thread.hxx>        // thread id to print
76 # include <cyg/kernel/thread.inl>        // ancillaries for above
77 #endif
78
79 #ifdef CYGSEM_HAL_VIRTUAL_VECTOR_SUPPORT
80 #include <cyg/hal/hal_if.h>
81 #endif
82
83 static inline const char *trim_file(const char *file)
84 {
85     if ( NULL == file )
86         file = "<nofile>";
87     
88     const char *f = file;
89     
90     while( *f ) f++;
91
92     while( *f != '/' && f != file ) f--;
93
94     return f==file?f:(f+1);
95 }
96
97 static inline const char *trim_func(const char *func)
98 {
99     static char fbuf[100];
100     int i;
101     
102     if ( NULL == func )
103         func = "<nofunc>";
104
105     for( i = 0; func[i] && func[i] != '(' ; i++ )
106         fbuf[i] = func[i];
107
108     fbuf[i++] = '(';
109     fbuf[i++] = ')';
110     fbuf[i  ] = 0;
111
112     return &fbuf[0];
113 }
114
115 static inline
116 void write_lnum( cyg_uint32 lnum)
117 {
118     diag_write_char('[');
119     diag_write_dec(lnum);
120     diag_write_char(']');
121 }
122
123 static inline
124 void write_thread_id()
125 {
126 #ifdef CYGPKG_KERNEL
127     Cyg_Thread *t = Cyg_Thread::self();
128     cyg_uint16 tid = 0xFFFF;
129
130     if( t != NULL ) tid = t->get_unique_id();
131
132     diag_write_char('<');
133     diag_write_hex(tid);
134     diag_write_char('>');
135 #endif
136 }
137
138 // Called from the CYG_ASSERT_DOCALL macro
139 externC void
140 cyg_assert_msg( const char *psz_func, const char *psz_file,
141                 cyg_uint32 linenum, const char *psz_msg ) __THROW
142 {
143     cyg_uint32 old_ints;
144
145     HAL_DISABLE_INTERRUPTS(old_ints);
146     DIAG_DEVICE_START_SYNC();
147
148 #ifdef CYG_HAL_DIAG_LOCK
149     CYG_HAL_DIAG_LOCK();
150 #endif    
151     
152 #ifdef CYGSEM_HAL_VIRTUAL_VECTOR_SUPPORT
153     {
154         int cur_console;
155         int i;
156         struct cyg_fconfig fc;
157
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;
161         fc.val = &i;
162         if (CYGACC_CALL_IF_FLASH_CFG_OP2(CYGNUM_CALL_IF_FLASH_CFG_GET, &fc)) {
163             if (i) {
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);
169                 }
170             }
171         }
172 #endif
173     diag_write_string("ASSERT FAIL: ");
174     write_thread_id();
175     diag_write_string(trim_file(psz_file));
176     write_lnum(linenum);
177     diag_write_string(trim_func(psz_func));
178     diag_write_char(' ');
179     diag_write_string(psz_msg);
180     diag_write_char('\n');
181
182 #ifdef CYGSEM_HAL_VIRTUAL_VECTOR_SUPPORT
183         CYGACC_CALL_IF_SET_CONSOLE_COMM(cur_console);
184     }
185 #endif
186 #ifdef CYG_HAL_DIAG_UNLOCK
187     CYG_HAL_DIAG_UNLOCK();
188 #endif    
189     
190     DIAG_DEVICE_END_SYNC();
191     HAL_RESTORE_INTERRUPTS(old_ints);
192 }
193
194 externC void
195 cyg_test_init(void)
196 {
197     // currently nothing
198 }
199
200 externC void
201 cyg_test_output(Cyg_test_code status, const char *msg, int line,
202                 const char *file)
203 {
204     char *st;
205
206     switch (status) {
207     case CYGNUM_TEST_FAIL:
208         st = (char *)"FAIL:";
209         break;
210     case CYGNUM_TEST_PASS:
211         st = (char *)"PASS:";
212         break;
213     case CYGNUM_TEST_EXIT:
214         st = (char *)"EXIT:";
215         break;
216     case CYGNUM_TEST_INFO:
217         st = (char *)"INFO:";
218         break;
219     case CYGNUM_TEST_GDBCMD:
220         st = (char *)"GDB:";
221         break;
222     case CYGNUM_TEST_NA:
223         st = (char *)"NOTAPPLICABLE:";
224         break;
225     default:
226         st = (char *)"UNKNOWN STATUS:";
227         break;
228     }
229
230 #ifdef CYG_HAL_DIAG_LOCK
231     CYG_HAL_DIAG_LOCK();
232 #endif    
233     
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);
243     }
244     diag_write_char('\n');
245
246 #ifdef CYG_HAL_DIAG_UNLOCK
247     CYG_HAL_DIAG_UNLOCK();
248 #endif    
249     
250     
251 }
252
253 // This is an appropriate function to set a breakpoint on
254 externC void
255 cyg_test_exit(void)
256 {
257 // workaround SH dwarf2 gen problem    
258 #if defined(CYGPKG_HAL_SH) && (__GNUC__ >= 3)
259     static volatile int i;
260     i++;
261 #endif
262 #ifdef CYGHWR_TEST_PROGRAM_EXIT
263     CYGHWR_TEST_PROGRAM_EXIT();
264 #endif
265 #ifdef CYGSEM_INFRA_RESET_ON_TEST_EXIT
266 #ifdef HAL_PLATFORM_RESET
267     HAL_PLATFORM_RESET();
268 #else
269 #warning "Reset selected for test case exit, but none defined"
270 #endif
271 #endif
272     // Default behaviour - simply hang in a loop
273     for(;;)
274         ;
275 }
276 // EOF tcdiag.cxx