Xcode 12 issues running multiple test suites with 'Underlying Error: Invalid device state' [only when running via SSH]

We're running into an odd issue only when running our test suite on CI (Jenkins) with Xcode 12: xctest reports

Code Block
xctest encountered an error (Failed to install or launch the test runner. If you believe this error represents a bug, please attach the result bundle at /Volumes/ebs_jenkins/workspace/xcode12-sandbox/derivedData/Logs/Test/Test-Xcode12Sandbox-2020.10.08_02-50-12-+0000.xcresult. (Underlying Error: Invalid device state))


Interestingly, this issue ONLY presents itself when initiated via SSH, when using Screen Sharing (VNC) and running the test suite via Xcode UI, tests pass as expected.

The tests also pass fine on the same CI machine with Xcode 11.5.

You can find a sample project that exhibits the problem here: https://github.com/opfeffer/xcode12-sandbox
This has been doing my head in for the last week.

I discovered that our CI was running in rosetta, which means in all child processes also running in rosetta. This included our final xcodebuild commands, which would then fail to run on an arm64 simulator.

From the Rosetta Documentation - there is the following note:

The system prevents you from mixing arm64 code and x86_64
code in the same process. Rosetta translation applies to an entire
process, including all code modules that the process loads dynamically.

I read this, but initially didn't realise this would apply to child processes, too.

The fix was to use the 'arch' command to force xcodebuild to run on arm64.

arch -arm64 xcodebuild ...

'arch' can also be run with no arguments to print the current environment (arm64 or i386 etc). You could then cater your pipeline to the different build environments.

I got the same error too with these spec
Xcode 12.5 beta 3
Mac os 11.2.3

Xcode, Terminal, and Simulator using Rosetta (I have several libs that does not support arm64 simulator yet)
When building, running the apps in the simulator, it works fine, as it run the UI testing

Unfortunately, it shows the same error when running the Unit Test
Perhaps it is because of this

The system prevents you from mixing arm64 code and x86_64 code in the same process

Since when we open the Xcode, the arch type is Intel, but the CoreSimulatorService and testmanagerd is running using arch Apple

Xcode 12 issues running multiple test suites with 'Underlying Error: Invalid device state' [only when running via SSH]
 
 
Q