aboutsummaryrefslogtreecommitdiff
path: root/testsuite/report-card.all/passes.exp
blob: 012e9ac97fef63e78fd996981c73e540e0fd5e4c (plain)
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
276
# Copyright (C) 2018 Free Software Foundation, Inc.
#
# This file is part of DejaGnu.
#
# DejaGnu 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 3 of the License, or
# (at your option) any later version.
#
# DejaGnu 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 DejaGnu; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.

# This file was written by Jacob Bachmeyer.

load_lib bohman_ssd.exp

set header_column_names { PASS FAIL ?PASS ?FAIL UNSUP UNRES UNTEST }
set result_column_map {
    PASS FAIL { KPASS XPASS } { KFAIL XFAIL }
    UNSUPPORTED UNRESOLVED UNTESTED
}

set test_results { PASS FAIL KPASS KFAIL XPASS XFAIL
		   UNSUPPORTED UNRESOLVED UNTESTED }

# each entry: { {mode n} { suffix_tag... } { pass... } { { result name }... } }
array unset tuplemap
array set tuplemap {
    basic	{ {S  3} { a b } { foo bar }
	{ { PASS pass } { FAIL fail } } }
    kxpass	{ {S  2} { a b } { foo bar }
	{ { KPASS kpass } { XPASS xpass } } }
    kxfail	{ {Sp 2} { a b } { foo bar }
	{ { KFAIL kfail } { XFAIL xfail } } }
    unresult	{ {S  2} { a b } { foo bar }
	{ { UNSUPPORTED unsupported }
	    { UNRESOLVED unresolved } { UNTESTED untested } } }
}

# Given: TUPLES: { { result ... }... }, PASSES: { pass... }
# Return: Cartesian product TUPLES x PASSES: { { result pass ... }... }
proc build_tuple_list { tuples passes } {
    set result [list]
    foreach cell $tuples {
	foreach pass $passes {
	    lappend result [linsert $cell 1 $pass]
	}
    }
    return $result
}

# Given: TUPLES: { { result pass name }... }, MODE: S | Sp, N
# Return: { { result pass name count }... } where COUNT is from an SSD-set
proc annotate_tuple_list { tuples mode n } {
    set m [llength $tuples]
    set ssd [switch -- $mode {
	S  { ::math_utils::Bohman_SSD::S  $n $m }
	Sp { ::math_utils::Bohman_SSD::Sp $n $m }
    }]
    set result [list]
    foreach cell $tuples ssdterm $ssd {
	lappend result [linsert $cell end $ssdterm]
    }
    return $result
}

# Given: TUPLES: { { result pass name count }... }; (RESULT,PASS) not unique
# Return: { { result pass expected_total }... } where (RESULT,PASS) is unique
proc compute_expected_pass_totals { tuples } {
    foreach cell $tuples {  set count([lrange $cell 0 1]) 0 }
    foreach cell $tuples { incr count([lrange $cell 0 1]) [lindex $cell 3] }
    set result [list]
    foreach name [lsort [array names count]] {
	lappend result [concat $name $count($name)]
    }
    return $result
}

# Given: TUPLES: { { result pass name count }... }; (RESULT,PASS) not unique
# Return: { { result expected_grand_total }... }
proc compute_expected_grand_totals { tuples } {
    foreach cell $tuples {  set count([lindex $cell 0]) 0 }
    foreach cell $tuples { incr count([lindex $cell 0]) [lindex $cell 3] }
    set result [list]
    foreach name [lsort [array names count]] {
	lappend result [list $name $count($name)]
    }
    return $result
}

# Given: TUPLES: { { result pass ... }... } where (RESULT,PASS) repeats later
# Return: { { { result pass ... }... }... }; (RESULT,PASS) unique per sublist
proc split_tuple_list { tuples } {
    set result [list]
    set sublist [list]
    foreach cell $tuples {
	if { [info exists seen([lrange $cell 0 1])] } {
	    # split here
	    lappend result $sublist
	    set sublist [list]
	    array unset seen
	}
	lappend sublist $cell
	set seen([lrange $cell 0 1]) 1
    }
    lappend result $sublist
    return $result
}

# TUPLES is: { { result pass name count }... }
proc write_file { basename tuples } {
    set fd [open [testsuite file -object -test passes ${basename}.sum] w]
    set pass {}
    foreach cell [lsort -index 1 $tuples] {
	if { $pass ne [lindex $cell 1] } {
	    puts $fd "Running pass `[lindex $cell 1]' ..."
	    set pass [lindex $cell 1]
	}
	for { set i 1 } { $i <= [lindex $cell 3] } { incr i } {
	    puts $fd "[lindex $cell 0]: [lindex $cell 1]:\
			[lindex $cell 2] test ${i}/[lindex $cell 3]"
	}
    }
    close $fd
}

proc run_multipass_output_test { filetag } {
    global LAUNCHER
    global header_column_names
    global result_column_map
    global test_results
    global tuplemap

    set ssdpar	[lindex $tuplemap($filetag) 0]
    set tags	[lindex $tuplemap($filetag) 1]
    set passes	[lindex $tuplemap($filetag) 2]
    set results	{}
    foreach dummy $tags { lappend results [lindex $tuplemap($filetag) 3] }
    set results [join $results]

    # initialize totals arrays to zero
    foreach result $test_results { set have_grand_totals($result) 0 }
    array set want_grand_totals [array get have_grand_totals]
    foreach cell [build_tuple_list $test_results $passes] {
	set have_pass_totals([join [lrange $cell 0 1] ","]) 0
    }
    array set want_pass_totals [array get have_pass_totals]

    # get the test list
    set list [build_tuple_list $results $passes]
    set list [annotate_tuple_list $list [lindex $ssdpar 0] [lindex $ssdpar 1]]

    # compute expected totals
    #  note that this only fills non-zero array positions
    foreach cell [compute_expected_pass_totals $list] {
	set want_pass_totals([join [lrange $cell 0 1] ","]) [lindex $cell 2]
    }
    array set want_grand_totals [join [compute_expected_grand_totals $list]]

    # write the test data files and store expected per-file counts
    foreach tag $tags fileset [split_tuple_list $list] {
	# write test file
	write_file "${filetag}-${tag}" $fileset
	# initialize test results for this file
	foreach result $test_results {
	    foreach pass $passes {
		set want_file_counts(${filetag}-${tag},$result,$pass) 0
		set have_file_counts(${filetag}-${tag},$result,$pass) 0
	    }
	}
	# store expected results for this file
	foreach cell $fileset {
	    set want_file_counts(${filetag}-${tag},[join [lrange $cell 0 1] \
							","]) [lindex $cell 3]
	}
    }

    # run the dejagnu-report-card tool
    set separator_count 0
    spawn /bin/sh -c \
	"cd [testsuite file -object -test passes]\
	 && exec $LAUNCHER report-card ${filetag}-*.sum"

    # skip header
    expect {
	-re {^[[:space:]]+_+[\r\n]+} { exp_continue }
	-re {^[[:space:]]+/([^\r\n]*)[\r\n]+} { exp_continue }
	-re {^[[:space:]]+\|-+[\r\n]+} { incr separator_count }
    }

    # read individual file lines
    set re_file_row {^[[:space:]]*}
    append re_file_row {(} $filetag {-[[:alpha:]]+)[[:space:]]+}
    append re_file_row {/[[:space:]]+([[:alpha:]]+)[[:space:]]+\|}
    append re_file_row {[[:space:]]*([[:digit:][:space:]]+)[\r\n]+}
    expect {
	-re $re_file_row {
	    foreach column $result_column_map colname $header_column_names \
		have $expect_out(3,string) {
		    set want 0
		    foreach rs $column {
			set tmp $expect_out(1,string),$rs,$expect_out(2,string)
			incr want $want_file_counts($tmp)
		    }
		    if { $have == $want } {
			pass "count $colname\
			      for pass $expect_out(2,string)\
			      in file $expect_out(1,string)"
		    } else {
			fail "count $colname\
			      for pass $expect_out(2,string)\
			      in file $expect_out(1,string)"
		    }
		}
	    exp_continue
	}
	-re {^[[:space:]]+\|-+[\r\n]+} { incr separator_count }
    }

    # read pass totals lines
    set re_pass_row {^[[:space:]]+([[:alpha:]]+)[[:space:]]+\|}
    append re_pass_row {[[:space:]]*([[:digit:][:space:]]+)[\r\n]+}
    expect {
	-re $re_pass_row {
	    foreach column $result_column_map colname $header_column_names \
		have $expect_out(2,string) {
		    set want 0
		    foreach rs $column {
			incr want $want_pass_totals($rs,$expect_out(1,string))
		    }
		    if { $have == $want } {
			pass "total $colname for pass $expect_out(1,string)"
		    } else {
			fail "total $colname for pass $expect_out(1,string)"
		    }
		}
	    exp_continue
	}
	-re {^[[:space:]]+\|-+[\r\n]+} { incr separator_count }
    }

    # read grand totals line
    expect -re {^[[:space:]]+\|[[:space:]]*([[:digit:][:space:]]+)[\r\n]+} {
	foreach column $result_column_map colname $header_column_names \
	    have $expect_out(1,string) {
		set want 0
		foreach rs $column { incr want $want_grand_totals($rs) }
		if { $have == $want } {
		    pass "grand total $colname"
		} else {
		    fail "grand total $colname"
		}
	    }
    }

    # skip the footer
    expect -re {.+} { exp_continue }

    if { $separator_count == 3 } {
	pass "expected separator lines"
    } else {
	fail "expected separator lines"
    }
}

foreach filetag [lsort [array names tuplemap]] {
    run_multipass_output_test $filetag
}

#EOF