[gdb/testsuite] Fix gdb.base/bg-exec-sigint-bp-cond.exp for signal merging

The test-case gdb.base/bg-exec-sigint-bp-cond.exp sends 10 SIGINTS to gdb, and
counts whether 10 have arrived.

Occasionally, less than 10 arrive due to signal merging [1].

This is more likely to happen when building gdb with -fsanitize=thread.

Fix this by instead, sending one SIGINT at a time, and waiting for it to
arrive.

This still makes the test-case fail if the fix fixing the PR that the
test-case was introduced for is reverted.

Tested on aarch64-linux and x86_64-linux.

PR testsuite/32329
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32329

[1] https://www.gnu.org/software/libc/manual/html_node/Merged-Signals.html
This commit is contained in:
Tom de Vries 2024-11-22 13:37:24 +01:00
parent c4df8ad79c
commit b200576fa0

View File

@ -40,39 +40,50 @@ proc test { {after_kill_cond ""} } {
set gdb_pid [exp_pid -i [board_info host fileid]]
# Number of times the breakpoint should be hit before stopping.
set num_hits 10
# A counter used in the breakpoint's condition to ensure that it
# causes a stop after NUM_HITS hits.
gdb_test "p \$hit_count = 0" " = 0" "reset hit counter"
# Set a breakpoint with a condition that sends a SIGINT to GDB. This
# emulates pressing Ctrl-C just while GDB is evaluating the breakpoint
# condition.
gdb_test \
"break foo if \$hit_count\+\+ == $num_hits || \$_shell(\"kill -INT $gdb_pid\") != 0 $after_kill_cond" \
"break foo if \$hit_count\+\+ == 1 || \$_shell(\"kill -INT $gdb_pid\") != 0 $after_kill_cond" \
"Breakpoint .*" \
"break foo if <condition>"
# Number of times we've seen GDB print "Quit" followed by the
# prompt. We should see that exactly $NUM_HITS times.
set quit_count 0
for { set i 0 } { $i < 10 } { incr i } {
set done 0
with_test_prefix $i {
gdb_test_multiple "c&" "SIGINT does not interrupt background execution" {
-re "^c&\r\nContinuing\\.\r\n$::gdb_prompt " {
exp_continue
}
-re "^Quit\r\n$::gdb_prompt " {
incr quit_count
verbose -log "quit_count=$quit_count"
exp_continue
}
-re "^\r\nBreakpoint .*return 0;" {
gdb_assert {$quit_count == $num_hits} $gdb_test_name
}
-re ".*Asynchronous execution not supported on this target\..*" {
unsupported "$gdb_test_name (asynchronous execution not supported)"
# A counter used in the breakpoint's condition to ensure that it
# causes a stop after one hit.
gdb_test "p \$hit_count = 0" " = 0" "reset hit counter"
# Number of times we've seen GDB print "Quit" followed by the
# prompt. We should see that exactly one time.
set quit_count 0
gdb_test_multiple "c&" "SIGINT does not interrupt background execution" {
-re "^c&\r\nContinuing\\.\r\n$::gdb_prompt " {
exp_continue
}
-re "^Quit\r\n$::gdb_prompt " {
incr quit_count
verbose -log "quit_count=$quit_count"
exp_continue
}
-re "^\r\nBreakpoint .*return 0;" {
gdb_assert {$quit_count == 1} $gdb_test_name
}
-re ".*Asynchronous execution not supported on this target\..*" {
unsupported "$gdb_test_name (asynchronous execution not supported)"
}
timeout {
set done 1
fail "$gdb_test_name (timeout)"
}
}
if { $done } {
break
}
}
}
}