OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [tools/] [src/] [infra/] [testsuite/] [cyginfra/] [tassert6.cxx] - Blame information for rev 321

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 26 unneback
//==========================================================================
2
//
3
//      tassert6.cxx
4
//
5
//      Assertion test case                                                                
6
//
7
//==========================================================================
8
//####COPYRIGHTBEGIN####
9
//                                                                          
10
// ----------------------------------------------------------------------------
11
// Copyright (C) 1998, 1999, 2000 Red Hat, Inc.
12
//
13
// This file is part of the eCos host tools.
14
//
15
// This program is free software; you can redistribute it and/or modify it 
16
// under the terms of the GNU General Public License as published by the Free 
17
// Software Foundation; either version 2 of the License, or (at your option) 
18
// any later version.
19
// 
20
// This program is distributed in the hope that it will be useful, but WITHOUT 
21
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
22
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for 
23
// more details.
24
// 
25
// You should have received a copy of the GNU General Public License along with
26
// this program; if not, write to the Free Software Foundation, Inc., 
27
// 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
28
//
29
// ----------------------------------------------------------------------------
30
//                                                                          
31
//####COPYRIGHTEND####
32
//==========================================================================
33
//#####DESCRIPTIONBEGIN####                                             
34
//
35
// Author(s):           bartv
36
// Contributors:        bartv
37
// Date:                1998-12-22
38
// Purpose:
39
// Description:         This routine checks that all the assertions can
40
//                      be triggered.
41
//
42
//####DESCRIPTIONEND####
43
//==========================================================================
44
 
45
 
46
#define CYG_DECLARE_HOST_ASSERTION_SUPPORT
47
#define CYGDBG_USE_ASSERTS
48
#define CYGDBG_INFRA_DEBUG_PRECONDITIONS
49
#define CYGDBG_INFRA_DEBUG_POSTCONDITIONS
50
#define CYGDBG_INFRA_DEBUG_LOOP_INVARIANTS
51
#define CYGDBG_INFRA_DEBUG_INVARIANTS
52
 
53
// Also redefine the zeal
54
#define CYG_ASSERT_CLASS_ZEAL (cyg_extreme)
55
 
56
#include <cyg/infra/testcase.h>
57
#include <cyg/infra/cyg_ass.h>
58
#include <cstdlib>
59
#include <csetjmp>
60
#include <cstring>
61
 
62
 
63
// This is used to "recover" from an assertion failure
64
static jmp_buf setjmp_buffer;
65
 
66
// The number of assertions that have triggered.
67
static int failed_assertions = 0;
68
 
69
// The number of assertions that have been triggered.
70
static int   counter = 0;
71
 
72
static const char message[] = "beware of the leopard";
73
 
74
// A dummy class is needed for some of the assertions.
75
class dummy {
76
  private:
77
    int       random;
78
  public:
79
    dummy() {
80
        random = rand();
81
    }
82
    ~dummy() {
83
        random = 0;
84
    }
85
    void assertions();
86
    void invariant1();
87
    void invariant2();
88
    static void invariant3(dummy&);
89
    static void invariant4(dummy&);
90
    static void invariant5(dummy*);
91
    static void invariant6(dummy*);
92
    static void extern_assertions(dummy*);
93
    bool check_this(cyg_assert_class_zeal) const;
94
};
95
 
96
bool
97
dummy::check_this(cyg_assert_class_zeal zeal) const
98
{
99
    // The default zeal should be cyg_quick.
100
    switch(zeal) {
101
    case cyg_extreme:
102
        return false;
103
    case cyg_system_test:
104
    case cyg_thorough:
105
    case cyg_quick:
106
    case cyg_trivial:
107
    case cyg_none:
108
        CYG_TEST_FAIL_FINISH("incorrect default zeal passed to check_this() member function");
109
        break;
110
    default:
111
        CYG_TEST_FAIL_FINISH("invalid zeal passed to check_this() member function");
112
        break;
113
    }
114
    return false;
115
}
116
 
117
void
118
dummy::invariant1(void)
119
{
120
    CYG_INVARIANT_THIS(dummy, message);
121
    CYG_TEST_FAIL("CYG_INVARIANT_THIS() did not trigger");
122
}
123
 
124
void
125
dummy::invariant2(void)
126
{
127
    CYG_INVARIANT_THISC(dummy);
128
    CYG_TEST_FAIL("CYG_INVARIANT_THISC() did not trigger");
129
}
130
 
