gdb/testsuite: Add gdb_test_name variable
authorAndrew Burgess <andrew.burgess@embecosm.com>
Tue, 1 Oct 2019 14:29:20 +0000 (15:29 +0100)
committerAndrew Burgess <andrew.burgess@embecosm.com>
Mon, 7 Oct 2019 10:26:11 +0000 (11:26 +0100)
commit3d63690a0316d92cf248542ee12a3fc8b30152ea
treed7d4e61e1e13b0cbc511f60a373fbd82addc74d5
parent760f7560fded879ddd072340bb2bdcd701cd1f7b
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.
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.base/annota1.exp
gdb/testsuite/lib/gdb.exp
This page took 0.02552 seconds and 4 git commands to generate.