aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Burgess <andrew.burgess@embecosm.com>2019-10-01 15:29:20 +0100
committerAndrew Burgess <andrew.burgess@embecosm.com>2019-10-07 11:26:11 +0100
commit3d63690a0316d92cf248542ee12a3fc8b30152ea (patch)
treed7d4e61e1e13b0cbc511f60a373fbd82addc74d5 /gdb/testsuite/lib
parent[gdb/doc] Fix some typos (diff)
downloadbinutils-gdb-3d63690a0316d92cf248542ee12a3fc8b30152ea.tar.gz
binutils-gdb-3d63690a0316d92cf248542ee12a3fc8b30152ea.tar.bz2
binutils-gdb-3d63690a0316d92cf248542ee12a3fc8b30152ea.zip
gdb/testsuite: Add gdb_test_name variable
This commit adds a new feature to gdb_test_multiple, an automatically created variable gdb_test_name. The idea is to make it easier to write tests using gdb_test_multiple, and avoid places where the string passed to pass/fail within an action element is different to the message passed to the top level gdb_test_multiple. As an example, previously you might write this: gdb_test_multiple "print foo" "test foo" { -re "expected output 1" { pass "test foo" } -re "expected output 2" { fail "test foo" } } This is OK, but it's easy for the pass/fail strings to come out of sync, or contain a typo. A better version would look like this: set testname "test foo" gdb_test_multiple "print foo" $testname { -re "expected output 1" { pass $testname } -re "expected output 2" { fail $testname } } This is better, but its a bit of a drag having to create a new variable each time. After this patch you can now write this: gdb_test_multiple "print foo" "test foo" { -re "expected output 1" { pass $gdb_test_name } -re "expected output 2" { fail $gdb_test_name } } The $gdb_test_name is setup by gdb_test_multiple, and cleaned up once the test has completed. Nested calls to gdb_test_multiple are supported, though $gdb_test_name will only ever contain the inner most test message (which is probably what you want). My only regret is that '$gdb_test_name' is so long, but I wanted something that was unlikely to clash with any existing variable name, or anything that a user is likely to want to use. I've tested this on x86-64/GNU Linux and see no test regressions, and I've converted one test script over to make use of this new technique both as an example, and to ensure that the new facility doesn't get broken. I have no plans to convert all tests over to this technique, but I hope others will find this useful for writing tests in the future. gdb/testsuite/ChangeLog: * lib/gdb.exp (gdb_test_multiple): Add gdb_test_name mechanism. * gdb.base/annota1.exp: Update to use gdb_test_name.
Diffstat (limited to 'gdb/testsuite/lib')
-rw-r--r--gdb/testsuite/lib/gdb.exp38
1 files changed, 36 insertions, 2 deletions
diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index 3a1f053cf8a..50db45d1b14 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -719,10 +719,24 @@ proc gdb_internal_error_resync {} {
#
# gdb_test_multiple "print foo" "test foo" {
# -re "expected output 1" {
-# pass "print foo"
+# pass "test foo"
# }
# -re "expected output 2" {
-# fail "print foo"
+# fail "test foo"
+# }
+# }
+#
+# Within action elements you can also make use of the variable
+# gdb_test_name. This variable is setup automatically by
+# gdb_test_multiple, and contains the value of MESSAGE. You can then
+# write this, which is equivalent to the above:
+#
+# gdb_test_multiple "print foo" "test foo" {
+# -re "expected output 1" {
+# pass $gdb_test_name
+# }
+# -re "expected output 2" {
+# fail $gdb_test_name
# }
# }
#
@@ -1038,8 +1052,28 @@ proc gdb_test_multiple { command message user_code { prompt_regexp "" } } {
}
}
+ # Create gdb_test_name in the parent scope. If this variable
+ # already exists, which it might if we have nested calls to
+ # gdb_test_multiple, then preserve the old value, otherwise,
+ # create a new variable in the parent scope.
+ upvar gdb_test_name gdb_test_name
+ if { [info exists gdb_test_name] } {
+ set gdb_test_name_old "$gdb_test_name"
+ }
+ set gdb_test_name "$message"
+
set result 0
set code [catch {gdb_expect $code} string]
+
+ # Clean up the gdb_test_name variable. If we had a
+ # previous value then restore it, otherwise, delete the variable
+ # from the parent scope.
+ if { [info exists gdb_test_name_old] } {
+ set gdb_test_name "$gdb_test_name_old"
+ } else {
+ unset gdb_test_name
+ }
+
if {$code == 1} {
global errorInfo errorCode
return -code error -errorinfo $errorInfo -errorcode $errorCode $string