Skip to content

Commit 83fee79

Browse files
committed
[test] rdar://85620934 Fix back deployment vs exclusivity checking tests
1 parent d08ecf3 commit 83fee79

File tree

2 files changed

+43
-12
lines changed

2 files changed

+43
-12
lines changed

validation-test/Runtime/ExclusivityTest.swift

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,52 @@
44
import StdlibUnittest
55
import RuntimeUnittest
66

7+
func hasBackdeployedConcurrencyRuntime() -> Bool {
8+
// If the stdlib we've loaded predates Swift 5.5, then we're running on a back
9+
// deployed concurrency runtime, which has the side effect of disabling
10+
// regular runtime exclusivity checks.
11+
if #available(SwiftStdlib 5.5, *) { return false } // recent enough production stdlib
12+
if #available(SwiftStdlib 9999, *) { return false } // dev stdlib
13+
return true
14+
}
15+
716
var ExclusivityTestSuite = TestSuite("Exclusivity")
817

9-
ExclusivityTestSuite.test("testExclusivityNullPC") {
18+
ExclusivityTestSuite.test("testExclusivityNullPC")
19+
.skip(.custom(
20+
{ hasBackdeployedConcurrencyRuntime() },
21+
reason: "the back deployed concurrency runtime doesn't do exclusivity checks"))
22+
.code {
1023
expectCrash(withMessage: "Simultaneous accesses") {
1124
SwiftRuntimeUnitTest.testExclusivityNullPC()
1225
}
1326
}
1427

15-
ExclusivityTestSuite.test("testExclusivityPCOne") {
28+
ExclusivityTestSuite.test("testExclusivityPCOne")
29+
.skip(.custom(
30+
{ hasBackdeployedConcurrencyRuntime() },
31+
reason: "the back deployed concurrency runtime doesn't do exclusivity checks"))
32+
.code {
1633
expectCrash(withMessage: "Simultaneous accesses") {
1734
SwiftRuntimeUnitTest.testExclusivityPCOne()
1835
}
1936
}
2037

21-
ExclusivityTestSuite.test("testExclusivityBogusPC") {
38+
ExclusivityTestSuite.test("testExclusivityBogusPC")
39+
.skip(.custom(
40+
{ hasBackdeployedConcurrencyRuntime() },
41+
reason: "the back deployed concurrency runtime doesn't do exclusivity checks"))
42+
.code {
2243
expectCrash(withMessage: "Simultaneous accesses") {
2344
SwiftRuntimeUnitTest.testExclusivityBogusPC()
2445
}
2546
}
2647

27-
ExclusivityTestSuite.test("testExclusivityNonNestedPC") {
48+
ExclusivityTestSuite.test("testExclusivityNonNestedPC")
49+
.skip(.custom(
50+
{ hasBackdeployedConcurrencyRuntime() },
51+
reason: "the back deployed concurrency runtime doesn't do exclusivity checks"))
52+
.code {
2853
SwiftRuntimeUnitTest.testExclusivityNonNestedPC()
2954
}
3055

validation-test/stdlib/ArrayTrapsObjC.swift

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ class ViolateInoutSafetySwitchToObjcBuffer {
124124
// loop calls a function that violates inout safety and overrides the array.
125125
let isNativeTypeChecked = A._hoistableIsNativeTypeChecked()
126126
for i in 0..<A.count {
127+
// Note: the compiler is sometimes able to eliminate this
128+
// `_checkSubscript` call when optimizations are enabled, skipping the
129+
// exclusivity check contained within.
127130
let t = A._checkSubscript(
128131
i, wasNativeTypeChecked: isNativeTypeChecked)
129132
_ = A._getElement(
@@ -141,11 +144,11 @@ class ViolateInoutSafetySwitchToObjcBuffer {
141144

142145
ArraySemanticOptzns.test("inout_rule_violated_isNativeBuffer")
143146
.skip(.custom(
144-
{ _isFastAssertConfiguration() },
145-
reason: "this trap is not guaranteed to happen in -Ounchecked"))
147+
{ !_isDebugAssertConfiguration() },
148+
reason: "this trap is not guaranteed to happen in -O or -Ounchecked"))
146149
.crashOutputMatches(
147-
!_isDebugAssertConfiguration() ? ""
148-
: hasBackdeployedConcurrencyRuntime() ? "inout rules were violated"
150+
hasBackdeployedConcurrencyRuntime()
151+
? "inout rules were violated"
149152
: "Fatal access conflict detected."
150153
)
151154
.code {
@@ -170,6 +173,9 @@ class ViolateInoutSafetyNeedElementTypeCheck {
170173
// loop calls a function that violates inout safety and overrides the array.
171174
let isNativeTypeChecked = A._hoistableIsNativeTypeChecked()
172175
for i in 0..<A.count {
176+
// Note: the compiler is sometimes able to eliminate this
177+
// `_checkSubscript` call when optimizations are enabled, skipping the
178+
// exclusivity check contained within.
173179
let t = A._checkSubscript(
174180
i, wasNativeTypeChecked: isNativeTypeChecked)
175181
_ = A._getElement(
@@ -187,11 +193,11 @@ class ViolateInoutSafetyNeedElementTypeCheck {
187193

188194
ArraySemanticOptzns.test("inout_rule_violated_needsElementTypeCheck")
189195
.skip(.custom(
190-
{ _isFastAssertConfiguration() },
191-
reason: "this trap is not guaranteed to happen in -Ounchecked"))
196+
{ !_isDebugAssertConfiguration() },
197+
reason: "this trap is not guaranteed to happen in -O or -Ounchecked"))
192198
.crashOutputMatches(
193-
!_isDebugAssertConfiguration() ? ""
194-
: hasBackdeployedConcurrencyRuntime() ? "inout rules were violated"
199+
hasBackdeployedConcurrencyRuntime()
200+
? "inout rules were violated"
195201
: "Fatal access conflict detected."
196202
)
197203
.code {

0 commit comments

Comments
 (0)