#
 # verify-lines -- check that line counts are as expected
 #
-# TESTCASE is the name of the test.
+# TESTNAME is the name of the test, including unique flags.
+# TESTCASE is the name of the test file.
 # FILE is the name of the gcov output file.
 #
-proc verify-lines { testcase file } {
+proc verify-lines { testname testcase file } {
     #send_user "verify-lines\n"
     global subdir
+
     set failed 0
     set fd [open $file r]
     while { [gets $fd line] >= 0 } {
                }
            }
            if { $is == "" } {
-               fail "$subdir/$testcase:$n:no data available for this line"
+               fail "$testname line $n: no data available"
                incr failed
            } elseif { $is != $shouldbe } {
-               fail "$subdir/$testcase:$n:is $is:should be $shouldbe"
+               fail "$testname line $n: is $is:should be $shouldbe"
                incr failed
            } else {
-               pass "$subdir/$testcase:$n line count"
+               pass "$testname count for line $n"
            }
        }
     }
 #
 # verify-branches -- check that branch percentages are as expected
 #
-# TESTCASE is the name of the test.
+# TESTNAME is the name of the test, including unique flags.
+# TESTCASE is the name of the test file.
 # FILE is the name of the gcov output file.
 #
 # Checks are based on comments in the source file.  This means to look for
 # branch instructions.  Don't check for branches that might be
 # optimized away or replaced with predicated instructions.
 #
-proc verify-branches { testcase file } {
+proc verify-branches { testname testcase file } {
     #send_user "verify-branches\n"
+
     set failed 0
     set shouldbe ""
     set fd [open $file r]
            if [regexp "branch\\((\[0-9 \]+)\\)" "$line" all new_shouldbe] {
                # All percentages in the current list should have been seen.
                if {[llength $shouldbe] != 0} {
-                   fail "$n: expected branch percentages not found: $shouldbe"
+                   fail "$testname line $n: expected branch percentages not found: $shouldbe"
                    incr failed
                    set shouldbe ""
                }
            } elseif [regexp "branch +\[0-9\]+ taken (-\[0-9\]+)%" "$line" \
                        all taken] {
                # Percentages should never be negative.
-               fail "$n: negative percentage: $taken"
+               fail "$testname line $n: negative percentage: $taken"
                incr failed
            } elseif [regexp "branch +\[0-9\]+ taken (\[0-9\]+)%" "$line" \
                        all taken] {
                #send_user "$n: taken = $taken\n"
                # Percentages should never be greater than 100.
                if {$taken > 100} {
-                   fail "$n: percentage greater than 100: $taken"
+                   fail "$testname line $n: branch percentage greater than 100: $taken"
                    incr failed
                }
                if {$taken > 50} {
            } elseif [regexp "branch\\(end\\)" "$line"] {
                # All percentages in the list should have been seen by now.
                if {[llength $shouldbe] != 0} {
-                   fail "$n: expected branch percentages not found: $shouldbe"
+                   fail "$testname line n: expected branch percentages not found: $shouldbe"
                    incr failed
                }
                set shouldbe ""
     }
     # All percentages in the list should have been seen.
     if {[llength $shouldbe] != 0} {
-       fail "$n: expected branch percentages not found: $shouldbe"
+       fail "$testname line $n: expected branch percentages not found: $shouldbe"
        incr failed
     }
     close $fd
 #
 # verify-calls -- check that call return percentages are as expected
 #
-# TESTCASE is the name of the test.
+# TESTNAME is the name of the test, including unique flags.
+# TESTCASE is the name of the test file.
 # FILE is the name of the gcov output file.
 #
 # Checks are based on comments in the source file.  This means to look for
 # call instructions.  Don't check for calls that are inserted by the
 # compiler or that might be inlined.
 #
-proc verify-calls { testcase file } {
+proc verify-calls { testname testcase file } {
     #send_user "verify-calls\n"
+
     set failed 0
     set shouldbe ""
     set fd [open $file r]
            if [regexp "returns\\((\[0-9 \]+)\\)" "$line" all new_shouldbe] {
                # All percentages in the current list should have been seen.
                if {[llength $shouldbe] != 0} {
-                   fail "$n: expected return percentages not found: $shouldbe"
+                   fail "$testname line $n: expected return percentages not found: $shouldbe"
                    incr failed
                    set shouldbe ""
                }
            } elseif [regexp "call +\[0-9\]+ returned (-\[0-9\]+)%" "$line" \
                        all returns] {
                # Percentages should never be negative.
-               fail "$n: negative percentage: $returns"
+               fail "$testname line $n: negative percentage: $returns"
                incr failed
            } elseif [regexp "call +\[0-9\]+ returned (\[0-9\]+)%" "$line" \
                        all returns] {
            } elseif [regexp "returns\\(end\\)" "$line"] {
                # All percentages in the list should have been seen by now.
                if {[llength $shouldbe] != 0} {
-                   fail "$n: expected return percentages not found: $shouldbe"
+                   fail "$testname line $n: expected return percentages not found: $shouldbe"
                    incr failed
                }
                set shouldbe ""
     }
     # All percentages in the list should have been seen.
     if {[llength $shouldbe] != 0} {
-       fail "$n: expected return percentages not found: $shouldbe"
+       fail "$testname line $n: expected return percentages not found: $shouldbe"
        incr failed
     }
     close $fd
        }
     }
 
-    # Extract the test name from the arguments.
+    # Get the test name, including options that make it unique, from gnu-test 2 levels up.
+    upvar 2 name testname
+
+    # Extract the test file name from the arguments.
     set testcase [lindex $gcov_args end]
 
     verbose "Running $GCOV $testcase" 2
        if { $xfailed } {
            setup_xfail "*-*-*"
        }
-       fail "$subdir/$testcase gcov failed: [lindex $result 1]"
+       fail "$testname gcov failed: [lindex $result 1]"
        clean-gcov $testcase
        return
     }
        if { $xfailed } {
            setup_xfail "*-*-*"
        }
-        fail "$subdir/$testcase gcov failed: $testcase.gcov does not exist"
+        fail "$testname gcov failed: $testcase.gov does not exist"
         clean-gcov $testcase
         return
     }
     remote_upload host $testcase.gcov $testcase.gcov
 
     # Check that line execution counts are as expected.
-    set lfailed [verify-lines $testcase $testcase.gcov]
+    set lfailed [verify-lines $testname $testcase $testcase.gcov]
 
     # If requested via the .x file, check that branch and call information
     # is correct.
     if { $gcov_verify_branches } {
-       set bfailed [verify-branches $testcase $testcase.gcov]
+       set bfailed [verify-branches $testname $testcase $testcase.gcov]
     } else {
        set bfailed 0
     }
     if { $gcov_verify_calls } {
-       set cfailed [verify-calls $testcase $testcase.gcov]
+       set cfailed [verify-calls $testname $testcase $testcase.gcov]
     } else {
        set cfailed 0
     }
        setup_xfail "*-*-*"
     }
     if { $tfailed > 0 } {
-       fail "$subdir/$testcase gcov: $lfailed failures in line counts, $bfailed in branch percentages, $cfailed in return percentages"
+       fail "$testname gcov: $lfailed failures in line counts, $bfailed in branch percentages, $cfailed in return percentages"
     } else {
-       pass "$subdir/$testcase gcov"
+       pass "$testname gcov"
        clean-gcov $testcase
     }
 }