1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
|
//==========================================================================
//
// tcdiag.cxx
//
// Infrastructure diag test harness.
//
//==========================================================================
// ####ECOSGPLCOPYRIGHTBEGIN####
// -------------------------------------------
// This file is part of eCos, the Embedded Configurable Operating System.
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
//
// eCos is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free
// Software Foundation; either version 2 or (at your option) any later
// version.
//
// eCos is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
// for more details.
//
// You should have received a copy of the GNU General Public License
// along with eCos; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
// As a special exception, if other files instantiate templates or use
// macros or inline functions from this file, or you compile this file
// and link it with other works to produce a work based on this file,
// this file does not by itself cause the resulting work to be covered by
// the GNU General Public License. However the source code for this file
// must still be made available in accordance with section (3) of the GNU
// General Public License v2.
//
// This exception does not invalidate any other reasons why a work based
// on this file might be covered by the GNU General Public License.
// -------------------------------------------
// ####ECOSGPLCOPYRIGHTEND####
//==========================================================================
//#####DESCRIPTIONBEGIN####
//
// Author(s): dsm
// Contributors: dsm, jlarmour
// Date: 1999-02-16
// Description: Test harness implementation that uses the infrastructure
// diag channel. This is intended for manual testing.
//
//####DESCRIPTIONEND####
#include <pkgconf/infra.h>
#include <pkgconf/system.h>
#include CYGBLD_HAL_TARGET_H // get initialization for
#include CYGBLD_HAL_PLATFORM_H // cyg_test_is_simulator
#include <cyg/infra/cyg_type.h> // base types
#include <cyg/hal/hal_arch.h> // any architecture specific stuff
#include <cyg/infra/diag.h> // HAL polled output
#include <cyg/infra/testcase.h> // what we implement
#include <cyg/hal/hal_intr.h> // exit macro, if defined
#ifdef CYGHWR_TARGET_SIMULATOR_NO_GDB_WORKING
int cyg_test_is_simulator = 1; // set this anyway
#else
int cyg_test_is_simulator = 0; // infrastructure changes as necessary
#endif
//----------------------------------------------------------------------------
// Functions ensuring we get pretty printed assertion messages in the
// farm - regardless of configuration and GDB capabilities.
#ifdef CYGPKG_KERNEL
# include <pkgconf/kernel.h>
# include <cyg/kernel/thread.hxx> // thread id to print
# include <cyg/kernel/thread.inl> // ancillaries for above
#endif
#ifdef CYGSEM_HAL_VIRTUAL_VECTOR_SUPPORT
#include <cyg/hal/hal_if.h>
#endif
static inline const char *trim_file(const char *file)
{
if ( NULL == file )
file = "<nofile>";
const char *f = file;
while( *f ) f++;
while( *f != '/' && f != file ) f--;
return f==file?f:(f+1);
}
static inline const char *trim_func(const char *func)
{
static char fbuf[100];
int i;
if ( NULL == func )
func = "<nofunc>";
for( i = 0; func[i] && func[i] != '(' ; i++ )
fbuf[i] = func[i];
fbuf[i++] = '(';
fbuf[i++] = ')';
fbuf[i ] = 0;
return &fbuf[0];
}
static inline
void write_lnum( cyg_uint32 lnum)
{
diag_write_char('[');
diag_write_dec(lnum);
diag_write_char(']');
}
static inline
void write_thread_id()
{
#ifdef CYGPKG_KERNEL
Cyg_Thread *t = Cyg_Thread::self();
cyg_uint16 tid = 0xFFFF;
if( t != NULL ) tid = t->get_unique_id();
diag_write_char('<');
diag_write_hex(tid);
diag_write_char('>');
#endif
}
// Called from the CYG_ASSERT_DOCALL macro
externC void
cyg_assert_msg( const char *psz_func, const char *psz_file,
cyg_uint32 linenum, const char *psz_msg ) __THROW
{
cyg_uint32 old_ints;
HAL_DISABLE_INTERRUPTS(old_ints);
DIAG_DEVICE_START_SYNC();
#ifdef CYG_HAL_DIAG_LOCK
CYG_HAL_DIAG_LOCK();
#endif
#ifdef CYGSEM_HAL_VIRTUAL_VECTOR_SUPPORT
{
int cur_console;
int i;
struct cyg_fconfig fc;
cur_console = CYGACC_CALL_IF_SET_CONSOLE_COMM(CYGNUM_CALL_IF_SET_COMM_ID_QUERY_CURRENT);
fc.key = (char *)"info_console_force";
fc.type = CYGNUM_FLASH_CFG_TYPE_CONFIG_BOOL;
fc.val = (void *)&i;
if (CYGACC_CALL_IF_FLASH_CFG_OP2(CYGNUM_CALL_IF_FLASH_CFG_GET, &fc)) {
if (i) {
fc.key = (char *)"info_console_number";
fc.type = CYGNUM_FLASH_CFG_TYPE_CONFIG_INT;
if (CYGACC_CALL_IF_FLASH_CFG_OP2(CYGNUM_CALL_IF_FLASH_CFG_GET, &fc)) {
// Then i is the console to force it to:
CYGACC_CALL_IF_SET_CONSOLE_COMM(i);
}
}
}
#endif
diag_write_string("ASSERT FAIL: ");
write_thread_id();
diag_write_string(trim_file(psz_file));
write_lnum(linenum);
diag_write_string(trim_func(psz_func));
diag_write_char(' ');
diag_write_string(psz_msg);
diag_write_char('\n');
#ifdef CYGSEM_HAL_VIRTUAL_VECTOR_SUPPORT
CYGACC_CALL_IF_SET_CONSOLE_COMM(cur_console);
}
#endif
#ifdef CYG_HAL_DIAG_UNLOCK
CYG_HAL_DIAG_UNLOCK();
#endif
DIAG_DEVICE_END_SYNC();
HAL_RESTORE_INTERRUPTS(old_ints);
}
externC void
cyg_test_init(void)
{
// currently nothing
}
externC void
cyg_test_output(Cyg_test_code status, const char *msg, int line,
const char *file)
{
char *st;
switch (status) {
case CYGNUM_TEST_FAIL:
st = (char *)"FAIL:";
break;
case CYGNUM_TEST_PASS:
st = (char *)"PASS:";
break;
case CYGNUM_TEST_EXIT:
st = (char *)"EXIT:";
break;
case CYGNUM_TEST_INFO:
st = (char *)"INFO:";
break;
case CYGNUM_TEST_GDBCMD:
st = (char *)"GDB:";
break;
case CYGNUM_TEST_NA:
st = (char *)"NOTAPPLICABLE:";
break;
default:
st = (char *)"UNKNOWN STATUS:";
break;
}
#ifdef CYG_HAL_DIAG_LOCK
CYG_HAL_DIAG_LOCK();
#endif
diag_write_string(st);
diag_write_char('<');
diag_write_string(msg);
diag_write_char('>');
if( CYGNUM_TEST_FAIL == status ) {
diag_write_string(" Line: ");
diag_write_dec(line);
diag_write_string(", File: ");
diag_write_string(file);
}
diag_write_char('\n');
#ifdef CYG_HAL_DIAG_UNLOCK
CYG_HAL_DIAG_UNLOCK();
#endif
}
// This is an appropriate function to set a breakpoint on
externC void
cyg_test_exit(void)
{
// workaround SH dwarf2 gen problem
#if defined(CYGPKG_HAL_SH) && (__GNUC__ >= 3)
static volatile int i;
i++;
#endif
#ifdef CYGHWR_TEST_PROGRAM_EXIT
CYGHWR_TEST_PROGRAM_EXIT();
#endif
#ifdef CYGSEM_INFRA_RESET_ON_TEST_EXIT
#ifdef HAL_PLATFORM_RESET
HAL_PLATFORM_RESET();
#else
#warning "Reset selected for test case exit, but none defined"
#endif
#endif
// Default behaviour - simply hang in a loop
for(;;)
;
}
// EOF tcdiag.cxx
|