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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [host/] [infra/] [testsuite/] [cyginfra/] [tassert7.cxx] - Blame information for rev 790

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

Line No. Rev Author Line
1 786 skrzyp
//==========================================================================
2
//
3
//      tassert7.cxx
4
//
5
//      Assertion test case                                                                
6
//
7
//==========================================================================
8
// ####ECOSHOSTGPLCOPYRIGHTBEGIN####                                        
9
// -------------------------------------------                              
10
// This file is part of the eCos host tools.                                
11
// Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc.            
12
//
13
// This program is free software; you can redistribute it and/or modify     
14
// it under the terms of the GNU General Public License as published by     
15
// the Free Software Foundation; either version 2 or (at your option) any   
16
// later version.                                                           
17
//
18
// This program is distributed in the hope that it will be useful, but      
19
// WITHOUT ANY WARRANTY; without even the implied warranty of               
20
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU        
21
// General Public License for more details.                                 
22
//
23
// You should have received a copy of the GNU General Public License        
24
// along with this program; if not, write to the                            
25
// Free Software Foundation, Inc., 51 Franklin Street,                      
26
// Fifth Floor, Boston, MA  02110-1301, USA.                                
27
// -------------------------------------------                              
28
// ####ECOSHOSTGPLCOPYRIGHTEND####                                          
29
//==========================================================================
30
//#####DESCRIPTIONBEGIN####                                             
31
//
32
// Author(s):           bartv
33
// Contributors:        bartv
34
// Date:                1998-12-23
35
// Purpose:
36
// Description:         This routine checks the invariant assertions.
37
//                      The entry tests will have been taken care of by
38
//                      tassert6.cxx, but it is also necessary to check
39
//                      the exit tests.
40
//
41
//####DESCRIPTIONEND####
42
//==========================================================================
43
 
44
 
45
#define CYG_DECLARE_HOST_ASSERTION_SUPPORT
46
#define CYGDBG_USE_ASSERTS
47
#define CYGDBG_INFRA_DEBUG_PRECONDITIONS
48
#define CYGDBG_INFRA_DEBUG_POSTCONDITIONS
49
#define CYGDBG_INFRA_DEBUG_LOOP_INVARIANTS
50
#define CYGDBG_INFRA_DEBUG_INVARIANTS
51
 
52
#include <cyg/infra/testcase.h>
53
#include <cyg/infra/cyg_ass.h>
54
#include <cstdlib>
55
#include <csetjmp>
56
#include <cstring>
57
 
58
// This is used to "recover" from an assertion failure
59
static jmp_buf setjmp_buffer;
60
 
61
// The number of assertions that have triggered.
62
static int failed_assertions = 0;
63
 
64
// The number of assertions that have been triggered.
65
static int counter = 0;
66
 
67
// Are objects currently valid?
68
static bool check_this_should_fail = false;
69
 
70
static const char message[] = "so long and thanks for all the fish";
71
 
72
class dummy {
73
  private:
74
    int         random;
75
 
76
  public:
77
    dummy() {
78
        random = rand();
79
    }
80
    ~dummy() {
81
        random = 0;
82
    }
83
 
84
    void invariant1();
85
    void invariant2();
86
    static void invariant3(dummy&);
87
    static void invariant4(dummy&);
88
    static void invariant5(dummy*);
89
    static void invariant6(dummy*);
90
    bool check_this(cyg_assert_class_zeal) const;
91
};
92
 
93
bool
94
dummy::check_this(cyg_assert_class_zeal zeal) const
95
{
96
    // The default zeal should be cyg_quick.
97
    switch(zeal) {
98
    case cyg_quick:
99
        return !check_this_should_fail;
100
 
101
    case cyg_system_test:
102
    case cyg_extreme:
103
    case cyg_thorough:
104
    case cyg_trivial:
105
    case cyg_none:
106
        CYG_TEST_FAIL_FINISH("incorrect default zeal passed to check_this() member function");
107
        break;
108
    default:
109
        CYG_TEST_FAIL_FINISH("invalid zeal passed to check_this() member function");
110
        break;
111
    }
112
    return false;
113
}
114
 
115
void
116
dummy::invariant1(void)
117
{
118
    CYG_INVARIANT_THIS(dummy, message);
119
    check_this_should_fail = true;
120
}
121
 
122
void
123
dummy::invariant2(void)
124
{
125
    CYG_INVARIANT_THISC(dummy);
126
    check_this_should_fail = true;
127
}
128
 
129
void
130
dummy::invariant3(dummy& obj)
131
{
132
    CYG_INVARIANT_CLASSO(dummy, obj, message);
133
    check_this_should_fail = true;
134
}
135
 
136
void
137
dummy::invariant4(dummy& obj)
138
{
139
    CYG_INVARIANT_CLASSOC(dummy, obj);
140
    check_this_should_fail = true;
141
}
142
 
143
void
144
dummy::invariant5(dummy* obj)
145
{
146
    CYG_INVARIANT_CLASS(dummy, obj, message);
147
    check_this_should_fail = true;
148
}
149
 
150
void
151
dummy::invariant6(dummy* obj)
152
{
153
    CYG_INVARIANT_CLASSC(dummy, obj);
154
    check_this_should_fail = true;
155
}
156
 
157
extern "C"
158
bool
159
failure_handler(const char* fn, const char* file, cyg_uint32 line, const char* msg)
160
{
161
    if (false == check_this_should_fail) {
162
        CYG_TEST_FAIL("assertion triggered when everything should be ok");
163
    }
164
    failed_assertions++;
165
    counter++;
166
    longjmp(setjmp_buffer, 1);
167
    return true;
168
}
169
 
170
int
171
main(int argc, char **argv)
172
{
173
    dummy object;
174
 
175
    cyg_assert_install_failure_handler(&failure_handler);
176
    setjmp(setjmp_buffer);
177
 
178
    for ( bool done = false; !done; counter++ ) {
179
        check_this_should_fail = false;
180
 
181
        switch(counter) {
182
        case 0:
183
            object.invariant1();
184
            CYG_TEST_FAIL("CYG_INVARIANT_THIS() test should not have returned");
185
            break;
186
 
187
        case 1:
188
            object.invariant2();
189
            CYG_TEST_FAIL("CYG_INVARIANT_THISC() test should not have returned");
190
            break;
191
 
192
        case 2:
193
            dummy::invariant3(object);
194
            CYG_TEST_FAIL("CYG_INVARIANT_CLASSO() test should not have returned");
195
            break;
196
 
197
        case 3:
198
            dummy::invariant4(object);
199
            CYG_TEST_FAIL("CYG_INVARIANT_CLASSOC() test should not have returned");
200
            break;
201
 
202
        case 4:
203
            dummy::invariant5(&object);
204
            CYG_TEST_FAIL("CYG_INVARIANT_CLASS() test should not have returned");
205
            break;
206
 
207
        case 5:
208
            dummy::invariant6(&object);
209
            CYG_TEST_FAIL("CYG_INVARIANT_CLASSC() test should not have returned");
210
            break;
211
 
212
        default:
213
            done = true;
214
            counter--;  // About to get incremented again...
215
            break;
216
        }
217
    }
218
 
219
    if (failed_assertions != 6) {
220
        CYG_TEST_FAIL("Broken test case, not all assertions have been tried");
221
    }
222
 
223
    if (failed_assertions == counter) {
224
        CYG_TEST_PASS("All assertions trigger successfully");
225
    } else {
226
        CYG_TEST_FAIL("Not all assertions trigger");
227
    }
228
    return 0;
229
}

powered by: WebSVN 2.1.0

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