diff options
author | Tom de Vries <tdevries@suse.de> | 2024-07-31 15:04:25 +0200 |
---|---|---|
committer | Tom de Vries <tdevries@suse.de> | 2024-07-31 15:04:25 +0200 |
commit | 35f09cd5d7fdd1a64f4d1751e73c3495bef1ed99 (patch) | |
tree | 78266ecbffb4d52f66da9254fb05a72a9aecd6f3 /gdb | |
parent | 61ed16ee6341535924e5e601964afc6c256258e6 (diff) | |
download | gdb-35f09cd5d7fdd1a64f4d1751e73c3495bef1ed99.zip gdb-35f09cd5d7fdd1a64f4d1751e73c3495bef1ed99.tar.gz gdb-35f09cd5d7fdd1a64f4d1751e73c3495bef1ed99.tar.bz2 |
[gdb/testsuite] Detect trailing-text-in-parentheses duplicates
When using a duplicate test name:
...
fail foo
fail foo
...
we get:
...
FAIL: $exp: foo
FAIL: $exp: foo
DUPLICATE: $exp: foo
...
But when we do:
...
fail foo
fail "foo (timeout)"
...
we get only:
...
FAIL: $exp: foo
FAIL: $exp: foo (timeout)
...
Trailing text between parentheses prefixed with a space is interpreted as
extra information, and not as part of the test name [1].
Consequently, "foo" and "foo (timeout)" do count as duplicate test names,
which should have been detected. This is PR testsuite/29772.
Fix this in CheckTestNames::_check_duplicates, such that we get:
...
FAIL: $exp: foo
FAIL: $exp: foo (timeout)
DUPLICATE: $exp: foo (timeout)
...
[ One note on the implementation: I used the regexp { \([^()]*\)$}. I don't
know whether that covers all required cases, due to the fact that those are
not unambiguousely specified. It might be possible to reverse-engineer that
information by reading or running the "regression analysis tools" mentioned on
the wiki page [1], but I haven't been able to. Regardless, the current regexp
covers a large amount of cases, which IMO should be sufficient to be
acceptable. ]
Doing so shows many new duplicates in the testsuite.
A significant number of those is due to using a message which is a copy of the
command:
...
gdb_test "print (1)"
...
Fix this by handling those cases using test names "gdb-command<print (1)>" and
"gdb-command<print (2)>.
Fix the remaining duplicates manually (split off as follow-up patch for
readability of this patch).
Tested on x86_64-linux and aarch64-linux.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29772
[1] https://sourceware.org/gdb/wiki/GDBTestcaseCookbook#Do_not_use_.22tail_parentheses.22_on_test_messages
Diffstat (limited to 'gdb')
-rw-r--r-- | gdb/testsuite/lib/check-test-names.exp | 10 | ||||
-rw-r--r-- | gdb/testsuite/lib/gdb.exp | 34 |
2 files changed, 39 insertions, 5 deletions
diff --git a/gdb/testsuite/lib/check-test-names.exp b/gdb/testsuite/lib/check-test-names.exp index 8f86f31..11aed63 100644 --- a/gdb/testsuite/lib/check-test-names.exp +++ b/gdb/testsuite/lib/check-test-names.exp @@ -64,6 +64,16 @@ namespace eval ::CheckTestNames { proc _check_duplicates { message } { variable all_test_names + # Remove test-case prefix, including the space separator. + set prefix [string_to_regexp "$::subdir/$::gdb_test_file_name.exp: "] + set message [regsub ^$prefix $message ""] + + # Remove the "extra information" part. + set message [regsub { \([^()]*\)$} $message ""] + + # Add back the test-case prefix. + set message "${prefix}$message" + # Initialise a count, or increment the count for this test name. if {![info exists all_test_names($message)]} { set all_test_names($message) 0 diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp index 8ca4b00..acb932e 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -982,6 +982,31 @@ proc fill_in_default_prompt {prompt_regexp with_anchor} { return $prompt_regexp } +# Generate message from COMMAND. +# +# This is not trivial in the case that the command contains parentheses. +# Trailing text between parentheses prefixed with a space is interpreted as +# extra information, and not as part of the test name [1]. Consequently, +# "PASS: print (1)" and "PASS: print (2)" count as duplicates. +# +# We fix this here by using "PASS: gdb-command<print (1)>" and +# "PASS: gdb-command<print (2)>". +# +# A trivial way to fix this in a test-case is by using gdb_test "print(1)", +# which produces the nicer-looking "PASS: print(1)". +# +# [1] https://sourceware.org/gdb/wiki/GDBTestcaseCookbook#Do_not_use_.22tail_parentheses.22_on_test_messages + +proc command_to_message { command } { + set message $command + + if { [regexp { \(([^()]*)\)$} $message] } { + set message gdb-command<$message> + } + + return $message +} + # gdb_test_multiple COMMAND MESSAGE [ -prompt PROMPT_REGEXP] [ -lbl ] # EXPECT_ARGUMENTS # Send a command to gdb; test the result. @@ -1112,7 +1137,7 @@ proc gdb_test_multiple { command message args } { set prompt_regexp [fill_in_default_prompt $prompt_regexp true] if { $message == "" } { - set message $command + set message [command_to_message $command] } if [string match "*\[\r\n\]" $command] { @@ -1488,7 +1513,6 @@ proc gdb_test_multiline { name args } { return 0 } - # gdb_test [-prompt PROMPT_REGEXP] [-lbl] # COMMAND [PATTERN] [MESSAGE] [QUESTION RESPONSE] # Send a command to gdb; test the result. @@ -1546,7 +1570,7 @@ proc gdb_test { args } { } if { $message == "" } { - set message $command + set message [command_to_message $command] } set prompt [fill_in_default_prompt $prompt [expr !${no-prompt-anchor}]] @@ -1812,7 +1836,7 @@ proc gdb_test_lines { command message re args } { } if { $message == ""} { - set message $command + set message [command_to_message $command] } set lines "" @@ -2029,7 +2053,7 @@ proc gdb_test_stdio {command inferior_pattern {gdb_pattern ""} {message ""}} { global gdb_prompt if {$message == ""} { - set message $command + set message [command_to_message $command] } set inferior_matched 0 |