Skip to content

Commit d2861f7

Browse files
committed
[test] Re-add crash tests for getObjects:andKeys:count:
On some platforms, when a new process is started, ARC’s autoreleased return value optimization is expected to fail the first time it is used in each linked dylib. StdlibUnittest takes care of warming up ARC for the stdlib (libswiftCore.dylib), but for Dictionary.swift, we also need to do it for Foundation, or there will be spurious leaks reported for tests immediately following a crash test. Add the necessary dummy operations to setUp, and re-add the crash tests that were removed in #17862. (As separate tests this time, so they don’t hide leaks in non-crashing test parts.)
1 parent 56f322f commit d2861f7

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

validation-test/stdlib/Dictionary.swift

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3429,6 +3429,12 @@ DictionaryTestSuite.test("BridgedToObjC.Verbatim.getObjects:andKeys:count:") {
34293429
}
34303430
}
34313431

3432+
DictionaryTestSuite.test("BridgedToObjC.Verbatim.getObjects:andKeys:count:/InvalidCount") {
3433+
expectCrashLater()
3434+
let d = getBridgedNSDictionaryOfRefTypesBridgedVerbatim()
3435+
checkGetObjectsAndKeys(d, count: -1)
3436+
}
3437+
34323438
//===---
34333439
// Dictionary -> NSDictionary bridging tests.
34343440
//
@@ -3534,6 +3540,12 @@ DictionaryTestSuite.test("BridgedToObjC.Custom.getObjects:andKeys:count:") {
35343540
}
35353541
}
35363542

3543+
DictionaryTestSuite.test("BridgedToObjC.Custom.getObjects:andKeys:count:/InvalidCount") {
3544+
expectCrashLater()
3545+
let d = getBridgedNSDictionaryOfKeyValue_ValueTypesCustomBridged()
3546+
checkGetObjectsAndKeys(d, count: -1)
3547+
}
3548+
35373549
func getBridgedNSDictionaryOfKey_ValueTypeCustomBridged() -> NSDictionary {
35383550
assert(!_isBridgedVerbatimToObjectiveC(TestBridgedKeyTy.self))
35393551
assert(_isBridgedVerbatimToObjectiveC(TestObjCValueTy.self))
@@ -4749,6 +4761,22 @@ DictionaryTestSuite.test("Hashable") {
47494761
}
47504762

47514763
DictionaryTestSuite.setUp {
4764+
#if _runtime(_ObjC)
4765+
// Exercise ARC's autoreleased return value optimization in Foundation.
4766+
//
4767+
// On some platforms, when a new process is started, the optimization is
4768+
// expected to fail the first time it is used in each linked
4769+
// dylib. StdlibUnittest takes care of warming up ARC for the stdlib
4770+
// (libswiftCore.dylib), but for this particular test we also need to do it
4771+
// for Foundation, or there will be spurious leaks reported for tests
4772+
// immediately following a crash test.
4773+
//
4774+
// <rdar://problem/42069800> stdlib tests: expectCrashLater() interferes with
4775+
// counting autoreleased live objects
4776+
let d = NSDictionary(objects: [1 as NSNumber], forKeys: [1 as NSNumber])
4777+
_ = d.object(forKey: 1 as NSNumber)
4778+
#endif
4779+
47524780
resetLeaksOfDictionaryKeysValues()
47534781
#if _runtime(_ObjC)
47544782
resetLeaksOfObjCDictionaryKeysValues()

0 commit comments

Comments
 (0)