OSDN Git Service

Update copyright year in most headers.
[pf3gnuchains/pf3gnuchains3x.git] / gdb / testsuite / gdb.threads / manythreads.exp
1 # manythreads.exp -- Expect script to test stopping many threads
2 # Copyright (C) 2004, 2006, 2007, 2008, 2009, 2010
3 # Free Software Foundation, Inc.
4
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
18 # This file was written by Jeff Johnston. (jjohnstn@redhat.com)
19
20 if $tracelevel then {
21         strace $tracelevel
22 }
23
24 set prms_id 0
25 set bug_id 0
26
27 set testfile "manythreads"
28 set srcfile ${testfile}.c
29 set binfile ${objdir}/${subdir}/${testfile}
30
31 if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug "incdir=${objdir}"]] != "" } {
32     return -1
33 }
34
35 gdb_start
36 gdb_reinitialize_dir $srcdir/$subdir
37 gdb_load ${binfile}
38 gdb_test "set print sevenbit-strings" ""
39 runto_main
40
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 # On Ultrix, we don't need it and it is really slow (because shell_escape
44 # doesn't use vfork).
45 if ![istarget "*-*-ultrix*"] then {
46     gdb_test "shell stty intr '^C'" ""
47 }
48
49 set message "first continue"
50 gdb_test_multiple "continue" "first continue" {
51   -re "error:.*$gdb_prompt $" {
52     fail "$message"
53   }
54   -re "Continuing" {
55     pass "$message"
56   }
57 }
58
59 # Wait one second.  This is better than the TCL "after" command, because
60 # we don't lose GDB's output while we do it.
61 remote_expect host 1 { timeout { } }
62
63 # Send a Ctrl-C and verify that we can do info threads and continue
64 send_gdb "\003"
65 set message "stop threads 1"
66 gdb_test_multiple "" "stop threads 1" {
67   -re "\\\[New \[^\]\]*\\\]\r\n" {
68     exp_continue
69   }
70   -re "\\\[\[^\]\]* exited\\\]\r\n" {
71     exp_continue
72   }
73   -re "Thread \[^\n\]* executing\r\n" {
74     exp_continue
75   }
76   -re "Program received signal SIGINT.*$gdb_prompt $" {
77     pass "$message"
78   }
79   timeout {
80     fail "$message (timeout)"
81   }
82 }
83
84 set cmd "info threads"
85 set ok 0
86 gdb_test_multiple $cmd $cmd {
87     -re " 1 Thread " {
88         set ok 1
89         exp_continue
90     }
91     -re ".*\r\n" {
92         # Eat this line and continue, to prevent the buffer overflowing.
93         exp_continue
94     }
95     -re "$gdb_prompt $" {
96         if { $ok } {
97             pass $cmd
98         } else {
99             fail $cmd
100         }
101     }
102 }
103
104 set message "second continue"
105 gdb_test_multiple "continue" "second continue" {
106   -re "error:.*$gdb_prompt $" {
107     fail "$message"
108   }
109   -re "Continuing" {
110     pass "$message"
111   }
112 }
113
114 # Wait another second.  If the program stops on its own, GDB has failed
115 # to handle duplicate SIGINTs sent to multiple threads.
116 set failed 0
117 remote_expect host 1 {
118   -re "\\\[New \[^\]\]*\\\]\r\n" {
119     exp_continue -continue_timer
120   }
121   -re "\\\[\[^\]\]* exited\\\]\r\n" {
122     exp_continue -continue_timer
123   }
124   -re "Thread \[^\n\]* executing\r\n" {
125     exp_continue -continue_timer
126   }
127   -re "Program received signal SIGINT.*$gdb_prompt $" {
128     if { $failed == 0 } {
129       fail "check for duplicate SIGINT"
130     }
131     send_gdb "continue\n"
132     set failed 1
133     exp_continue
134   }
135   timeout {
136     if { $failed == 0 } {
137       pass "check for duplicate SIGINT"
138     }
139   }
140 }
141
142 # Send another Ctrl-C and verify that we can do info threads and quit
143 send_gdb "\003"
144 set message "stop threads 2"
145 gdb_test_multiple "" "stop threads 2" {
146   -re "\\\[New \[^\]\]*\\\]\r\n" {
147     exp_continue
148   }
149   -re "\\\[\[^\]\]* exited\\\]\r\n" {
150     exp_continue
151   }
152   -re "Thread \[^\n\]* executing\r\n" {
153     exp_continue
154   }
155   -re "Program received signal SIGINT.*$gdb_prompt $" {
156     pass "$message"
157   }
158   timeout {
159     fail "$message (timeout)"
160   }
161
162
163 gdb_test_multiple "quit" "GDB exits after stopping multithreaded program" {
164     -re "Quit anyway\\? \\(y or n\\) $" {
165         send_gdb "y\n"
166         exp_continue
167     }
168     eof {
169         pass "GDB exits after stopping multithreaded program"
170     }
171     timeout {
172         fail "GDB exits after stopping multithreaded program (timeout)"
173     }
174 }
175