File: TestCancelAttach.py

package info (click to toggle)
llvm-toolchain-19 1%3A19.1.7-3~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,998,492 kB
  • sloc: cpp: 6,951,680; ansic: 1,486,157; asm: 913,598; python: 232,024; f90: 80,126; objc: 75,281; lisp: 37,276; pascal: 16,990; sh: 10,009; ml: 5,058; perl: 4,724; awk: 3,523; makefile: 3,167; javascript: 2,504; xml: 892; fortran: 664; cs: 573
file content (58 lines) | stat: -rw-r--r-- 2,077 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
"""
Test using SendAsyncInterrupt to interrupt an "attach wait"
"""

import lldb
import sys
import time
import threading
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
import lldbsuite.test.lldbutil


class AttachCancelTestCase(TestBase):
    NO_DEBUG_INFO_TESTCASE = True

    def test_scripted_implementation(self):
        """Test that cancelling a stuck "attach waitfor" works."""
        # First make an empty target for the attach:
        target = self.dbg.CreateTarget(None)

        # We need to cancel this, so we need to do the attach
        # on a separate thread:
        class AttachThread(threading.Thread):
            def __init__(self, target, error):
                # Make this a daemon thread so if we don't manage to interrupt,
                # Python will keep this thread from hanging the test.
                threading.Thread.__init__(self, daemon=True)
                self.target = target
                self.error = error

            def run(self):
                self.target.AttachToProcessWithName(
                    lldb.SBListener(), "LLDB-No-Such-Process", True, self.error
                )

        error = lldb.SBError()
        thread = AttachThread(target, error)
        thread.start()

        # Now wait till the attach on the child thread has made a process
        # for the attach attempt:
        while not target.process.IsValid():
            time.sleep(1)
        # I don't have a positive signal for "we started the attach attempt"
        # so the best I can do is sleep a bit more here to give that a chance
        # to start:
        time.sleep(1)

        # Now send the attach interrupt:
        target.process.SendAsyncInterrupt()
        # We don't want to stall if we can't interrupt, so join with a timeout:
        thread.join(60)
        if thread.is_alive():
            self.fail("The attach thread is alive after timeout interval")

        # Now check the error, should say the attach was interrupted:
        self.assertTrue(error.Fail(), "We succeeded in not attaching")