131
void
132
dummy::invariant3(dummy& obj)
133
{
134
    CYG_INVARIANT_CLASSO(dummy, obj, message);
135
    CYG_TEST_FAIL("CYG_INVARIANT_CLASSO() did not trigger");
136
}
137
 
138
void
139
dummy::invariant4(dummy& obj)
140
{
141
    CYG_INVARIANT_CLASSOC(dummy, obj);
142
    CYG_TEST_FAIL("CYG_INVARIANT_CLASSOC() did not trigger");
143
}
144
 
145
void
146
dummy::invariant5(dummy* obj)
147
{
148
    CYG_INVARIANT_CLASS(dummy, obj, message);
149
    CYG_TEST_FAIL("CYG_INVARIANT_CLASS() did not trigger");
150
}
151
 
152
void
153
dummy::invariant6(dummy* obj)
154
{
155
    CYG_INVARIANT_CLASSC(dummy, obj);
156
    CYG_TEST_FAIL("CYG_INVARIANT_CLASSC() did not trigger");
157
}
158
 
159
void
160
dummy::assertions(void)
161
{
162
    switch(counter) {
163
 
164
    case 33:
165
        CYG_ASSERT_THIS(message);
166
        CYG_TEST_FAIL("CYG_ASSERT_THIS() did not trigger");
167
        break;
168
 
169
    case 34:
170
        CYG_ASSERT_THISC();
171
        CYG_TEST_FAIL("CYG_ASSERT_THISC() did not trigger");
172
        break;
173
 
174
    case 35:
175
        CYG_PRECONDITION_THIS(message);
176
        CYG_TEST_FAIL("CYG_PRECONDITION_THIS() did not trigger");
177
        break;
178
 
179
    case 36:
180
        CYG_PRECONDITION_THISC();
181
        CYG_TEST_FAIL("CYG_PRECONDITION_THISC() did not trigger");
182
        break;
183
 
184
    case 37:
185
        CYG_POSTCONDITION_THIS(message);
186
        CYG_TEST_FAIL("CYG_POSTCONDITION_THIS() did not trigger");
187
        break;
188
 
189
    case 38:
190
        CYG_POSTCONDITION_THISC();
191
        CYG_TEST_FAIL("CYG_POSTCONDITION_THISC() did not trigger");
192
        break;
193
 
194
    case 39:
195
        CYG_LOOP_INVARIANT_THIS(message);
196
        CYG_TEST_FAIL("CYG_LOOP_INVARIANT_THIS() did not trigger");
197
        break;
198
 
199
    case 40:
200
        CYG_LOOP_INVARIANT_THISC();
201
        CYG_TEST_FAIL("CYG_LOOP_INVARIANT_THISC() did not trigger");
202
        break;
203
 
204
    default:
205
        CYG_TEST_FAIL("dummy::assertions() invoked for no reason");
206
        break;
207
    }
208
}
209
 
210
void
211
dummy::extern_assertions(dummy* obj)
212
{
213
    switch(counter) {
214
    case 41:
215
        CYG_ASSERT_ZERO_OR_CLASS(obj, message);
216
        CYG_TEST_FAIL("CYG_ASSERT_ZERO_OR_CLASS() did not trigger");
217
        break;
218
 
219
    case 42:
220
        CYG_ASSERT_ZERO_OR_CLASSC(obj);
221
        CYG_TEST_FAIL("CYG_ASSERT_ZERO_OR_CLASSC() did not trigger");
222
        break;
223
 
224
    case 43:
225
        CYG_PRECONDITION_ZERO_OR_CLASS(obj, message);
226
        CYG_TEST_FAIL("CYG_PRECONDITION_ZERO_OR_CLASS() did not trigger");
227
        break;
228
 
229
    case 44:
230
        CYG_PRECONDITION_ZERO_OR_CLASSC(obj);
231
        CYG_TEST_FAIL("CYG_PRECONDITION_ZERO_OR_CLASSC() did not trigger");
232
        break;
233
 
234
    case 45:
235
        CYG_POSTCONDITION_ZERO_OR_CLASS(obj, message);
236
        CYG_TEST_FAIL("CYG_POSTCONDITION_ZERO_OR_CLASS() did not trigger");
237
        break;
238
 
239
    case 46:
240
        CYG_POSTCONDITION_ZERO_OR_CLASSC(obj);
241
        CYG_TEST_FAIL("CYG_POSTCONDITION_ZERO_OR_CLASSC() did not trigger");
242
        break;
243
 
244
    case 47:
245
        CYG_LOOP_INVARIANT_ZERO_OR_CLASS(obj, message);
246
        CYG_TEST_FAIL("CYG_LOOP_INVARIANT_ZERO_OR_CLASS() did not trigger");
247
        break;
248
 
249
    case 48:
250
        CYG_LOOP_INVARIANT_ZERO_OR_CLASSC(obj);
251
        CYG_TEST_FAIL("CYG_LOOP_INVARIANT_ZERO_OR_CLASSC() did not trigger");
252
        break;
253
 
254
    default:
255
        CYG_TEST_FAIL("dummy::extern_assertions() invoked for no reason");
256
        break;
257
    }
258
 
259
}
260
 
