From 884e37dceb64daa1c6d33f007fb294e809c47847 Mon Sep 17 00:00:00 2001 From: Pedro Alves Date: Wed, 19 Mar 2014 15:22:45 +0000 Subject: [PATCH] gdb.base/async.exp: Factor out test pattern to a procedure. All the tests here follow the same pattern (and they all have the same problem, not fixed here yet). Add a new procedure, factoring out the pattern to a simple place. gdb/testsuite/ 2014-03-19 Pedro Alves * gdb.base/async.exp (test_background): New procedure. Use it for all background execution command tests. --- gdb/testsuite/ChangeLog | 5 ++ gdb/testsuite/gdb.base/async.exp | 96 ++++++++++++++------------------ 2 files changed, 47 insertions(+), 54 deletions(-) diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index bb3d559f823..509472d9ba9 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2014-03-19 Pedro Alves + + * gdb.base/async.exp (test_background): New procedure. + Use it for all background execution command tests. + 2014-03-19 Pedro Alves * gdb.base/async.exp: Use prepare_for_testing. diff --git a/gdb/testsuite/gdb.base/async.exp b/gdb/testsuite/gdb.base/async.exp index 02ca4d151e8..65bec4da3fb 100644 --- a/gdb/testsuite/gdb.base/async.exp +++ b/gdb/testsuite/gdb.base/async.exp @@ -49,69 +49,57 @@ gdb_test "break baz" ".*" "" # gdb_test_no_output "set exec-done-display on" - -send_gdb "next&\n" -gdb_expect { - -re "^next&\r\n$gdb_prompt.*z = 9.*completed\.\r\n" { pass "next &" } - -re "$gdb_prompt.*completed\.$" { fail "next &" } - timeout { fail "(timeout) next &" } +# Test a background execution command. COMMAND is the command to +# send. BEFORE_PROMPT is the pattern expected before the GDB prompt +# is output. AFTER_PROMPT is the pattern expected after the prompt +# and before "completed". MESSAGE is optional, and is the pass/fail +# message to br printed. If omitted, then the command string is used +# as message. +proc test_background {command before_prompt after_prompt {message ""}} { + global gdb_prompt + + if {$message eq ""} { + set message $command + } + + send_gdb "$command\n" + gdb_expect { + -re "^$command\r\n${before_prompt}${gdb_prompt}${after_prompt}completed\.\r\n" { + pass "$message" + } + -re "$gdb_prompt.*completed\.$" { + fail "$message" + } + timeout { + fail "$message (timeout)" + } + } } -send_gdb "step&\n" -gdb_expect { - -re "^step&\r\n$gdb_prompt.*y = foo \\(\\).*completed\.\r\n" { pass "step &" } - -re "$gdb_prompt.*completed\.$" { fail "step &" } - timeout { fail "(timeout) step &" } -} +test_background "next&" "" ".*z = 9.*" -send_gdb "step&\n" -gdb_expect { - -re "^step&\r\n$gdb_prompt foo \\(\\) at .*async.c.*x = 5.*completed\.\r\n" \ - { pass "step &" } - -re "$gdb_prompt.*completed\.$" { fail "step &" } - timeout { fail "(timeout) step &" } -} +test_background "step&" "" ".*y = foo \\(\\).*" -send_gdb "stepi&\n" -gdb_expect { - -re "^stepi&\r\n$gdb_prompt.*$hex.*x = 5.*completed\.\r\n" { pass "stepi &" } - -re "$gdb_prompt.*completed\.$" { fail "stepi &" } - timeout { fail "(timeout) stepi &" } -} +test_background "step&" "" " foo \\(\\) at .*async.c.*x = 5.*" -send_gdb "nexti&\n" -gdb_expect { - -re "^nexti&\r\n$gdb_prompt.*y = 3.*completed\.\r\n" { pass "nexti &" } - -re "$gdb_prompt.*completed\.$" { fail "nexti &" } - timeout { fail "(timeout) nexti &" } -} +test_background "stepi&" "" ".*$hex.*x = 5.*" -send_gdb "finish&\n" -gdb_expect { - -re "^finish&\r\nRun till exit from #0 foo \\(\\) at.*async.c.*\r\n$gdb_prompt.*$hex in main \\(\\) at.*async.c.*y = foo \\(\\).*Value returned is.*= 8.*completed\.\r\n" \ - { pass "finish &" } - -re "$gdb_prompt.*completed\.$" { fail "finish &" } - timeout { fail "(timeout) finish &" } -} +test_background "nexti&" "" ".*y = 3.*" -set jump_here [gdb_get_line_number "jump here"] +test_background "finish&" \ + "Run till exit from #0 foo \\(\\) at.*async.c.*\r\n" \ + ".*$hex in main \\(\\) at.*async.c.*y = foo \\(\\).*Value returned is.*= 8.*" -send_gdb "jump $jump_here&\n" -gdb_expect { - -re "^jump $jump_here&.*Continuing at $hex.*$gdb_prompt.*Breakpoint 2, baz \\(\\) at.*async.c.*return 5.*completed\.\r\n" \ - { pass "jump &" } - -re ".*$gdb_prompt.*completed\.$" { fail "jump &" } - timeout { fail "(timeout) jump &" } -} +set jump_here [gdb_get_line_number "jump here"] +test_background "jump $jump_here&" \ + ".*Continuing at $hex.*" \ + ".*Breakpoint 2, baz \\(\\) at.*async.c.*return 5.*" \ + "jump&" set until_here [gdb_get_line_number "until here"] - -send_gdb "until $until_here&\n" -gdb_expect { - -re "^until $until_here&.*$gdb_prompt.*$hex in main \\(\\) at.*async.c.*y = baz \\(\\).*completed\.\r\n" \ - { pass "until &" } - -re "$gdb_prompt.*completed\.$" { fail "until &" } - timeout { fail "(timeout) until &" } -} +test_background "until $until_here&" \ + ".*" \ + ".*$hex in main \\(\\) at.*async.c.*y = baz \\(\\).*" \ + "until&" gdb_test_no_output "set exec-done-display off" -- 2.30.2