Update copyright year range in header of all files managed by GDB
[binutils-gdb.git] / gdb / testsuite / gdb.threads / async.exp
bloba217fc8acf93511c8c829d71103fa9cb54691865
1 # Copyright (C) 2019-2023 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 standard_testfile
18 if {[build_executable "failed to prepare" $testfile $srcfile {debug pthreads}] == -1} {
19     return -1
22 # At this point GDB will be busy handling the breakpoint hits and
23 # re-resuming the program.  Even if GDB internally switches thread
24 # context, the user should not notice it.  The following part of the
25 # testcase ensures that.
27 # Switch to thread EXPECTED_THR, and then confirm that the thread
28 # stays selected.
30 proc test_current_thread {expected_thr} {
31     global decimal
32     global gdb_prompt
33     global binfile
35     clean_restart $binfile
37     if {![runto "all_started"]} {
38         return
39     }
41     # Set a breakpoint that continuously fires but doeesn't cause a stop.
42     gdb_breakpoint [concat [gdb_get_line_number "set breakpoint here"] " if 0"]
44     gdb_test "thread $expected_thr" "Switching to thread $expected_thr .*" \
45         "switch to thread $expected_thr"
47     # Continue the program in the background.
48     set test "continue&"
49     gdb_test_multiple "continue&" $test {
50         -re "Continuing\\.\r\n$gdb_prompt " {
51             pass $test
52         }
53     }
55     set test "current thread is $expected_thr"
56     set fails 0
57     for {set i 0} {$i < 10} {incr i} {
58         after 200
60         set cur_thread 0
61         gdb_test_multiple "thread" $test {
62             -re "Current thread is ($decimal) .*$gdb_prompt " {
63                 set cur_thread $expect_out(1,string)
64             }
65         }
67         if {$cur_thread != $expected_thr} {
68             incr fails
69         }
70     }
72     gdb_assert {$fails == 0} $test
74     # Explicitly interrupt the target, because in all-stop/remote,
75     # that's all we can do when the target is running.  If we don't do
76     # this, we'd time out trying to kill the target, while bringing
77     # down gdb & gdbserver.
78     set test "interrupt"
79     gdb_test_multiple $test $test {
80         -re "^interrupt\r\n$gdb_prompt " {
81             gdb_test_multiple "" $test {
82                 -re "Thread .* received signal SIGINT, Interrupt\\." {
83                     pass $test
84                 }
85             }
86         }
87     }
90 # Try once with each thread as current, to avoid missing a bug just
91 # because some part of GDB manages to switch to the right thread by
92 # chance.
93 for {set thr 1} {$thr <= 3} {incr thr} {
94     with_test_prefix "thread $thr" {
95         test_current_thread $thr
96     }