From f21a314003389b4500841272cecb17abc5454714 Mon Sep 17 00:00:00 2001 From: Adrian Prantl Date: Wed, 18 Jan 2023 14:37:24 -0800 Subject: [PATCH 1/2] Make the playgrounds test more robust --- lldb/test/API/lang/swift/playgrounds/Concurrency.swift | 10 +++++++--- .../API/lang/swift/playgrounds/TestSwiftPlaygrounds.py | 3 +++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lldb/test/API/lang/swift/playgrounds/Concurrency.swift b/lldb/test/API/lang/swift/playgrounds/Concurrency.swift index 4c768c6981865..43b85d6b755be 100644 --- a/lldb/test/API/lang/swift/playgrounds/Concurrency.swift +++ b/lldb/test/API/lang/swift/playgrounds/Concurrency.swift @@ -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, *) { @@ -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 diff --git a/lldb/test/API/lang/swift/playgrounds/TestSwiftPlaygrounds.py b/lldb/test/API/lang/swift/playgrounds/TestSwiftPlaygrounds.py index 9c5e2590c4c0c..1dc2779625d7c 100644 --- a/lldb/test/API/lang/swift/playgrounds/TestSwiftPlaygrounds.py +++ b/lldb/test/API/lang/swift/playgrounds/TestSwiftPlaygrounds.py @@ -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()") From 3ea909d6cc17c348d164f8d3970793d9ca2ce556 Mon Sep 17 00:00:00 2001 From: Adrian Prantl Date: Wed, 18 Jan 2023 17:03:47 -0800 Subject: [PATCH 2/2] verbose --- lldb/test/API/lang/swift/playgrounds/TestSwiftPlaygrounds.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lldb/test/API/lang/swift/playgrounds/TestSwiftPlaygrounds.py b/lldb/test/API/lang/swift/playgrounds/TestSwiftPlaygrounds.py index 1dc2779625d7c..cc2addc107fc4 100644 --- a/lldb/test/API/lang/swift/playgrounds/TestSwiftPlaygrounds.py +++ b/lldb/test/API/lang/swift/playgrounds/TestSwiftPlaygrounds.py @@ -145,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) @@ -158,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)