Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / lldb / test / API / tools / lldb-server / vCont-threads / TestSignal.py
blob2223202e4c08ad20a7788b85ffb2c0a7f7b3f6e3
1 import re
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(
14 "read packet: $c#63",
15 {"direction": "send", "regex": "[$]T.*;reason:signal.*"},
17 True,
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()
28 return threads
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",
38 True,
40 exp = self.expect_gdbremote_sequence()
41 self.reset_test_sequence()
42 tids = []
43 for line in exp["O_content"].decode().splitlines():
44 m = self.SIGNAL_MATCH_RE.match(line)
45 if m is not None:
46 tids.append(int(m.group(1), 16))
47 self.assertEqual(sorted(tids), sorted(threads))
49 def get_pid(self):
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)
56 @skipIfWindows
57 @skipIfDarwin
58 @expectedFailureNetBSD
59 @expectedFailureAll(
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):
65 self.build()
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):
78 self.build()
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]
87 @skipIfWindows
88 @skipIfDarwin
89 @expectedFailureNetBSD
90 @expectedFailureAll(
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):
96 self.build()
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
105 threads,
108 @skipIfWindows
109 @expectedFailureNetBSD
110 @expectedFailureAll(
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):
117 self.build()
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()
125 threads,
128 @skipIfWindows
129 @expectedFailureNetBSD
130 @expectedFailureAll(
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):
137 self.build()
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
145 @skipIfWindows
146 @expectedFailureNetBSD
147 @expectedFailureAll(
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):
153 self.build()
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
161 @skipIfWindows
162 @expectedFailureNetBSD
163 @expectedFailureAll(
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):
170 self.build()
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
179 threads,
182 @skipIfWindows
183 @expectedFailureNetBSD
184 @expectedFailureAll(
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):
191 self.build()
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()
199 threads,
202 @skipIfWindows
203 @expectedFailureNetBSD
204 @expectedFailureAll(
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):
211 self.build()
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):
222 self.build()
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$"},
234 True,
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):
243 self.build()
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"),
252 threads[0],
253 lldbutil.get_signal_number("SIGUSR2"),
254 threads[1],
256 {"direction": "send", "regex": r"^\$E1e#db$"},
258 True,
261 context = self.expect_gdbremote_sequence()
262 self.assertIsNotNone(context)