Xcode 7 fails to run unit tests on iOS device due to broken code signature (7A218)

Originator:ben.kennedy
Number:rdar://22634495 Date Originated:09-Sep-2015 03:29 PM
Status:Open Resolved:
Product:Developer Tools Product Version:7.0
Classification:Serious Bug Reproducible:Always
 
Summary:
It is not possible to build and run unit tests on a physical iOS device using Xcode 7.

Steps to Reproduce:
1. Create a new iOS project (any template, e.g. "single view application").
2. Attach a hardware device, and select it in the run destination menu.
3. Run unit tests.


Expected Results:
The empty test suite, provided by the Xcode project template, runs successfully on the device.

Actual Results:
Xcode fails to deploy the test bundle to the device, and tests do not run.

An EXC_ARM_BREAKPOINT is reached; continuing past it, the run aborts with a message logged to console:

dyld: could not load inserted library '/private/var/mobile/Containers/Data/Application/616B220C-B8EF-4D25-84DA-064401FE55A7/tmp/IDEBundleInjection.framework/IDEBundleInjection' because no suitable image found.  Did find:
	/private/var/mobile/Containers/Data/Application/616B220C-B8EF-4D25-84DA-064401FE55A7/tmp/IDEBundleInjection.framework/IDEBundleInjection: mmap() errno=1 validating first page of '/private/var/mobile/Containers/Data/Application/616B220C-B8EF-4D25-84DA-064401FE55A7/tmp/IDEBundleInjection.framework/IDEBundleInjection'

Examining the build product, it is obvious the code signature is broken:

retinafey:Kashoo ben$ codesign -vv /private/tmp/Test/build/Test/Build/Products/Debug-iphoneos/TestTests.xctest
/private/tmp/Test/build/Test/Build/Products/Debug-iphoneos/TestTests.xctest: a sealed resource is missing or invalid
file added: /private/tmp/Test/build/Test/Build/Products/Debug-iphoneos/TestTests.xctest/TestTests-EFFB6ADD-A953-430A-8454-438682317D22.xctestconfiguration

Xcode has contaminated the .xctest package with an .xctestconfiguration file which invalidates the code signature.

Manually deleting the .xctestconfiguration file causes code signature validation to pass. However, this cannot be worked around even using a build phase shell script, since the latter runs prior to Xcode's code signing, and the molestation of the package occurs thereafter.


Version:
Xcode 7 GM. First observed in Xcode 7 beta 6. May well have existed in many versions prior to that; have not tried running unit tests on hardware in quite some time.


Notes:


Configuration:
Mac OS 10.10.5.
Xcode 7 GM.
iOS test devices 8.4.1 and 9.0 (13A4325c).

Comments

Same issue with Xcode 7.2

rdar://23934110

Summary: 2015-12-16 22:13:53.603 MyProject[734:90400] The bundle “MyProjectTests” couldn’t be loaded because it is damaged or missing necessary resources. Try reinstalling the bundle. 2015-12-16 22:13:53.603 MyProject734:90400: no suitable image found. Did find: /var/mobile/Containers/Data/Application/912619A5-E413-4F7B-9676-8C03662DFCB1/tmp/MyProjectTests.xctest/MyProjectTests: mmap() errno=1 validating first page of '/var/mobile/Containers/Data/Application/912619A5-E413-4F7B-9676-8C03662DFCB1/tmp/MyProjectTests.xctest/MyProjectTests')

Steps to Reproduce: 1. Create new Xcode project from a template with Unit Tests 2. Run tests in Simulator successfully 3. Run same tests on device fails to start

Expected Results: XCTests to run on iOS device

Actual Results: Unit Tests fails to start

Version: Version 7.2 (7C68)

Configuration: iOS 9 SDK


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!