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