Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions lldb/test/API/lang/swift/playgrounds/Concurrency.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import Darwin
import Dispatch
// Test that the pass pipeline is set up to support concurrency.

let semaphore = DispatchSemaphore(value: 0)
var i: Int = 0

if #available(macOS 12, iOS 15, watchOS 8, tvOS 15, *) {
Expand All @@ -9,14 +11,16 @@ if #available(macOS 12, iOS 15, watchOS 8, tvOS 15, *) {
}

let queue = Actor()
async {
Task.detached() {
i = await queue.f()
semaphore.signal()
}

} else {
// Still make the test pass if we don't have concurrency.
i = 42
semaphore.signal()
}

while (i == 0) { sleep(1) }
semaphore.wait()
i - 19
8 changes: 8 additions & 0 deletions lldb/test/API/lang/swift/playgrounds/TestSwiftPlaygrounds.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ def do_test(self, force_target):
options = lldb.SBExpressionOptions()
options.SetLanguage(lldb.eLanguageTypeSwift)
options.SetPlaygroundTransformEnabled()
# The concurrency expressions will spawn multiple threads.
options.SetOneThreadTimeoutInMicroSeconds(1)
options.SetTryAllThreads(True)

self.frame().EvaluateExpression(contents, options)
ret = self.frame().EvaluateExpression("get_output()")
Expand All @@ -142,10 +145,13 @@ def do_test(self, force_target):
self.assertTrue("=\\'11\\'" in playground_output)

# Test concurrency
self.expect('log enable lldb all -f ' + self.getBuildArtifact('types.log'))
contents = "error"
with open('Concurrency.swift', 'r') as contents_file:
contents = contents_file.read()
print("self.frame().EvaluateExpression(%s)"%contents, file=sys.stderr)
res = self.frame().EvaluateExpression(contents, options)
print("self.frame().EvaluateExpression(%s)"%"get_output()", file=sys.stderr)
ret = self.frame().EvaluateExpression("get_output()")
playground_output = ret.GetSummary()
self.assertTrue(playground_output is not None)
Expand All @@ -155,7 +161,9 @@ def do_test(self, force_target):
log = self.getBuildArtifact('types.log')
self.expect('log enable lldb types -f ' + log)
contents = "import Dylib\nf()\n"
print("self.frame().EvaluateExpression(%s)"%contents, file=sys.stderr)
res = self.frame().EvaluateExpression(contents, options)
print("self.frame().EvaluateExpression(%s)"%"get_output()", file=sys.stderr)
ret = self.frame().EvaluateExpression("get_output()")
playground_output = ret.GetSummary()
self.assertTrue(playground_output is not None)
Expand Down