1 # Copyright (C) 2014-2015 Free Software Foundation, Inc.
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 # Test that GDB in non-stop mode gives roughly equal priority to
17 # events of all threads.
20 set executable ${testfile}
22 if [target_info exists gdb,nosignals] {
23 verbose "Skipping ${testfile}.exp because of nosignals."
27 set options { "additional_flags=-DTIMEOUT=$timeout" debug pthreads }
28 if {[prepare_for_testing "failed to prepare" $testfile $srcfile $options] == -1} {
32 gdb_test_no_output "set non-stop on"
38 # We want "handle print", to make sure the target backend reports the
39 # signal to the run control core.
40 gdb_test "handle SIGUSR1 print nostop pass" ""
42 # Get current value of VAR from the inferior. TEST is used as test
45 proc get_value {var test} {
51 gdb_test_multiple "print $var" "$test" {
52 -re ".*= ($decimal).*\r\n$gdb_prompt $" {
53 set value $expect_out(1,string)
60 set NUM_THREADS [get_value "num_threads" "get num_threads"]
62 # Account for the main thread.
65 # Run threads to their start positions. This prepares for a new test
74 gdb_test "print got_sig = 0" " = 0"
76 gdb_breakpoint [gdb_get_line_number "set thread breakpoint here"]
77 gdb_breakpoint [gdb_get_line_number "set kill breakpoint here"]
79 set test "continue -a&"
80 gdb_test_multiple $test $test {
81 -re "Continuing.\r\n$gdb_prompt " {
86 for {set i 1} { $i <= $NUM_THREADS } { incr i } {
87 set test "thread $i restarted"
88 gdb_test_multiple "" $test {
89 -re "breakpoint here" {
90 # The prompt was already matched in the "continue &"
91 # test above. We're now consuming asynchronous output
92 # that comes after the prompt.
101 # The test proper. SIGNAL_THREAD is the thread that has been elected
102 # to receive the SIGUSR1 signal.
104 proc test {signal_thread} {
108 with_test_prefix "signal_thread=$signal_thread" {
111 # Set all threads stepping the infinite loop line in parallel.
112 for {set i 2} { $i <= $NUM_THREADS } { incr i } {
113 gdb_test "thread $i" \
114 "child_function.*set thread breakpoint here.*" \
115 "switch to thread $i to step it"
117 if {$i == $signal_thread} {
118 gdb_test "print signal_thread = self" " = .*"
121 gdb_test "step&" "" "set $i thread stepping"
124 gdb_test "thread 1" "Switching to .*" \
125 "switch to the main thread to queue signal"
127 # Let the main thread queue the signal.
128 gdb_breakpoint "loop_broke"
129 set test "continue &"
130 gdb_test_multiple $test $test {
131 -re "Continuing.\r\n$gdb_prompt " {
136 # Wait for all threads to finish their steps, and for the main
137 # thread to hit the breakpoint.
138 for {set i 1} { $i <= $NUM_THREADS } { incr i } {
139 set test "thread $i broke out of loop"
140 gdb_test_multiple "" $test {
142 # The prompt was already matched in the "continue
143 # &" test above. We're now consuming asynchronous
144 # output that comes after the prompt.
150 # It's helpful to have this in the log if the test ever
152 gdb_test "info threads"
156 # The kernel/debug API may always walk its thread list looking for the
157 # first with an event, resulting in giving priority to e.g. the thread
158 # with lowest kernel thread ID. So test once with the signal pending
159 # in each thread, except the main thread.
160 for {set i 2} { $i <= $NUM_THREADS } { incr i } {