1 # Copyright (C) 1996-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 # This file was written by Daniel Jacobowitz <drow@mvista.com>
17 # (parts based on pthreads.exp by Fred Fish (fnf@cygnus.com).
19 # It tests miscellaneous actions with multiple threads, including
20 # handling for thread exit.
25 # regexp for "horizontal" text (i.e. doesn't include newline or
27 set horiz "\[^\n\r\]*"
29 if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable debug] != "" } {
33 # Now we can proceed with the real testing.
35 clean_restart ${binfile}
37 gdb_test_no_output "set print sevenbit-strings"
38 #gdb_test_no_output "set print address off"
39 gdb_test_no_output "set width 0"
41 # We'll need this when we send_gdb a ^C to GDB. Need to do it before we
42 # run the program and gdb starts saving and restoring tty states.
43 gdb_test "shell stty intr '^C'" ".*"
45 proc test_all_threads { name kill } {
46 global gdb_prompt inferior_exited_re
50 gdb_test_multiple "continue" "all threads ran once" {
51 -re "Breakpoint \[0-9\]+, thread_function \\(arg=.*\\) at .*print-threads.c:\[0-9\]+.*$gdb_prompt" {
53 pass "Hit thread_function breakpoint, $i ($name)"
57 -re "Breakpoint \[0-9\]+, .* kill \\(.*\\) .*$gdb_prompt" {
60 pass "Hit kill breakpoint, $j ($name)"
62 fail "Hit kill breakpoint, $j ($name) (unexpected)"
67 -re "$inferior_exited_re normally.\[\r\n\]+$gdb_prompt" {
68 pass "program exited normally"
70 pass "all threads ran once ($name)"
72 fail "all threads ran once ($name) (total $i threads ran)"
75 -re "Program received signal SIGTRAP.*(Thread \[-0-9a-fx\]* \\(zombie\\)|0x00000000 in ).*$gdb_prompt $" {
77 kfail "gdb/1265" "Running threads ($name) (zombie thread)"
79 fail "Running threads ($name) (unknown output)"
85 # Record the old timeout, we need to extend it for slower tests.
86 set oldtimeout $timeout
89 gdb_test "break thread_function" "Breakpoint \[0-9\]+ at 0x\[0-9a-f\]+: file .*print-threads.c, line \[0-9\]*\\."
90 gdb_test_no_output "set var slow = 0"
91 test_all_threads "fast" 0
94 gdb_test "break thread_function" "Breakpoint \[0-9\]+ at 0x\[0-9a-f\]+: file .*print-threads.c, line \[0-9\]*\\." "break thread_function (2)"
95 gdb_test_no_output "set var slow = 1"
96 # Extend the timeout for slower tests.
97 set timeout [expr $oldtimeout + 120]
98 test_all_threads "slow" 0
99 set timeout $oldtimeout
102 gdb_test "break thread_function" "Breakpoint \[0-9\]+ at 0x\[0-9a-f\]+: file .*print-threads.c, line \[0-9\]*\\." "break thread_function (3)"
103 gdb_test_no_output "set var slow = 1" "set var slow = 1 (2)"
104 gdb_breakpoint "kill"
105 # Extend the timeout for slower tests.
106 set timeout [expr $oldtimeout + 120]
107 test_all_threads "slow with kill breakpoint" 1
108 set timeout $oldtimeout