Skip to content

Commit 6e9ba48

Browse files
committed
Enhance NSConditionLock crash test even more
1 parent 9278728 commit 6e9ba48

File tree

5 files changed

+59
-26
lines changed

5 files changed

+59
-26
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import Foundation
2+
3+
import ArgumentParser
4+
5+
import SignalHandling
6+
7+
8+
9+
struct ConditionLock : ParsableCommand {
10+
11+
func run() throws {
12+
try Sigaction(handler: .ansiC({ _ in ConditionLock.exit() })).install(on: .terminated)
13+
14+
NSConditionLock(condition: 0).lock(whenCondition: 1)
15+
}
16+
17+
}

Sources/signal-handling-tests-helper/main.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@ struct SignalHandlingTestsHelper : ParsableCommand {
1111
subcommands: [
1212
ManualTest.self,
1313
ManualDispatchMemTest.self,
14+
1415
DelaySignalBlock.self,
15-
DelaySignalUnsigaction.self
16+
DelaySignalUnsigaction.self,
17+
18+
ConditionLock.self
1619
]
1720
)
1821

Tests/SignalHandlingTests/LockTest.swift

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,23 @@ import XCTest
66
final class NSConditionLockTest : XCTestCase {
77

88
func testNSConditionLock() throws {
9-
/* https://bugs.swift.org/browse/SR-14676 */
10-
// Thread(block: { NSConditionLock(condition: 0).lock(whenCondition: 1) }).start()
11-
Thread.sleep(forTimeInterval: 0.1)
12-
13-
#if !os(Linux)
14-
XCTAssert(true)
15-
#else
169
/* Apparently XCTExpectFailure does not exist on Linux. */
10+
// #if os(Linux)
1711
// XCTExpectFailure("Linux has a crash in NSConditionLock. This test is only here to remember to check if the bug is fixed from time to time (simply uncomment the second line of the test; if test does not crash on Linux we’re good).")
18-
XCTAssert(false, "Linux has a crash in NSConditionLock. This test is only here to remember to check if the bug is fixed from time to time (simply uncomment the second line of the test; if test does not crash on Linux we’re good).")
19-
#endif
12+
// #endif
13+
14+
let p = Process()
15+
p.executableURL = Utils.helperURL
16+
p.arguments = ["condition-lock"]
17+
18+
try p.run()
19+
20+
Thread.sleep(forTimeInterval: 0.125) /* We wait a little bit to let the helper test have the time to crash */
21+
p.terminate()
22+
Thread.sleep(forTimeInterval: 0.125) /* We wait a little bit to let the helper test process the signal and quit */
23+
24+
XCTAssertEqual(p.terminationStatus, 0)
25+
XCTAssertEqual(p.terminationReason, .exit)
2026
}
2127

2228
}

Tests/SignalHandlingTests/SignalHandlingTests.swift

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ import Logging
1111
@available(OSX 10.15.4, *)
1212
final class SignalHandlingTests : XCTestCase {
1313

14-
static let helperURL = productsDirectory.appendingPathComponent("signal-handling-tests-helper")
15-
1614
override class func setUp() {
1715
super.setUp()
1816

@@ -27,7 +25,7 @@ final class SignalHandlingTests : XCTestCase {
2725

2826
let p = Process()
2927
p.standardOutput = pipe
30-
p.executableURL = Self.helperURL
28+
p.executableURL = Utils.helperURL
3129
p.arguments = ["delay-signal-unsigaction", "--signal-number", "\(Signal.terminated.rawValue)"]
3230

3331
try p.run()
@@ -53,7 +51,7 @@ final class SignalHandlingTests : XCTestCase {
5351

5452
let p = Process()
5553
p.standardOutput = pipe
56-
p.executableURL = Self.helperURL
54+
p.executableURL = Utils.helperURL
5755
p.arguments = ["delay-signal-block", "--signal-number", "\(Signal.terminated.rawValue)"]
5856

5957
try p.run()
@@ -74,16 +72,4 @@ final class SignalHandlingTests : XCTestCase {
7472
""".utf8))
7573
}
7674

77-
/** Returns the path to the built products directory. */
78-
private static var productsDirectory: URL {
79-
#if os(macOS)
80-
for bundle in Bundle.allBundles where bundle.bundlePath.hasSuffix(".xctest") {
81-
return bundle.bundleURL.deletingLastPathComponent()
82-
}
83-
fatalError("couldn't find the products directory")
84-
#else
85-
return Bundle.main.bundleURL
86-
#endif
87-
}
88-
8975
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import Foundation
2+
3+
4+
5+
enum Utils {
6+
7+
static let helperURL = productsDirectory.appendingPathComponent("signal-handling-tests-helper")
8+
9+
/** Returns the path to the built products directory. */
10+
private static var productsDirectory: URL {
11+
#if os(macOS)
12+
for bundle in Bundle.allBundles where bundle.bundlePath.hasSuffix(".xctest") {
13+
return bundle.bundleURL.deletingLastPathComponent()
14+
}
15+
fatalError("couldn't find the products directory")
16+
#else
17+
return Bundle.main.bundleURL
18+
#endif
19+
}
20+
21+
}

0 commit comments

Comments
 (0)