Crash on thread id wrap around
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.threads / non-stop-fair-events.exp
CommitLineData
ede9f622
PA
1# Copyright (C) 2014-2015 Free Software Foundation, Inc.
2
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.
7#
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.
12#
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/>.
15
16# Test that GDB in non-stop mode gives roughly equal priority to
17# events of all threads.
18
19standard_testfile
20set executable ${testfile}
21
22if [target_info exists gdb,nosignals] {
23 verbose "Skipping ${testfile}.exp because of nosignals."
24 return -1
25}
26
27if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug pthreads}] == -1} {
28 return -1
29}
30
31gdb_test_no_output "set non-stop on"
32
33if ![runto_main] {
34 return -1
35}
36
37# We want "handle print", to make sure the target backend reports the
38# signal to the run control core.
39gdb_test "handle SIGUSR1 print nostop pass" ""
40
41# Get current value of VAR from the inferior. TEST is used as test
42# message.
43
44proc get_value {var test} {
45 global expect_out
46 global gdb_prompt
47 global decimal
48
49 set value -1
50 gdb_test_multiple "print $var" "$test" {
51 -re ".*= ($decimal).*\r\n$gdb_prompt $" {
52 set value $expect_out(1,string)
53 pass "$test"
54 }
55 }
56 return ${value}
57}
58
59set NUM_THREADS [get_value "num_threads" "get num_threads"]
60
61# Account for the main thread.
62incr NUM_THREADS
63
64# Run threads to their start positions. This prepares for a new test
65# sequence.
66
67proc restart {} {
68 global gdb_prompt
69 global NUM_THREADS
70
71 delete_breakpoints
72
73 gdb_test "print got_sig = 0" " = 0"
74
75 gdb_breakpoint [gdb_get_line_number "set thread breakpoint here"]
76 gdb_breakpoint [gdb_get_line_number "set kill breakpoint here"]
77
78 set test "continue -a&"
79 gdb_test_multiple $test $test {
80 -re "Continuing.\r\n$gdb_prompt " {
81 pass $test
82 }
83 }
84
85 for {set i 1} { $i <= $NUM_THREADS } { incr i } {
86 set test "thread $i restarted"
87 gdb_test_multiple "" $test {
88 -re "breakpoint here" {
89 # The prompt was already matched in the "continue &"
90 # test above. We're now consuming asynchronous output
91 # that comes after the prompt.
92 pass $test
93 }
94 }
95 }
96
97 delete_breakpoints
98}
99
100# The test proper. SIGNAL_THREAD is the thread that has been elected
101# to receive the SIGUSR1 signal.
102
103proc test {signal_thread} {
104 global gdb_prompt
105 global NUM_THREADS
106
107 with_test_prefix "signal_thread=$signal_thread" {
108 restart
109
110 # Set all threads stepping the infinite loop line in parallel.
111 for {set i 2} { $i <= $NUM_THREADS } { incr i } {
112 gdb_test "thread $i" \
113 "child_function.*set thread breakpoint here.*" \
114 "switch to thread $i to step it"
115
116 if {$i == $signal_thread} {
117 gdb_test "print signal_thread = self" " = .*"
118 }
119
120 gdb_test "step&" "" "set $i thread stepping"
121 }
122
123 gdb_test "thread 1" "Switching to .*" \
124 "switch to the main thread to queue signal"
125
126 # Let the main thread queue the signal.
127 gdb_breakpoint "loop_broke"
128 set test "continue &"
129 gdb_test_multiple $test $test {
130 -re "Continuing.\r\n$gdb_prompt " {
131 pass $test
132 }
133 }
134
135 # Wait for all threads to finish their steps, and for the main
136 # thread to hit the breakpoint.
137 for {set i 1} { $i <= $NUM_THREADS } { incr i } {
138 set test "thread $i broke out of loop"
139 gdb_test_multiple "" $test {
140 -re "loop_broke" {
141 # The prompt was already matched in the "continue
142 # &" test above. We're now consuming asynchronous
143 # output that comes after the prompt.
144 pass $test
145 }
146 }
147 }
148
149 # It's helpful to have this in the log if the test ever
150 # happens to fail.
151 gdb_test "info threads"
152 }
153}
154
155# The kernel/debug API may always walk its thread list looking for the
156# first with an event, resulting in giving priority to e.g. the thread
157# with lowest kernel thread ID. So test once with the signal pending
158# in each thread, except the main thread.
159for {set i 2} { $i <= $NUM_THREADS } { incr i } {
160 test $i
161}
This page took 0.055442 seconds and 4 git commands to generate.