File: TestSwiftInterfaceDsym.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 (167 lines) | stat: -rw-r--r-- 6,851 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# TestSwiftInterfaceDSYM.py
#
# This source file is part of the Swift.org open source project
#
# Copyright (c) 2019 Apple Inc. and the Swift project authors
# Licensed under Apache License v2.0 with Runtime Library Exception
#
# See https://swift.org/LICENSE.txt for license information
# See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
#
# -----------------------------------------------------------------------------

import lldb
import os
from lldbsuite.test.lldbtest import *
from lldbsuite.test.decorators import *
import lldbsuite.test.lldbutil as lldbutil
import unittest2


class TestSwiftInterfaceDSYM(TestBase):
    @swiftTest
    @skipIf(archs=no_match("x86_64"))
    @skipIf(debug_info=no_match(["dsym"]))
    def test_dsym_swiftinterface(self):
        """Test that LLDB can import .swiftinterface files inside a .dSYM bundle."""
        self.build()
        self.assertFalse(os.path.isdir(self.getBuildArtifact("AA.dylib.dSYM")),
                        "dylib dsym exists")

        # The custom swift module cache location
        swift_mod_cache = self.getBuildArtifact("cache")
        self.assertTrue(os.path.isfile(self.getBuildArtifact(
            "a.out.dSYM/Contents/Resources/Swift/x86_64/AA.swiftinterface")),
            "dsymutil doesn't support Swift interfaces")
        # Delete the .swiftinterface form the build dir.
        os.remove(self.getBuildArtifact("AA.swiftinterface"))

        # Clear the swift module cache (populated by the Makefile build)
        shutil.rmtree(swift_mod_cache)
        import glob
        self.assertFalse(os.path.isdir(swift_mod_cache),
                         "module cache should not exist")

        # Update the settings to use the custom module cache location
        self.runCmd('settings set symbols.clang-modules-cache-path "%s"'
                    % swift_mod_cache)

        # Set a breakpoint in and launch the main executable
        lldbutil.run_to_source_breakpoint(
            self, "break here", lldb.SBFileSpec("main.swift"))

        # Check we are able to access the public fields of variables whose
        # types are from the .swiftinterface-only dylibs
        var = self.frame().FindVariable("x")
        lldbutil.check_variable(self, var, False, typename="AA.MyPoint")

        child_y = var.GetChildMemberWithName("y") # MyPoint.y is public
        lldbutil.check_variable(self, child_y, False, value="0")

        # MyPoint.x isn't public, but LLDB can find it through type metadata.
        child_x = var.GetChildMemberWithName("x")
        self.assertTrue(child_x.IsValid())

        # Expression evaluation using types from the .swiftinterface only
        # dylibs should work too
        lldbutil.check_expression(
            self, self.frame(), "y.magnitudeSquared", "404", use_summary=False)
        lldbutil.check_expression(
            self, self.frame(), "MyPoint(x: 1, y: 2).magnitudeSquared", "5",
            use_summary=False)

        # Check the swift module cache was populated with the .swiftmodule
        # files of the loaded modules
        self.assertTrue(os.path.isdir(swift_mod_cache), "module cache exists")
        a_modules = glob.glob(os.path.join(swift_mod_cache, 'AA-*.swiftmodule'))
        self.assertEqual(len(a_modules), 1)

    @swiftTest
    @skipIf(archs=no_match("x86_64"))
    @skipIf(debug_info=no_match(["dsym"]))
    def test_sanity_negative(self):
        """without the swiftinterface the test should fail"""
        self.build()
        self.assertFalse(os.path.isdir(self.getBuildArtifact("AA.dylib.dSYM")),
                        "dylib dsym exists")

        swift_mod_cache = self.getBuildArtifact("cache")

        # Delete the .swiftinterfaces from the .dSYM bundle.
        shutil.rmtree(
            self.getBuildArtifact("a.out.dSYM/Contents/Resources/Swift"),
            ignore_errors=True)

        # Delete the .swiftinterface form the build dir.
        os.remove(self.getBuildArtifact("AA.swiftinterface"))
        shutil.rmtree(swift_mod_cache)
        self.runCmd('settings set symbols.clang-modules-cache-path "%s"'
                    % swift_mod_cache)

        # Set a breakpoint in and launch the main executable
        lldbutil.run_to_source_breakpoint(
            self, "break here", lldb.SBFileSpec("main.swift"))

        # We should not find a type for x.
        var = self.frame().FindVariable("x")
        # This was true for SwiftASTContext, but
        # TypeSystemSwiftTyperef succeeds, because this test it only
        # prints the type *name*.
        self.assertEqual(var.GetTypeName(), "AA.MyPoint")
        # Evaluating an expression fails, though.
        self.expect("expression x", error=1)

    @swiftTest
    @skipIf(archs=no_match("x86_64"))
    @skipIf(debug_info=no_match(["dsym"]))
    def test_sanity_positive(self):
        """Test that the presence of a .swiftinterface doesn't shadow a
           .swiftmodule"""
        self.build(dictionary={'DYLIB_DSYM': 'YES'})
        self.assertTrue(os.path.isdir(self.getBuildArtifact("libAA.dylib.dSYM")),
                        "dylib dsym exists")

        swift_mod_cache = self.getBuildArtifact("cache")
        self.assertTrue(os.path.isdir("%s.dSYM/Contents/Resources/Swift"
                                      %self.getBuildArtifact()),
                        "dsymutil doesn't support Swift interfaces")

        shutil.rmtree(swift_mod_cache)
        self.runCmd('settings set symbols.clang-modules-cache-path "%s"'
                    % swift_mod_cache)

        # Set a breakpoint in and launch the main executable
        target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(
            self, "break here", lldb.SBFileSpec("main.swift"))
        self.expect('breakpoint set -f AA.swift -l 11')

        #
        # main.swift
        #

        # We *should* find a type for x.
        var = self.frame().FindVariable("x")
        lldbutil.check_variable(self, var, typename="AA.MyPoint")
        # MyPoint.x is private.
        child_x = var.GetChildMemberWithName("x")
        self.assertTrue(child_x.IsValid())

        # The expression evaluator sees the whole program, so it also
        # sees the private members.
        self.expect("expression x", substrs=["x = 10"])
        # FIXME: this doesn't work, the summary/value is null/null.
        #lldbutil.check_expression(
        #    self, frame, "x", "x = 10", use_summary=False)

        #
        # AA.swift
        #

        process.Continue()
        var = self.frame().FindVariable("self")
        lldbutil.check_variable(self, var, typename="AA.MyPoint")
        # MyPoint.x is private and we should still see it.
        child_x = var.GetChildMemberWithName("x")
        lldbutil.check_variable(self, child_x, value="10")
        self.expect("expression self", substrs=["x = 10"])