@@ -184,6 +184,121 @@ ExclusiveAccessTestSuite.test("PerThreadEnforcement") {
184
184
}
185
185
}
186
186
187
+ // Helpers
188
+ func doOne( _ f: ( ) -> ( ) ) { f ( ) }
187
189
190
+ func doTwo( _ f1: ( ) -> ( ) , _ f2: ( ) -> ( ) ) { f1 ( ) ; f2 ( ) }
191
+
192
+ // No crash.
193
+ ExclusiveAccessTestSuite . test ( " WriteNoescapeWrite " ) {
194
+ var x = 3
195
+ let c = { x = 7 }
196
+ // Inside may-escape closure `c`: [read] [dynamic]
197
+ // Inside never-escape closure: [modify] [dynamic]
198
+ doTwo ( c, { x = 42 } )
199
+ _blackHole ( x)
200
+ }
201
+
202
+ // No crash.
203
+ ExclusiveAccessTestSuite . test ( " InoutReadEscapeRead " ) {
204
+ var x = 3
205
+ let c = { let y = x; _blackHole ( y) }
206
+ readAndPerform ( & x, closure: c)
207
+ _blackHole ( x)
208
+ }
209
+
210
+ ExclusiveAccessTestSuite . test ( " InoutReadEscapeWrite " )
211
+ . skip ( . custom(
212
+ { _isFastAssertConfiguration ( ) } ,
213
+ reason: " this trap is not guaranteed to happen in -Ounchecked " ) )
214
+ . crashOutputMatches ( " Previous access (a read) started at " )
215
+ . crashOutputMatches ( " Current access (a modification) started at " )
216
+ . code
217
+ {
218
+ var x = 3
219
+ let c = { x = 42 }
220
+ expectCrashLater ( )
221
+ readAndPerform ( & x, closure: c)
222
+ _blackHole ( x)
223
+ }
224
+
225
+ ExclusiveAccessTestSuite . test ( " InoutWriteEscapeRead " )
226
+ . skip ( . custom(
227
+ { _isFastAssertConfiguration ( ) } ,
228
+ reason: " this trap is not guaranteed to happen in -Ounchecked " ) )
229
+ . crashOutputMatches ( " Previous access (a modification) started at " )
230
+ . crashOutputMatches ( " Current access (a read) started at " )
231
+ . code
232
+ {
233
+ var x = 3
234
+ let c = { let y = x; _blackHole ( y) }
235
+ expectCrashLater ( )
236
+ modifyAndPerform ( & x, closure: c)
237
+ _blackHole ( x)
238
+ }
239
+
240
+ ExclusiveAccessTestSuite . test ( " InoutWriteEscapeWrite " )
241
+ . skip ( . custom(
242
+ { _isFastAssertConfiguration ( ) } ,
243
+ reason: " this trap is not guaranteed to happen in -Ounchecked " ) )
244
+ . crashOutputMatches ( " Previous access (a modification) started at " )
245
+ . crashOutputMatches ( " Current access (a modification) started at " )
246
+ . code
247
+ {
248
+ var x = 3
249
+ let c = { x = 42 }
250
+ expectCrashLater ( )
251
+ modifyAndPerform ( & x, closure: c)
252
+ _blackHole ( x)
253
+ }
254
+
255
+ // No crash.
256
+ ExclusiveAccessTestSuite . test ( " InoutReadNoescapeRead " ) {
257
+ var x = 3
258
+ let c = { let y = x; _blackHole ( y) }
259
+ doOne { readAndPerform ( & x, closure: c) }
260
+ }
261
+
262
+ ExclusiveAccessTestSuite . test ( " InoutReadNoescapeWrite " )
263
+ . skip ( . custom(
264
+ { _isFastAssertConfiguration ( ) } ,
265
+ reason: " this trap is not guaranteed to happen in -Ounchecked " ) )
266
+ . crashOutputMatches ( " Previous access (a read) started at " )
267
+ . crashOutputMatches ( " Current access (a modification) started at " )
268
+ . code
269
+ {
270
+ var x = 3
271
+ let c = { x = 7 }
272
+ expectCrashLater ( )
273
+ doOne { readAndPerform ( & x, closure: c) }
274
+ }
275
+
276
+ ExclusiveAccessTestSuite . test ( " InoutWriteEscapeRead " )
277
+ . skip ( . custom(
278
+ { _isFastAssertConfiguration ( ) } ,
279
+ reason: " this trap is not guaranteed to happen in -Ounchecked " ) )
280
+ . crashOutputMatches ( " Previous access (a modification) started at " )
281
+ . crashOutputMatches ( " Current access (a read) started at " )
282
+ . code
283
+ {
284
+ var x = 3
285
+ let c = { let y = x; _blackHole ( y) }
286
+ expectCrashLater ( )
287
+ doOne { modifyAndPerform ( & x, closure: c) }
288
+ }
289
+
290
+ ExclusiveAccessTestSuite . test ( " InoutWriteEscapeWrite " )
291
+ . skip ( . custom(
292
+ { _isFastAssertConfiguration ( ) } ,
293
+ reason: " this trap is not guaranteed to happen in -Ounchecked " ) )
294
+ . crashOutputMatches ( " Previous access (a modification) started at " )
295
+ . crashOutputMatches ( " Current access (a modification) started at " )
296
+ . code
297
+ {
298
+ var x = 3
299
+ let c = { x = 7 }
300
+ expectCrashLater ( )
301
+ doOne { modifyAndPerform ( & x, closure: c) }
302
+ }
188
303
189
304
runAllTests ( )
0 commit comments