EXC_BAD_INSTRUCTION with XCTest notification expectations

Originator:defagos
Number:rdar://32670300 Date Originated:June 9 2017
Status:Closed Resolved:Duplicate
Product:Xcode Product Version:8.3
Classification:Bug Reproducible:Always
 
Summary:
When running some AVPlayer-related unit tests which were working perfectly fine until Xcode 8.2.1, and starting with Xcode 8.3, I am getting EXC_BAD_INSTRUCTION crashes consistently for some of them. 

I strongly suspect internal implementation changes to XCTest notification expectations might explain these new crashes. Significant changes were namely introduced with Xcode 8.3 (see Xcode 8.3 release notes about ref. 22539853).

Steps to Reproduce:
There is simply no easy way to create a sample project to reproduce this issue, I therefore suggest you should run one of the tests I am experiencing the crash on. This is easy since the project I am working on is open source:

1. Simply clone the project from github:
        $ git clone https://github.com/SRGSSR/SRGMediaPlayer-iOS.git
    and switch to tag 2.0.1:
        $ git checkout tags/2.0.1

2. Carthage (https://github.com/Carthage/Carthage) is required to fetch a few dependencies required to build the project. You can install it simply via:
         $ brew install carthage
Then run the following command from the main repository directory to retrieve and build the dependencies:
         $ carthage bootstrap

3. Run the test called 'testSeekInterruption' with Xcode 8.2.1 (works fine), then again with Xcode 8.3 (crashes with EXC_BAD_INSTRUCTION).

Expected Results:
The test should run fine and succeed.

Observed Results:
The test crashes with the following backtrace:

(lldb) bt
* thread #1, queue = 'com.apple.dt.xctest.notification-expectation', stop reason = EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)
    frame #0: 0x0000000106bb439a libdispatch.dylib`_dispatch_barrier_sync_f_slow + 679
    frame #1: 0x0000000000003177
    frame #2: 0x0000000104f7ee94 XCTest`-[_XCTNSNotificationExpectationImplementation _observeExpectedNotification:] + 85
    frame #3: 0x00000001055dcc2c CoreFoundation`__CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 12
    frame #4: 0x00000001055dcb29 CoreFoundation`_CFXRegistrationPost + 425
    frame #5: 0x00000001055dc892 CoreFoundation`___CFXNotificationPost_block_invoke + 50
    frame #6: 0x00000001055a0102 CoreFoundation`-[_CFXNotificationRegistrar find:object:observer:enumerator:] + 1826
    frame #7: 0x000000010559f261 CoreFoundation`_CFXNotificationPost + 673
    frame #8: 0x0000000104a3fca4 Foundation`-[NSNotificationCenter postNotificationName:object:userInfo:] + 66
...

Version:
Xcode 8.3 (problem was also reproduced with Xcode 9.0 beta 1), running on macOS 10.12.5 (16F73)

Notes:


Configuration:

Comments

Closed as duplicate of my other rdar://36902658.


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!