Always organize test artifacts in a directory hierarchy
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.threads / attach-into-signal.exp
CommitLineData
618f726f 1# Copyright 2008-2016 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
20if { ![isnative] || [is_remote host] || [target_info exists use_gdb_stub]
21 || ![istarget *-linux*] } {
a0ef4274
DJ
22 continue
23}
24
0efbbabc 25standard_testfile
cc51a170
PA
26set executable_nothr ${testfile}-nothr
27set executable_thr ${testfile}-thr
a0ef4274 28
cc51a170 29proc 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
2c8c5d37
PA
47 set test_spawn_id [spawn_wait_for_attach $binfile]
48 set testpid [spawn_id_get_pid $test_spawn_id]
13fc3e3c
PA
49
50 # Run 2 passes of the test.
51 # The C file inferior stops pending its signals if a single one is lost,
52 # we test successful redelivery of the caught signal by the 2nd pass.
53
54 # linux-2.6.20.4.x86_64 had maximal attempt # 20 in 4 test runs.
55 set attempts 100
56 set attempt 1
57 set passes 1
58 while { $passes < 3 && $attempt <= $attempts } {
7da5b897
SDJ
59 with_test_prefix "attempt $attempt" {
60 set stoppedtry 0
61 while { $stoppedtry < 10 } {
62 with_test_prefix "stoppedtry $stoppedtry" {
63 if [catch {open /proc/${testpid}/status r} fileid] {
64 set stoppedtry 10
65 break
66 }
67 gets $fileid line1
68 gets $fileid line2
69 close $fileid
70
71 if {![string match "*(stopped)*" $line2]} {
72 # No PASS message as we may be looping in multiple
73 # attempts.
74 break
75 }
76 sleep 1
77 set stoppedtry [expr $stoppedtry + 1]
78 }
13fc3e3c 79 }
7da5b897
SDJ
80 if { $stoppedtry >= 10 } {
81 verbose -log $line2
82 set test "process is still running on the attempt # $attempt of $attempts"
13fc3e3c
PA
83 break
84 }
a0ef4274 85
7da5b897
SDJ
86 # Main test:
87 set test "attach (pass $passes), pending signal catch"
88 if {[gdb_test_multiple "attach $testpid" $test {
89 -re "Attaching to program.*`?$escapedbinfile'?, process $testpid.*Program received signal SIGALRM.*$gdb_prompt $" {
90 # nonthreaded:
13fc3e3c
PA
91 pass $test
92 verbose -log "$test succeeded on the attempt # $attempt of $attempts"
93 set passes [expr $passes + 1]
94 }
7da5b897
SDJ
95 -re "Attaching to program.*`?$escapedbinfile'?, process $testpid.*$gdb_prompt $" {
96 set ok 0
97
98 if { $threadtype == "threaded" } {
99 # In the threaded case, the signal is left
100 # pending on the second thread. Check for
101 # that by peeking at the thread's siginfo.
102 # SIGALRM is 14, SIGSTOP is 19.
103
104 set test2 "thread apply 2 print \$_siginfo.si_signo"
105 gdb_test_multiple $test2 $test2 {
106 -re " = 14\r\n$gdb_prompt $" {
107 set ok 1
108 }
109 -re " = 19\r\n$gdb_prompt $" {
110 }
111 }
112 } else {
113 # In the nonthreaded case, GDB should tell the
114 # user about having seen a signal.
115 }
116
117 if { $ok == 0} {
118 # We just lack the luck, we should try it again.
119 set attempt [expr $attempt + 1]
120 } else {
121 pass $test
122 verbose -log "$test succeeded on the attempt # $attempt of $attempts"
123 set passes [expr $passes + 1]
124 }
125 }
126 }] != 0 } {
127 break
c5a006e6 128 }
a0ef4274 129
7da5b897
SDJ
130 gdb_test "detach" "Detaching from.*" ""
131 }
13fc3e3c 132 }
7da5b897 133
13fc3e3c
PA
134 if {$passes < 3} {
135 if {$attempt > $attempts} {
136 unresolved $test
137 } else {
138 fail $test
139 }
a0ef4274 140 }
a0ef4274 141
13fc3e3c 142 # Exit and detach the process.
13fc3e3c 143 gdb_exit
a0ef4274 144
13fc3e3c
PA
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}"
7da5b897 148
2c8c5d37 149 kill_wait_spawned_process $test_spawn_id
13fc3e3c 150 }
cc51a170 151}
a0ef4274
DJ
152
153# build the test case first without threads
154#
cc51a170
PA
155if {[build_executable $testfile $executable_nothr $srcfile] == -1} {
156 untested "attach-into-signal.exp (nonthreaded)"
c7a6ca08 157 return -1
a0ef4274
DJ
158}
159
cc51a170 160corefunc nonthreaded ${executable_nothr}
a0ef4274
DJ
161
162# build the test case also with threads
163#
0efbbabc 164if { [gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" [standard_output_file ${executable_thr}] executable {debug additional_flags=-DUSE_THREADS}] != "" } {
c7a6ca08
PA
165 untested "attach-into-signal.exp (threaded)"
166 return -1
a0ef4274
DJ
167}
168
cc51a170 169corefunc threaded ${executable_thr}
This page took 0.873682 seconds and 4 git commands to generate.