File: TestSwiftStepInAsync.py

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (64 lines) | stat: -rw-r--r-- 2,966 bytes parent folder | download
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
59
60
61
62
63
64
import lldb
from lldbsuite.test.decorators import *
import lldbsuite.test.lldbtest as lldbtest
import lldbsuite.test.lldbutil as lldbutil
import re

class TestCase(lldbtest.TestBase):

    mydir = lldbtest.TestBase.compute_mydir(__file__)

    @swiftTest
    @skipIf(oslist=['windows', 'linux'])
    @skipIf(bugnumber="rdar://116529018")
    def test(self):
        """Test step-in to async functions"""
        self.build()
        src = lldb.SBFileSpec('main.swift')
        _, process, _, _ = lldbutil.run_to_source_breakpoint(self, 'await', src)

        # When run with debug info enabled builds, this prevents stepping from
        # stopping in Swift Concurrency runtime functions.
        self.runCmd("settings set target.process.thread.step-avoid-libraries libswift_Concurrency.dylib")

        # All thread actions are done on the currently selected thread.
        thread = process.GetSelectedThread

        num_async_steps = 0
        while True:
            stop_reason = thread().stop_reason
            if stop_reason == lldb.eStopReasonNone:
                break
            elif stop_reason == lldb.eStopReasonPlanComplete:
                # Run until the next `await` breakpoint.
                process.Continue()
            elif stop_reason == lldb.eStopReasonBreakpoint:
                caller_before = thread().frames[0].function.GetDisplayName()
                line_before = thread().frames[0].line_entry.line
                thread().StepInto()
                caller_after = thread().frames[1].function.GetDisplayName()
                line_after = thread().frames[0].line_entry.line

                # Breakpoints on lines with an `await` may result in more than
                # one breakpoint location. Specifically a location before an
                # async function is called, and then a location on the resume
                # function. In this case, running `step` on these lines will
                # move execution forward within the same function, _not_ step
                # into a new function.
                #
                # As this test is for stepping into async functions, when the
                # step-in keeps execution on the same or next line -- not a
                # different function, then it can be ignored. rdar://76116620
                if line_after in (line_before, line_before + 1):
                    # When stepping stops at breakpoint, don't continue.
                    if thread().stop_reason != lldb.eStopReasonBreakpoint:
                        process.Continue()
                    continue

                # The entry function is missing this prefix dedicating resume functions.
                prefix = re.compile(r'^\([0-9]+\) await resume partial function for ')
                self.assertEqual(prefix.sub('', caller_after),
                                 prefix.sub('', caller_before))
                num_async_steps += 1

        self.assertGreater(num_async_steps, 0)