Skip to content
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

[Test] Replaced temporary function with async main. #35642

Merged
merged 1 commit into from
Jan 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 5 additions & 3 deletions test/Concurrency/Runtime/actor_counters.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-run-simple-swift(-Xfrontend -enable-experimental-concurrency %import-libdispatch)
// RUN: %target-run-simple-swift(-Xfrontend -enable-experimental-concurrency %import-libdispatch -parse-as-library)

// REQUIRES: executable_test
// REQUIRES: concurrency
Expand Down Expand Up @@ -81,6 +81,8 @@ func runTest(numCounters: Int, numWorkers: Int, numIterations: Int) async {
print("DONE!")
}

runAsyncAndBlock {
await runTest(numCounters: 10, numWorkers: 100, numIterations: 1000)
@main struct Main {
static func main() async {
await runTest(numCounters: 10, numWorkers: 100, numIterations: 1000)
}
}
8 changes: 5 additions & 3 deletions test/Concurrency/Runtime/async_let_fibonacci.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-run-simple-swift(-Xfrontend -enable-experimental-concurrency %import-libdispatch)
// RUN: %target-run-simple-swift(-Xfrontend -enable-experimental-concurrency %import-libdispatch -parse-as-library)

// REQUIRES: executable_test
// REQUIRES: concurrency
Expand Down Expand Up @@ -48,6 +48,8 @@ func runFibonacci(_ n: Int) async {
assert(result == fib(n))
}

runAsyncAndBlock {
await runFibonacci(10)
@main struct Main {
static func main() async {
await runFibonacci(10)
}
}
8 changes: 3 additions & 5 deletions test/Concurrency/Runtime/async_task_priority_current.swift
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
// RUN: %target-run-simple-swift(-Xfrontend -enable-experimental-concurrency) | %FileCheck %s
// RUN: %target-run-simple-swift(-Xfrontend -enable-experimental-concurrency -parse-as-library) | %FileCheck %s
// REQUIRES: executable_test
// REQUIRES: concurrency

func test_getPriority() {
runAsyncAndBlock {
@main struct Main {
static func main() async {
let p = await Task.currentPriority()
// CHECK: priority: default
print("priority: \(p)")
assert(p == Task.Priority.default)
}
}

test_getPriority()
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-run-simple-swift(-Xfrontend -enable-experimental-concurrency) | %FileCheck %s --dump-input=always
// RUN: %target-run-simple-swift(-Xfrontend -enable-experimental-concurrency -parse-as-library) | %FileCheck %s --dump-input=always
// REQUIRES: executable_test
// REQUIRES: concurrency
// REQUIRES: OS=macosx
Expand Down Expand Up @@ -65,4 +65,8 @@ func test_sum_nextOnPending() async {
assert(sum == 6, "Expected \(6) but got \(sum)")
}

runAsyncAndBlock(test_sum_nextOnPending)
@main struct Main {
static func main() async {
await test_sum_nextOnPending()
}
}
8 changes: 6 additions & 2 deletions test/Concurrency/Runtime/async_taskgroup_is_empty.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-run-simple-swift(-Xfrontend -enable-experimental-concurrency) | %FileCheck %s --dump-input always
// RUN: %target-run-simple-swift(-Xfrontend -enable-experimental-concurrency -parse-as-library) | %FileCheck %s --dump-input always
// REQUIRES: executable_test
// REQUIRES: concurrency
// REQUIRES: OS=macosx
Expand Down Expand Up @@ -40,4 +40,8 @@ func test_taskGroup_isEmpty() async {
}
}

runAsyncAndBlock(test_taskGroup_isEmpty)
@main struct Main {
static func main() async {
await test_taskGroup_isEmpty()
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-run-simple-swift(-Xfrontend -enable-experimental-concurrency) | %FileCheck %s --dump-input=always
// RUN: %target-run-simple-swift(-Xfrontend -enable-experimental-concurrency -parse-as-library) | %FileCheck %s --dump-input=always
// REQUIRES: executable_test
// REQUIRES: concurrency
// REQUIRES: OS=macosx
Expand Down Expand Up @@ -43,4 +43,8 @@ func test_skipCallingNext_butInvokeCancelAll() async {
assert(result == 0)
}

runAsyncAndBlock(test_skipCallingNext_butInvokeCancelAll)
@main struct Main {
static func main() async {
await test_skipCallingNext_butInvokeCancelAll()
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-run-simple-swift(-Xfrontend -enable-experimental-concurrency) | %FileCheck %s --dump-input=always
// RUN: %target-run-simple-swift(-Xfrontend -enable-experimental-concurrency -parse-as-library) | %FileCheck %s --dump-input=always
// REQUIRES: executable_test
// REQUIRES: concurrency
// REQUIRES: OS=macosx
Expand Down Expand Up @@ -36,5 +36,9 @@ func test_skipCallingNext() async {
assert(result == 0)
}

runAsyncAndBlock(test_skipCallingNext)
@main struct Main {
static func main() async {
await test_skipCallingNext()
}
}

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-run-simple-swift(-Xfrontend -enable-experimental-concurrency) | %FileCheck %s --dump-input=always
// RUN: %target-run-simple-swift(-Xfrontend -enable-experimental-concurrency -parse-as-library) | %FileCheck %s --dump-input=always
// REQUIRES: executable_test
// REQUIRES: concurrency
// REQUIRES: OS=macosx
Expand Down Expand Up @@ -69,4 +69,8 @@ func test_sum_nextOnCompleted() async {
print("result: \(sum)")
}

runAsyncAndBlock(test_sum_nextOnCompleted)
@main struct Main {
static func main() async {
await test_sum_nextOnCompleted()
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-run-simple-swift(-Xfrontend -enable-experimental-concurrency) | %FileCheck %s --dump-input=always
// RUN: %target-run-simple-swift(-Xfrontend -enable-experimental-concurrency -parse-as-library) | %FileCheck %s --dump-input=always
// REQUIRES: executable_test
// REQUIRES: concurrency
// REQUIRES: OS=macosx
Expand Down Expand Up @@ -56,4 +56,8 @@ func test_sum_nextOnPending() async {
assert(sum == expected, "Expected: \(expected), got: \(sum)")
}

runAsyncAndBlock(test_sum_nextOnPending)
@main struct Main {
static func main() async {
await test_sum_nextOnPending()
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-run-simple-swift(-Xfrontend -enable-experimental-concurrency) | %FileCheck %s --dump-input always
// RUN: %target-run-simple-swift(-Xfrontend -enable-experimental-concurrency -parse-as-library) | %FileCheck %s --dump-input always
// REQUIRES: executable_test
// REQUIRES: concurrency
// REQUIRES: OS=macosx
Expand Down Expand Up @@ -83,4 +83,9 @@ func test_taskGroup_throws() async {
}
}

runAsyncAndBlock(test_taskGroup_throws)

@main struct Main {
static func main() async {
await test_taskGroup_throws()
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-run-simple-swift(-Xfrontend -enable-experimental-concurrency) | %FileCheck %s --dump-input always
// RUN: %target-run-simple-swift(-Xfrontend -enable-experimental-concurrency -parse-as-library) | %FileCheck %s --dump-input always
// REQUIRES: executable_test
// REQUIRES: concurrency
// REQUIRES: OS=macosx
Expand Down Expand Up @@ -43,4 +43,8 @@ func test_taskGroup_throws_rethrows() async {

// CHECK: error caught and rethrown in group: Boom()
// CHECK: rethrown: Boom()
runAsyncAndBlock(test_taskGroup_throws_rethrows)
@main struct Main {
static func main() async {
await test_taskGroup_throws_rethrows()
}
}
57 changes: 30 additions & 27 deletions test/Concurrency/Runtime/basic_future.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-run-simple-swift(-Xfrontend -enable-experimental-concurrency %import-libdispatch)
// RUN: %target-run-simple-swift(-Xfrontend -enable-experimental-concurrency %import-libdispatch -parse-as-library)

// REQUIRES: executable_test
// REQUIRES: concurrency
Expand All @@ -22,7 +22,7 @@ func formGreeting(name: String) async -> String {

func testSimple(
name: String, dogName: String, shouldThrow: Bool, doSuspend: Bool
) {
) async {
print("Testing name: \(name), dog: \(dogName), shouldThrow: \(shouldThrow) doSuspend: \(doSuspend)")

var completed = false
Expand All @@ -46,36 +46,39 @@ func testSimple(
return greeting + "!"
}

runAsyncAndBlock {
// If the intent is not to test suspending, wait a bit so the first task
// can complete.
if !doSuspend {
print("+ Reader sleeping")
sleep(1)
}
// If the intent is not to test suspending, wait a bit so the first task
// can complete.
if !doSuspend {
print("+ Reader sleeping")
sleep(1)
}

do {
print("+ Reader waiting for the result")
let result = try await taskHandle.get()
completed = true
print("+ Normal return: \(result)")
assert(result == "Hello \(name) from async world!")
} catch HomeworkError.dogAteIt(let badDog) {
completed = true
print("+ Error return: HomeworkError.dogAteIt(\(badDog))")
assert(badDog == dogName + " the dog")
} catch {
fatalError("Caught a different exception?")
}
do {
print("+ Reader waiting for the result")
let result = try await taskHandle.get()
completed = true
print("+ Normal return: \(result)")
assert(result == "Hello \(name) from async world!")
} catch HomeworkError.dogAteIt(let badDog) {
completed = true
print("+ Error return: HomeworkError.dogAteIt(\(badDog))")
assert(badDog == dogName + " the dog")
} catch {
fatalError("Caught a different exception?")
}

assert(completed)
print("Finished test")
}

testSimple(name: "Ted", dogName: "Hazel", shouldThrow: false, doSuspend: false)
testSimple(name: "Ted", dogName: "Hazel", shouldThrow: true, doSuspend: false)
testSimple(name: "Ted", dogName: "Hazel", shouldThrow: false, doSuspend: true)
testSimple(name: "Ted", dogName: "Hazel", shouldThrow: true, doSuspend: true)

print("Done")
@main struct Main {
static func main() async {
await testSimple(name: "Ted", dogName: "Hazel", shouldThrow: false, doSuspend: false)
await testSimple(name: "Ted", dogName: "Hazel", shouldThrow: true, doSuspend: false)
await testSimple(name: "Ted", dogName: "Hazel", shouldThrow: false, doSuspend: true)
await testSimple(name: "Ted", dogName: "Hazel", shouldThrow: true, doSuspend: true)

print("Done")
}
}
15 changes: 8 additions & 7 deletions test/Concurrency/Runtime/future_fibonacci.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-run-simple-swift(-Xfrontend -enable-experimental-concurrency %import-libdispatch)
// RUN: %target-run-simple-swift(-Xfrontend -enable-experimental-concurrency %import-libdispatch -parse-as-library)

// REQUIRES: executable_test
// REQUIRES: concurrency
Expand Down Expand Up @@ -47,15 +47,16 @@ func asyncFib(_ n: Int) async -> Int {
return result
}

func runFibonacci(_ n: Int) {
var result = 0
runAsyncAndBlock {
result = await asyncFib(n)
}
func runFibonacci(_ n: Int) async {
var result = await asyncFib(n)

print()
print("Async fib = \(result), sequential fib = \(fib(n))")
assert(result == fib(n))
}

runFibonacci(15)
@main struct Main {
static func main() async {
await runFibonacci(15)
}
}
7 changes: 5 additions & 2 deletions test/Concurrency/Runtime/objc_async.swift
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
// RUN: %empty-directory(%t)
// RUN: %target-clang %S/Inputs/objc_async.m -c -o %t/objc_async_objc.o
// RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -import-objc-header %S/Inputs/objc_async.h %s %t/objc_async_objc.o -o %t/objc_async
// RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -parse-as-library -module-name main -import-objc-header %S/Inputs/objc_async.h %s %t/objc_async_objc.o -o %t/objc_async
// RUN: %target-run %t/objc_async | %FileCheck %s

// REQUIRES: executable_test
// REQUIRES: concurrency
// REQUIRES: objc_interop

runAsyncAndBlock {

@main struct Main {
static func main() async {
let butt = Butt()
let result = await butt.butt(1738)
print("finishing \(result)")
}
}

// CHECK: starting 1738
Expand Down
9 changes: 6 additions & 3 deletions test/DebugInfo/async-args.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// RUN: %target-swift-frontend %s -emit-ir -g -o - \
// RUN: -module-name M -enable-experimental-concurrency | %FileCheck %s
// RUN: -module-name M -enable-experimental-concurrency \
// RUN: -parse-as-library | %FileCheck %s
// REQUIRES: concurrency

func use<T>(_ t: T) {}
Expand Down Expand Up @@ -32,8 +33,10 @@ func withGenericArg<T>(_ msg: T) async {
use(msg)
}
// CHECK-LABEL: {{^define }}
runAsyncAndBlock {
await withGenericArg("hello (asynchronously)")
@main struct Main {
static func main() async {
await withGenericArg("hello (asynchronously)")
}
}
// CHECK: ![[MSG]] = !DILocalVariable(name: "msg", arg: 1,
// CHECK: ![[TAU]] = !DILocalVariable(name: "$\CF\84_0_0",
Expand Down
12 changes: 7 additions & 5 deletions test/IRGen/async/run-call-class-witnessmethod-void-to-void.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// RUN: %empty-directory(%t)
// RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency %s -emit-ir | %FileCheck %s --check-prefix=CHECK-LL
// RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency %s -module-name main -o %t/main
// RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency %s -parse-as-library -emit-ir -module-name main | %FileCheck %s --check-prefix=CHECK-LL
// RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency %s -parse-as-library -module-name main -o %t/main
// RUN: %target-codesign %t/main
// RUN: %target-run %t/main | %FileCheck %s

Expand Down Expand Up @@ -52,7 +52,9 @@ func call_f<T : P>(_ t: T) async {

class X {}

runAsyncAndBlock {
let x = X()
await call_f(x)
@main struct Main {
static func main() async {
let x = X()
await call_f(x)
}
}
12 changes: 7 additions & 5 deletions test/IRGen/async/run-call-dynamic-void_to_void.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// RUN: %empty-directory(%t)
// RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency %s -emit-ir | %FileCheck %s --check-prefix=CHECK-LL
// RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency %s -module-name main -o %t/main %target-rpath(%t)
// RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency %s -emit-ir -parse-as-library -module-name main | %FileCheck %s --check-prefix=CHECK-LL
// RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency %s -parse-as-library -module-name main -o %t/main %target-rpath(%t)
// RUN: %target-codesign %t/main
// RUN: %target-run %t/main | %FileCheck %s

Expand All @@ -14,13 +14,15 @@ import _Concurrency

// CHECK: running

// CHECK-LL: @"$s4mainyyYcfU_Tu" = internal global %swift.async_func_pointer
// CHECK-LL: @"$s4main3runyyYFTu" = hidden global %swift.async_func_pointer

// CHECK-LL: define hidden swiftcc void @"$s4main3runyyYF"(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* swiftasync {{%[0-9]+}}) {{#[0-9]*}} {
dynamic func run() async {
print("running")
}

runAsyncAndBlock {
await run()
@main struct Main {
static func main() async {
await run()
}
}