1 #===============================================================================
7 #===============================================================================
8 ######COPYRIGHTBEGIN####
10 # ----------------------------------------------------------------------------
11 # Copyright (C) 1998, 1999, 2000 Red Hat, Inc.
13 # This file is part of the eCos host tools.
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)
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
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.
29 # ----------------------------------------------------------------------------
31 ######COPYRIGHTEND####
32 #===============================================================================
33 ######DESCRIPTIONBEGIN####
39 #####DESCRIPTIONEND####
40 #===============================================================================
42 # ----------------------------------------------------------------------------
43 # Start with the simple tests.
49 # tassert5 is not buildable under Linux. It is a C program linked with
50 # a C++ library, and there are dependencies on the default new and
51 # delete operators which are not satisfied.
53 if { [string match "cl*" $::hosttest_data(CC)] } {
56 unsupported "using the infrastructure from C code"
62 # ----------------------------------------------------------------------------
63 # tassert8 is a bit more complicated. It involves an assertion which
64 # is not caught in any way by the application code. Therefore the
65 # output of the program has to be analysed to make sure it is
66 # reasonable. There is also going to be a dump file that needs
67 # to be analysed and cleaned up.
69 proc tassert8_filter { name result output } {
74 fail "testcase $name should have a non-zero exit code"
78 # Convert the output to a list of lines.
79 set lines [split $output "\n"]
81 # The first line of interest should contain the phrase
82 # "Assertion failure" and the string embedded in tassert8.cxx
84 if { [llength $lines] == 0 } {
86 fail "No \"Assertion failure\" message detected in program output"
89 set line [lindex $lines 0]
90 set lines [lreplace $lines 0 0]
91 if { [regexp -nocase -- {^assertion failure.*it seemed like a good idea at the time$} $line] } {
96 # The next line should indicate the file and the line number
97 if { [llength $lines] == 0 } {
99 fail "No file name or line number information"
101 set line [lindex $lines 0]
102 set lines [lreplace $lines 0 0]
103 if { [regexp -nocase -- {^file .*tassert8.cxx.*line number [0-9]+$} $line] == 0} {
104 fail "Output did not contain the expected filename and linenumber"
107 # There may or may not be a line containing the function name.
108 # This should not be checked, it depends on compiler support
109 # for __PRETTY_FUNCTION__. The next line of interest is
110 # "Writing additional output to xxx", where xxx is a filename.
112 if { [llength $lines] == 0 } {
114 fail "Output did not specify where the dump information was stored"
117 set line [lindex $lines 0]
118 set lines [lreplace $lines 0 0]
121 if { [regexp -- {^Writing additional output to (.*)$} $line dummy match] } {
122 tassert8_process_dump $match all_ok
129 pass "Assertions generate sensible output"
135 proc tassert8_process_dump { filename all_ok_arg } {
137 upvar $all_ok_arg all_ok
138 set realname [hosttest_translate_existing_filename $filename]
139 if { $realname == "" } {
141 fail "Unable to find assertion dump file $filename"
146 set fd [open $realname r]
149 set lines [split $data "\n"]
150 if { [llength $lines] == 0 } {
152 fail "The assertion dump file $realname contains no data"
155 if { $status != 0 } {
157 fail "Unable to open assertion output file $realname, $message"
159 set status [ catch { file delete $realname } message ]
160 if { $status != 0 } {
161 warning "Unable to delete assertion dump file $realname, $message" 0
163 if { [llength $lines] == 0 } {
167 # We have some data to process. The information should include
169 # 1) a line Assertion failure msg
170 # 2) a line with the filename and the linenumber
171 # 3) optionally a line with the function name. This depends on
173 # 4) information from callback1
174 # 5) information from callback2
176 # The relative order of (4) and (5) is not defined.
178 if { [llength $lines] == 0 } {
180 fail "No \"Assertion failure\" message detected in output file"
183 set line [lindex $lines 0]
184 set lines [lreplace $lines 0 0]
185 if { [regexp -nocase -- {^assertion failure.*it seemed like a good idea at the time$} $line] } {
190 if { [llength $lines] == 0 } {
192 fail "No file name or line number information"
194 set line [lindex $lines 0]
195 set lines [lreplace $lines 0 0]
196 if { [regexp -nocase -- {^file .*tassert8.cxx.*line number [0-9]+$} $line] == 0} {
198 fail "Output did not contain the expected filename and linenumber"
204 while { [llength $lines] > 0 } {
206 set line [lindex $lines 0]
207 set lines [lreplace $lines 0 0]
209 if { [regexp -nocase -- {^\# \{\{\{.*callback1.*$} $line] } {
210 if { $seen_callback1 != 0 } {
212 fail "Output contains multiple occurrences of callback1"
217 while { [llength $lines] > 0 } {
218 set line [lindex $lines 0]
219 set lines [lreplace $lines 0 0]
221 if { [regexp -nocase -- {^\# \}\}\}.*$} $line] } {
225 # callback1 should not generate any output so only blank lines
227 if { [regexp -nocase -- {^ *$} $line] != 1} {
229 fail "Unexpected data in callback1 output: $line"
230 # Do not repeat this failure message. This break will
231 # do near enough the right thing.
236 } elseif { [regexp -nocase -- {^\# \{\{\{.*callback2.*$} $line] } {
237 if { $seen_callback2 != 0 } {
239 fail "Output contains multiple occurrences of callback2"
243 while { [llength $lines] > 0 } {
244 set line [lindex $lines 0]
245 set lines [lreplace $lines 0 0]
247 if { [regexp -nocase -- {^\# \}\}\}.*$} $line] } {
251 # callback2 is allowed to generate blank lines and
253 if { [regexp -nocase -- {^ *$} $line] == 1 } {
256 if { $line == "callback2 output" } {
260 fail "Unexpected data in callback2 output: $line"
265 if { ($seen_callback1 == 0) || ($seen_callback2 == 0) } {
267 fail "Output did not contain all the callback information"
271 hosttest_run_test_with_filter tassert8 tassert8_filter {} {} {} cyginfra {}
273 # ----------------------------------------------------------------------------
274 # Strictly speaking this is not an assertion test. However there are some
275 # support routines in hosttest.exp which are tried closely to the
276 # implementation of the assertion code, and it is worthwhile checking
277 # these. The tassert8 testcase can be reused for this.
279 proc tassert9_filter { name result output } {
281 if { [hosttest_assert_check $result $output] == 0 } {
282 fail "testcase did not generate a recognised assertion"
286 set output [hosttest_assert_read_dump $output]
287 if { $output == "" } {
288 fail "testcase did not generate a recognised assertion dump"
294 set callback1_output [hosttest_assert_extract_callback $output "callback1"]
295 set callback2_output [hosttest_assert_extract_callback $output "callback2"]
297 # Callback1 output should be empty, all blank lines should have been filtered
299 if { $callback1_output != "" } {
301 fail "callback1 output should be empty"
303 set lines [split $callback2_output "\n"]
304 if { [llength $lines] == 0 } {
306 fail "callback2 should have produced some output"
307 } elseif { [llength $lines] < 10} {
309 fail "callback2 is supposted to have at least ten lines of output"
311 # There should be ten lines of output, possibly followed by
313 for { set i 0 } { $i < 10 } { incr i } {
314 set line [lindex $lines 0]
315 set lines [lreplace $lines 0 0]
316 if { $line != "callback2 output" } {
318 fail "incorrect output from callback2"
323 while { [llength $lines] > 0 } {
324 set line [lindex $lines 0]
325 set lines [lreplace $lines 0 0]
326 if { [regexp -- {^ *$} $line] != 1 } {
328 fail "callback2 output contains unexpected data"
335 pass "assertion output and dump file format match test harness expectations"
340 hosttest_run_test_with_filter tassert9 tassert9_filter tassert8.cxx {} {} cyginfra {}