]>
Commit | Line | Data |
---|---|---|
c5a57081 | 1 | # Copyright 2008-2012 Free Software Foundation, Inc. |
a0ef4274 DJ |
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 | |
3a3dad98 JK |
20 | if { ![isnative] || [is_remote host] || [target_info exists use_gdb_stub] |
21 | || ![istarget *-linux*] } { | |
a0ef4274 DJ |
22 | continue |
23 | } | |
24 | ||
25 | set testfile "attach-into-signal" | |
26 | set srcfile ${testfile}.c | |
cc51a170 PA |
27 | set executable_nothr ${testfile}-nothr |
28 | set executable_thr ${testfile}-thr | |
a0ef4274 | 29 | |
cc51a170 PA |
30 | remote_exec build "rm -f ${objdir}/${subdir}/${executable_nothr}" |
31 | remote_exec build "rm -f ${objdir}/${subdir}/${executable_thr}" | |
a0ef4274 DJ |
32 | # For debugging this test |
33 | # | |
34 | #log_user 1 | |
35 | ||
cc51a170 | 36 | proc corefunc { threadtype executable } { |
a0ef4274 | 37 | global srcfile |
a0ef4274 | 38 | global srcdir |
cc51a170 | 39 | global objdir |
a0ef4274 DJ |
40 | global subdir |
41 | global gdb_prompt | |
cc51a170 PA |
42 | global pf_prefix |
43 | ||
44 | set save_pf_prefix $pf_prefix | |
45 | lappend pf_prefix "$threadtype:" | |
46 | ||
47 | clean_restart ${executable} | |
48 | gdb_test_no_output "set debug lin-lwp 1" "" | |
49 | ||
50 | set binfile ${objdir}/${subdir}/${executable} | |
51 | set escapedbinfile [string_to_regexp ${objdir}/${subdir}/${executable}] | |
a0ef4274 DJ |
52 | |
53 | if [get_compiler_info ${binfile}] { | |
cc51a170 | 54 | set pf_prefix $save_pf_prefix |
a0ef4274 DJ |
55 | return -1 |
56 | } | |
57 | ||
58 | # Start the program running and then wait for a bit, to be sure | |
59 | # that it can be attached to. | |
60 | # Statistically there is a better chance without giving process a nice. | |
61 | ||
62 | set testpid [eval exec $binfile &] | |
63 | exec sleep 2 | |
64 | ||
65 | # Run 2 passes of the test. | |
66 | # The C file inferior stops pending its signals if a single one is lost, | |
67 | # we test successful redelivery of the caught signal by the 2nd pass. | |
68 | ||
69 | # linux-2.6.20.4.x86_64 had maximal attempt # 20 in 4 test runs. | |
70 | set attempts 100 | |
71 | set attempt 1 | |
72 | set passes 1 | |
73 | while { $passes < 3 && $attempt <= $attempts } { | |
74 | set stoppedtry 0 | |
75 | while { $stoppedtry < 10 } { | |
76 | if [catch {open /proc/${testpid}/status r} fileid] { | |
77 | set stoppedtry 10 | |
78 | break | |
79 | } | |
80 | gets $fileid line1; | |
81 | gets $fileid line2; | |
82 | close $fileid; | |
83 | ||
84 | if {![string match "*(stopped)*" $line2]} { | |
85 | # No PASS message as we may be looping in multiple attempts. | |
86 | break | |
87 | } | |
88 | sleep 1 | |
89 | set stoppedtry [expr $stoppedtry + 1] | |
90 | } | |
91 | if { $stoppedtry >= 10 } { | |
92 | verbose -log $line2 | |
cc51a170 | 93 | set test "process is still running on the attempt # $attempt of $attempts" |
a0ef4274 DJ |
94 | break |
95 | } | |
96 | ||
97 | # Main test: | |
cc51a170 | 98 | set test "attach (pass $passes), pending signal catch" |
a0ef4274 DJ |
99 | if {[gdb_test_multiple "attach $testpid" $test { |
100 | -re "Attaching to program.*`?$escapedbinfile'?, process $testpid.*Received Alarm clock.*$gdb_prompt $" { | |
101 | # nonthreaded: | |
102 | pass $test | |
103 | verbose -log "$test succeeded on the attempt # $attempt of $attempts" | |
104 | set passes [expr $passes + 1] | |
105 | } | |
106 | -re "Attaching to program.*`?$escapedbinfile'?, process $testpid.*$gdb_prompt $" { | |
107 | # nonthreaded: | |
108 | # We just lack the luck, we should try it again. | |
109 | set attempt [expr $attempt + 1] | |
110 | } | |
111 | -re "Attaching to process $testpid.*Received Alarm clock.*$gdb_prompt $" { | |
112 | # threaded: | |
113 | pass $test | |
114 | verbose -log "$test succeeded on the attempt # $attempt of $attempts" | |
115 | set passes [expr $passes + 1] | |
116 | } | |
117 | -re "Attaching to process $testpid.*$gdb_prompt $" { | |
118 | # threaded: | |
119 | # We just lack the luck, we should try it again. | |
120 | set attempt [expr $attempt - 1] | |
121 | } | |
122 | }] != 0 } { | |
123 | break | |
124 | } | |
125 | ||
126 | gdb_test "detach" "Detaching from.*" "" | |
127 | } | |
128 | if {$passes < 3} { | |
129 | if {$attempt > $attempts} { | |
130 | unresolved $test | |
131 | } else { | |
132 | fail $test | |
133 | } | |
134 | } | |
135 | ||
136 | # Exit and detach the process. | |
137 | ||
138 | gdb_exit | |
139 | ||
140 | # Make sure we don't leave a process around to confuse | |
141 | # the next test run (and prevent the compile by keeping | |
142 | # the text file busy), in case the "set should_exit" didn't | |
143 | # work. | |
144 | ||
145 | # Continue the program - some Linux kernels need it before -9 if the | |
146 | # process is stopped. | |
147 | remote_exec build "kill -s CONT ${testpid}" | |
148 | ||
149 | remote_exec build "kill -9 ${testpid}" | |
a0ef4274 | 150 | |
cc51a170 PA |
151 | set pf_prefix $save_pf_prefix |
152 | } | |
a0ef4274 DJ |
153 | |
154 | # build the test case first without threads | |
155 | # | |
cc51a170 PA |
156 | if {[build_executable $testfile $executable_nothr $srcfile] == -1} { |
157 | untested "attach-into-signal.exp (nonthreaded)" | |
c7a6ca08 | 158 | return -1 |
a0ef4274 DJ |
159 | } |
160 | ||
cc51a170 | 161 | corefunc nonthreaded ${executable_nothr} |
a0ef4274 DJ |
162 | |
163 | # build the test case also with threads | |
164 | # | |
cc51a170 | 165 | if { [gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${objdir}/${subdir}/${executable_thr}" executable {debug additional_flags=-DUSE_THREADS}] != "" } { |
c7a6ca08 PA |
166 | untested "attach-into-signal.exp (threaded)" |
167 | return -1 | |
a0ef4274 DJ |
168 | } |
169 | ||
cc51a170 | 170 | corefunc threaded ${executable_thr} |