Files
dotnet-runtime/docs/workflow/testing/libraries/testing-apple.md
T
Simon RozsivalandAlexander Köplinger 6cf785d9fb Support Process.Start() on MacCatalyst (#61507)
* Modify existing tests

* Enable process start and kill on MacCatalyst

* Typo

* Temporarily enable ProcessTests for MacCatalyst

* Temporarily enable ProcessTests for MacCatalyst - attempt 2

* Allow running Mac Catalyst builds in App Sandbox

* Allow enabling app sandbox for the other Mac Catalyst sample

* Add missing parameter to XCode project generator

* Remove unnecessary MacCatalyst detection

* Enable App Sandbox for Mac Catalyst tests

* Create a separate test branch for App Sandbox

* Remove the restriction to enable app sandbox just for Mac Catalyst apps

* Do not throw PNSE for Mac Catalyst

* Clean-up platform-specific conditions

* Build correct Process implementation for MacCatalyst

* Try to get more information from CI for further investigation of the failing build

* Revert "Try to get more information from CI for further investigation of the failing build"

This reverts commit fc63a370d688aa0d1dc890e6928a8d031d148e56.

* Add MacCatalyst target framework for System.Diagnostics.Process

* Add supported platform annotations for Mac Catalyst

* Fix annotations

* Remove incorrectly placed attributes

* Update attributes including the reference file

* Change platform attributes

* Generate app.entitlements in the BuildAppleAppBundles test build target

* Revert "Generate app.entitlements in the BuildAppleAppBundles test build target"

This reverts commit abbe2241586e3469c3d3e9d4ecd2cea2e09d3641.

* Enable AppSandbox when generating CMakeLists.txt for libraries tests

* Try implementing a workaround for app sandbox mode

* Fix app sandbox detection bug

* Add explanation comment

* Enable more tests for MacCatalyst

* Add apple app builder input validation

* Add Mac Catalyst w/ App Sandbox enabled to runtime-manual test pipeline

* Enable networking in App Sandbox mode

* Skip test which won't work on Mac Catalyst

* Skip some tests in app sandbox mode

* Update src/tasks/AppleAppBuilder/AppleAppBuilder.cs

Co-authored-by: Alexander Köplinger <[email protected]>

* Add a clarification comment for a networking entitlement

* Simplify supported platform condition

* Remove temporarily enabled test

* Remove unnecessary attributes

* Replace checking env variable with checking errno in libproc

* Update docs

* Remove unnecessary changes

* Temporarily enable running System.Diagnostics.Process.Tests for this PR

This reverts commit 02d370c2cf730bf67a3cf6fca8fcb8c5e4ff1ccd.

* Revert "Temporarily enable running System.Diagnostics.Process.Tests for this PR"

This reverts commit dc72f0f1d068314317d088d33ec87f9aa6447854.

* Fix job suffix in runtime-manual

* Remove attributes

* Revert "Remove attributes"

This reverts commit 704e9fa73cd40854d1becc2889569bab3c47d62d.

* Try changing the order of attributes to please CI

* Update ApiCompat baseline

* ApiCompat step 1: remove all attributes for MaxWorkingSet setter

* Revert "Update ApiCompat baseline"

This reverts commit a2ad03207c5f9f40b9dd2c335a1b0f31c37a0ac5.

* Revert "ApiCompat step 1: remove all attributes for MaxWorkingSet setter"

This reverts commit be72a3d2564afb89a83198ef010b3d4622799601.

* Update ApiCompat baseline

* Update ApiCompat baseline after pulling upstream main

* Remove trailing whitespace

Co-authored-by: Alexander Köplinger <[email protected]>
2021-12-07 20:33:38 +01:00

4.8 KiB

Testing Libraries on iOS, tvOS, and MacCatalyst

Prerequisites

  • XCode 11.3 or higher
  • a certificate and provisioning profile if using a device
  • a simulator with a proper device type and OS version. Go XCode > Window > Devices and Simulators to revise the list of the available simulators and then "+" button on bottom left > OS Version dropdown selection > Download more simulator runtimes in case you need to download more simulators.

Building Libs and Tests

You can build and run the library tests:

  • on a simulator;
  • on a device.

Run the following command in a terminal:

./build.sh mono+libs -os <TARGET_OS> -arch <TARGET_ARCHITECTURE>

where <TARGET_OS> is one of the following:

  • iOSSimulator
  • tvOSSimulator
  • MacCatalyst
  • iOS
  • tvOS

and <TARGET_ARCHITECTURE> is one of the following:

  • x64
  • arm64 (for device)

e.g., to build for an iOS simulator, run:

./build.sh mono+libs -os iOSSimulator -arch x64

Run tests one by one for each test suite on a simulator:

./build.sh libs.tests -os iOSSimulator -arch x64 -test

Building for a device

In order to run the tests on a device:

For example:

./build.sh libs.tests -os iOS -arch x64 -test /p:DevTeamProvisioning=H1A2B3C4D5

AppleAppBuilder generates temp Xcode projects you can manually open and resolve provisioning issues there using native UI and deploy to your devices.

Running individual test suites

  • The following shows how to run tests for a specific library:
./dotnet.sh build src/libraries/System.Numerics.Vectors/tests /t:Test /p:TargetOS=iOS /p:TargetArchitecture=x64

Also you can run the built test app through Xcode by opening the corresponding .xcodeproj and setting up the right scheme, app, and even signing if using a local device.

There's also an option to run a .app through xcrun, which is simulator specific. Consider the following shell script:

    xcrun simctl shutdown <IOSSIMULATOR_NAME>
    xcrun simctl boot <IOSSIMULATOR_NAME>
    open -a Simulator
    xcrun simctl install <IOSSIMULATOR_NAME> <APP_BUNDLE_PATH>
    xcrun simctl launch --console booted <IOS_APP_NAME>

where <IOSSIMULATOR_NAME> is a name of the simulator to start, e.g. "iPhone 11", <APP_BUNDLE_PATH> is a path to the iOS test app bundle, <IOS_APP_NAME> is a name of the iOS test app

Running the functional tests

There are functional tests which aim to test some specific features/configurations/modes on a target mobile platform.

A functional test can be run the same way as any library test suite, e.g.:

./dotnet.sh build /t:Test -c Release /p:TargetOS=iOSSimulator /p:TargetArchitecture=x64 src/tests/FunctionalTests/iOS/Simulator/PInvoke/iOS.Simulator.PInvoke.Test.csproj

Currently functional tests are expected to return 42 as a success code so please be careful when adding a new one.

Viewing logs

  • see the logs generated by the XHarness tool
  • use the Console app on macOS: Command + Space, type in Console, search the appropriate process (System.Buffers.Tests for example).

Testing various configurations

It's possible to test various configurations by setting a combination of additional MSBuild properties such as RunAOTCompilation,MonoEnableInterpreter, and some more.

  1. Interpreter Only

This configuration is necessary for hot reload scenarios.

To enable the interpreter, add /p:RunAOTCompilation=true /p:MonoEnableInterpreter=true to a build command.

  1. AOT only

To build for AOT only mode, add /p:RunAOTCompilation=true /p:MonoEnableInterpreter=false to a build command.

  1. AOT-LLVM

To build for AOT-LLVM mode, add /p:RunAOTCompilation=true /p:MonoEnableInterpreter=false /p:MonoEnableLLVM=true to a build command.

  1. App Sandbox

To build the test app bundle with the App Sandbox entitlement, add /p:EnableAppSandbox=true to a build command.

Test App Design

iOS/tvOS *.app (or *.ipa) is basically a simple ObjC app that inits the Mono Runtime. This Mono Runtime starts a simple xunit test runner called XHarness.TestRunner (see https://github.com/dotnet/xharness) which runs tests for all *.Tests.dll libs in the bundle. There is also XHarness.CLI tool to deploy *.app and *.ipa to a target (device or simulator) and listens for logs via network sockets.

Existing Limitations

  • Simulator uses JIT mode only at the moment (to be extended with FullAOT and Interpreter)
  • Interpreter is not enabled yet.