Skip to content

Commit 80a0f3e

Browse files
ylnJulian Lettner
andauthored
[Sanitizer] Add smoke test for report symbolication (#33656)
Add a test that checks symbolication for out-of-process and in-process symbolication for both Apple platforms and Linux. Note that there already exist tests in the compiler-rt test suite that check report symbolication. The purpose of this test is to have simple smoke tests for Swift, and specifically Swift demangling. rdar://62753845 Co-authored-by: Julian Lettner <[email protected]>
1 parent d7c791a commit 80a0f3e

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// RUN: %target-build-swift %s -sanitize=address -g -target %sanitizers-target-triple -o %t
2+
// RUN: env %env-ASAN_OPTIONS=abort_on_error=0 not %target-run %t 2>&1 | %swift-demangle | %FileCheck %s -check-prefix=OOP
3+
// In-process symbolication doesn't work on Linux (yet)
4+
// XXX: env %env-ASAN_OPTIONS=abort_on_error=0,external_symbolizer_path= not %target-run %t 2>&1 | %swift-demangle | %FileCheck %s -check-prefix=IP
5+
// REQUIRES: executable_test
6+
// REQUIRES: asan_runtime
7+
// REQUIRES: OS=linux-gnu
8+
9+
// Check that Sanitizer reports are properly symbolicated on Linux, both
10+
// out-of-process (via `llvm-symbolizer`) and when falling back to in-process
11+
// symbolication. Note that `llvm-symbolizer` does not demangle Swift symbol
12+
// names, so we use `swift demangle`.
13+
14+
func foo() {
15+
let x = UnsafeMutablePointer<Int>.allocate(capacity: 1)
16+
x.deallocate()
17+
print(x.pointee)
18+
}
19+
20+
func bar() {
21+
foo()
22+
}
23+
24+
bar()
25+
26+
27+
// Out-of-process
28+
// OOP: #0 0x{{[0-9a-f]+}} in main.foo() -> () {{.*}}symbolication-linux.swift:[[@LINE-11]]
29+
// OOP-NEXT: #1 0x{{[0-9a-f]+}} in main.bar() -> () {{.*}}symbolication-linux.swift:[[@LINE-8]]
30+
// OOP-NEXT: #2 0x{{[0-9a-f]+}} in main {{.*}}symbolication-linux.swift:[[@LINE-6]]
31+
32+
// In-process
33+
// IP: #0 0x{{[0-9a-f]+}} in main.foo() -> ()+0x
34+
// IP-NEXT: #1 0x{{[0-9a-f]+}} in main.bar() -> ()+0x
35+
// IP-NEXT: #2 0x{{[0-9a-f]+}} in main+0x

test/Sanitizers/symbolication.swift

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// RUN: %target-build-swift %s -sanitize=address -g -target %sanitizers-target-triple -o %t
2+
// RUN: env %env-ASAN_OPTIONS=abort_on_error=0 not %target-run %t 2>&1 | %FileCheck %s -check-prefix=OOP
3+
// RUN: env %env-ASAN_OPTIONS=abort_on_error=0,external_symbolizer_path= not %target-run %t 2>&1 | %FileCheck %s -check-prefix=IP
4+
// REQUIRES: executable_test
5+
// REQUIRES: asan_runtime
6+
// REQUIRES: VENDOR=apple
7+
8+
// Check that Sanitizer reports are properly symbolicated on Apple platforms,
9+
// both out-of-process (via `atos`) and when falling back to in-process
10+
// symbolication. Note that `atos` also demangles Swift symbol names.
11+
12+
func foo() {
13+
let x = UnsafeMutablePointer<Int>.allocate(capacity: 1)
14+
x.deallocate()
15+
print(x.pointee)
16+
}
17+
18+
func bar() {
19+
foo()
20+
}
21+
22+
bar()
23+
24+
25+
// Out-of-process
26+
// OOP: #0 0x{{[0-9a-f]+}} in foo() symbolication.swift:[[@LINE-11]]
27+
// OOP-NEXT: #1 0x{{[0-9a-f]+}} in bar() symbolication.swift:[[@LINE-8]]
28+
// OOP-NEXT: #2 0x{{[0-9a-f]+}} in main symbolication.swift:[[@LINE-6]]
29+
30+
// In-process
31+
// IP: #0 0x{{[0-9a-f]+}} in main.foo() -> ()+0x
32+
// IP-NEXT: #1 0x{{[0-9a-f]+}} in main.bar() -> ()+0x
33+
// IP-NEXT: #2 0x{{[0-9a-f]+}} in main+0x

0 commit comments

Comments
 (0)