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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [host/] [infra/] [testsuite/] [cyginfra/] [assert.exp] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
#===============================================================================
2
#
3
#    assert.exp
4
#
5
#    Assertion test cases
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-11-25
35
#
36
#####DESCRIPTIONEND####
37
#===============================================================================
38
 
39
# ----------------------------------------------------------------------------
40
# Start with the simple tests.
41
${tool}_load tassert1
42
${tool}_load tassert2
43
${tool}_load tassert3
44
${tool}_load tassert4
45
 
46
# tassert5 is not buildable under Linux. It is a C program linked with
47
# a C++ library, and there are dependencies on the default new and
48
# delete operators which are not satisfied.
49
 
50
if { [string match "cl*" $::hosttest_data(CC)] } {
51
    ${tool}_load tassert5
52
} else {
53
    unsupported "using the infrastructure from C code"
54
}
55
 
56
${tool}_load tassert6
57
${tool}_load tassert7
58
 
59
# ----------------------------------------------------------------------------
60
# tassert8 is a bit more complicated. It involves an assertion which
61
# is not caught in any way by the application code. Therefore the
62
# output of the program has to be analysed to make sure it is
63
# reasonable. There is also going to be a dump file that needs
64
# to be analysed and cleaned up.
65
 
66
proc tassert8_filter { name result output } {
67
 
68
    set all_ok 1
69
 
70
    if { $result == 0 } {
71
        fail "testcase $name should have a non-zero exit code"
72
        set all_ok 0
73
    }
74
 
75
    # Convert the output to a list of lines.
76
    set lines [split $output "\n"]
77
 
78
    # The first line of interest should contain the phrase
79
    # "Assertion failure" and the string embedded in tassert8.cxx
80
    while { 1 } {
81
        if { [llength $lines] == 0 } {
82
            set all_ok 0
83
            fail "No \"Assertion failure\" message detected in program output"
84
            break
85
        }
86
        set line  [lindex $lines 0]
87
        set lines [lreplace $lines 0 0]
88
        if { [regexp -nocase -- {^assertion failure.*it seemed like a good idea at the time$} $line] } {
89
            break
90
        }
91
    }
92
 
93
    # The next line should indicate the file and the line number
94
    if { [llength $lines] == 0 } {
95
        set all_ok 0
96
        fail "No file name or line number information"
97
    } else {
98
        set line  [lindex $lines 0]
99
        set lines [lreplace $lines 0 0]
100
        if { [regexp -nocase -- {^file .*tassert8.cxx.*line number [0-9]+$} $line] == 0} {
101
            fail "Output did not contain the expected filename and linenumber"
102
        }
103
    }
104
    # There may or may not be a line containing the function name.
105
    # This should not be checked, it depends on compiler support
106
    # for __PRETTY_FUNCTION__. The next line of interest is
107
    # "Writing additional output to xxx", where xxx is a filename.
108
    while { 1 } {
109
        if { [llength $lines] == 0 } {
110
            set all_ok 0
111
            fail "Output did not specify where the dump information was stored"
112
            break
113
        } else {
114
            set line  [lindex $lines 0]
115
            set lines [lreplace $lines 0 0]
116
            set dummy ""
117
            set match ""
118
            if { [regexp -- {^Writing additional output to (.*)$} $line dummy match] } {
119
                tassert8_process_dump $match all_ok
120
                break
121
            }
122
        }
123
    }
124
 
125
    if { $all_ok } {
126
        pass "Assertions generate sensible output"
127
    }
128
 
129
    return 0
130
}
131
 
