Commit | Line | Data |
---|---|---|
c5a57081 JB |
1 | # Copyright (C) 1996-1997, 2002-2003, 2007-2012 Free Software |
2 | # Foundation, Inc. | |
0312286c DJ |
3 | |
4 | # This program is free software; you can redistribute it and/or modify | |
5 | # it under the terms of the GNU General Public License as published by | |
e22f8b7c | 6 | # the Free Software Foundation; either version 3 of the License, or |
0312286c | 7 | # (at your option) any later version. |
e22f8b7c | 8 | # |
0312286c DJ |
9 | # This program is distributed in the hope that it will be useful, |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. | |
e22f8b7c | 13 | # |
0312286c | 14 | # You should have received a copy of the GNU General Public License |
e22f8b7c | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
0312286c | 16 | |
0312286c DJ |
17 | # This file was written by Daniel Jacobowitz <drow@mvista.com> |
18 | # (parts based on pthreads.exp by Fred Fish (fnf@cygnus.com). | |
19 | # | |
20 | # It tests miscellaneous actions with multiple threads, including | |
21 | # handling for thread exit. | |
22 | ||
23 | if $tracelevel then { | |
24 | strace $tracelevel | |
25 | } | |
26 | ||
0312286c DJ |
27 | |
28 | set testfile "print-threads" | |
29 | set srcfile ${testfile}.c | |
30 | set binfile ${objdir}/${subdir}/${testfile} | |
31 | ||
32 | # regexp for "horizontal" text (i.e. doesn't include newline or | |
33 | # carriage return) | |
34 | set horiz "\[^\n\r\]*" | |
35 | ||
b5ab8ff3 | 36 | if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug "incdir=${objdir}"]] != "" } { |
0312286c DJ |
37 | return -1 |
38 | } | |
39 | ||
40 | # Now we can proceed with the real testing. | |
41 | ||
42 | # Start with a fresh gdb. | |
43 | ||
44 | gdb_exit | |
45 | gdb_start | |
46 | gdb_reinitialize_dir $srcdir/$subdir | |
47 | gdb_load ${binfile} | |
48 | ||
12b5d08a MS |
49 | gdb_test_no_output "set print sevenbit-strings" |
50 | #gdb_test_no_output "set print address off" | |
51 | gdb_test_no_output "set width 0" | |
0312286c DJ |
52 | |
53 | # We'll need this when we send_gdb a ^C to GDB. Need to do it before we | |
54 | # run the program and gdb starts saving and restoring tty states. | |
55 | # On Ultrix, we don't need it and it is really slow (because shell_escape | |
56 | # doesn't use vfork). | |
57 | if ![istarget "*-*-ultrix*"] then { | |
f6978de9 | 58 | gdb_test "shell stty intr '^C'" ".*" |
0312286c DJ |
59 | } |
60 | ||
61 | proc test_all_threads { name kill } { | |
fda326dd | 62 | global gdb_prompt inferior_exited_re |
0312286c DJ |
63 | |
64 | set i 0 | |
65 | set j 0 | |
9db70545 | 66 | gdb_test_multiple "continue" "all threads ran once" { |
0312286c DJ |
67 | -re "Breakpoint \[0-9\]+, thread_function \\(arg=.*\\) at .*print-threads.c:\[0-9\]+.*$gdb_prompt" { |
68 | set i [expr $i + 1] | |
69 | pass "Hit thread_function breakpoint, $i ($name)" | |
70 | send_gdb "continue\n" | |
71 | exp_continue | |
72 | } | |
73 | -re "Breakpoint \[0-9\]+, .* kill \\(.*\\) .*$gdb_prompt" { | |
74 | set j [expr $j + 1] | |
75 | if { $kill == 1 } { | |
76 | pass "Hit kill breakpoint, $j ($name)" | |
77 | } else { | |
78 | fail "Hit kill breakpoint, $j ($name) (unexpected)" | |
79 | } | |
80 | send_gdb "continue\n" | |
81 | exp_continue | |
82 | } | |
fda326dd | 83 | -re "$inferior_exited_re normally.\[\r\n\]+$gdb_prompt" { |
0312286c DJ |
84 | pass "program exited normally" |
85 | if {$i == 5} { | |
86 | pass "all threads ran once ($name)" | |
87 | } else { | |
88 | fail "all threads ran once ($name) (total $i threads ran)" | |
89 | } | |
90 | } | |
027c0295 | 91 | -re "Program received signal SIGTRAP.*(Thread \[-0-9a-fx\]* \\(zombie\\)|0x00000000 in ).*$gdb_prompt $" { |
f56973f8 DJ |
92 | if { $kill == 1 } { |
93 | kfail "gdb/1265" "Running threads ($name) (zombie thread)" | |
94 | } else { | |
95 | fail "Running threads ($name) (unknown output)" | |
96 | } | |
97 | } | |
0312286c DJ |
98 | } |
99 | } | |
100 | ||
a4b5b48a DE |
101 | # Record the old timeout, we need to extend it for slower tests. |
102 | set oldtimeout $timeout | |
103 | ||
0312286c DJ |
104 | runto_main |
105 | gdb_test "break thread_function" "Breakpoint \[0-9\]+ at 0x\[0-9a-f\]+: file .*print-threads.c, line \[0-9\]*\\." | |
12b5d08a | 106 | gdb_test_no_output "set var slow = 0" |
0312286c DJ |
107 | test_all_threads "fast" 0 |
108 | ||
109 | runto_main | |
110 | gdb_test "break thread_function" "Breakpoint \[0-9\]+ at 0x\[0-9a-f\]+: file .*print-threads.c, line \[0-9\]*\\." "break thread_function (2)" | |
12b5d08a | 111 | gdb_test_no_output "set var slow = 1" |
a4b5b48a DE |
112 | # Extend the timeout for slower tests. |
113 | set timeout [expr $oldtimeout + 120] | |
0312286c | 114 | test_all_threads "slow" 0 |
a4b5b48a | 115 | set timeout $oldtimeout |
0312286c DJ |
116 | |
117 | runto_main | |
118 | gdb_test "break thread_function" "Breakpoint \[0-9\]+ at 0x\[0-9a-f\]+: file .*print-threads.c, line \[0-9\]*\\." "break thread_function (3)" | |
12b5d08a | 119 | gdb_test_no_output "set var slow = 1" "set var slow = 1 (2)" |
6afcfa39 | 120 | gdb_breakpoint "kill" |
a4b5b48a DE |
121 | # Extend the timeout for slower tests. |
122 | set timeout [expr $oldtimeout + 120] | |
0312286c | 123 | test_all_threads "slow with kill breakpoint" 1 |
a4b5b48a | 124 | set timeout $oldtimeout |
0312286c DJ |
125 | |
126 | return 0 |