|
1 | | -# Testing Libraries on iOS and tvOS |
| 1 | +# Testing Libraries on iOS, tvOS, and MacCatalyst |
2 | 2 |
|
3 | | -In order to build libraries and tests for iOS or tvOS you need recent version of XCode installed (e.g. 11.3 or higher). |
| 3 | +## Prerequisites |
4 | 4 |
|
5 | | -Build Libraries for iOS Simulator: |
| 5 | +- XCode 11.3 or higher |
| 6 | +- a certificate and provisioning profile if using a device |
| 7 | +- a simulator with a proper device type and OS version. |
| 8 | +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. |
| 9 | + |
| 10 | +## Building Libs and Tests |
| 11 | + |
| 12 | +You can build and run the library tests: |
| 13 | +- on a simulator; |
| 14 | +- on a device. |
| 15 | + |
| 16 | +Run the following command in a terminal: |
| 17 | +``` |
| 18 | +./build.sh mono+libs -os <TARGET_OS> -arch <TARGET_ARCHITECTURE> |
| 19 | +``` |
| 20 | +where `<TARGET_OS>` is one of the following: |
| 21 | +- iOSSimulator |
| 22 | +- tvOSSimulator |
| 23 | +- MacCatalyst |
| 24 | +- iOS |
| 25 | +- tvOS |
| 26 | + |
| 27 | +and `<TARGET_ARCHITECTURE>` is one of the following: |
| 28 | +- x64 |
| 29 | +- arm64 (for device) |
| 30 | + |
| 31 | +e.g., to build for an iOS simulator, run: |
6 | 32 | ``` |
7 | 33 | ./build.sh mono+libs -os iOSSimulator -arch x64 |
8 | 34 | ``` |
| 35 | + |
9 | 36 | Run tests one by one for each test suite on a simulator: |
10 | 37 | ``` |
11 | 38 | ./build.sh libs.tests -os iOSSimulator -arch x64 -test |
12 | 39 | ``` |
| 40 | + |
| 41 | +### Building for a device |
| 42 | + |
13 | 43 | In order to run the tests on a device: |
14 | | -- Set the os to `iOS` instead of `iOSSimulator` |
15 | | -- Specify `DevTeamProvisioning` (see [developer.apple.com/account/#/membership](https://developer.apple.com/account/#/membership), scroll down to `Team ID`): |
| 44 | +- Set the `-os` parameter to a device-related value (see above) |
| 45 | +- Specify `DevTeamProvisioning` (see [developer.apple.com/account/#/membership](https://developer.apple.com/account/#/membership), scroll down to `Team ID`). |
| 46 | + |
| 47 | +For example: |
16 | 48 | ``` |
17 | 49 | ./build.sh libs.tests -os iOS -arch x64 -test /p:DevTeamProvisioning=H1A2B3C4D5 |
18 | 50 | ``` |
19 | | -[AppleAppBuilder](https://github.com/dotnet/runtime/blob/main/src/mono/msbuild/AppleAppBuilder/AppleAppBuilder.cs) generates temp Xcode projects you can manually open and resolve provisioning issues there using native UI and deploy to your devices. |
| 51 | +[AppleAppBuilder](https://github.com/dotnet/runtime/blob/main/src/tasks/AppleAppBuilder/AppleAppBuilder.cs) generates temp Xcode projects you can manually open and resolve provisioning issues there using native UI and deploy to your devices. |
20 | 52 |
|
21 | 53 | ### Running individual test suites |
| 54 | + |
22 | 55 | - The following shows how to run tests for a specific library: |
23 | 56 | ``` |
24 | 57 | ./dotnet.sh build src/libraries/System.Numerics.Vectors/tests /t:Test /p:TargetOS=iOS /p:TargetArchitecture=x64 |
25 | 58 | ``` |
26 | 59 |
|
| 60 | +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. |
| 61 | + |
| 62 | +There's also an option to run a `.app` through `xcrun`, which is simulator specific. Consider the following shell script: |
| 63 | + |
| 64 | +``` |
| 65 | + xcrun simctl shutdown <IOSSIMULATOR_NAME> |
| 66 | + xcrun simctl boot <IOSSIMULATOR_NAME> |
| 67 | + open -a Simulator |
| 68 | + xcrun simctl install <IOSSIMULATOR_NAME> <APP_BUNDLE_PATH> |
| 69 | + xcrun simctl launch --console booted <IOS_APP_NAME> |
| 70 | +``` |
| 71 | + |
| 72 | +where |
| 73 | +`<IOSSIMULATOR_NAME>` is a name of the simulator to start, e.g. `"iPhone 11"`, |
| 74 | +`<APP_BUNDLE_PATH>` is a path to the iOS test app bundle, |
| 75 | +`<IOS_APP_NAME>` is a name of the iOS test app |
| 76 | + |
| 77 | +### Running the functional tests |
| 78 | + |
| 79 | +There are [functional tests](https://github.com/dotnet/runtime/tree/main/src/tests/FunctionalTests/) which aim to test some specific features/configurations/modes on a target mobile platform. |
| 80 | + |
| 81 | +A functional test can be run the same way as any library test suite, e.g.: |
| 82 | +``` |
| 83 | +./dotnet.sh build /t:Test -c Release /p:TargetOS=iOSSimulator /p:TargetArchitecture=x64 src/tests/FunctionalTests/iOS/Simulator/PInvoke/iOS.Simulator.PInvoke.Test.csproj |
| 84 | +``` |
| 85 | + |
| 86 | +Currently functional tests are expected to return `42` as a success code so please be careful when adding a new one. |
| 87 | + |
| 88 | +### Viewing logs |
| 89 | +- see the logs generated by the XHarness tool |
| 90 | +- use the `Console` app on macOS: |
| 91 | +`Command + Space`, type in `Console`, search the appropriate process (System.Buffers.Tests for example). |
| 92 | + |
| 93 | +### Testing various configurations |
| 94 | + |
| 95 | +It's possible to test various configurations by setting a combination of additional MSBuild properties such as `RunAOTCompilation`,`MonoEnableInterpreter`, and some more. |
| 96 | + |
| 97 | +1. Interpreter Only |
| 98 | + |
| 99 | +This configuration is necessary for hot reload scenarios. |
| 100 | + |
| 101 | +To enable the interpreter, add `/p:RunAOTCompilation=true /p:MonoEnableInterpreter=true` to a build command. |
| 102 | + |
| 103 | +2. AOT only |
| 104 | + |
| 105 | +To build for AOT only mode, add `/p:RunAOTCompilation=true /p:MonoEnableInterpreter=false` to a build command. |
| 106 | + |
| 107 | +3. AOT-LLVM |
| 108 | + |
| 109 | +To build for AOT-LLVM mode, add `/p:RunAOTCompilation=true /p:MonoEnableInterpreter=false /p:MonoEnableLLVM=true` to a build command. |
| 110 | + |
27 | 111 | ### Test App Design |
28 | | -iOS/tvOS `*.app` (or `*.ipa`) is basically a simple [ObjC app](https://github.com/dotnet/runtime/blob/main/src/mono/msbuild/AppleAppBuilder/Templates/main-console.m) that inits the Mono Runtime. This Mono Runtime starts a simple xunit test |
| 112 | +iOS/tvOS `*.app` (or `*.ipa`) is basically a simple [ObjC app](https://github.com/dotnet/runtime/blob/main/src/tasks/AppleAppBuilder/Templates/main-console.m) that inits the Mono Runtime. This Mono Runtime starts a simple xunit test |
29 | 113 | 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. |
30 | 114 |
|
31 | 115 | ### Existing Limitations |
32 | | -- Most of the test suites crash on devices due to #35674 |
33 | 116 | - Simulator uses JIT mode only at the moment (to be extended with FullAOT and Interpreter) |
34 | 117 | - Interpreter is not enabled yet. |
0 commit comments