xref: /llvm-project/lldb/test/API/tools/lldb-server/vCont-threads/TestSignal.py (revision 2238dcc39358353cac21df75c3c3286ab20b8f53)
19790406aSMichał Górnyimport re
29790406aSMichał Górny
39790406aSMichał Górnyimport gdbremote_testcase
49790406aSMichał Górnyfrom lldbsuite.test.decorators import *
59790406aSMichał Górnyfrom lldbsuite.test.lldbtest import *
69790406aSMichał Górnyfrom lldbsuite.test import lldbutil
79790406aSMichał Górny
89790406aSMichał Górny
99790406aSMichał Górnyclass TestSignal(gdbremote_testcase.GdbRemoteTestCaseBase):
109790406aSMichał Górny    def start_threads(self, num):
119790406aSMichał Górny        procs = self.prep_debug_monitor_and_inferior(inferior_args=[str(num)])
12*2238dcc3SJonas Devlieghere        self.test_sequence.add_log_lines(
13*2238dcc3SJonas Devlieghere            [
149790406aSMichał Górny                "read packet: $c#63",
159790406aSMichał Górny                {"direction": "send", "regex": "[$]T.*;reason:signal.*"},
16*2238dcc3SJonas Devlieghere            ],
17*2238dcc3SJonas Devlieghere            True,
18*2238dcc3SJonas Devlieghere        )
199790406aSMichał Górny        self.add_threadinfo_collection_packets()
209790406aSMichał Górny
219790406aSMichał Górny        context = self.expect_gdbremote_sequence()
229790406aSMichał Górny        self.assertIsNotNone(context)
239790406aSMichał Górny        threads = self.parse_threadinfo_packets(context)
249790406aSMichał Górny        self.assertIsNotNone(threads)
259790406aSMichał Górny        self.assertEqual(len(threads), num + 1)
269790406aSMichał Górny
279790406aSMichał Górny        self.reset_test_sequence()
289790406aSMichał Górny        return threads
299790406aSMichał Górny
309790406aSMichał Górny    SIGNAL_MATCH_RE = re.compile(r"received SIGUSR1 on thread id: ([0-9a-f]+)")
319790406aSMichał Górny
329790406aSMichał Górny    def send_and_check_signal(self, vCont_data, threads):
33*2238dcc3SJonas Devlieghere        self.test_sequence.add_log_lines(
34*2238dcc3SJonas Devlieghere            [
359790406aSMichał Górny                "read packet: $vCont;{0}#00".format(vCont_data),
369790406aSMichał Górny                "send packet: $W00#00",
37*2238dcc3SJonas Devlieghere            ],
38*2238dcc3SJonas Devlieghere            True,
39*2238dcc3SJonas Devlieghere        )
409790406aSMichał Górny        exp = self.expect_gdbremote_sequence()
419790406aSMichał Górny        self.reset_test_sequence()
429790406aSMichał Górny        tids = []
439790406aSMichał Górny        for line in exp["O_content"].decode().splitlines():
449790406aSMichał Górny            m = self.SIGNAL_MATCH_RE.match(line)
459790406aSMichał Górny            if m is not None:
469790406aSMichał Górny                tids.append(int(m.group(1), 16))
479790406aSMichał Górny        self.assertEqual(sorted(tids), sorted(threads))
489790406aSMichał Górny
499790406aSMichał Górny    def get_pid(self):
509790406aSMichał Górny        self.add_process_info_collection_packets()
519790406aSMichał Górny        context = self.expect_gdbremote_sequence()
529790406aSMichał Górny        self.assertIsNotNone(context)
539790406aSMichał Górny        procinfo = self.parse_process_info_response(context)
54*2238dcc3SJonas Devlieghere        return int(procinfo["pid"], 16)
559790406aSMichał Górny
569790406aSMichał Górny    @skipIfWindows
579790406aSMichał Górny    @skipIfDarwin
589790406aSMichał Górny    @expectedFailureNetBSD
59*2238dcc3SJonas Devlieghere    @expectedFailureAll(
60*2238dcc3SJonas Devlieghere        oslist=["freebsd"], bugnumber="github.com/llvm/llvm-project/issues/56086"
61*2238dcc3SJonas Devlieghere    )
629790406aSMichał Górny    @skipIfAsan  # Times out under asan
639790406aSMichał Górny    @skipIf(oslist=["linux"], archs=["arm", "aarch64"])  # Randomly fails on buildbot
649790406aSMichał Górny    def test_signal_process_without_tid(self):
659790406aSMichał Górny        self.build()
669790406aSMichał Górny        self.set_inferior_startup_launch()
679790406aSMichał Górny
689790406aSMichał Górny        threads = self.start_threads(1)
699790406aSMichał Górny        self.send_and_check_signal(
70*2238dcc3SJonas Devlieghere            "C{0:x}".format(lldbutil.get_signal_number("SIGUSR1")), threads
71*2238dcc3SJonas Devlieghere        )
729790406aSMichał Górny
739790406aSMichał Górny    @skipUnlessPlatform(["netbsd"])
749790406aSMichał Górny    @expectedFailureNetBSD
759790406aSMichał Górny    @skipIfAsan  # Times out under asan
769790406aSMichał Górny    @skipIf(oslist=["linux"], archs=["arm", "aarch64"])  # Randomly fails on buildbot
779790406aSMichał Górny    def test_signal_one_thread(self):
789790406aSMichał Górny        self.build()
799790406aSMichał Górny        self.set_inferior_startup_launch()
809790406aSMichał Górny
819790406aSMichał Górny        threads = self.start_threads(1)
829790406aSMichał Górny        # try sending a signal to one of the two threads
839790406aSMichał Górny        self.send_and_check_signal(
84*2238dcc3SJonas Devlieghere            "C{0:x}:{1:x};c".format(lldbutil.get_signal_number("SIGUSR1")), threads[:1]
85*2238dcc3SJonas Devlieghere        )
869790406aSMichał Górny
879790406aSMichał Górny    @skipIfWindows
889790406aSMichał Górny    @skipIfDarwin
899790406aSMichał Górny    @expectedFailureNetBSD
90*2238dcc3SJonas Devlieghere    @expectedFailureAll(
91*2238dcc3SJonas Devlieghere        oslist=["freebsd"], bugnumber="github.com/llvm/llvm-project/issues/56086"
92*2238dcc3SJonas Devlieghere    )
939790406aSMichał Górny    @skipIfAsan  # Times out under asan
949790406aSMichał Górny    @skipIf(oslist=["linux"], archs=["arm", "aarch64"])  # Randomly fails on buildbot
959790406aSMichał Górny    def test_signal_all_threads(self):
969790406aSMichał Górny        self.build()
979790406aSMichał Górny        self.set_inferior_startup_launch()
989790406aSMichał Górny
999790406aSMichał Górny        threads = self.start_threads(1)
1009790406aSMichał Górny        # try sending a signal to two threads (= the process)
1019790406aSMichał Górny        self.send_and_check_signal(
1029790406aSMichał Górny            "C{0:x}:{1:x};C{0:x}:{2:x}".format(
103*2238dcc3SJonas Devlieghere                lldbutil.get_signal_number("SIGUSR1"), *threads
104*2238dcc3SJonas Devlieghere            ),
105*2238dcc3SJonas Devlieghere            threads,
106*2238dcc3SJonas Devlieghere        )
1079790406aSMichał Górny
1089790406aSMichał Górny    @skipIfWindows
1099790406aSMichał Górny    @expectedFailureNetBSD
110*2238dcc3SJonas Devlieghere    @expectedFailureAll(
111*2238dcc3SJonas Devlieghere        oslist=["freebsd"], bugnumber="github.com/llvm/llvm-project/issues/56086"
112*2238dcc3SJonas Devlieghere    )
1139790406aSMichał Górny    @add_test_categories(["llgs"])
1149790406aSMichał Górny    @skipIfAsan  # Times out under asan
1159790406aSMichał Górny    @skipIf(oslist=["linux"], archs=["arm", "aarch64"])  # Randomly fails on buildbot
1169790406aSMichał Górny    def test_signal_process_by_pid(self):
1179790406aSMichał Górny        self.build()
1189790406aSMichał Górny        self.set_inferior_startup_launch()
1199790406aSMichał Górny
1209790406aSMichał Górny        threads = self.start_threads(1)
1219790406aSMichał Górny        self.send_and_check_signal(
1229790406aSMichał Górny            "C{0:x}:p{1:x}".format(
123*2238dcc3SJonas Devlieghere                lldbutil.get_signal_number("SIGUSR1"), self.get_pid()
124*2238dcc3SJonas Devlieghere            ),
125*2238dcc3SJonas Devlieghere            threads,
126*2238dcc3SJonas Devlieghere        )
1279790406aSMichał Górny
1289790406aSMichał Górny    @skipIfWindows
1299790406aSMichał Górny    @expectedFailureNetBSD
130*2238dcc3SJonas Devlieghere    @expectedFailureAll(
131*2238dcc3SJonas Devlieghere        oslist=["freebsd"], bugnumber="github.com/llvm/llvm-project/issues/56086"
132*2238dcc3SJonas Devlieghere    )
1339790406aSMichał Górny    @add_test_categories(["llgs"])
1349790406aSMichał Górny    @skipIfAsan  # Times out under asan
1359790406aSMichał Górny    @skipIf(oslist=["linux"], archs=["arm", "aarch64"])  # Randomly fails on buildbot
1369790406aSMichał Górny    def test_signal_process_minus_one(self):
1379790406aSMichał Górny        self.build()
1389790406aSMichał Górny        self.set_inferior_startup_launch()
1399790406aSMichał Górny
1409790406aSMichał Górny        threads = self.start_threads(1)
1419790406aSMichał Górny        self.send_and_check_signal(
142*2238dcc3SJonas Devlieghere            "C{0:x}:p-1".format(lldbutil.get_signal_number("SIGUSR1")), threads
143*2238dcc3SJonas Devlieghere        )
1449790406aSMichał Górny
1459790406aSMichał Górny    @skipIfWindows
1469790406aSMichał Górny    @expectedFailureNetBSD
147*2238dcc3SJonas Devlieghere    @expectedFailureAll(
148*2238dcc3SJonas Devlieghere        oslist=["freebsd"], bugnumber="github.com/llvm/llvm-project/issues/56086"
149*2238dcc3SJonas Devlieghere    )
1509790406aSMichał Górny    @add_test_categories(["llgs"])
1519790406aSMichał Górny    @skipIf(oslist=["linux"], archs=["arm", "aarch64"])  # Randomly fails on buildbot
1529790406aSMichał Górny    def test_signal_minus_one(self):
1539790406aSMichał Górny        self.build()
1549790406aSMichał Górny        self.set_inferior_startup_launch()
1559790406aSMichał Górny
1569790406aSMichał Górny        threads = self.start_threads(1)
1579790406aSMichał Górny        self.send_and_check_signal(
158*2238dcc3SJonas Devlieghere            "C{0:x}:-1".format(lldbutil.get_signal_number("SIGUSR1")), threads
159*2238dcc3SJonas Devlieghere        )
1609790406aSMichał Górny
1619790406aSMichał Górny    @skipIfWindows
1629790406aSMichał Górny    @expectedFailureNetBSD
163*2238dcc3SJonas Devlieghere    @expectedFailureAll(
164*2238dcc3SJonas Devlieghere        oslist=["freebsd"], bugnumber="github.com/llvm/llvm-project/issues/56086"
165*2238dcc3SJonas Devlieghere    )
1669790406aSMichał Górny    @add_test_categories(["llgs"])
1679790406aSMichał Górny    @skipIfAsan  # Times out under asan
1689790406aSMichał Górny    @skipIf(oslist=["linux"], archs=["arm", "aarch64"])  # Randomly fails on buildbot
1699790406aSMichał Górny    def test_signal_all_threads_by_pid(self):
1709790406aSMichał Górny        self.build()
1719790406aSMichał Górny        self.set_inferior_startup_launch()
1729790406aSMichał Górny
1739790406aSMichał Górny        threads = self.start_threads(1)
1749790406aSMichał Górny        # try sending a signal to two threads (= the process)
1759790406aSMichał Górny        self.send_and_check_signal(
1769790406aSMichał Górny            "C{0:x}:p{1:x}.{2:x};C{0:x}:p{1:x}.{3:x}".format(
177*2238dcc3SJonas Devlieghere                lldbutil.get_signal_number("SIGUSR1"), self.get_pid(), *threads
178*2238dcc3SJonas Devlieghere            ),
179*2238dcc3SJonas Devlieghere            threads,
180*2238dcc3SJonas Devlieghere        )
1819790406aSMichał Górny
1829790406aSMichał Górny    @skipIfWindows
1839790406aSMichał Górny    @expectedFailureNetBSD
184*2238dcc3SJonas Devlieghere    @expectedFailureAll(
185*2238dcc3SJonas Devlieghere        oslist=["freebsd"], bugnumber="github.com/llvm/llvm-project/issues/56086"
186*2238dcc3SJonas Devlieghere    )
1879790406aSMichał Górny    @add_test_categories(["llgs"])
1889790406aSMichał Górny    @skipIfAsan  # Times out under asan
1899790406aSMichał Górny    @skipIf(oslist=["linux"], archs=["arm", "aarch64"])  # Randomly fails on buildbot
1909790406aSMichał Górny    def test_signal_minus_one_by_pid(self):
1919790406aSMichał Górny        self.build()
1929790406aSMichał Górny        self.set_inferior_startup_launch()
1939790406aSMichał Górny
1949790406aSMichał Górny        threads = self.start_threads(1)
1959790406aSMichał Górny        self.send_and_check_signal(
1969790406aSMichał Górny            "C{0:x}:p{1:x}.-1".format(
197*2238dcc3SJonas Devlieghere                lldbutil.get_signal_number("SIGUSR1"), self.get_pid()
198*2238dcc3SJonas Devlieghere            ),
199*2238dcc3SJonas Devlieghere            threads,
200*2238dcc3SJonas Devlieghere        )
2019790406aSMichał Górny
2029790406aSMichał Górny    @skipIfWindows
2039790406aSMichał Górny    @expectedFailureNetBSD
204*2238dcc3SJonas Devlieghere    @expectedFailureAll(
205*2238dcc3SJonas Devlieghere        oslist=["freebsd"], bugnumber="github.com/llvm/llvm-project/issues/56086"
206*2238dcc3SJonas Devlieghere    )
2079790406aSMichał Górny    @add_test_categories(["llgs"])
2089790406aSMichał Górny    @skipIfAsan  # Times out under asan
2099790406aSMichał Górny    @skipIf(oslist=["linux"], archs=["arm", "aarch64"])  # Randomly fails on buildbot
2109790406aSMichał Górny    def test_signal_minus_one_by_minus_one(self):
2119790406aSMichał Górny        self.build()
2129790406aSMichał Górny        self.set_inferior_startup_launch()
2139790406aSMichał Górny
2149790406aSMichał Górny        threads = self.start_threads(1)
2159790406aSMichał Górny        self.send_and_check_signal(
216*2238dcc3SJonas Devlieghere            "C{0:x}:p-1.-1".format(lldbutil.get_signal_number("SIGUSR1")), threads
217*2238dcc3SJonas Devlieghere        )
2189790406aSMichał Górny
2199790406aSMichał Górny    @skipUnlessPlatform(["netbsd"])
2209790406aSMichał Górny    @skipIf(oslist=["linux"], archs=["arm", "aarch64"])  # Randomly fails on buildbot
2219790406aSMichał Górny    def test_signal_two_of_three_threads(self):
2229790406aSMichał Górny        self.build()
2239790406aSMichał Górny        self.set_inferior_startup_launch()
2249790406aSMichał Górny
2259790406aSMichał Górny        threads = self.start_threads(2)
2269790406aSMichał Górny        # try sending a signal to 2 out of 3 threads
227*2238dcc3SJonas Devlieghere        self.test_sequence.add_log_lines(
228*2238dcc3SJonas Devlieghere            [
2299790406aSMichał Górny                "read packet: $vCont;C{0:x}:{1:x};C{0:x}:{2:x};c#00".format(
230*2238dcc3SJonas Devlieghere                    lldbutil.get_signal_number("SIGUSR1"), threads[1], threads[2]
231*2238dcc3SJonas Devlieghere                ),
2329790406aSMichał Górny                {"direction": "send", "regex": r"^\$E1e#db$"},
233*2238dcc3SJonas Devlieghere            ],
234*2238dcc3SJonas Devlieghere            True,
235*2238dcc3SJonas Devlieghere        )
2369790406aSMichał Górny
2379790406aSMichał Górny        context = self.expect_gdbremote_sequence()
2389790406aSMichał Górny        self.assertIsNotNone(context)
2399790406aSMichał Górny
2409790406aSMichał Górny    @skipUnlessPlatform(["netbsd"])
2419790406aSMichał Górny    @skipIf(oslist=["linux"], archs=["arm", "aarch64"])  # Randomly fails on buildbot
2429790406aSMichał Górny    def test_signal_two_signals(self):
2439790406aSMichał Górny        self.build()
2449790406aSMichał Górny        self.set_inferior_startup_launch()
2459790406aSMichał Górny
2469790406aSMichał Górny        threads = self.start_threads(1)
2479790406aSMichał Górny        # try sending two different signals to two threads
248*2238dcc3SJonas Devlieghere        self.test_sequence.add_log_lines(
249*2238dcc3SJonas Devlieghere            [
2509790406aSMichał Górny                "read packet: $vCont;C{0:x}:{1:x};C{2:x}:{3:x}#00".format(
251*2238dcc3SJonas Devlieghere                    lldbutil.get_signal_number("SIGUSR1"),
252*2238dcc3SJonas Devlieghere                    threads[0],
253*2238dcc3SJonas Devlieghere                    lldbutil.get_signal_number("SIGUSR2"),
254*2238dcc3SJonas Devlieghere                    threads[1],
255*2238dcc3SJonas Devlieghere                ),
2569790406aSMichał Górny                {"direction": "send", "regex": r"^\$E1e#db$"},
257*2238dcc3SJonas Devlieghere            ],
258*2238dcc3SJonas Devlieghere            True,
259*2238dcc3SJonas Devlieghere        )
2609790406aSMichał Górny
2619790406aSMichał Górny        context = self.expect_gdbremote_sequence()
2629790406aSMichał Górny        self.assertIsNotNone(context)
263