Skip to content

Engine iOS unit tests do not run on a real device #87699

@jmagman

Description

@jmagman

iOS engine device tests pass on a simulator, but fail on a real device.

Steps to reproduce

  1. Build ios_debug_unopt and ios_test_flutter
$  ./flutter/tools/gn --no-goma --unoptimized --ios && ninja -C out/ios_debug_unopt ios_test_flutter
  1. Open in Xcode
$ open flutter/testing/ios/IosUnitTests/IosUnitTests.xcodeproj
  1. Replace contents of FlutterEngineConfig.xcconfig
FLUTTER_ENGINE=ios_debug_unopt
  1. Set signing team in both targets, run unit tests on real (not simulator) iPhone, see it crash:
2021-08-04 17:16:10.060629-0700 IosUnitTests[5916:8586338] Failed to load test bundle from file:///private/var/containers/Bundle/Application/26CD81D5-0183-43CD-802D-1F5278BABB72/IosUnitTests.app/PlugIns/IosUnitTestsTests.xctest/: Error Domain=NSCocoaErrorDomain Code=3587 "dlopen_preflight(/var/containers/Bundle/Application/26CD81D5-0183-43CD-802D-1F5278BABB72/IosUnitTests.app/PlugIns/IosUnitTestsTests.xctest/IosUnitTestsTests): Library not loaded: @rpath/Frameworks/libocmock_shared.dylib
  Referenced from: /var/containers/Bundle/Application/26CD81D5-0183-43CD-802D-1F5278BABB72/IosUnitTests.app/PlugIns/IosUnitTestsTests.xctest/IosUnitTestsTests
  Reason: image not found" UserInfo={NSLocalizedFailureReason=The bundle is damaged or missing necessary resources., NSLocalizedRecoverySuggestion=Try reinstalling the bundle., NSFilePath=/var/containers/Bundle/Application/26CD81D5-0183-43CD-802D-1F5278BABB72/IosUnitTests.app/PlugIns/IosUnitTestsTests.xctest/IosUnitTestsTests, NSDebugDescription=dlopen_preflight(/var/containers/Bundle/Application/26CD81D5-0183-43CD-802D-1F5278BABB72/IosUnitTests.app/PlugIns/IosUnitTestsTests.xctest/IosUnitTestsTests): Library not loaded: @rpath/Frameworks/libocmock_shared.dylib
  Referenced from: /var/containers/Bundle/Application/26CD81D5-0183-43CD-802D-1F5278BABB72/IosUnitTests.app/PlugIns/IosUnitTestsTests.xctest/IosUnitTestsTests
  Reason: image not found, NSBundlePath=/var/containers/Bundle/Application/26CD81D5-0183-43CD-802D-1F5278BABB72/IosUnitTests.app/PlugIns/IosUnitTestsTests.xctest, NSLocalizedDescription=The bundle “IosUnitTestsTests” couldn’t be loaded because it is damaged or missing necessary resources.}
2021-08-04 17:16:11.006344-0700 IosUnitTests[5916:8586338] The bundle “IosUnitTestsTests” couldn’t be loaded because it is damaged or missing necessary resources. Try reinstalling the bundle.
2021-08-04 17:16:11.006578-0700 IosUnitTests[5916:8586338] (dlopen_preflight(/var/containers/Bundle/Application/26CD81D5-0183-43CD-802D-1F5278BABB72/IosUnitTests.app/PlugIns/IosUnitTestsTests.xctest/IosUnitTestsTests): Library not loaded: @rpath/Frameworks/libocmock_shared.dylib
  Referenced from: /var/containers/Bundle/Application/26CD81D5-0183-43CD-802D-1F5278BABB72/IosUnitTests.app/PlugIns/IosUnitTestsTests.xctest/IosUnitTestsTests
  Reason: image not found)

The same tests pass on a simulator.

A few problems here:

  1. The dylibs aren't actually being embedded in the app. However, the same problem persists when I fix that.
xcode_frameworks_dir="${TARGET_BUILD_DIR}/${PlugIns/IosUnitTestsTests.xctest/Frameworks/}"

should be:

xcode_frameworks_dir="${TARGET_BUILD_DIR}/${PLUGINS_FOLDER_PATH}/IosUnitTestsTests.xctest/Frameworks/"
  1. When I set DYLD_PRINT_LIBRARIES=1 in the scheme environment variables I can see that the dylib still doesn't load, same crash.
  2. dylibs aren't supported on iOS and therefore don't load. "Dynamic libraries outside of a framework bundle, which typically have the file extension .dylib, are not supported on iOS, watchOS, or tvOS, except for the system Swift libraries provided by Xcode."
    https://developer.apple.com/library/archive/technotes/tn2435/_index.html

libocmock_shared.dylib and libios_test_flutter.dylib instead should be generated as framework bundles.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work lista: tests"flutter test", flutter_test, or one of our testsengineflutter/engine related. See also e: labels.platform-iosiOS applications specificallyteam-iosOwned by iOS platform teamtriaged-iosTriaged by iOS platform team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions