Debian Codegraph @

gcc/testsuite/lib/gcov.exp

raw
1 # Copyright (C) 1997-2025 Free Software Foundation, Inc.
2
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with GCC; see the file COPYING3. If not see
15 # <http://www.gnu.org/licenses/>.
16
17 # Verify various kinds of gcov output: line counts, branch percentages,
18 # and call return percentages. None of this is language-specific.
19
20 load_lib "target-supports.exp"
21
22 global GCOV
23
24 #
25 # clean-gcov-file -- delete a working file the compiler creates for gcov
26 #
27 # TESTCASE is the name of the test.
28 # SUFFIX is file suffix
29
30 proc clean-gcov-file { testcase suffix } {
31 set basename [file tail $testcase]
32 set base [file rootname $basename]
33 remote_file host delete $base.$suffix
34 }
35
36 #
37 # clean-gcov -- delete the working files the compiler creates for gcov
38 #
39 # TESTCASE is the name of the test.
40 #
41 proc clean-gcov { testcase } {
42 clean-gcov-file $testcase "gcno"
43 clean-gcov-file $testcase "gcda"
44 clean-gcov-file $testcase "h.gcov"
45 remote_file host delete "$testcase.gcov"
46 }
47
48 #
49 # verify-lines -- check that line counts are as expected
50 #
51 # TESTNAME is the name of the test, including unique flags.
52 # TESTCASE is the name of the test file.
53 # FILE is the name of the gcov output file.
54 #
55 proc verify-lines { testname testcase file } {
56 #send_user "verify-lines\n"
57 global subdir
58
59 set failed 0
60 set fd [open $file r]
61 while { [gets $fd line] >= 0 } {
62 # We want to match both "-" and "#####" as count as well as numbers,
63 # since we want to detect lines that shouldn't be marked as covered.
64 if [regexp "^ *(\[^:]*): *(\[0-9\\-#]+):.*count\\((\[0-9\\-#=\\.kMGTPEZY\*]+)\\)(.*)" \
65 "$line" all is n shouldbe rest] {
66 if [regexp "^ *{(.*)}" $rest all xfailed] {
67 switch [dg-process-target $xfailed] {
68 "N" { continue }
69 "F" { setup_xfail "*-*-*" }
70 }
71 }
72 if { $is == "" } {
73 fail "$testname line $n: no data available"
74 incr failed
75 } elseif { $is != $shouldbe } {
76 fail "$testname line $n: is $is:should be $shouldbe"
77 incr failed
78 } else {
79 pass "$testname count for line $n"
80 }
81 }
82 }
83 close $fd
84 return $failed
85 }
86
87
88 #
89 # verify-branches -- check that branch percentages are as expected
90 #
91 # TESTNAME is the name of the test, including unique flags.
92 # TESTCASE is the name of the test file.
93 # FILE is the name of the gcov output file.
94 #
95 # Checks are based on comments in the source file. This means to look for
96 # branch percentages 10 or 90, 20 or 80, and # 70 or 30:
97 # /* branch(10, 20, 70) */
98 # This means that all specified percentages should have been seen by now:
99 # /* branch(end) */
100 # All specified percentages must also be seen by the next branch(n) or
101 # by the end of the file.
102 #
103 # Each check depends on the compiler having generated the expected
104 # branch instructions. Don't check for branches that might be
105 # optimized away or replaced with predicated instructions.
106 #
107 proc verify-branches { testname testcase file } {
108 #send_user "verify-branches\n"
109
110 set failed 0
111 set shouldbe ""
112 set fd [open $file r]
113 set n 0
114 while { [gets $fd line] >= 0 } {
115 regexp "^\[^:\]+: *(\[0-9\]+):" "$line" all n
116 if [regexp "branch" $line] {
117 verbose "Processing branch line $n: $line" 3
118 if [regexp "branch\\((\[0-9 \]+)\\)" "$line" all new_shouldbe] {
119 # All percentages in the current list should have been seen.
120 if {[llength $shouldbe] != 0} {
121 fail "$testname line $n: expected branch percentages not found: $shouldbe"
122 incr failed
123 set shouldbe ""
124 }
125 set shouldbe $new_shouldbe
126 #send_user "$n: looking for: $shouldbe\n"
127 # Record the percentages to check for. Replace percentage
128 # n > 50 with 100-n, since block ordering affects the
129 # direction of a branch.
130 for {set i 0} {$i < [llength $shouldbe]} {incr i} {
131 set num [lindex $shouldbe $i]
132 if {$num > 50} {
133 set shouldbe [lreplace $shouldbe $i $i [expr 100 - $num]]
134 }
135 }
136 } elseif [regexp "branch +\[0-9\]+ taken (-\[0-9\]+)%" "$line" \
137 all taken] {
138 # Percentages should never be negative.
139 fail "$testname line $n: negative percentage: $taken"
140 incr failed
141 } elseif [regexp "branch +\[0-9\]+ taken (\[0-9\]+)%" "$line" \
142 all taken] {
143 #send_user "$n: taken = $taken\n"
144 # Percentages should never be greater than 100.
145 if {$taken > 100} {
146 fail "$testname line $n: branch percentage greater than 100: $taken"
147 incr failed
148 }
149 if {$taken > 50} {
150 set taken [expr 100 - $taken]
151 }
152 # If this percentage is one to check for then remove it
153 # from the list. It's normal to ignore some reports.
154 set i [lsearch $shouldbe $taken]
155 if {$i != -1} {
156 set shouldbe [lreplace $shouldbe $i $i]
157 }
158 } elseif [regexp "branch\\(end\\)" "$line"] {
159 # All percentages in the list should have been seen by now.
160 if {[llength $shouldbe] != 0} {
161 fail "$testname line n: expected branch percentages not found: $shouldbe"
162 incr failed
163 }
164 set shouldbe ""
165 }
166 }
167 }
168 # All percentages in the list should have been seen.
169 if {[llength $shouldbe] != 0} {
170 fail "$testname line $n: expected branch percentages not found: $shouldbe"
171 incr failed
172 }
173 close $fd
174 return $failed
175 }
176
177 #
178 # verify-conditions -- check that conditions are checked as expected
179 #
180 # TESTNAME is the name of the test, including unique flags.
181 # TESTCASE is the name of the test file.
182 # FILE is the name of the gcov output file.
183 #
184 # Checks are based on comments in the source file. Condition coverage comes
185 # with with two types of output, a summary and a list of the uncovered
186 # conditions. Both must be checked to pass the test
187 #
188 # To check for conditions, add a comment the line of a conditional:
189 # /* conditions(n/m) true(0 1) false(1) */
190 #
191 # where n/m are the covered and total conditions in the expression. The true()
192 # and false() take the indices expected *not* covered.
193 #
194 # This means that all coverage statements should have been seen:
195 # /* conditions(end) */
196 #
197 # If all conditions are covered i.e. n == m, then conditions(end) can be
198 # omitted. If either true() or false() are empty they can be omitted too.
199 #
200 # In some very specific cases there is a need to match multiple conditions on
201 # the same line, for example if (a && fn (b || c) && d), which is interpreted
202 # roughly as tmp _bc = b || c; if (a && _bc && d). The argument to fn is
203 # considered its own expression and its coverage report will be written on the
204 # same line. For these cases, use conditions(n/m; n/m;...) true(0 1;;...)
205 # where ; marks the end of the list element where the ith list matches the ith
206 # expression. The true()/false() matchers can be omitted if no expression
207 # expects them, otherwise use the empty list if all true/false outcomes are
208 # covered.
209 #
210 # C++ can insert conditionals in the CFG that are not present in source code.
211 # These must be manually suppressed since unexpected and unhandled conditions
212 # are an error (to help combat regressions). Output can be suppressed with
213 # conditions(suppress) and conditions(end). suppress should usually be on a
214 # closing brace.
215 #
216 # Some expressions, when using unnamed temporaries as operands, will have
217 # destructors in expressions. The coverage of the destructor will be reported
218 # on the same line as the expression itself, but suppress() would also swallow
219 # the expected tested-for messages. To handle these, use the destructor() [1]
220 # which will suppress everything from and including the second "conditions
221 # covered".
222 #
223 # [1] it is important that the destructor() is *on the same line* as the
224 # conditions(m/n)
225 proc verify-conditions { testname testcase file } {
226 set failed 0
227 set suppress 0
228 set destructor 0
229 set should ""
230 set shouldt ""
231 set shouldf ""
232 set shouldall ""
233 set fd [open $file r]
234 set lineno 0
235 set checks [list]
236 set keywords {"end" "suppress"}
237 while {[gets $fd line] >= 0} {
238 regexp "^\[^:\]+: *(\[0-9\]+):" "$line" all lineno
239 set prefix "$testname line $lineno"
240
241 if {![regexp "condition" $line]} {
242 continue
243 }
244
245 # Missing coverage for both true and false will cause a failure, but
246 # only count it once for the report.
247 set ok 1
248 if [regexp {conditions *\([0-9a-z/; ]+\)} "$line" all] {
249 # *Very* coarse sanity check: conditions() should either be a
250 # keyword or n/m, anything else means a buggy test case. end is
251 # optional for cases where all conditions are covered, since it
252 # only expects a single line of output.
253 regexp {conditions *\(([0-9a-z/]+)\)} "$line" all e
254 if {([lsearch -exact $keywords $e] >= 0 || [regexp {\d+/\d+} "$e"]) == 0} {
255 fail "$prefix: expected conditions (n/m), (suppress) or (end); was ($e)"
256 incr failed
257 continue
258 }
259
260 # Any keyword means a new context. Set the error flag if not all
261 # expected output has been seen, and reset the state.
262 if {[llength $shouldt] != 0} {
263 fail "$prefix: expected 'not covered (true)' for terms: $shouldt"
264 set ok 0
265 }
266
267 if {[llength $shouldf] != 0} {
268 fail "$prefix: expected 'not covered (false)' for terms: $shouldf"
269 set ok 0
270 }
271
272 if {$shouldall ne ""} {
273 fail "$prefix: coverage summary not found; expected $shouldall"
274 set ok 0
275 }
276
277 if {[llength $checks] != 0} {
278 set missing [llength checks]
279 fail "$prefix: expected $missing more conditions"
280 set ok 0
281 }
282
283 set suppress 0
284 set destructor 0
285 set setup 0
286 set checks [list]
287
288 if [regexp {destructor\(\)} "$line"] {
289 set destructor 1
290 }
291
292 # Find the expressions on this line. There may be more, to support
293 # constructs like (a && fn (b && c) && d).
294 # The match produces lists like [conditions(n/m) n m]
295 set argconds ""
296 set argtrue ""
297 set argfalse ""
298 regexp {conditions *\(([0-9 /;]+)\)} $line _ argconds
299 regexp {true *\(([0-9 ;]+)\)} $line _ argtrue
300 regexp {false *\(([0-9 ;]+)\)} $line _ argfalse
301 set condv [split $argconds ";"]
302 set truev [split $argtrue ";"]
303 set falsev [split $argfalse ";"]
304 set ncases [llength $condv]
305
306 for {set i 0} {$i < $ncases} {incr i} {
307 set summary [lindex $condv $i]
308 set n [lindex [split $summary "/"] 0]
309 set m [lindex [split $summary "/"] 1]
310 set newt [lindex $truev $i]
311 set newf [lindex $falsev $i]
312
313 # Sanity check - if the true() and false() vectors should have
314 # m-n elements to cover all uncovered conditions. Because of
315 # masking it can sometimes be surprising what terms are
316 # independent, so this makes for more robust test at the cost
317 # of being slightly more annoying to write.
318 set nterms [expr [llength $newt] + [llength $newf]]
319 set nexpected [expr {$m - $n}]
320 if {$nterms != $nexpected} {
321 fail "$prefix: expected $nexpected uncovered terms; got $nterms"
322 set ok 0
323 }
324 set shouldall $e
325 set should ""
326 set shouldt $newt
327 set shouldf $newf
328 set shouldall [regsub -all { } "$n/$m" ""]
329 lappend checks [list $should $shouldt $shouldf $shouldall $newt $newf]
330 }
331
332 if {[llength $checks] > 0} {
333 # no-op - the stack of checks to do is set up
334 } elseif {$e == "end"} {
335 # no-op - state should already been reset, and errors flagged
336 } elseif {$e == "suppress"} {
337 set suppress 1
338 } else {
339 # this should be unreachable,
340 fail "$prefix: unhandled control ($e), should be unreachable"
341 set ok 0
342 }
343 } elseif {$suppress == 1} {
344 # ignore everything in a suppress block. C++ especially can insert
345 # conditionals in exceptions and destructors which would otherwise
346 # be considered unhandled.
347 continue
348 } elseif [regexp {condition +(\d+) not covered \((.*)\)} "$line" all cond condv] {
349 foreach v {true false} {
350 if [regexp $v $condv] {
351 if {"$v" == "true"} {
352 set should shouldt
353 } else {
354 set should shouldf
355 }
356
357 set i [lsearch [set $should] $cond]
358 if {$i != -1} {
359 set $should [lreplace [set $should] $i $i]
360 } else {
361 fail "$prefix: unexpected uncovered term $cond ($v)"
362 set ok 0
363 }
364 }
365 }
366 } elseif [regexp {condition outcomes covered (\d+/\d+)} "$line" all cond] {
367 # the destructor-generated "conditions covered" lines will be
368 # written after all expression-related output. Handle these by
369 # turning on suppression if the destructor-suppression is
370 # requested.
371 if {$shouldall == "" && $destructor == 1} {
372 set suppress 1
373 continue
374 }
375
376 if {[llength $checks] == 0} {
377 fail "$prefix: unexpected summary $cond"
378 set ok 0
379 } else {
380 # Report any missing conditions from the previous set if this
381 # is not the first condition block
382 if {$setup == 1} {
383 if {[llength $shouldt] != 0} {
384 fail "$prefix: expected 'not covered (true)' for terms: $shouldt"
385 set ok 0
386 }
387 if {[llength $shouldf] != 0} {
388 fail "$prefix: expected 'not covered (false)' for terms: $shouldf"
389 set ok 0
390 }
391 if {$shouldall ne ""} {
392 fail "$prefix: coverage summary not found; expected $shouldall"
393 set ok 0
394 }
395 }
396 set setup 1
397 set current [lindex $checks 0]
398 set checks [lreplace $checks 0 0]
399 set should [lindex $current 0]
400 set shouldt [lindex $current 1]
401 set shouldf [lindex $current 2]
402 set shouldall [lindex $current 3]
403 set newt [lindex $current 4]
404 set newf [lindex $current 5]
405
406 if {$cond == $shouldall} {
407 set shouldall ""
408 } else {
409 fail "$prefix: unexpected summary - expected $shouldall, got $cond"
410 set ok 0
411 }
412 }
413 }
414
415 if {$ok != 1} {
416 incr failed
417 }
418 }
419 close $fd
420 return $failed
421 }
422
423 #
424 # verify-calls -- check that call return percentages are as expected
425 #
426 # TESTNAME is the name of the test, including unique flags.
427 # TESTCASE is the name of the test file.
428 # FILE is the name of the gcov output file.
429 #
430 # Checks are based on comments in the source file. This means to look for
431 # call return percentages 50, 20, 33:
432 # /* returns(50, 20, 33) */
433 # This means that all specified percentages should have been seen by now:
434 # /* returns(end) */
435 # All specified percentages must also be seen by the next returns(n) or
436 # by the end of the file.
437 #
438 # Each check depends on the compiler having generated the expected
439 # call instructions. Don't check for calls that are inserted by the
440 # compiler or that might be inlined.
441 #
442 proc verify-calls { testname testcase file } {
443 #send_user "verify-calls\n"
444
445 set failed 0
446 set shouldbe ""
447 set fd [open $file r]
448 set n 0
449 while { [gets $fd line] >= 0 } {
450 regexp "^\[^:\]+: *(\[0-9\]+):" "$line" all n
451 if [regexp "return" $line] {
452 verbose "Processing returns line $n: $line" 3
453 if [regexp "returns\\((\[0-9 \]+)\\)" "$line" all new_shouldbe] {
454 # All percentages in the current list should have been seen.
455 if {[llength $shouldbe] != 0} {
456 fail "$testname line $n: expected return percentages not found: $shouldbe"
457 incr failed
458 set shouldbe ""
459 }
460 # Record the percentages to check for.
461 set shouldbe $new_shouldbe
462 } elseif [regexp "call +\[0-9\]+ returned (-\[0-9\]+)%" "$line" \
463 all returns] {
464 # Percentages should never be negative.
465 fail "$testname line $n: negative percentage: $returns"
466 incr failed
467 } elseif [regexp "call +\[0-9\]+ returned (\[0-9\]+)%" "$line" \
468 all returns] {
469 # For branches we check that percentages are not greater than
470 # 100 but call return percentages can be, as for setjmp(), so
471 # don't count that as an error.
472 #
473 # If this percentage is one to check for then remove it
474 # from the list. It's normal to ignore some reports.
475 set i [lsearch $shouldbe $returns]
476 if {$i != -1} {
477 set shouldbe [lreplace $shouldbe $i $i]
478 }
479 } elseif [regexp "returns\\(end\\)" "$line"] {
480 # All percentages in the list should have been seen by now.
481 if {[llength $shouldbe] != 0} {
482 fail "$testname line $n: expected return percentages not found: $shouldbe"
483 incr failed
484 }
485 set shouldbe ""
486 }
487 }
488 }
489 # All percentages in the list should have been seen.
490 if {[llength $shouldbe] != 0} {
491 fail "$testname line $n: expected return percentages not found: $shouldbe"
492 incr failed
493 }
494 close $fd
495 return $failed
496 }
497
498 # Verify that report filtering includes and excludes the right functions.
499 proc verify-filters { testname testcase file expected unexpected } {
500 set fd [open $file r]
501
502 set seen {}
503 set ex [concat $expected $unexpected]
504
505 while { [gets $fd line] >= 0 } {
506 foreach sym $ex {
507 if [regexp "$sym" "$line"] {
508 lappend seen $sym
509 }
510 }
511 }
512
513 set seen [lsort -unique $seen]
514
515 set ex {}
516 foreach key $expected {
517 if { $key ni $seen } {
518 lappend ex $key
519 }
520 }
521 set unex {}
522 foreach key $unexpected {
523 if { $key in $seen } {
524 lappend unex $key
525 }
526 }
527
528 foreach sym $ex {
529 fail "Did not see expected symbol '$sym'"
530 }
531
532 foreach sym $unex {
533 fail "Found unexpected symbol '$sym'"
534 }
535
536 close $fd
537 return [expr [llength $ex] + [llength $unex]]
538 }
539
540 proc verify-prime-paths { testname testcase file } {
541 set failed 0
542 set fd [open $file r]
543
544 set expected_n -1
545 set expected_m -1
546 set recording 0
547 set expected ""
548
549 while { [gets $fd line] >= 0 } {
550 regexp "^\[^:\]+: *(\[0-9\]+):" "$line" all lineno
551 set prefix "$testname line $lineno"
552
553 if {[regexp "BEGIN *paths" $line]} {
554 set recording 1
555 set expected ""
556 set expected_covered ""
557 set expected_n -1
558 set expected_m -1
559 set seen ""
560 continue
561 }
562
563 if { $recording != 1 } {
564 continue
565 }
566
567 if [regexp {summary: *(\d+)/(\d+)} $line _ n m] {
568 set expected_n $n
569 set expected_m $m
570 }
571
572 if [regexp "expect: *(.*)" $line all ln] {
573 set cases ""
574 set ln [regsub -all {\s+} $ln " "]
575 foreach case [split $ln " "] {
576 lappend cases $case
577 }
578 lappend expected $cases
579 }
580
581 if [regexp "expect covered: *(.*)" $line all ln] {
582 set cases ""
583 set ln [regsub -all {\s+} $ln " "]
584 foreach case [split $ln " "] {
585 lappend cases $case
586 }
587 lappend expected_covered $cases
588 }
589
590 if [regexp "END" $line] {
591 if {$recording != 1} {
592 incr failed
593 fail "unexpected END at line $lineno, missing BEGIN"
594
595 # Abort the test if there is a mismatch, to avoid creating
596 # unecessary errors. At this point the test itself is broken.
597 break
598 }
599 set recording 0
600
601 if {[llength $expected] > 0} {
602 incr failed
603 fail "expected: '$expected'"
604 }
605
606 if {[llength $expected_covered] > 0} {
607 incr failed
608 fail "expected covered: '$expected_covered'"
609 }
610 }
611
612 if [regexp {paths covered (\d+) of (\d+)} $line _ n m] {
613 if { $n ne $expected_n || $m ne $expected_m } {
614 incr failed
615 fail "$prefix: expected $expected_n/$expected_m covered paths, was $n/$m"
616 }
617 }
618
619 if [regexp {path *\d+ not covered: lines (.*)} $line _ path] {
620 set pathl ""
621 foreach ln [split $path " "] {
622 if [regexp {\s*(.*)\s*} $ln _ key] {
623 lappend pathl $key
624 }
625 }
626 set i [lsearch $expected $pathl]
627 set expected [lreplace $expected $i $i]
628 }
629
630 if [regexp {path *\d+ covered: lines (.*)} $line _ path] {
631 set pathl ""
632 foreach ln [split $path " "] {
633 if [regexp {\s*(.*)\s*} $ln _ key] {
634 lappend pathl $key
635 }
636 }
637 set i [lsearch $expected_covered $pathl]
638 set expected_covered [lreplace $expected_covered $i $i]
639 }
640 }
641
642 close $fd
643 return $failed
644 }
645
646 proc gcov-pytest-format-line { args } {
647 global subdir
648
649 set testcase [lindex $args 0]
650 set pytest_script [lindex $args 1]
651 set output_line [lindex $args 2]
652
653 set index [string first "::" $output_line]
654 set test_output [string range $output_line [expr $index + 2] [string length $output_line]]
655
656 return "$subdir/$testcase ${pytest_script}::${test_output}"
657 }
658
659 # Call by dg-final to run gcov --json-format which produces a JSON file
660 # that is later analysed by a pytest Python script.
661 # We pass filename of a test via GCOV_PATH environment variable.
662
663 proc run-gcov-pytest { args } {
664 global GCOV
665 global srcdir subdir
666 # Extract the test file name from the arguments.
667 set testcase [lindex $args 0]
668
669 verbose "Running $GCOV $testcase in $srcdir/$subdir" 2
670 set testcase [remote_download host $testcase]
671 set result [remote_exec host $GCOV "$testcase -i -abc"]
672
673 set pytest_script [lindex $args 1]
674 if { ![check_effective_target_pytest3] } {
675 unsupported "$pytest_script pytest python3 is missing"
676 return
677 }
678
679 setenv GCOV_PATH $testcase
680 spawn -noecho python3 -m pytest --color=no -rap -s --tb=no $srcdir/$subdir/$pytest_script
681
682 set prefix "\[^\r\n\]*"
683 expect {
684 -re "FAILED($prefix)\[^\r\n\]+\r\n" {
685 set output [gcov-pytest-format-line $testcase $pytest_script $expect_out(1,string)]
686 fail $output
687 exp_continue
688 }
689 -re "ERROR($prefix)\[^\r\n\]+\r\n" {
690 set output [gcov-pytest-format-line $testcase $pytest_script $expect_out(1,string)]
691 fail $output
692 exp_continue
693 }
694 -re "PASSED($prefix)\[^\r\n\]+\r\n" {
695 set output [gcov-pytest-format-line $testcase $pytest_script $expect_out(1,string)]
696 pass $output
697 exp_continue
698 }
699 }
700
701 clean-gcov $testcase
702 }
703
704 # Called by dg-final to run gcov and analyze the results.
705 #
706 # ARGS consists of the optional strings "branches" and/or "calls",
707 # (indicating that these things should be verified) followed by a
708 # list of arguments to provide to gcov, including the name of the
709 # source file.
710
711 proc run-gcov { args } {
712 global GCOV
713 global srcdir subdir
714
715 set gcov_args ""
716 set gcov_verify_calls 0
717 set gcov_verify_branches 0
718 set gcov_verify_conditions 0
719 set gcov_verify_prime_paths 0
720 set gcov_verify_lines 1
721 set gcov_verify_intermediate 0
722 set gcov_verify_filters 0
723 set gcov_remove_gcda 0
724 set xfailed 0
725
726 foreach a $args {
727 if { $a == "calls" } {
728 set gcov_verify_calls 1
729 } elseif { $a == "branches" } {
730 set gcov_verify_branches 1
731 } elseif { $a == "conditions" } {
732 set gcov_verify_conditions 1
733 } elseif { [lindex $a 0] == "filters" } {
734 set gcov_verify_filters 1
735 set verify_filters_expected [lindex $a 1]
736 set verify_filters_unexpected [lindex $a 2]
737 } elseif { $a == "prime-paths" } {
738 set gcov_verify_prime_paths 1
739 } elseif { $a == "intermediate" } {
740 set gcov_verify_intermediate 1
741 set gcov_verify_calls 0
742 set gcov_verify_branches 0
743 set gcov_verify_conditions 0
744 set gcov_verify_lines 0
745 set gcov_verify_filters 0
746 } elseif { $a == "remove-gcda" } {
747 set gcov_remove_gcda 1
748 } elseif { $gcov_args == "" } {
749 set gcov_args $a
750 } else {
751 switch [dg-process-target $a] {
752 "N" { return }
753 "F" { set xfailed 1 }
754 }
755 }
756 }
757
758 set testname [testname-for-summary]
759
760 # Extract the test file name from the arguments.
761 set testcase [lindex $gcov_args end]
762
763 if { $gcov_remove_gcda } {
764 verbose "Removing $testcase.gcda"
765 clean-gcov-file $testcase "gcda"
766 }
767
768 verbose "Running $GCOV $testcase" 2
769 set testcase [remote_download host $testcase]
770 set result [remote_exec host $GCOV $gcov_args]
771 if { [lindex $result 0] != 0 } {
772 if { $xfailed } {
773 setup_xfail "*-*-*"
774 }
775 fail "$testname gcov failed: [lindex $result 1]"
776 clean-gcov $testcase
777 return
778 }
779
780 set builtin_index [string first "File '<built-in>'" $result]
781 if { $builtin_index != -1 } {
782 fail "$testname gcov failed: <built-in>.gcov should not be created"
783 clean-gcov $testcase
784 return
785 }
786
787 # Get the gcov output file after making sure it exists.
788 set files [glob -nocomplain $testcase.gcov]
789 if { $files == "" } {
790 if { $xfailed } {
791 setup_xfail "*-*-*"
792 }
793 fail "$testname gcov failed: $testcase.gcov does not exist"
794 clean-gcov $testcase
795 return
796 }
797 remote_upload host $testcase.gcov $testcase.gcov
798
799 # Check that line execution counts are as expected.
800 if { $gcov_verify_lines } {
801 # Check that line execution counts are as expected.
802 set lfailed [verify-lines $testname $testcase $testcase.gcov]
803 } else {
804 set lfailed 0
805 }
806
807 # If requested via the .x file, check that branch and call information
808 # is correct.
809 if { $gcov_verify_branches } {
810 set bfailed [verify-branches $testname $testcase $testcase.gcov]
811 } else {
812 set bfailed 0
813 }
814 if { $gcov_verify_conditions } {
815 set cdfailed [verify-conditions $testname $testcase $testcase.gcov]
816 } else {
817 set cdfailed 0
818 }
819 if { $gcov_verify_prime_paths } {
820 set ppfailed [verify-prime-paths $testname $testcase $testcase.gcov]
821 } else {
822 set ppfailed 0
823 }
824 if { $gcov_verify_calls } {
825 set cfailed [verify-calls $testname $testcase $testcase.gcov]
826 } else {
827 set cfailed 0
828 }
829 if { $gcov_verify_intermediate } {
830 # Check that intermediate format has the expected format
831 set ifailed [verify-intermediate $testname $testcase $testcase.gcov]
832 } else {
833 set ifailed 0
834 }
835 if { $gcov_verify_filters } {
836 set ffailed [verify-filters $testname $testcase $testcase.gcov $verify_filters_expected $verify_filters_unexpected]
837 } else {
838 set ffailed 0
839 }
840
841 # Report whether the gcov test passed or failed. If there were
842 # multiple failures then the message is a summary.
843 set tfailed [expr $lfailed + $bfailed + $cdfailed + $ppfailed + $cfailed + $ifailed + $ffailed]
844 if { $xfailed } {
845 setup_xfail "*-*-*"
846 }
847 if { $tfailed > 0 } {
848 fail "$testname gcov: $lfailed failures in line counts, $bfailed in branch percentages, $cdfailed in condition/decision, $ppfailed in prime-paths, $cfailed in return percentages, $ifailed in intermediate format, $ffailed failed in filters"
849 if { $xfailed } {
850 clean-gcov $testcase
851 }
852 } else {
853 pass "$testname gcov"
854 clean-gcov $testcase
855 }
856 }