forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 344
Move (most of) No.Swiftmodule into a proper API test. #3895
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
adrian-prantl
merged 1 commit into
swiftlang:stable/20211026
from
adrian-prantl:reflection-test
Feb 14, 2022
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
SWIFT_SOURCES := main.swift | ||
HIDE_SWIFTMODULE := YES | ||
|
||
SWIFTFLAGS_EXTRAS := -I. -enable-library-evolution | ||
|
||
LD_EXTRAS = -L. -Xlinker -rpath -Xlinker $(BUILDDIR) -ldynamic_lib | ||
|
||
all: dylib $(EXE) | ||
.PHONY: dylib | ||
|
||
include Makefile.rules | ||
dylib: lib.swift | ||
$(MAKE) -f $(MAKEFILE_RULES) \ | ||
MAKE_DSYM=YES DYLIB_ONLY=YES DYLIB_NAME=dynamic_lib \ | ||
DYLIB_SWIFT_SOURCES="lib.swift" \ | ||
DYLIB_HIDE_SWIFTMODULE=YES \ | ||
SWIFTFLAGS_EXTRAS="-I$(BUILDDIR) $(SWIFTFLAGS_EXTRAS)" |
91 changes: 91 additions & 0 deletions
91
lldb/test/API/lang/swift/reflection_only/TestSwiftReflectionOnly.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import lldb | ||
from lldbsuite.test.decorators import * | ||
import lldbsuite.test.lldbtest as lldbtest | ||
import lldbsuite.test.lldbutil as lldbutil | ||
import unittest2 | ||
import re | ||
|
||
class TestSwiftReflectionOnly(lldbtest.TestBase): | ||
NO_DEBUG_INFO_TESTCASE = True | ||
|
||
mydir = lldbtest.TestBase.compute_mydir(__file__) | ||
|
||
@swiftTest | ||
def test(self): | ||
"""Test debugging a program without swiftmodules is functional""" | ||
self.build() | ||
|
||
target, process, thread, bkpt = lldbutil.run_to_source_breakpoint( | ||
self, 'Set breakpoint here', lldb.SBFileSpec('main.swift'), | ||
extra_images=['dynamic_lib']) | ||
log = self.getBuildArtifact('types.log') | ||
self.expect('log enable lldb types -f ' + log) | ||
|
||
check_var = lldbutil.check_variable | ||
frame = thread.frames[0] | ||
var_self = frame.FindVariable("self") | ||
var_self_x = var_self.GetChildMemberWithName("x") | ||
check_var(self, var_self_x, value="42") | ||
|
||
check_var(self, frame.FindVariable("number"), value="1") | ||
|
||
array = frame.FindVariable("array") | ||
check_var(self, array, num_children=3) | ||
check_var(self, array.GetChildAtIndex(0), value="1") | ||
check_var(self, array.GetChildAtIndex(1), value="2") | ||
check_var(self, array.GetChildAtIndex(2), value="3") | ||
|
||
check_var(self, frame.FindVariable("string"), summary='"hello"') | ||
|
||
tup = frame.FindVariable("tuple") | ||
check_var(self, tup, num_children=2) | ||
check_var(self, tup.GetChildAtIndex(0), value="0") | ||
check_var(self, tup.GetChildAtIndex(1), value="1") | ||
|
||
strct = frame.FindVariable("strct") | ||
check_var(self, strct, num_children=5) | ||
check_var(self, strct.GetChildMemberWithName("pub"), value="1") | ||
check_var(self, strct.GetChildMemberWithName("priv"), value="2") | ||
check_var(self, strct.GetChildMemberWithName("filepriv"), value="3") | ||
s_priv = strct.GetChildMemberWithName("s_priv") | ||
check_var(self, s_priv, num_children=1) | ||
check_var(self, s_priv.GetChildMemberWithName("i"), value="2") | ||
s_filepriv = strct.GetChildMemberWithName("s_filepriv") | ||
check_var(self, s_filepriv, num_children=1) | ||
check_var(self, s_filepriv.GetChildMemberWithName("i"), value="3") | ||
|
||
# FIXME: scratch context assertion | ||
# check_var(self, frame.FindVariable("generic"), use_dynamic=True, value="42") | ||
|
||
# gtup = frame.FindVariable("generic_tuple") | ||
# check_var(self, gtup, num_children=2) | ||
# check_var(self, gtup.GetChildAtIndex(0), use_dynamic=True, value="42") | ||
# check_var(self, gtup.GetChildAtIndex(1), use_dynamic=True, value="42") | ||
|
||
check_var(self, frame.FindVariable("word"), value="0") | ||
check_var(self, frame.FindVariable("enum1"), value="second") | ||
enum2 = frame.FindVariable("enum2") | ||
check_var(self, enum2, value="with") | ||
check_var(self, enum2, num_children=1) | ||
# FIXME: Fails in swift::reflection::NoPayloadEnumTypeInfo::projectEnumValue: .second | ||
# check_var(self, enum2.GetChildAtIndex(0), value="42") | ||
|
||
# Scan through the types log. | ||
logfile = open(log, "r") | ||
found_ref_exe = 0 | ||
found_ref_lib = 0 | ||
found_ast_exe = 0 | ||
found_ast_lib = 0 | ||
for line in logfile: | ||
if 'SwiftASTContextForExpressions::RegisterSectionModules("a.out")' in line: | ||
found_ast_exe += 1 | ||
elif 'SwiftASTContextForExpressions::RegisterSectionModules("dyld")' in line: | ||
found_ast_lib += 1 | ||
elif re.search(r'Adding reflection metadata in .*a\.out', line): | ||
found_ref_exe += 1 | ||
elif re.search(r'Adding reflection metadata in .*dynamic_lib', line): | ||
found_ref_lib += 1 | ||
self.assertEqual(found_ref_exe, 1) | ||
self.assertEqual(found_ref_lib, 1) | ||
self.assertEqual(found_ast_exe, 0) | ||
self.assertEqual(found_ast_lib, 0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
public struct S { | ||
public init() {} | ||
public let pub = 1 | ||
private let priv = 2 | ||
fileprivate let filepriv = 3 | ||
|
||
private let s_priv = SPriv() | ||
fileprivate let s_filepriv = SFilePriv() | ||
} | ||
|
||
private struct SPriv { | ||
let i = 2 | ||
} | ||
|
||
fileprivate struct SFilePriv { | ||
let i = 3 | ||
} | ||
|
||
open class Base { | ||
public let x : Int = 42 | ||
public init() {} | ||
} | ||
|
||
public enum NoPayload { | ||
case first | ||
case second | ||
} | ||
|
||
public enum WithPayload { | ||
case empty | ||
case with(i: Int) | ||
} | ||
Comment on lines
+29
to
+32
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just a thought: should we include a multi-payload enum here, commented out, with a link to the radar? |
||
|
||
public protocol P {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import dynamic_lib | ||
|
||
struct MyP : P { | ||
let i = 1 | ||
} | ||
|
||
class C : Base { | ||
func f<T>(_ t: T, _ p : P) { | ||
let number = 1 | ||
let array = [1, 2, 3] | ||
let string = "hello" | ||
let tuple = (0, 1) | ||
let strct = S() | ||
let generic = t | ||
let generic_tuple = (t, t) | ||
let word = 0._builtinWordValue | ||
let enum1 = NoPayload.second | ||
// FIXME: Fails in swift::reflection::NoPayloadEnumTypeInfo::projectEnumValue: .second | ||
let enum2 = WithPayload.with(i:42) | ||
print("Set breakpoint here") | ||
} | ||
} | ||
|
||
let c = C() | ||
c.f(42, MyP()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Turns out this was no longer used by any test...