File tree Expand file tree Collapse file tree 2 files changed +38
-0
lines changed
stdlib/private/StdlibUnittest
validation-test/StdlibUnittest Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -573,3 +573,31 @@ public func consumeCPU(units amountOfWork: Int) {
573
573
}
574
574
}
575
575
}
576
+
577
+ internal struct ClosureBasedRaceTest : RaceTestWithPerTrialData {
578
+ static var thread : ( ) -> ( ) = { }
579
+
580
+ class RaceData { }
581
+ typealias ThreadLocalData = Void
582
+ typealias Observation = Void
583
+
584
+ func makeRaceData( ) -> RaceData { return RaceData ( ) }
585
+ func makeThreadLocalData( ) -> Void { return Void ( ) }
586
+
587
+ func thread1(
588
+ _ raceData: RaceData , _ threadLocalData: inout ThreadLocalData
589
+ ) {
590
+ ClosureBasedRaceTest . thread ( )
591
+ }
592
+
593
+ func evaluateObservations(
594
+ _ observations: [ Observation ] ,
595
+ _ sink: ( RaceTestObservationEvaluation ) -> Void
596
+ ) { }
597
+ }
598
+
599
+ public func runRaceTest( trials: Int , threads: Int ? = nil , body: ( ) -> ( ) ) {
600
+ ClosureBasedRaceTest . thread = body
601
+ runRaceTest ( ClosureBasedRaceTest . self, trials: trials, threads: threads)
602
+ }
603
+
Original file line number Diff line number Diff line change @@ -92,6 +92,16 @@ RaceTestSuite.test("fails") {
92
92
// CHECK: stdout>>> Failure: 1 times
93
93
// CHECK: stdout>>> Failure (65534): 3 times
94
94
// CHECK: [ FAIL ] Race.fails
95
+
96
+ RaceTestSuite . test ( " closure " ) {
97
+ let count = _stdlib_AtomicInt ( 0 )
98
+ runRaceTest ( trials: 10 ) {
99
+ _ = count. fetchAndAdd ( 1 )
100
+ }
101
+ expectNotEqual ( 0 , count. load ( ) )
102
+ }
103
+ // CHECK: [ RUN ] Race.closure
104
+ // CHECK: [ OK ] Race.closure
95
105
// CHECK: Race: Some tests failed, aborting
96
106
97
107
runAllTests ( )
You can’t perform that action at this time.
0 commit comments