binutils-gdb/gdb/testsuite/gdb.base/starti.exp

52 lines
1.5 KiB
Plaintext
Raw Normal View History

# Copyright 2017 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
standard_testfile
if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} {
return -1
}
# Define a stop hook that outputs the value of 'x'
gdb_test_multiple "define hook-stop" "hook-stop" {
-re "Type commands for definition of \"hook-stop\".\r\nEnd with a line saying just \"end\".\r\n>$" {
gdb_test "print x\nend" "" "hook-stop"
}
}
if { [gdb_starti_cmd] < 0 } {
untested starti
return -1
}
# The program should stop at the first instruction, so the constructor
# should not have run yet and 'x' should be 0.
gdb_test_sequence "" "starti" {
"Program stopped."
"\\$1 = 0"
}
# Continue to the start of main(). The constructor should have run so
# 'x' should be 1.
gdb_breakpoint main
gdb_test_sequence "continue" "" {
"\\$2 = 1"
Fix gdb.base/starti.exp racy test This commit fixes a couple problems with gdb.base/starti.exp, causing spurious FAILs. The first is a double-prompt problem: ~~~ (gdb) PASS: gdb.base/starti.exp: hook-stop starti [....] gdb_expect_list pattern: /\$1 = 0/ $1 = 0 gdb_expect_list pattern: // 0x00007ffff7ddcc80 in _start () from /lib64/ld-linux-x86-64.so.2 (gdb) # EXPECTED PROMPT (gdb) PASS: gdb.base/starti.exp: starti # ANOTHER PROMPT! break main ~~~ This happens because the test uses gdb_test_sequence with no command, like this: gdb_test_sequence "" "starti" { "Program stopped." "\\$1 = 0" } but gdb_test_sequence doesn't have a check for empty command like gdb_test_multiple does, and so sends "\n" to GDB: proc gdb_test_sequence { command test_name expected_output_list } { global gdb_prompt if { $test_name == "" } { set test_name $command } lappend expected_output_list ""; # implicit ".*" before gdb prompt send_gdb "$command\n" return [gdb_expect_list $test_name "$gdb_prompt $" $expected_output_list] } "starti" is a no-repeat command, so pressing <ret> just makes another prompt appear, confusing the following gdb_test/gdb_test_multiple/etc. Even with that fixed, the testcase is still racy though. The second problem is that sometimes the "continue" test times out here: ~~~ continue Continuing. $2 = 1 gdb_expect_list pattern: /.*Breakpoint .*main \(\) at .*starti.c.*/ Breakpoint 1, main () at /home/pedro/src/gdb/testsuite/gdb.base/starti.c:29 29 return 0; (gdb) gdb_expect_list pattern: // * hung here * ~~~ The problem is that the too-greedy ".*" trailing match in gdb_expect_list's pattern ends up consuming GDB's prompt too soon. Fix that by removing the unnecessary trailing ".*". While at it, remove all ".*"s to be stricter. Tested on x86_64 GNU/Linux. gdb/testsuite/ChangeLog: 2017-11-16 Pedro Alves <palves@redhat.com> * gdb.base/starti.exp ("continue" test): Remove ".*"s from pattern. * lib/gdb.exp (gdb_test_sequence): Don't send empty command to GDB.
2017-11-16 12:57:01 +01:00
"Breakpoint \[^\r\n\]*main \\(\\) at \[^\r\n\]*starti.c"
}