mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Stress tests are, by definition, stressful. They intentionally burn a lot of resources by using randomness to hopefully surface state machine bugs. Additionally, many stress tests are multi-threaded these days and they may attempt to use all of the available CPUs to better uncover bugs. In isolation, this is not a problem, but the test suite as a whole assumes that individual tests are single threaded and therefore running multiple stress tests at once can quickly spiral out of control. This change formalizes stress tests and then treats them like long tests, i.e. tested via 'check-swift-all' and otherwise opt-in. Finally, with this change, the CI build bots might need to change if they are still only testing 'validation' instead of all of the tests. I see three options: 1) Run all of the tests. -- There are very few long tests left these days, and the additional costs seems small relative to the cost of the whole validation test suite before this change. 2) Continue checking 'validation', now sans stress tests. 3) Check 'validation', *then* the stress tests. If the former doesn't pass, then there is no point in the latter, and by running the stress tests separately, they stand a better chance of uncovering bugs and not overwhelming build bot resources.
123 lines
3.3 KiB
Swift
123 lines
3.3 KiB
Swift
// RUN: %empty-directory(%t)
|
|
//
|
|
// RUN: %target-clang -fobjc-arc %S/Inputs/SlurpFastEnumeration/SlurpFastEnumeration.m -c -o %t/SlurpFastEnumeration.o
|
|
// RUN: echo '#sourceLocation(file: "%s", line: 1)' > "%t/main.swift" && cat "%s" >> "%t/main.swift" && chmod -w "%t/main.swift"
|
|
// RUN: %target-build-swift -Xfrontend -disable-access-control -I %S/Inputs/SlurpFastEnumeration/ %t/main.swift %S/Inputs/DictionaryKeyValueTypes.swift %S/Inputs/DictionaryKeyValueTypesObjC.swift -Xlinker %t/SlurpFastEnumeration.o -o %t.out -O
|
|
// RUN: %target-run %t.out
|
|
// REQUIRES: executable_test
|
|
|
|
// REQUIRES: objc_interop
|
|
// REQUIRES: executable_test
|
|
// REQUIRES: stress_test
|
|
// UNSUPPORTED: nonatomic_rc
|
|
|
|
import StdlibUnittest
|
|
import Foundation
|
|
import SlurpFastEnumeration
|
|
|
|
|
|
struct ArrayBridge_objectAtIndex_RaceTest : RaceTestWithPerTrialData {
|
|
class RaceData {
|
|
var nsa: NSArray
|
|
init(nsa: NSArray) {
|
|
self.nsa = nsa
|
|
}
|
|
}
|
|
|
|
typealias ThreadLocalData = Void
|
|
typealias Observation = Observation1UInt
|
|
|
|
func makeRaceData() -> RaceData {
|
|
let nsa = getBridgedNSArrayOfValueTypeCustomBridged(numElements: 1)
|
|
return RaceData(nsa: nsa)
|
|
}
|
|
|
|
func makeThreadLocalData() -> Void {
|
|
return Void()
|
|
}
|
|
|
|
func thread1(
|
|
_ raceData: RaceData, _ threadLocalData: inout ThreadLocalData
|
|
) -> Observation {
|
|
let nsa = raceData.nsa
|
|
let v = nsa.object(at: 0) as AnyObject
|
|
return Observation(unsafeBitCast(v, to: UInt.self))
|
|
}
|
|
|
|
func evaluateObservations(
|
|
_ observations: [Observation],
|
|
_ sink: (RaceTestObservationEvaluation) -> Void
|
|
) {
|
|
sink(evaluateObservationsAllEqual(observations))
|
|
}
|
|
}
|
|
|
|
struct ArrayBridge_FastEnumeration_ObjC_RaceTest :
|
|
RaceTestWithPerTrialData {
|
|
class RaceData {
|
|
var nsa: NSArray
|
|
init(nsa: NSArray) {
|
|
self.nsa = nsa
|
|
}
|
|
}
|
|
|
|
typealias ThreadLocalData = Void
|
|
typealias Observation = Observation4UInt
|
|
|
|
func makeRaceData() -> RaceData {
|
|
let nsa = getBridgedNSArrayOfValueTypeCustomBridged(numElements: 4)
|
|
return RaceData(nsa: nsa)
|
|
}
|
|
|
|
func makeThreadLocalData() -> Void {
|
|
return Void()
|
|
}
|
|
|
|
func thread1(
|
|
_ raceData: RaceData, _ threadLocalData: inout ThreadLocalData
|
|
) -> Observation {
|
|
let nsa = raceData.nsa
|
|
let objcValues = NSMutableArray()
|
|
slurpFastEnumerationOfArrayFromObjCImpl(nsa, nsa, objcValues)
|
|
return Observation(
|
|
unsafeBitCast(objcValues[0] as AnyObject, to: UInt.self),
|
|
unsafeBitCast(objcValues[1] as AnyObject, to: UInt.self),
|
|
unsafeBitCast(objcValues[2] as AnyObject, to: UInt.self),
|
|
unsafeBitCast(objcValues[3] as AnyObject, to: UInt.self))
|
|
}
|
|
|
|
func evaluateObservations(
|
|
_ observations: [Observation],
|
|
_ sink: (RaceTestObservationEvaluation) -> Void
|
|
) {
|
|
sink(evaluateObservationsAllEqual(observations))
|
|
}
|
|
}
|
|
|
|
var ArrayTestSuite = TestSuite("Array")
|
|
|
|
ArrayTestSuite.test(
|
|
"BridgedToObjC/Custom/objectAtIndex/RaceTest") {
|
|
runRaceTest(ArrayBridge_objectAtIndex_RaceTest.self, trials: 100)
|
|
}
|
|
|
|
ArrayTestSuite.test(
|
|
"BridgedToObjC/Custom/FastEnumeration/UseFromObjC/RaceTest") {
|
|
runRaceTest(
|
|
ArrayBridge_FastEnumeration_ObjC_RaceTest.self,
|
|
trials: 100)
|
|
}
|
|
|
|
ArrayTestSuite.setUp {
|
|
resetLeaksOfDictionaryKeysValues()
|
|
resetLeaksOfObjCDictionaryKeysValues()
|
|
}
|
|
|
|
ArrayTestSuite.tearDown {
|
|
expectNoLeaksOfDictionaryKeysValues()
|
|
expectNoLeaksOfObjCDictionaryKeysValues()
|
|
}
|
|
|
|
runAllTests()
|
|
|