132
proc tassert8_process_dump { filename all_ok_arg } {
133
 
134
    upvar $all_ok_arg all_ok
135
    set realname [hosttest_translate_existing_filename $filename]
136
    if { $realname == "" } {
137
        set all_ok 0
138
        fail "Unable to find assertion dump file $filename"
139
        return
140
    }
141
    set lines {}
142
    set status [ catch {
143
        set fd   [open $realname r]
144
        set data [read $fd]
145
        close $fd
146
        set lines [split $data "\n"]
147
        if { [llength $lines] == 0 } {
148
            set all_ok 0
149
            fail "The assertion dump file $realname contains no data"
150
        }
151
    } message ]
152
    if { $status != 0 } {
153
        set all_ok 0
154
        fail "Unable to open assertion output file $realname, $message"
155
    }
156
    set status [ catch { file delete $realname } message ]
157
    if { $status != 0 } {
158
        warning "Unable to delete assertion dump file $realname, $message" 0
159
    }
160
    if { [llength $lines] == 0 } {
161
        return
162
    }
163
 
164
    # We have some data to process. The information should include
165
    # the following:
166
    # 1) a line Assertion failure msg
167
    # 2) a line with the filename and the linenumber
168
    # 3) optionally a line with the function name. This depends on
169
    #    compiler support.
170
    # 4) information from callback1
171
    # 5) information from callback2
172
    #
173
    # The relative order of (4) and (5) is not defined.
174
    while { 1 } {
175
        if { [llength $lines] == 0 } {
176
            set all_ok 0
177
            fail "No \"Assertion failure\" message detected in output file"
178
            break
179
        }
180
        set line  [lindex $lines 0]
181
        set lines [lreplace $lines 0 0]
182
        if { [regexp -nocase -- {^assertion failure.*it seemed like a good idea at the time$} $line] } {
183
            break
184
        }
185
    }
186
 
187
    if { [llength $lines] == 0 } {
188
        set all_ok 0
189
        fail "No file name or line number information"
190
    } else {
191
        set line  [lindex $lines 0]
192
        set lines [lreplace $lines 0 0]
193
        if { [regexp -nocase -- {^file .*tassert8.cxx.*line number [0-9]+$} $line] == 0} {
194
            set all_ok 0
195
            fail "Output did not contain the expected filename and linenumber"
196
        }
197
    }
198
 
199
    set seen_callback1 0
200
    set seen_callback2 0
201
    while { [llength $lines] > 0 } {
202
 
203
        set line  [lindex $lines 0]
204
        set lines [lreplace $lines 0 0]
205
 
206
        if { [regexp -nocase -- {^\# \{\{\{.*callback1.*$} $line] } {
207
            if { $seen_callback1 != 0 } {
208
                set all_ok 0
209
                fail "Output contains multiple occurrences of callback1"
210
                continue
211
            }
212
            set seen_callback1 1
213
 
214
            while { [llength $lines] > 0 } {
215
                set line  [lindex   $lines 0]
216
                set lines [lreplace $lines 0 0]
217
 
218
                if { [regexp -nocase -- {^\# \}\}\}.*$} $line] } {
219
                    break
220
                }
221
 
222
                # callback1 should not generate any output so only blank lines
223
                # are acceptable
224
                if { [regexp -nocase -- {^ *$} $line] != 1} {
225
                    set all_ok 0
226
                    fail "Unexpected data in callback1 output: $line"
227
                    # Do not repeat this failure message. This break will
228
                    # do near enough the right thing.
229
                    break
230
                }
231
            }
232
 
233
        } elseif  { [regexp -nocase -- {^\# \{\{\{.*callback2.*$} $line] } {
234
            if { $seen_callback2 != 0 } {
235
                set all_ok 0
236
                fail "Output contains multiple occurrences of callback2"
237
            }
238
            set seen_callback2 1
239
 
240
            while { [llength $lines] > 0 } {
241
                set line  [lindex   $lines 0]
242
                set lines [lreplace $lines 0 0]
243
 
244
                if { [regexp -nocase -- {^\# \}\}\}.*$} $line] } {
245
                    break
246
                }
247
 
248
                # callback2 is allowed to generate blank lines and
249
                # fixed lines.
250
                if { [regexp -nocase -- {^ *$} $line] == 1 } {
251
                    continue
252
                }
253
                if { $line == "callback2 output" } {
254
                    continue
255
                }
256
                set all_ok 0
257
                fail "Unexpected data in callback2 output: $line"
258
            }
259
 
260
        }
261
    }
262
    if { ($seen_callback1 == 0) || ($seen_callback2 == 0) } {
263
        set all_ok 0
264
        fail "Output did not contain all the callback information"
265
    }
266
}
267
 
268
hosttest_run_test_with_filter tassert8 tassert8_filter {} {} {} cyginfra {}
269
 
270
# ----------------------------------------------------------------------------
271
# Strictly speaking this is not an assertion test. However there are some
272
# support routines in hosttest.exp which are tried closely to the
273
# implementation of the assertion code, and it is worthwhile checking
274
# these. The tassert8 testcase can be reused for this.
275
 
276
proc tassert9_filter { name result output } {
277
 
278
    if { [hosttest_assert_check $result $output] == 0 } {
279
        fail "testcase did not generate a recognised assertion"
280
        return
281
    }
282
 
283
    set output [hosttest_assert_read_dump $output]
284
    if { $output == "" } {
285
        fail "testcase did not generate a recognised assertion dump"
286
        return
287
    }
288
 
289
    set all_ok 1
290
 
291
    set callback1_output [hosttest_assert_extract_callback $output "callback1"]
292
    set callback2_output [hosttest_assert_extract_callback $output "callback2"]
293
 
294
    # Callback1 output should be empty, all blank lines should have been filtered
295
    # out.
296
    if { $callback1_output != "" } {
297
        set all_ok 0
298
        fail "callback1 output should be empty"
299
    }
300
    set lines [split $callback2_output "\n"]
301
    if { [llength $lines] == 0 } {
302
        set all_ok 0
303
        fail "callback2 should have produced some output"
304
    } elseif { [llength $lines] < 10} {
305
        set all_ok 0
306
        fail "callback2 is supposted to have at least ten lines of output"
307
    } else {
308
        # There should be ten lines of output, possibly followed by
309
        # some blanks.
310
        for { set i 0 } { $i < 10 } { incr i } {
311
            set line  [lindex $lines 0]
312
            set lines [lreplace $lines 0 0]
313
            if { $line != "callback2 output" } {
314
                set all_ok 0
315
                fail "incorrect output from callback2"
316
                break
317
            }
318
        }
319
 
320
        while { [llength $lines] > 0 } {
321
            set line  [lindex $lines 0]
322
            set lines [lreplace $lines 0 0]
323
            if { [regexp -- {^ *$} $line] != 1 } {
324
                set all_ok 0
325
                fail "callback2 output contains unexpected data"
326
                break
327
            }
328
        }
329
    }
330
 
331
    if { $all_ok } {
332
        pass "assertion output and dump file format match test harness expectations"
333
    }
334
    return 0
335
}
336
 
337
hosttest_run_test_with_filter tassert9 tassert9_filter tassert8.cxx {} {} cyginfra {}
338
 

powered by: WebSVN 2.1.0

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