patrol icon indicating copy to clipboard operation
patrol copied to clipboard

Could not launch "RunnerUITests" (OSStatus error -10661.)

Open bartekpacia opened this issue 1 year ago • 14 comments

I am unable to run tests on latest master branch (9f5cb3dd940c3905d7d042cb26daee283d1bb717). I'm getting very weird errors that I am unable to resolve.

I run:

  • patrol test -t integration_test/main_test.dart -v in packages/patrol/example
  • patrol test -t integration_test/example_test.dart -v in dev/e2e_app

I tried:

  • removing, re-cloning the repo
  • clearing DerivedData directory rm -rf ~/Library/Developer/Xcode/DerivedData/*
  • clearing app's build directory
  • restarting computer
Logs
$ xcodebuild test-without-building -xctestrun /Users/bartek/dev/leancode/patrol/packages/patrol/example/build/ios_integ/Build/Products/Runner_TestPlan_iphonesimulator17.0-arm64-x86_64.xctestrun -only-testing RunnerUITests -destination platform=iOS Simulator,name=iPhone 15 -resultBundlePath /Users/bartek/dev/leancode/patrol/packages/patrol/example/build/ios_results_1702301088962.xcresult
	Command line invocation:
	    /Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild test-without-building -xctestrun /Users/bartek/dev/leancode/patrol/packages/patrol/example/build/ios_integ/Build/Products/Runner_TestPlan_iphonesimulator17.0-arm64-x86_64.xctestrun -only-testing RunnerUITests -destination "platform=iOS Simulator,name=iPhone 15" -resultBundlePath /Users/bartek/dev/leancode/patrol/packages/patrol/example/build/ios_results_1702301088962.xcresult

	User defaults from command line:
	    IDEBuildOperationResultBundlePath = /Users/bartek/dev/leancode/patrol/packages/patrol/example/build/ios_results_1702301088962.xcresult
	    IDEPackageSupportUseBuiltinSCM = YES

	Writing result bundle at path:
		/Users/bartek/dev/leancode/patrol/packages/patrol/example/build/ios_results_1702301088962.xcresult

	--- xcodebuild: WARNING: Using the first of multiple matching destinations:
	{ platform:macOS, arch:arm64e, id:00008103-000C258C0EBB001E }
	{ platform:macOS, arch:arm64, id:00008103-000C258C0EBB001E }
	{ platform:macOS, arch:x86_64, id:00008103-000C258C0EBB001E }
	{ platform:macOS, arch:arm64e, variant:Mac Catalyst, id:00008103-000C258C0EBB001E }
	{ platform:macOS, arch:arm64, variant:Mac Catalyst, id:00008103-000C258C0EBB001E }
	{ platform:macOS, arch:x86_64, variant:Mac Catalyst, id:00008103-000C258C0EBB001E }
	{ platform:macOS, arch:arm64e, variant:DriverKit, id:00008103-000C258C0EBB001E }
	{ platform:macOS, arch:arm64, variant:DriverKit, id:00008103-000C258C0EBB001E }
	{ platform:macOS, arch:arm64, variant:Designed for [iPad,iPhone], id:00008103-000C258C0EBB001E }
	{ platform:iOS, id:dvtdevice-DVTiPhonePlaceholder-iphoneos:placeholder, name:Any iOS Device }
	{ platform:iOS Simulator, id:dvtdevice-DVTiOSDeviceSimulatorPlaceholder-iphonesimulator:placeholder, name:Any iOS Simulator Device }
	{ platform:macOS, name:Any Mac }
	{ platform:macOS, variant:Mac Catalyst, name:Any Mac }
	{ platform:tvOS, id:dvtdevice-DVTiOSDevicePlaceholder-appletvos:placeholder, name:Any tvOS Device }
	{ platform:tvOS Simulator, id:dvtdevice-DVTiOSDeviceSimulatorPlaceholder-appletvsimulator:placeholder, name:Any tvOS Simulator Device }
	{ platform:watchOS, id:dvtdevice-DVTiOSDevicePlaceholder-watchos:placeholder, name:Any watchOS Device }
	{ platform:watchOS Simulator, id:dvtdevice-DVTiOSDeviceSimulatorPlaceholder-watchsimulator:placeholder, name:Any watchOS Simulator Device }
	{ platform:iOS Simulator, id:7F715B15-1747-43BE-91ED-DFF46CCB7F8A, OS:17.0.1, name:iPad (10th generation) }
	{ platform:iOS Simulator, id:7F715B15-1747-43BE-91ED-DFF46CCB7F8A, OS:17.0.1, name:iPad (10th generation) }
	{ platform:iOS Simulator, id:4BF16D73-5A86-4C46-8734-AB31E296FBBC, OS:17.0.1, name:iPad Air (5th generation) }
	{ platform:iOS Simulator, id:4BF16D73-5A86-4C46-8734-AB31E296FBBC, OS:17.0.1, name:iPad Air (5th generation) }
	{ platform:iOS Simulator, id:B2432105-8161-4013-AF08-496F26452B6C, OS:17.0.1, name:iPad Pro (11-inch) (4th generation) }
	{ platform:iOS Simulator, id:B2432105-8161-4013-AF08-496F26452B6C, OS:17.0.1, name:iPad Pro (11-inch) (4th generation) }
	{ platform:iOS Simulator, id:329EA370-1B14-4B52-849A-D2D21F38D07F, OS:17.0.1, name:iPad Pro (12.9-inch) (6th generation) }
	{ platform:iOS Simulator, id:329EA370-1B14-4B52-849A-D2D21F38D07F, OS:17.0.1, name:iPad Pro (12.9-inch) (6th generation) }
	{ platform:iOS Simulator, id:8CB87DC5-1846-49AA-9DC8-1D529815CE9B, OS:17.0.1, name:iPad mini (6th generation) }
	{ platform:iOS Simulator, id:8CB87DC5-1846-49AA-9DC8-1D529815CE9B, OS:17.0.1, name:iPad mini (6th generation) }
	{ platform:iOS Simulator, id:14F71B6C-42E4-4312-9230-2CB2828CCBFE, OS:17.0.1, name:iPhone 15 }
	{ platform:iOS Simulator, id:14F71B6C-42E4-4312-9230-2CB2828CCBFE, OS:17.0.1, name:iPhone 15 }
	{ platform:iOS Simulator, id:74447F48-37AC-4DCA-AE0A-D8BAF7FD2090, OS:17.0.1, name:iPhone 15 }
	{ platform:iOS Simulator, id:74447F48-37AC-4DCA-AE0A-D8BAF7FD2090, OS:17.0.1, name:iPhone 15 }
	{ platform:iOS Simulator, id:69B2F2BB-44C4-48C1-903F-40475090C1AE, OS:17.0.1, name:iPhone 15 Plus }
	{ platform:iOS Simulator, id:69B2F2BB-44C4-48C1-903F-40475090C1AE, OS:17.0.1, name:iPhone 15 Plus }
	{ platform:iOS Simulator, id:ED9FC97A-B7E6-4BBB-BE41-5D12E94C6332, OS:17.0.1, name:iPhone 15 Pro }
	{ platform:iOS Simulator, id:ED9FC97A-B7E6-4BBB-BE41-5D12E94C6332, OS:17.0.1, name:iPhone 15 Pro }
	{ platform:iOS Simulator, id:2279BFB8-D2DB-4680-8B70-26A8F9F6114F, OS:17.0.1, name:iPhone 15 Pro Max }
	{ platform:iOS Simulator, id:2279BFB8-D2DB-4680-8B70-26A8F9F6114F, OS:17.0.1, name:iPhone 15 Pro Max }
	{ platform:iOS Simulator, id:BF7AADBE-7D77-43E7-9F65-91EE4F0AE20D, OS:17.0.1, name:iPhone SE (3rd generation) }
	{ platform:iOS Simulator, id:BF7AADBE-7D77-43E7-9F65-91EE4F0AE20D, OS:17.0.1, name:iPhone SE (3rd generation) }
	2023-12-11 14:24:51.387 xcodebuild[76667:623924]  IDELaunchReport: 4b09cc2c7898b8c0:4b09cc2c7898b8c0: Finished with error: Could not launch “RunnerUITests”
	Domain: IDELaunchErrorDomain
	Code: 20
	Recovery Suggestion: LaunchServices has returned error -10661. Please check the system logs for the underlying cause of the error.
	User Info: {
	    DVTRadarComponentKey = 113722;
	    IDERunOperationFailingWorker = IDELaunchServicesLauncher;
	}
	--
	The operation couldn’t be completed. (OSStatus error -10661.)
	Domain: NSOSStatusErrorDomain
	Code: -10661
	User Info: {
	    "_LSFunction" = "_LSOpenStuffCallLocal";
	    "_LSLine" = 4141;
	}
	--
	2023-12-11 14:24:51.387 xcodebuild[76667:623924]  IDELaunchReport: 4b09cc2c7898b8c0:4b09cc2c7898b8c0: com.apple.dt.IDERunOperationWorkerFinished {
	    "device_model" = "MacBookAir10,1";
	    "device_osBuild" = "14.1.2 (23B92)";
	    "device_platform" = "com.apple.platform.macosx";
	    "dvt_coredevice_version" = "348.1";
	    "dvt_mobiledevice_version" = "1643.40.14";
	    "launchSession_schemeCommand" = Test;
	    "launchSession_state" = 1;
	    "launchSession_targetArch" = arm64e;
	    "operation_duration_ms" = 29;
	    "operation_errorCode" = 20;
	    "operation_errorDomain" = IDELaunchErrorDomain;
	    "operation_errorWorker" = IDELaunchServicesLauncher;
	    "operation_name" = IDERunOperationWorkerGroup;
	    "param_debugger_attachToExtensions" = 0;
	    "param_debugger_attachToXPC" = 0;
	    "param_debugger_type" = 1;
	    "param_destination_isProxy" = 0;
	    "param_destination_platform" = "com.apple.platform.macosx";
	    "param_diag_MainThreadChecker_stopOnIssue" = 0;
	    "param_diag_MallocStackLogging_enableDuringAttach" = 0;
	    "param_diag_MallocStackLogging_enableForXPC" = 0;
	    "param_diag_allowLocationSimulation" = 1;
	    "param_diag_checker_tpc_enable" = 0;
	    "param_diag_gpu_frameCapture_enable" = 3;
	    "param_diag_gpu_shaderValidation_enable" = 0;
	    "param_diag_gpu_validation_enable" = 1;
	    "param_diag_memoryGraphOnResourceException" = 0;
	    "param_diag_queueDebugging_enable" = 1;
	    "param_diag_runtimeProfile_generate" = 0;
	    "param_diag_sanitizer_asan_enable" = 0;
	    "param_diag_sanitizer_tsan_enable" = 0;
	    "param_diag_sanitizer_tsan_stopOnIssue" = 0;
	    "param_diag_sanitizer_ubsan_stopOnIssue" = 0;
	    "param_diag_showNonLocalizedStrings" = 0;
	    "param_diag_viewDebugging_enabled" = 0;
	    "param_diag_viewDebugging_insertDylibOnLaunch" = 0;
	    "param_install_style" = 2;
	    "param_launcher_UID" = 2;
	    "param_launcher_allowDeviceSensorReplayData" = 0;
	    "param_launcher_kind" = 0;
	    "param_launcher_style" = 0;
	    "param_launcher_substyle" = 8192;
	    "param_runnable_appExtensionHostRunMode" = 0;
	    "param_runnable_productType" = "com.apple.product-type.application";
	    "param_structuredConsoleMode" = 0;
	    "param_testing_launchedForTesting" = 1;
	    "param_testing_suppressSimulatorApp" = 1;
	    "param_testing_usingCLI" = 0;
	    "sdk_canonicalName" = "macosx14.0";
	    "sdk_osVersion" = "14.0";
	    "sdk_variant" = macos;
	}


	*** If you believe this error represents a bug, please attach the result bundle at /Users/bartek/dev/leancode/patrol/packages/patrol/example/build/ios_results_1702301088962.xcresult

	2023-12-11 14:24:55.784 xcodebuild[76667:623907] [MT] IDETestOperationsObserverDebug: 5.522 elapsed -- Testing started completed.
	2023-12-11 14:24:55.784 xcodebuild[76667:623907] [MT] IDETestOperationsObserverDebug: 0.000 sec, +0.000 sec -- start
	2023-12-11 14:24:55.784 xcodebuild[76667:623907] [MT] IDETestOperationsObserverDebug: 5.522 sec, +5.522 sec -- end

	Test session results, code coverage, and logs:
		/Users/bartek/dev/leancode/patrol/packages/patrol/example/build/ios_results_1702301088962.xcresult

	Testing failed:
		Could not launch “RunnerUITests”
		RunnerUITests-Runner encountered an error (Failed to install or launch the test runner. (Underlying Error: Could not launch “RunnerUITests”. LaunchServices has returned error -10661. Please check the system logs for the underlying cause of the error. (Underlying Error: The operation couldn’t be completed. (OSStatus error -10661.))))

	** TEST EXECUTE FAILED **

	Testing started
✗ Failed to execute tests of app with entrypoint test_bundle.dart for iOS simulator on simulator iPhone 15 (xcodebuild exited with code 65) (10.0s)
Error: xcodebuild exited with code 65
#0      throwToolExit (package:patrol_cli/src/base/exceptions.dart:7:3)
#1      IOSTestBackend.execute.<anonymous closure> (package:patrol_cli/src/ios/ios_test_backend.dart:188:9)
<asynchronous suspension>
#2      DisposeScope.run (package:dispose_scope/src/dispose_scope.dart:46:7)
<asynchronous suspension>
#3      IOSTestBackend.execute (package:patrol_cli/src/ios/ios_test_backend.dart:148:5)
<asynchronous suspension>
#4      TestCommand._execute (package:patrol_cli/src/commands/test.dart:272:7)
<asynchronous suspension>
#5      TestCommand.run (package:patrol_cli/src/commands/test.dart:169:23)
<asynchronous suspension>
#6      CommandRunner.runCommand (package:args/command_runner.dart:212:13)
<asynchronous suspension>
#7      PatrolCommandRunner.runCommand (package:patrol_cli/src/runner/patrol_command_runner.dart:318:18)
<asynchronous suspension>
#8      PatrolCommandRunner.run (package:patrol_cli/src/runner/patrol_command_runner.dart:262:18)
<asynchronous suspension>
#9      patrolCommandRunner (package:patrol_cli/src/runner/patrol_command_runner.dart:68:20)
<asynchronous suspension>
#10     main (file:///Users/bartek/.pub-cache/hosted/pub.dev/patrol_cli-2.3.1+1/bin/main.dart:6:20)
<asynchronous suspension>

See the logs above to learn what happened. Also consider running with --verbose. If the logs still aren't useful, then it's a bug - please report it.
$ xcrun simctl uninstall 14F71B6C-42E4-4312-9230-2CB2828CCBFE pl.leancode.patrol.Example
$ xcrun simctl uninstall 14F71B6C-42E4-4312-9230-2CB2828CCBFE pl.leancode.patrol.Example.RunnerUITests.xctrunner
patrol doctor
$ patrol doctor
Patrol CLI version: 2.3.1+1
Program adb found in /Users/bartek/androidsdk/platform-tools/adb
Env var $ANDROID_HOME set to /Users/bartek/androidsdk
Program xcodebuild found in /usr/bin/xcodebuild
Program ideviceinstaller found in /opt/homebrew/bin/ideviceinstaller
flutter doctor
[✓] Flutter (Channel stable, 3.16.0, on macOS 14.1.2 23B92 darwin-arm64, locale en-PL)
    • Flutter version 3.16.0 on channel stable at /Users/bartek/fvm/versions/3.16.0
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision db7ef5bf9f (4 weeks ago), 2023-11-15 11:25:44 -0800
    • Engine revision 74d16627b9
    • Dart version 3.2.0
    • DevTools version 2.28.2

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /Users/bartek/androidsdk
    • Platform android-34, build-tools 34.0.0
    • ANDROID_HOME = /Users/bartek/androidsdk
    • Java binary at: /Users/bartek/Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.7+0-17.0.7b1000.6-10550314)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.0.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15A507
    • CocoaPods version 1.14.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2023.1)
    • Android Studio at /Users/bartek/Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.7+0-17.0.7b1000.6-10550314)

[✓] IntelliJ IDEA Ultimate Edition (version 2023.3)
    • IntelliJ at /Users/bartek/Applications/IntelliJ IDEA Ultimate.app
    • Flutter plugin version 77.0.1
    • Dart plugin version 233.11799.172

[✓] VS Code (version 1.85.0)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.78.0

[✓] Connected device (3 available)
    • iPhone 15 (mobile) • 14F71B6C-42E4-4312-9230-2CB2828CCBFE • ios            • com.apple.CoreSimulator.SimRuntime.iOS-17-0 (simulator)
    • macOS (desktop)    • macos                                • darwin-arm64   • macOS 14.1.2 23B92 darwin-arm64
    • Chrome (web)       • chrome                               • web-javascript • Google Chrome 119.0.6045.199

[✓] Network resources
    • All expected network resources are available.

• No issues found!
Xcode
$ xcodebuild -version
Xcode 15.0.1
Build version 15A507

bartekpacia avatar Dec 11 '23 13:12 bartekpacia

It seems as if it tries running my tests not on the iOS Simulator, but on my MacBook.

bartekpacia avatar Dec 11 '23 13:12 bartekpacia

I tried running it today and magically, it (patrol test in both apps) started working. More precisely, it seems that the -destination flag started working:

-- xcodebuild: WARNING: Using the first of multiple matching destinations:
	{ platform:iOS Simulator, id:42D0DABF-5641-42E8-9184-B51281116BA5, OS:17.0.1, name:iPhone 15 }
	{ platform:iOS Simulator, id:42D0DABF-5641-42E8-9184-B51281116BA5, OS:17.0.1, name:iPhone 15 }

It no longer finds "all the devices" and starts running on macOS beacuse it's "the first of multiple matching destinations".

The questions remains why it duplicates these iPhone 15 simulator lines in output, but at least it works.

bartekpacia avatar Dec 12 '23 12:12 bartekpacia

I was not able to reproduce this issue. I found a discussion about this. Seems like some random issue with XCode 15.

piotruela avatar Dec 13 '23 08:12 piotruela

Good find @piotruela.

I also found a nice post by Bitrise (linked to from the Discussion you found):

I also saw much higher CPU usage when running tests on Xcode 15.

bartekpacia avatar Dec 13 '23 11:12 bartekpacia

Xcode 15.1 got released today

EDIT It doesn't help.

bartekpacia avatar Dec 13 '23 17:12 bartekpacia

@bartekpacia were you able to resolve this?

MirzaCickusic avatar Jan 12 '24 17:01 MirzaCickusic

Nope.

bartekpacia avatar Jan 14 '24 18:01 bartekpacia

How can i run test with this error? Any solutions?

Noxiver avatar Jan 20 '24 17:01 Noxiver

I was able to resolve this by updating to the latest code xcode 15.2 and running the tests on 17.2 iOS. Patrol CLI version: 2.6.2

MirzaCickusic avatar Feb 02 '24 21:02 MirzaCickusic

This issue is probably caused by some changes in Xcode 15 - I got the same error and we noticed that patrol chooses wrong version of simulator sdk to build the tests. In my case, it always chooses 17.5, but tries to run on iOS 16.4 (that's the version I wanted to run).

WORKAROUND:

  1. Install Xcode 14.x (or older)
  2. Set it as active eg. using xcodes tool. This way, Patrol can use xcode command-line tools in version shipped with older xcode

Now the build is correct, but you can experience another issue - no matching destinations found. Somehow xcodebuild command assumes, that if we don't specify OS version in -destination argument, it picks latest, which is wrong in this case. To fix this, you can modify this line, so it looks like this: 'platform=${device.real ? 'iOS' : 'iOS Simulator'},OS=16.4,name=${device.name}', where 16.4 is OS version on your device or simulator you want to use. Unfortunately then you have to use local version of patrol_cli, so use dart run /path/to/patrol/packages/patrol_cli/bin/main.dart develop and usual arguments you use

jBorkowska avatar May 28 '24 14:05 jBorkowska

@jBorkowska can you share the example of "...local version of patrol_cli, so use dart run /path/to/patrol/packages/patrol_cli/bin/main.dart develop and usual arguments you use" full command? Originally my issue posted here - I've turned off parallelization for all schemes, this fixed emulator cloning but the "--- xcodebuild: WARNING: Using the first of multiple matching destinations:" with 2 same simulators is still there. So I've installed Xcode 14.3.1 but nothing is changed - after appearing permission dialog nothing happens (I have code for native permission, but it just freezes) and no error in terminal - it just never ends. TY in advance!

UPD: Discord

ivan-horchakov avatar Jun 05 '24 14:06 ivan-horchakov

@ivan-horchakov I used dart run /Users/julia/patrol/packages/patrol_cli/bin/main.dart develop -t integration_test/example_test.dart

jBorkowska avatar Jun 12 '24 11:06 jBorkowska

Is it fixed in xcode 16? I cant use xcodes because I need to login with apple id inside xcode ui, that I can't run because of old version. Any solutions?

UPD: xcode 16 - still reproducing

andreyshutov1992 avatar Sep 18 '24 12:09 andreyshutov1992

I've managed to fix this. After update to macos 16:

  1. Delete all ios emulators
  2. rm -rf /Users/user/Library/Developer/Xcode/DerivedData
  3. Mac System Settings -> Storage -> Developer(delete there all data)
  4. Install iPhone 16 pro emulator (iOS 18.0)

andreyshutov1992 avatar Sep 19 '24 10:09 andreyshutov1992

I have also this problem sometimes, especially after connect external disk to macOS and move repo there (maybe not related). But I deleted all iOS versions from xcode and then install just iOS 17.5 it's working for now.

Kendru98 avatar Oct 07 '24 11:10 Kendru98