261
extern "C"
262
bool
263
failure_handler(const char* fn, const char* file, cyg_uint32 line, const char* msg)
264
{
265
    failed_assertions++;
266
    counter++;
267
    longjmp(setjmp_buffer, 1);
268
    return true;
269
}
270
 
271
int
272
main(int argc, char** argv)
273
{
274
    dummy object;
275
 
276
    cyg_assert_install_failure_handler(&failure_handler);
277
    setjmp(setjmp_buffer);
278
 
279
    for ( bool done = false; !done; counter++ ) {
280
        switch(counter) {
281
        case 0:
282
            CYG_ASSERT(false, message);
283
            CYG_TEST_FAIL("CYG_ASSERT() did not trigger");
284
            break;
285
 
286
        case 1:
287
            CYG_ASSERTC(false);
288
            CYG_TEST_FAIL("CYG_ASSERTC() did not trigger");
289
            break;
290
 
291
        case 2:
292
            CYG_FAIL(message);
293
            CYG_TEST_FAIL("CYG_FAIL() did not trigger");
294
            break;
295
 
296
        case 3:
297
            CYG_CHECK_DATA_PTR(0, message);
298
            CYG_TEST_FAIL("CHECK_CHECK_DATA_PTR() did not trigger");
299
            break;
300
 
301
        case 4:
302
            CYG_CHECK_DATA_PTRC(0);
303
            CYG_TEST_FAIL("CHECK_CHECK_DATA_PTRC() did not trigger");
304
            break;
305
 
306
        case 5:
307
            CYG_CHECK_FUNC_PTR(0, message);
308
            CYG_TEST_FAIL("CHECK_CHECK_FUNC_PTR() did not trigger");
309
            break;
310
 
311
        case 6:
312
            CYG_CHECK_DATA_PTRC(0);
313
            CYG_TEST_FAIL("CHECK_CHECK_FUNC_PTRC() did not trigger");
314
            break;
315
 
316
        case 7:
317
            CYG_ASSERT_CLASS(&object, message);
318
            CYG_TEST_FAIL("CYG_ASSERT_CLASS() did not trigger");
319
            break;
320
 
321
        case 8:
322
            CYG_ASSERT_CLASSC(&object);
323
            CYG_TEST_FAIL("CYG_ASSERT_CLASSC() did not trigger");
324
            break;
325
 
326
        case 9:
327
            CYG_ASSERT_CLASSO(object, message);
328
            CYG_TEST_FAIL("CYG_ASSERT_CLASSO() did not trigger");
329
            break;
330
 
331
        case 10:
332
            CYG_ASSERT_CLASSOC(object);
333
            CYG_TEST_FAIL("CYG_ASSERT_CLASSOC() did not trigger");
334
            break;
335
 
336
        case 11:
337
            CYG_PRECONDITION(false, message);
338
            CYG_TEST_FAIL("CYG_PRECONDITION() did not trigger");
339
            break;
340
 
341
        case 12:
342
            CYG_PRECONDITIONC(false);
343
            CYG_TEST_FAIL("CYG_PRECONDITIONC() did not trigger");
344
            break;
345
 
346
        case 13:
347
            CYG_PRECONDITION_CLASS(&object, message);
348
            CYG_TEST_FAIL("CYG_PRECONDITION_CLASS() did not trigger");
349
            break;
350
 
351
        case 14:
352
            CYG_PRECONDITION_CLASSC(&object);
353
            CYG_TEST_FAIL("CYG_PRECONDITION_CLASSC() did not trigger");
354
            break;
355
 
356
        case 15:
357
            CYG_PRECONDITION_CLASSO(object, message);
358
            CYG_TEST_FAIL("CYG_PRECONDITION_CLASSO() did not trigger");
359
            break;
360
 
361
        case 16:
362
            CYG_PRECONDITION_CLASSOC(object);
363
            CYG_TEST_FAIL("CYG_PRECONDITION_CLASSOC() did not trigger");
364
            break;
365
 
366
        case 17:
367
            CYG_POSTCONDITION(false, message);
368
            CYG_TEST_FAIL("CYG_POSTCONDITION() did not trigger");
369
            break;
370
 
371
        case 18:
372
            CYG_POSTCONDITIONC(false);
373
            CYG_TEST_FAIL("CYG_POSTCONDITIONC() did not trigger");
374
            break;
375
 
376
        case 19:
377
            CYG_POSTCONDITION_CLASS(&object, message);
378
            CYG_TEST_FAIL("CYG_POSTCONDITION_CLASS() did not trigger");
379
            break;
380
 
381
        case 20:
382
            CYG_POSTCONDITION_CLASSC(&object);
383
            CYG_TEST_FAIL("CYG_POSTCONDITION_CLASSC() did not trigger");
384
            break;
385
 
386
        case 21:
387
            CYG_POSTCONDITION_CLASSO(object, message);
388
            CYG_TEST_FAIL("CYG_POSTCONDITION_CLASSO() did not trigger");
389
            break;
390
 
391
        case 22:
392
            CYG_POSTCONDITION_CLASSOC(object);
393
            CYG_TEST_FAIL("CYG_POSTCONDITION_CLASSOC() did not trigger");
394
            break;
395
 
396
        case 23:
397
            CYG_LOOP_INVARIANT(false, message);
398
            CYG_TEST_FAIL("CYG_LOOP_INVARIANT() did not trigger");
399
            break;
400
 
401
        case 24:
402
            CYG_LOOP_INVARIANTC(false);
403
            CYG_TEST_FAIL("CYG_LOOP_INVARIANTC() did not trigger");
404
            break;
405
 
406
        case 25:
407
            CYG_LOOP_INVARIANT_CLASS(&object, message);
408
            CYG_TEST_FAIL("CYG_LOOP_INVARIANT_CLASS() did not trigger");
409
            break;
410
 
411
        case 26:
412
            CYG_LOOP_INVARIANT_CLASSC(&object);
413
            CYG_TEST_FAIL("CYG_LOOP_INVARIANT_CLASSC() did not trigger");
414
            break;
415
 
416
        case 27:
417
            CYG_LOOP_INVARIANT_CLASSO(object, message);
418
            CYG_TEST_FAIL("CYG_LOOP_INVARIANT_CLASSO() did not trigger");
419
            break;
420
 
421
        case 28:
422
            CYG_LOOP_INVARIANT_CLASSOC(object);
423
            CYG_TEST_FAIL("CYG_LOOP_INVARIANT_CLASSOC() did not trigger");
424
            break;
425
 
426
        case 29:
427
            CYG_INVARIANT(false, message);
428
            CYG_TEST_FAIL("CYG_INVARIANT() did not trigger");
429
            break;
430
 
431
        case 30:
432
            CYG_INVARIANTC(false);
433
            CYG_TEST_FAIL("CYG_INVARIANTC() did not trigger");
434
            break;
435
 
436
        case 31:
437
            object.invariant1();
438
            break;
439
 
440
        case 32:
441
            object.invariant2();
442
            break;
443
 
444
        case 33:
445
        case 34:
446
        case 35:
447
        case 36:
448
        case 37:
449
        case 38:
450
        case 39:
451
        case 40:
452
            object.assertions();
453
            break;
454
 
455
        case 41:
456
        case 42:
457
        case 43:
458
        case 44:
459
        case 45:
460
        case 46:
461
        case 47:
462
        case 48:
463
            dummy::extern_assertions(&object);
464
            break;
465
 
466
        case 49:
467
            dummy::invariant3(object);
468
            break;
469
 
470
        case 50:
471
            dummy::invariant4(object);
472
            break;
473
 
474
        case 51:
475
            dummy::invariant5(&object);
476
            break;
477
 
478
        case 52:
479
            dummy::invariant6(&object);
480
            break;
481
 
482
        default:
483
            done = true;
484
            counter--;  // About to get incremented again...
485
            break;
486
        }
487
    }
488
 
489
    if (failed_assertions != 53) {
490
        CYG_TEST_FAIL("Broken test case, not all assertions have been tried");
491
    }
492
 
493
    if (failed_assertions == counter) {
494
        CYG_TEST_PASS("All assertions trigger successfully");
495
    } else {
496
        CYG_TEST_FAIL("Not all assertions trigger");
497
    }
498
 
499
    return 0;
500
}
501
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.