Skip to content

Commit

Permalink
[tsan] Add basic ASan and TSan round trip tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
AnnaZaks committed May 23, 2016
1 parent 1a0891c commit 7f3a150
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
17 changes: 17 additions & 0 deletions test/Sanitizers/asan.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// RUN: %target-swiftc_driver %s -g -sanitize=address -o %t_tsan-binary
// RUN: not env ASAN_OPTIONS=abort_on_error=0 %target-run %t_tsan-binary 2>&1 | FileCheck %s
// REQUIRES: executable_test
// REQUIRES: objc_interop
// XFAIL: linux

// Test AddressSanitizer execution end-to-end.

var a = UnsafeMutablePointer<Int>(allocatingCapacity: 1)
a.initialize(with: 5)
a.deinitialize(count: 1)
a.deallocateCapacity(1)
print(a.pointee)
a.deinitialize(count: 1)
a.deallocateCapacity(1)

// CHECK: AddressSanitizer: heap-use-after-free
29 changes: 29 additions & 0 deletions test/Sanitizers/tsan.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// RUN: %target-swiftc_driver %s -g -sanitize=thread -o %t_tsan-binary
// RUN: not env TSAN_OPTIONS=abort_on_error=0 %target-run %t_tsan-binary 2>&1 | FileCheck %s
// REQUIRES: executable_test
// REQUIRES: objc_interop
// REQUIRES: CPU=x86_64
// XFAIL: linux

// Test ThreadSanitizer execution end-to-end.

import Darwin
var user_interactive_thread: pthread_t? = nil
var user_interactive_thread2: pthread_t? = nil
var racey_x: Int;

pthread_create(&user_interactive_thread, nil, { _ in
print("pthread ran")
racey_x = 5;

return nil
}, nil)

pthread_create(&user_interactive_thread2, nil, { _ in
print("pthread2 ran")
racey_x = 6;

return nil
}, nil)

// CHECK: ThreadSanitizer: data race

0 comments on commit 7f3a150

Please sign in to comment.