diff options
author | Andrew Burgess <aburgess@redhat.com> | 2024-11-09 15:02:15 +0000 |
---|---|---|
committer | Andrew Burgess <aburgess@redhat.com> | 2024-11-12 14:41:23 +0000 |
commit | 06b8b0ad976aa3ad5864bbe4b196ba737f677efb (patch) | |
tree | 635546e551d1d795aa859efba728aff0abb7bd35 /gdb | |
parent | 26885b2b6cad0294f867e46325127639cfbe4ce5 (diff) | |
download | gdb-06b8b0ad976aa3ad5864bbe4b196ba737f677efb.zip gdb-06b8b0ad976aa3ad5864bbe4b196ba737f677efb.tar.gz gdb-06b8b0ad976aa3ad5864bbe4b196ba737f677efb.tar.bz2 |
gdb/testsuite: some cleanups in gdb.base/annota{1,3}.exp tests
Fedora GDB has, for years, carried an out of tree patch for the
gdb.base/annota{1,3}.exp tests. The patch simply adds a call to 'set
breakpoint pending off' near the start of each test.
Normally GDB tests are written using gdb_test or gdb_test_multiple,
with gdb_test being a wrapper around gdb_test_multiple. Inside
gdb_test_multiple we add a test pattern which detects if GDB offers
the user an interactive yes/no prompt and immediately fails the test.
What this means is that if something goes wrong with a test like:
gdb_test "break main" ".*"
and GDB ends up offering this prompt:
Make breakpoint pending on future shared library load? (y or [n])
then instead of hanging waiting for the test to timeout, DejaGNU will
spot the interactive prompt and immediately fail the test.
In the gdb.base/annota{1,3}.exp tests we turn on GDB's annotation
mode, and many of the tests in these scripts are written using
send_gdb and gdb_expect or gdb_expect_list. This is done because in
the past, gdb_test_multiple and friends were hard-coded to use the
"normal" GDB prompt, and these tests instead expect the annotated
prompt. Specifically, gdb_test_multiple expects '$gdb_prompt $' as
the full prompt, that is the value of $gdb_prompt followed by a single
white space. The annotation tests do update the value of $gdb_prompt,
but with annotations on there is no trailing whitespace, so
gdb_test_multiple's default behaviour doesn't work, which is why the
test scripts originally avoided using gdb_test_multiple.
As a result none of the tests in these files would early exit if we
got an interactive yes/no prompt, and instead we'd be relying on each
test to timeout, which could take a while.
However, gdb_test_multiple now accepts a -prompt argument, so we can
modify the prompt we are looking for, which is neat.
So, I started off by going through these tests an changing all of the
tests that create a breakpoint to use gdb_test, passing the -prompt
option to change the prompt.
While doing that I noticed some other things that I could improve in
these tests, I've cleaned up the use of standard_testfile, switched to
use prepare_for_testing, and removed some redundant clean_restart and
'set height 0' calls (set height 0 is done within clean_restart, which
is called by prepare_for_testing).
I've updated some comments which said "we can't use gdb_test" to say
"we can use gdb_test with -prompt option", and I've removed some
commented out debug code (e.g. setting 'exp_internal').
Finally, I ran these two tests through check-all-boards, and spotted
that annota1.exp failed when using a remote host. This is because one
test checks for a full path to the binary in some output, and with a
remote host the binary ends up being copied and the path is not as
expected.
I'm assuming that checking the full path is important, so I've
disabled this test on remote host boards.
After all these changes I checked using 'make check-all-boards' and
there are no unexpected results on either of these tests.
Tested-By: Tom de Vries <tdevries@suse.de>
Acked-By: Tom de Vries <tdevries@suse.de>
Diffstat (limited to 'gdb')
-rw-r--r-- | gdb/testsuite/gdb.base/annota1.exp | 39 | ||||
-rw-r--r-- | gdb/testsuite/gdb.base/annota3.exp | 57 |
2 files changed, 32 insertions, 64 deletions
diff --git a/gdb/testsuite/gdb.base/annota1.exp b/gdb/testsuite/gdb.base/annota1.exp index f3a6dfa..927e8a7 100644 --- a/gdb/testsuite/gdb.base/annota1.exp +++ b/gdb/testsuite/gdb.base/annota1.exp @@ -21,26 +21,23 @@ # require target_can_use_run_cmd +# This test checks the full path to the binary in the output of some +# tests, as a result this test will not work for remote host boards +# where we have to first copy the binary to the remote host. +require {!is_remote host} + set breakpoints_invalid "\r\n\032\032breakpoints-invalid\r\n" # # test running programs # -standard_testfile .c +standard_testfile -if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug nowarnings}] != "" } { - untested "failed to compile" +if { [prepare_for_testing "failed to prepare" $testfile $srcfile] } { return -1 } - -clean_restart ${binfile} - -# The commands we test here produce many lines of output; disable "press -# <return> to continue" prompts. -gdb_test_no_output "set height 0" - # # break in main # @@ -54,10 +51,10 @@ gdb_test "break ${srcfile}:${main_line}" \ # # NOTE: this prompt is OK only when the annotation level is > 1 -# NOTE: When this prompt is in use the gdb_test procedure cannot be used because -# it assumes that the last char after the gdb_prompt is a white space. This is not -# true with this annotated prompt. So we must use send_gdb and gdb_expect. -# +# NOTE: When this prompt is in use the gdb_test procedure must be +# called with '-prompt "$gdb_prompt$"' otherwise it assumes the +# last char after the gdb_prompt is a white space. This is not +# true with this annotated prompt. set old_gdb_prompt $gdb_prompt set gdb_prompt "\r\n\032\032pre-prompt\r\n$gdb_prompt \r\n\032\032prompt\r\n" @@ -77,13 +74,8 @@ set escapedsrcfile [string_to_regexp ${srcdir}/${subdir}/${srcfile}] # annotate-prompt # annotate-post-prompt (in the next block) # -send_gdb "set annotate 2\n" -gdb_expect { - -re "set annotate 2\r\n$gdb_prompt$" { pass "annotation set at level 2" } - -re ".*$gdb_prompt$" { fail "annotation set at level 2" } - timeout { fail "annotation set at level 2 (timeout)" } - } - +gdb_test_no_output -prompt "$gdb_prompt$" "set annotate 2" \ + "annotation set at level 2" # # info break will test: @@ -122,7 +114,7 @@ gdb_test_multiple "info break" "breakpoint info" { # annotate-frame-end # annotate-stopped # -#exp_internal 1 + set binexp [string_to_regexp $binfile] set warning_slow_re \ @@ -196,8 +188,6 @@ gdb_test_multiple "run" "run until main breakpoint" { pass $gdb_test_name } } -#exp_internal 0 -#exit 0 # # Let's do a next, to get to a point where the array is initialized @@ -236,7 +226,6 @@ gdb_test_multiple "print my_array" "print array" { # FIXME: annotate-error not tested # -#exp_internal 1 gdb_test_multiple "print non_existent_value" "print non_existent_value" { -re "\r\n\032\032post-prompt\r\n\r\n\032\032error-begin\r\nNo symbol \"non_existent_value\" in current context.\r\n\r\n\032\032error\r\n$gdb_prompt$" { pass $gdb_test_name diff --git a/gdb/testsuite/gdb.base/annota3.exp b/gdb/testsuite/gdb.base/annota3.exp index 20e0c4d..134a3d3 100644 --- a/gdb/testsuite/gdb.base/annota3.exp +++ b/gdb/testsuite/gdb.base/annota3.exp @@ -26,20 +26,13 @@ require target_can_use_run_cmd # test running programs # -standard_testfile .c +standard_testfile -if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug nowarnings}] != "" } { - untested "failed to compile" +if { [prepare_for_testing "failed to prepare" $testfile $srcfile] } { return -1 } -clean_restart ${binfile} - -# The commands we test here produce many lines of output; disable "press -# <return> to continue" prompts. -gdb_test_no_output "set height 0" - # # break in main # @@ -53,10 +46,10 @@ gdb_test "break ${srcfile}:${main_line}" \ # NOTE: this prompt is OK only when the annotation level is > 1 -# NOTE: When this prompt is in use the gdb_test procedure cannot be -# used because it assumes that the last char after the gdb_prompt is a -# white space. This is not true with this annotated prompt. So we must -# use send_gdb and gdb_expect or gdb_expect_list. +# NOTE: When this prompt is in use the gdb_test procedure must be +# called with '-prompt "$gdb_prompt$"' otherwise it assumes the +# last char after the gdb_prompt is a white space. This is not +# true with this annotated prompt. set old_gdb_prompt $gdb_prompt set gdb_prompt "\r\n\032\032pre-prompt\r\n$gdb_prompt \r\n\032\032prompt\r\n" @@ -71,10 +64,8 @@ set gdb_prompt "\r\n\032\032pre-prompt\r\n$gdb_prompt \r\n\032\032prompt\r\n" # annotate-prompt # annotate-post-prompt (in the next block) # -send_gdb "set annotate 3\n" -gdb_expect_list "annotation set at level 3" "\r\n$gdb_prompt$" { +gdb_test_no_output -prompt "$gdb_prompt$" "set annotate 3" \ "set annotate 3" -} # # if construct: @@ -104,7 +95,6 @@ gdb_expect_list "breakpoint info" "$gdb_prompt$" [concat { # # run to a break point will test: # -#exp_internal 1 send_gdb "run\n" gdb_expect_list "run until main breakpoint" "$gdb_prompt$" [concat { "\r\n\032\032post-prompt\r\n" @@ -118,8 +108,6 @@ gdb_expect_list "run until main breakpoint" "$gdb_prompt$" [concat { "\r\n\032\032source.*annota3.c:$main_line:.*:beg:0x\[0-9a-z\]+\r\n"] { "\r\n\032\032stopped\r\n" }] -#exp_internal 0 -#exit 0 # # Let's do a next, to get to a point where the array is initialized @@ -151,7 +139,6 @@ gdb_expect_list "print array" "$gdb_prompt$" { # FIXME: annotate-error not tested # -#exp_internal 1 send_gdb "print non_existent_value\n" gdb_expect_list "print non_existent_value" "$gdb_prompt$" { "\r\n\032\032post-prompt\r\n" @@ -164,20 +151,14 @@ gdb_expect_list "print non_existent_value" "$gdb_prompt$" { # # break at signal handler # -send_gdb "break handle_USR1\n" -gdb_expect_list "breakpoint handle_USR1" "$gdb_prompt$" { - "\r\n\032\032post-prompt\r\n" - "Breakpoint.*at 0x\[0-9a-z\]+: file.*annota3.c, line.*\r\n" -} +gdb_test -prompt "$gdb_prompt$" "break handle_USR1" \ + "\r\n\032\032post-prompt\r\nBreakpoint \[^\r\n\]+ at $hex: file \[^\r\n\]+/$srcfile, line\[^\r\n\]+\\." # -# break at printf. When we are stopped at printf, we can test +# Break at printf. # -send_gdb "break printf\n" -gdb_expect_list "breakpoint printf" "$gdb_prompt$" { - "\r\n\032\032post-prompt\r\n" - "Breakpoint.*at 0x\[0-9a-z\]+.*" -} +gdb_test -prompt "$gdb_prompt$" "break printf" \ + "\r\n\032\032post-prompt\r\nBreakpoint \[^\r\n\]+ at $hex\[^\r\n\]+" # # get to printf @@ -257,10 +238,9 @@ gdb_expect_list "delete bp 3" "$gdb_prompt$" { # break in main, after value is initialized. This is in preparation # to test the annotate output for the display command. # -send_gdb "break ${srcfile}:${main_line}\n" -gdb_expect_list "break in main" "$gdb_prompt$" [concat { - "\r\n\032\032post-prompt\r\n" } [list \ - "Breakpoint 4 at 0x\[0-9a-z\]+: file .*annota3.c, line $main_line.\r\n"]] +gdb_test -prompt "$gdb_prompt$" "break ${srcfile}:${main_line}" \ + "\r\n\032\032post-prompt\r\nBreakpoint 4 at $hex: file \[^\r\n\]+/$srcfile, line $main_line\\." \ + "break in main" # # display the value @@ -305,10 +285,9 @@ gdb_expect { set value_inc_line [gdb_get_line_number "increment value"] -send_gdb "break $value_inc_line\n" -gdb_expect_list "break at value++" "$gdb_prompt$" [concat { - "\r\n\032\032post-prompt\r\n" } [list \ - "Breakpoint 5 at 0x\[0-9a-z\]+: file .*annota3.c, line $value_inc_line.\r\n"]] +gdb_test -prompt "$gdb_prompt$" "break $value_inc_line" \ + "\r\n\032\032post-prompt\r\nBreakpoint 5 at $hex: file\[^\r\n\]*$srcfile, line $value_inc_line\\." \ + "break at value++" send_gdb "ignore 5 4\n" gdb_expect_list "ignore 5 4" "$gdb_prompt$" { |