Skip to content

Re-enable TSan versions of async_let_fibonacci.swift test #39319

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
merged 1 commit into from
Sep 16, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions test/Sanitizers/symbolication.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
// REQUIRES: asan_runtime
// REQUIRES: VENDOR=apple

// rdar://80274830 ([Swift CI] Sanitizer report symbolication fails because we fail to start atos, sanbox issue?)
// REQUIRES: 80274830
// Might be related/same issue as below

// rdar://75365575 (Failing to start atos external symbolizer)
// UNSUPPORTED: OS=watchos

Expand Down
18 changes: 6 additions & 12 deletions test/Sanitizers/tsan/async_let_fibonacci.swift
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
// RUN: %target-run-simple-swift( %import-libdispatch -parse-as-library -sanitize=thread)
// RUN: %target-run-simple-swift( -Xfrontend -disable-availability-checking %import-libdispatch -parse-as-library -sanitize=thread)

// REQUIRES: executable_test
// REQUIRES: concurrency
// REQUIRES: libdispatch
// REQUIRES: tsan_runtime
// UNSUPPORTED: use_os_stdlib

// REQUIRES: radar76446550
// rdar://76038845
// REQUIRES: concurrency_runtime
// UNSUPPORTED: back_deployment_runtime

#if canImport(Darwin)
import Darwin
#elseif canImport(Glibc)
import Glibc
#endif

@available(SwiftStdlib 5.5, *)
func fib(_ n: Int) -> Int {
var first = 0
var second = 1
Expand All @@ -36,12 +30,12 @@ func asyncFib(_ n: Int) async -> Int {
async let second = await asyncFib(n-1)

// Sleep a random amount of time waiting on the result producing a result.
await Task.sleep(UInt64.random(in: 0..<100) * 1000)
await Task.sleep(UInt64.random(in: 0..<100) * 1_000_000)

let result = await first + second

// Sleep a random amount of time before producing a result.
await Task.sleep(UInt64.random(in: 0..<100) * 1000)
await Task.sleep(UInt64.random(in: 0..<100) * 1_000_000)

return result
}
Expand Down
23 changes: 8 additions & 15 deletions test/Sanitizers/tsan/racy_async_let_fibonacci.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-swiftc_driver %s -parse-as-library %import-libdispatch -target %sanitizers-target-triple -g -sanitize=thread -o %t
// RUN: %target-swiftc_driver %s -Xfrontend -disable-availability-checking -parse-as-library %import-libdispatch -target %sanitizers-target-triple -g -sanitize=thread -o %t
// RUN: %target-codesign %t
// RUN: env %env-TSAN_OPTIONS="abort_on_error=0" not %target-run %t 2>&1 | %swift-demangle --simplified | %FileCheck %s

Expand All @@ -8,21 +8,12 @@
// REQUIRES: tsan_runtime

// rdar://76038845
// UNSUPPORTED: use_os_stdlib

// rdar://80274830 ([Swift CI] Sanitizer report symbolication fails because we fail to start atos, sanbox issue?)
// REQUIRES: 80274830
// Might be related/same issue as below
// REQUIRES: concurrency_runtime
// UNSUPPORTED: back_deployment_runtime

// rdar://75365575 (Failing to start atos external symbolizer)
// UNSUPPORTED: OS=watchos

#if canImport(Darwin)
import Darwin
#elseif canImport(Glibc)
import Glibc
#endif

func fib(_ n: Int) -> Int {
var first = 0
var second = 1
Expand All @@ -36,6 +27,7 @@ func fib(_ n: Int) -> Int {

var racyCounter = 0

@available(SwiftStdlib 5.5, *)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@available(SwiftStdlib 5.5, *)

Could be removed since the -disable-availability-checking was passed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests mirror what is in test/Concurrency/Runtime/async_let_fibonacci.swift. If this is worth cleaning up, please apply the changes consistently across all versions.

func asyncFib(_ n: Int) async -> Int {
racyCounter += 1
if n == 0 || n == 1 {
Expand All @@ -46,25 +38,26 @@ func asyncFib(_ n: Int) async -> Int {
async let second = await asyncFib(n-1)

// Sleep a random amount of time waiting on the result producing a result.
usleep(UInt32.random(in: 0..<100) * 1000)
await Task.sleep(UInt64.random(in: 0..<100) * 1_000_000)

let result = await first + second

// Sleep a random amount of time before producing a result.
usleep(UInt32.random(in: 0..<100) * 1000)
await Task.sleep(UInt64.random(in: 0..<100) * 1_000_000)

return result
}

@available(SwiftStdlib 5.5, *)
func runFibonacci(_ n: Int) async {
let result = await asyncFib(n)

print()
print("Async fib = \(result), sequential fib = \(fib(n))")
assert(result == fib(n))
print("asyncFib() called around \(racyCounter) times")
}

@available(SwiftStdlib 5.5, *)
@main struct Main {
static func main() async {
await runFibonacci(10)
Expand Down