Test step-over-{lands-on-breakpoint|trips-on-watchpoint}.exp with displaced stepping
[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
337532fa
YQ
27set options { "additional_flags=-DTIMEOUT=$timeout" debug pthreads }
28if {[prepare_for_testing "failed to prepare" $testfile $srcfile $options] == -1} {
ede9f622
PA
29 return -1
30}
31
32gdb_test_no_output "set non-stop on"
33
34if ![runto_main] {
35 return -1
36}
37
38# We want "handle print", to make sure the target backend reports the
39# signal to the run control core.
40gdb_test "handle SIGUSR1 print nostop pass" ""
41
42# Get current value of VAR from the inferior. TEST is used as test
43# message.
44
45proc get_value {var test} {
46 global expect_out
47 global gdb_prompt
48 global decimal
49
50 set value -1
51 gdb_test_multiple "print $var" "$test" {
52 -re ".*= ($decimal).*\r\n$gdb_prompt $" {
53 set value $expect_out(1,string)
54 pass "$test"
55 }
56 }
57 return ${value}
58}
59
60set NUM_THREADS [get_value "num_threads" "get num_threads"]
61
62# Account for the main thread.
63incr NUM_THREADS
64
65# Run threads to their start positions. This prepares for a new test
66# sequence.
67
68proc restart {} {
69 global gdb_prompt
70 global NUM_THREADS
71
72 delete_breakpoints
73
74 gdb_test "print got_sig = 0" " = 0"
75
76 gdb_breakpoint [gdb_get_line_number "set thread breakpoint here"]
77 gdb_breakpoint [gdb_get_line_number "set kill breakpoint here"]
78
79 set test "continue -a&"
80 gdb_test_multiple $test $test {
81 -re "Continuing.\r\n$gdb_prompt " {
82 pass $test
83 }
84 }
85
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.
93 pass $test
94 }
95 }
96 }
97
98 delete_breakpoints
99}
100
101# The test proper. SIGNAL_THREAD is the thread that has been elected
102# to receive the SIGUSR1 signal.
103
104proc test {signal_thread} {
105 global gdb_prompt
106 global NUM_THREADS
107
108 with_test_prefix "signal_thread=$signal_thread" {
109 restart
110
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"
116
117 if {$i == $signal_thread} {
118 gdb_test "print signal_thread = self" " = .*"
119 }
120
121 gdb_test "step&" "" "set $i thread stepping"
122 }
123
124 gdb_test "thread 1" "Switching to .*" \
125 "switch to the main thread to queue signal"
126
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 " {
132 pass $test
133 }
134 }
135
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 {
141 -re "loop_broke" {
142 # The prompt was already matched in the "continue
143 # &" test above. We're now consuming asynchronous
144 # output that comes after the prompt.
145 pass $test
146 }
147 }
148 }
149
150 # It's helpful to have this in the log if the test ever
151 # happens to fail.
152 gdb_test "info threads"
153 }
154}
155
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.
160for {set i 2} { $i <= $NUM_THREADS } { incr i } {
161 test $i
162}
This page took 0.059401 seconds and 4 git commands to generate.