* lib/gdb.exp (skip_altivec_tests, skip_vsx_tests)
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.threads / attach-into-signal.exp
1 # Copyright 2008-2012 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 # This test was created by modifying attach-stopped.exp.
17 # This file was created by Jan Kratochvil <jan.kratochvil@redhat.com>.
18
19 # This test only works on Linux
20 if { ![isnative] || [is_remote host] || [target_info exists use_gdb_stub]
21 || ![istarget *-linux*] } {
22 continue
23 }
24
25 set testfile "attach-into-signal"
26 set srcfile ${testfile}.c
27 set executable_nothr ${testfile}-nothr
28 set executable_thr ${testfile}-thr
29
30 remote_exec build "rm -f ${objdir}/${subdir}/${executable_nothr}"
31 remote_exec build "rm -f ${objdir}/${subdir}/${executable_thr}"
32 # For debugging this test
33 #
34 #log_user 1
35
36 proc corefunc { threadtype executable } {
37 global srcfile
38 global srcdir
39 global objdir
40 global subdir
41 global gdb_prompt
42
43 with_test_prefix "$threadtype" {
44 clean_restart ${executable}
45
46 set binfile ${objdir}/${subdir}/${executable}
47 set escapedbinfile [string_to_regexp ${objdir}/${subdir}/${executable}]
48
49 if [get_compiler_info] {
50 return -1
51 }
52
53 gdb_test "handle SIGALRM stop print pass" "Yes.*Yes.*Yes.*"
54
55 # Start the program running and then wait for a bit, to be sure
56 # that it can be attached to.
57 # Statistically there is a better chance without giving process a nice.
58
59 set testpid [eval exec $binfile &]
60 exec sleep 2
61
62 # Run 2 passes of the test.
63 # The C file inferior stops pending its signals if a single one is lost,
64 # we test successful redelivery of the caught signal by the 2nd pass.
65
66 # linux-2.6.20.4.x86_64 had maximal attempt # 20 in 4 test runs.
67 set attempts 100
68 set attempt 1
69 set passes 1
70 while { $passes < 3 && $attempt <= $attempts } {
71 set stoppedtry 0
72 while { $stoppedtry < 10 } {
73 if [catch {open /proc/${testpid}/status r} fileid] {
74 set stoppedtry 10
75 break
76 }
77 gets $fileid line1;
78 gets $fileid line2;
79 close $fileid;
80
81 if {![string match "*(stopped)*" $line2]} {
82 # No PASS message as we may be looping in multiple
83 # attempts.
84 break
85 }
86 sleep 1
87 set stoppedtry [expr $stoppedtry + 1]
88 }
89 if { $stoppedtry >= 10 } {
90 verbose -log $line2
91 set test "process is still running on the attempt # $attempt of $attempts"
92 break
93 }
94
95 # Main test:
96 set test "attach (pass $passes), pending signal catch"
97 if {[gdb_test_multiple "attach $testpid" $test {
98 -re "Attaching to program.*`?$escapedbinfile'?, process $testpid.*Program received signal SIGALRM.*$gdb_prompt $" {
99 # nonthreaded:
100 pass $test
101 verbose -log "$test succeeded on the attempt # $attempt of $attempts"
102 set passes [expr $passes + 1]
103 }
104 -re "Attaching to program.*`?$escapedbinfile'?, process $testpid.*$gdb_prompt $" {
105 set ok 0
106
107 if { $threadtype == "threaded" } {
108 # In the threaded case, the signal is left
109 # pending on the second thread. Check for
110 # that by peeking at the thread's siginfo.
111 # SIGALRM is 14, SIGSTOP is 19.
112
113 # With remote targets, we need to pull the
114 # thread list explicitly before GDB even knows
115 # about thread 2.
116 set test2 "pull thread list"
117 gdb_test_multiple "info threads" $test2 {
118 -re "\r\n$gdb_prompt $" {
119 }
120 }
121
122 set test2 "thread apply 2 print \$_siginfo.si_signo"
123 gdb_test_multiple $test2 $test2 {
124 -re " = 14\r\n$gdb_prompt $" {
125 set ok 1
126 }
127 -re " = 19\r\n$gdb_prompt $" {
128 }
129 }
130 } else {
131 # In the nonthreaded case, GDB should tell the
132 # user about having seen a signal.
133 }
134
135 if { $ok == 0} {
136 # We just lack the luck, we should try it again.
137 set attempt [expr $attempt + 1]
138 } else {
139 pass $test
140 verbose -log "$test succeeded on the attempt # $attempt of $attempts"
141 set passes [expr $passes + 1]
142 }
143 }
144 }] != 0 } {
145 break
146 }
147
148 gdb_test "detach" "Detaching from.*" ""
149 }
150 if {$passes < 3} {
151 if {$attempt > $attempts} {
152 unresolved $test
153 } else {
154 fail $test
155 }
156 }
157
158 # Exit and detach the process.
159
160 gdb_exit
161
162 # Make sure we don't leave a process around to confuse the
163 # next test run (and prevent the compile by keeping the text
164 # file busy), in case the "set should_exit" didn't work.
165
166 # Continue the program - some Linux kernels need it before -9 if the
167 # process is stopped.
168 remote_exec build "kill -s CONT ${testpid}"
169
170 remote_exec build "kill -9 ${testpid}"
171
172 }
173 }
174
175 # build the test case first without threads
176 #
177 if {[build_executable $testfile $executable_nothr $srcfile] == -1} {
178 untested "attach-into-signal.exp (nonthreaded)"
179 return -1
180 }
181
182 corefunc nonthreaded ${executable_nothr}
183
184 # build the test case also with threads
185 #
186 if { [gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${objdir}/${subdir}/${executable_thr}" executable {debug additional_flags=-DUSE_THREADS}] != "" } {
187 untested "attach-into-signal.exp (threaded)"
188 return -1
189 }
190
191 corefunc threaded ${executable_thr}
This page took 0.051171 seconds and 5 git commands to generate.