Skip to content

Commit 17eb08a

Browse files
committed
[Backtracing] Add some more tests.
Add tests for the new immediate on-crash message and the backtrace timing message. rdar://118055527
1 parent 2ac8460 commit 17eb08a

File tree

2 files changed

+89
-0
lines changed

2 files changed

+89
-0
lines changed

test/Backtracing/EarlyMessage.swift

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-build-swift %s -parse-as-library -Onone -g -o %t/EarlyMessage
3+
// RUN: (env SWIFT_BACKTRACE=enable=yes,cache=no %target-run %t/EarlyMessage 2>&1 || true) | %FileCheck %s
4+
5+
// UNSUPPORTED: use_os_stdlib
6+
// UNSUPPORTED: back_deployment_runtime
7+
// UNSUPPORTED: asan
8+
// REQUIRES: executable_test
9+
// REQUIRES: backtracing
10+
// REQUIRES: OS=macosx || OS=linux-gnu
11+
12+
func level1() {
13+
level2()
14+
}
15+
16+
func level2() {
17+
level3()
18+
}
19+
20+
func level3() {
21+
level4()
22+
}
23+
24+
func level4() {
25+
level5()
26+
}
27+
28+
func level5() {
29+
print("About to crash")
30+
let ptr = UnsafeMutablePointer<Int>(bitPattern: 4)!
31+
ptr.pointee = 42
32+
}
33+
34+
@main
35+
struct EarlyMessage {
36+
static func main() {
37+
level1()
38+
}
39+
}
40+
41+
// Make sure we get the early crash message from the backtracer (the first
42+
// part is generated by the runtime itself; the "done ***" on the end is from
43+
// swift-backtrace).
44+
45+
// CHECK: *** Signal {{[0-9]+}}: Backtracing from 0x{{[0-9a-f]+}}... done ***

test/Backtracing/Timing.swift

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-build-swift %s -parse-as-library -Onone -g -o %t/Timing
3+
// RUN: (env SWIFT_BACKTRACE=enable=yes,cache=no %target-run %t/Timing 2>&1 || true) | %FileCheck %s
4+
5+
// UNSUPPORTED: use_os_stdlib
6+
// UNSUPPORTED: back_deployment_runtime
7+
// UNSUPPORTED: asan
8+
// REQUIRES: executable_test
9+
// REQUIRES: backtracing
10+
// REQUIRES: OS=macosx || OS=linux-gnu
11+
12+
func level1() {
13+
level2()
14+
}
15+
16+
func level2() {
17+
level3()
18+
}
19+
20+
func level3() {
21+
level4()
22+
}
23+
24+
func level4() {
25+
level5()
26+
}
27+
28+
func level5() {
29+
print("About to crash")
30+
let ptr = UnsafeMutablePointer<Int>(bitPattern: 4)!
31+
ptr.pointee = 42
32+
}
33+
34+
@main
35+
struct Timing {
36+
static func main() {
37+
level1()
38+
}
39+
}
40+
41+
// The backtracer should say how long the backtrace took, in seconds, with
42+
// two decimal places.
43+
44+
// CHECK: Backtrace took {{[0-9]+}}.{{[0-9][0-9]}}s

0 commit comments

Comments
 (0)