3 import gdbremote_testcase
4 from lldbsuite
.test
.decorators
import *
5 from lldbsuite
.test
.lldbtest
import *
6 from lldbsuite
.test
import lldbutil
9 class TestSignal(gdbremote_testcase
.GdbRemoteTestCaseBase
):
10 def start_threads(self
, num
):
11 procs
= self
.prep_debug_monitor_and_inferior(inferior_args
=[str(num
)])
12 self
.test_sequence
.add_log_lines(
15 {"direction": "send", "regex": "[$]T.*;reason:signal.*"},
19 self
.add_threadinfo_collection_packets()
21 context
= self
.expect_gdbremote_sequence()
22 self
.assertIsNotNone(context
)
23 threads
= self
.parse_threadinfo_packets(context
)
24 self
.assertIsNotNone(threads
)
25 self
.assertEqual(len(threads
), num
+ 1)
27 self
.reset_test_sequence()
30 SIGNAL_MATCH_RE
= re
.compile(r
"received SIGUSR1 on thread id: ([0-9a-f]+)")
32 def send_and_check_signal(self
, vCont_data
, threads
):
33 self
.test_sequence
.add_log_lines(
35 "read packet: $vCont;{0}#00".format(vCont_data
),
36 "send packet: $W00#00",
40 exp
= self
.expect_gdbremote_sequence()
41 self
.reset_test_sequence()
43 for line
in exp
["O_content"].decode().splitlines():
44 m
= self
.SIGNAL_MATCH_RE
.match(line
)
46 tids
.append(int(m
.group(1), 16))
47 self
.assertEqual(sorted(tids
), sorted(threads
))
50 self
.add_process_info_collection_packets()
51 context
= self
.expect_gdbremote_sequence()
52 self
.assertIsNotNone(context
)
53 procinfo
= self
.parse_process_info_response(context
)
54 return int(procinfo
["pid"], 16)
58 @expectedFailureNetBSD
60 oslist
=["freebsd"], bugnumber
="github.com/llvm/llvm-project/issues/56086"
62 @skipIfAsan # Times out under asan
63 @skipIf(oslist
=["linux"], archs
=["arm", "aarch64"]) # Randomly fails on buildbot
64 def test_signal_process_without_tid(self
):
66 self
.set_inferior_startup_launch()
68 threads
= self
.start_threads(1)
69 self
.send_and_check_signal(
70 "C{0:x}".format(lldbutil
.get_signal_number("SIGUSR1")), threads
73 @skipUnlessPlatform(["netbsd"])
74 @expectedFailureNetBSD
75 @skipIfAsan # Times out under asan
76 @skipIf(oslist
=["linux"], archs
=["arm", "aarch64"]) # Randomly fails on buildbot
77 def test_signal_one_thread(self
):
79 self
.set_inferior_startup_launch()
81 threads
= self
.start_threads(1)
82 # try sending a signal to one of the two threads
83 self
.send_and_check_signal(
84 "C{0:x}:{1:x};c".format(lldbutil
.get_signal_number("SIGUSR1")), threads
[:1]
89 @expectedFailureNetBSD
91 oslist
=["freebsd"], bugnumber
="github.com/llvm/llvm-project/issues/56086"
93 @skipIfAsan # Times out under asan
94 @skipIf(oslist
=["linux"], archs
=["arm", "aarch64"]) # Randomly fails on buildbot
95 def test_signal_all_threads(self
):
97 self
.set_inferior_startup_launch()
99 threads
= self
.start_threads(1)
100 # try sending a signal to two threads (= the process)
101 self
.send_and_check_signal(
102 "C{0:x}:{1:x};C{0:x}:{2:x}".format(
103 lldbutil
.get_signal_number("SIGUSR1"), *threads
109 @expectedFailureNetBSD
111 oslist
=["freebsd"], bugnumber
="github.com/llvm/llvm-project/issues/56086"
113 @add_test_categories(["llgs"])
114 @skipIfAsan # Times out under asan
115 @skipIf(oslist
=["linux"], archs
=["arm", "aarch64"]) # Randomly fails on buildbot
116 def test_signal_process_by_pid(self
):
118 self
.set_inferior_startup_launch()
120 threads
= self
.start_threads(1)
121 self
.send_and_check_signal(
122 "C{0:x}:p{1:x}".format(
123 lldbutil
.get_signal_number("SIGUSR1"), self
.get_pid()
129 @expectedFailureNetBSD
131 oslist
=["freebsd"], bugnumber
="github.com/llvm/llvm-project/issues/56086"
133 @add_test_categories(["llgs"])
134 @skipIfAsan # Times out under asan
135 @skipIf(oslist
=["linux"], archs
=["arm", "aarch64"]) # Randomly fails on buildbot
136 def test_signal_process_minus_one(self
):
138 self
.set_inferior_startup_launch()
140 threads
= self
.start_threads(1)
141 self
.send_and_check_signal(
142 "C{0:x}:p-1".format(lldbutil
.get_signal_number("SIGUSR1")), threads
146 @expectedFailureNetBSD
148 oslist
=["freebsd"], bugnumber
="github.com/llvm/llvm-project/issues/56086"
150 @add_test_categories(["llgs"])
151 @skipIf(oslist
=["linux"], archs
=["arm", "aarch64"]) # Randomly fails on buildbot
152 def test_signal_minus_one(self
):
154 self
.set_inferior_startup_launch()
156 threads
= self
.start_threads(1)
157 self
.send_and_check_signal(
158 "C{0:x}:-1".format(lldbutil
.get_signal_number("SIGUSR1")), threads
162 @expectedFailureNetBSD
164 oslist
=["freebsd"], bugnumber
="github.com/llvm/llvm-project/issues/56086"
166 @add_test_categories(["llgs"])
167 @skipIfAsan # Times out under asan
168 @skipIf(oslist
=["linux"], archs
=["arm", "aarch64"]) # Randomly fails on buildbot
169 def test_signal_all_threads_by_pid(self
):
171 self
.set_inferior_startup_launch()
173 threads
= self
.start_threads(1)
174 # try sending a signal to two threads (= the process)
175 self
.send_and_check_signal(
176 "C{0:x}:p{1:x}.{2:x};C{0:x}:p{1:x}.{3:x}".format(
177 lldbutil
.get_signal_number("SIGUSR1"), self
.get_pid(), *threads
183 @expectedFailureNetBSD
185 oslist
=["freebsd"], bugnumber
="github.com/llvm/llvm-project/issues/56086"
187 @add_test_categories(["llgs"])
188 @skipIfAsan # Times out under asan
189 @skipIf(oslist
=["linux"], archs
=["arm", "aarch64"]) # Randomly fails on buildbot
190 def test_signal_minus_one_by_pid(self
):
192 self
.set_inferior_startup_launch()
194 threads
= self
.start_threads(1)
195 self
.send_and_check_signal(
196 "C{0:x}:p{1:x}.-1".format(
197 lldbutil
.get_signal_number("SIGUSR1"), self
.get_pid()
203 @expectedFailureNetBSD
205 oslist
=["freebsd"], bugnumber
="github.com/llvm/llvm-project/issues/56086"
207 @add_test_categories(["llgs"])
208 @skipIfAsan # Times out under asan
209 @skipIf(oslist
=["linux"], archs
=["arm", "aarch64"]) # Randomly fails on buildbot
210 def test_signal_minus_one_by_minus_one(self
):
212 self
.set_inferior_startup_launch()
214 threads
= self
.start_threads(1)
215 self
.send_and_check_signal(
216 "C{0:x}:p-1.-1".format(lldbutil
.get_signal_number("SIGUSR1")), threads
219 @skipUnlessPlatform(["netbsd"])
220 @skipIf(oslist
=["linux"], archs
=["arm", "aarch64"]) # Randomly fails on buildbot
221 def test_signal_two_of_three_threads(self
):
223 self
.set_inferior_startup_launch()
225 threads
= self
.start_threads(2)
226 # try sending a signal to 2 out of 3 threads
227 self
.test_sequence
.add_log_lines(
229 "read packet: $vCont;C{0:x}:{1:x};C{0:x}:{2:x};c#00".format(
230 lldbutil
.get_signal_number("SIGUSR1"), threads
[1], threads
[2]
232 {"direction": "send", "regex": r
"^\$E1e#db$"},
237 context
= self
.expect_gdbremote_sequence()
238 self
.assertIsNotNone(context
)
240 @skipUnlessPlatform(["netbsd"])
241 @skipIf(oslist
=["linux"], archs
=["arm", "aarch64"]) # Randomly fails on buildbot
242 def test_signal_two_signals(self
):
244 self
.set_inferior_startup_launch()
246 threads
= self
.start_threads(1)
247 # try sending two different signals to two threads
248 self
.test_sequence
.add_log_lines(
250 "read packet: $vCont;C{0:x}:{1:x};C{2:x}:{3:x}#00".format(
251 lldbutil
.get_signal_number("SIGUSR1"),
253 lldbutil
.get_signal_number("SIGUSR2"),
256 {"direction": "send", "regex": r
"^\$E1e#db$"},
261 context
= self
.expect_gdbremote_sequence()
262 self
.assertIsNotNone(context
)