xamarin-macios/tests
Rolf Bjarne Kvinge 5ef0d91b33
[msbuild/tests] Use 'dotnet test' for the MSBuild tests (take 2). (#21363)
This is another step towards removing Mono.

This required a few changes:

* Nullability updates in test code.
* Explicitly sorted list of strings in a warning message, to make the warning text stable.
* Stopped allowing the test assemblies to see internals of the task assembly. This was necessary for to solve a problem with duplicate types:
    * The netstandard2.0 version of `System.Reflection.Metadata.dll` contains
      the `UnconditionalSuppressMessageAttribute` type (internally).
    * Since we ILMerge the tasks assembly, this type ends up in
      Xamarin.iOS.Tasks.dll (internally).
    * The test assembly can't be a net472 assembly, because that means using
      the netfx/desktop versions of the Microsoft.Build.* assemblies, which
      don't work on .NET (they check for Mono, but .NET isn't Mono, so the
      check fails and a PlatformNotSupportedException is thrown).
    * So I bumped the test assembly to be a net8.0 assembly, but then there's
      a conflict between the `UnconditionalSuppressMessageAttribute` shipped
      in .NET vs the one in `Xamarin.iOS.Tasks.dll` (because the test assembly
      can see the internals of `Xamarin.iOS.Tasks.dll`).
    * The fix that _doesn't work_ is to not merge system assemblies in the
      `Xamarin.iOS.Tasks.dll` assembly anymore. `Xamarin.iOS.Tasks.Windows.dll`
      already does this, but it doesn't work when building remotely.
    * The fix that seems to work is to just not allow the test assemblies to
      see the internals of the task assembly. This is really an anti-pattern
      anyway, so no big loss. This required a few changes (make some API in
      the task assembly public, remove some legacy tests that don't apply
      anymore in .NET, etc.)
2024-10-07 18:14:01 +02:00
..
.nuget/packages
BundledResources
EmbeddedResources
api-shared
bcl-test/templates [tests] Remove the BCL tests. (#21197) 2024-09-18 17:59:23 +02:00
bgen [bgen] Fix compiler warnings. (#21184) 2024-09-09 12:25:03 +02:00
bindings-framework-test
bindings-test
bindings-test2
bindings-xcframework-test
cecil-tests [Vision] Bind VNVisionVersionNumber. Fixes #21342. (#21350) 2024-10-03 11:15:02 +02:00
common Merge remote-tracking branch 'origin/net9.0' into merge-net9.0-into-main 2024-10-01 17:03:30 +02:00
dotnet [tests] Update list of expected native libraries we link with for .NET 9. 2024-10-03 10:45:58 +02:00
framework-test
fsharp
fsharplibrary
generator Merge net9.0 into main. (#21349) 2024-10-04 09:22:01 +02:00
interdependent-binding-projects
introspection Merge remote-tracking branch 'origin/main' into dev/rolf/merge-net9.0-into-main 2024-10-02 20:02:22 +02:00
linker Merge remote-tracking branch 'origin/main' into dev/rolf/bump-main-in-net9.0-2024-09-18 2024-09-19 09:48:34 +02:00
mac-binding-project
misc
mmp-regression
mmptest Merge remote-tracking branch 'origin/net9.0' into merge-net9.0-into-main 2024-10-01 17:03:30 +02:00
monotouch-test Merge net9.0 into main. (#21349) 2024-10-04 09:22:01 +02:00
msbuild [msbuild/tests] Use 'dotnet test' for the MSBuild tests (take 2). (#21363) 2024-10-07 18:14:01 +02:00
mtouch Merge remote-tracking branch 'origin/net9.0' into merge-net9.0-into-main 2024-10-01 17:03:30 +02:00
perftest
qa-regression
scripted
templates
test-libraries Merge remote-tracking branch 'origin/main' into dev/rolf/merge-net9.0-into-main 2024-10-02 20:02:22 +02:00
xammac_tests
xcframework-test
xharness [msbuild/tests] Use 'dotnet test' for the MSBuild tests (take 2). (#21363) 2024-10-07 18:14:01 +02:00
xtro-sharpie [Vision] Bind VNVisionVersionNumber. Fixes #21342. (#21350) 2024-10-03 11:15:02 +02:00
.gitignore [tests] Remove the BCL tests. (#21197) 2024-09-18 17:59:23 +02:00
ComputeRegistrarConstant.targets
Directory.Build.props
Directory.Build.targets
HtmlTransform.xslt
Makefile [msbuild/tests] Use 'dotnet test' for the MSBuild tests (take 2). (#21363) 2024-10-07 18:14:01 +02:00
README.md [tests] Remove the BCL tests. (#21197) 2024-09-18 17:59:23 +02:00
nunit.framework.targets
nunit.framework.xml
package-dotnet-tests.sh
package-mac-tests.sh
packaged-macos-tests.mk
run-with-timeout.csharp
run-with-timeout.sh
test-dependencies.sh [system-dependencies] We don't need autotools anymore, so don't check for it. (#21104) 2024-08-26 11:34:44 +02:00
tests-mac.sln
tests.sln [tests] Remove the BCL tests. (#21197) 2024-09-18 17:59:23 +02:00

README.md

Various tests to be executed prior to releases

Test permissions

There are a number of tests that acccess the file system and the bluetooh. For these tests to correctly execute you have to ensure that the terminal application that you are using to execute the tests has access to the full filesystem and the bluetooth. If you do not do this step the macOS tests will crash.

Test solutions

Many of the test solutions and test projects are generated, and will only be available after running make once.

  • tests.sln: This is the base test solution for Xamarin.iOS, which targets iOS using the Unified API. Not generated.
  • tests-tvos.sln: All the TVOS test projects. Generated.
  • tests-watchos.sln: All the WatchOS test projects. Generated.
  • tests-mac.sln: This is the base test solution for Xamarin.Mac. Not generated.

Test solution/project generation

The tool that generates the test solutions / projects is called xharness, and lives in the xharness subdirectory.

Types of Tests

Unit Tests

Most of the projects are using NUnit[Lite] and looks like unit tests. They are meant to be executed on the target: simulator, devices, OSX.

In reality most of them are regression tests - but that does not change the need to execute and continually expand them to cover new code.

Introspection Tests

Introspection tests are executed on target (both simulator and device for iOS) or a specific version of OSX. The application proceed to analyze itself using:

  • System.Reflection for managed code; and
  • the ObjectiveC runtime library for native code

and compare the results. E.g. if using .NET reflection it can see a binding for a NSBundle type then it should be able to find a native NSBundle type using the ObjC runtime functions. Otherwise an error is raised...

Since the application analyze itself it must contains everything we wish to test. That's why the introspection tests are part of the dontlink.app application (for iOS) and the dontlink-mac project (for OSX).

Pros

  • They always tell the truth, which can differ from documentation

Cons

  • Incomplete - Not everything is encoded in the metadata / executable;
  • Too complete - Not every truth is good to be known (or published)

Extrospection Tests

Extrospection tests takes data from some outside sources and see if our implementation match the information, e.g.

  • Header files from the SDK;
  • Rules, like Gendarme or FxCop;

Since this is done externally there's no need to run them on the devices, simulator or even a specific version of OSX.

Pro

  • There is more data available, e.g. information lost when compiling

Con

  • The data might not represent the truth (errors, false positives...)

Xamarin.Mac

Many tests when run for macOS use a integration hack which helps handle a number of issues:

  • Allowing command line arguments to tests while excluding "psn" arguments passed in while debugging with Visual Studio for Mac
  • Invoking _exit to work around a number of post-test hangs. See the bug for details.

One very useful "hack" this support adds is the ability to run a single test from the command line via the XM_TEST_NAME environmental variable. For example

XM_TEST_NAME=MonoTouchFixtures.Security.KeyTest.CreateRandomKeyWithParametersTests make run-mac-unified-xammac_tests

Test Suites

*-tests : where * is the assembly name, e.g. monotouch

Use the project defaults for linking, i.e.

  • "Don't link" for simulator

  • "Link SDK assemblies only" for devices

  • regression testing without using the linker

  • both simulator and devices are set to "Don't link"

linkall

  • regression testing using the linker on the all assemblies

  • "Link all assemblies" for both simulator/devices

linksdk

  • regression testing using the linker on the SDK assemblies

  • "Link SDK assemblies only" for both simulator/devices

Common make targets

Run every test in both the simulator and on device, using both the compat and the new profile (for the simulator both in 32 and 64bit mode).

$ make run

Run every test in the simulator, using both the compat and the new profile (both 32 and 64bit simulators).

$ make run-all-sim

Run every test on device, using both the compat and the new profile

$ make run-all-dev

Detailed make targets

  • Main target

    • run-what-where-project: Builds, installs (if applicable) and runs the specified test project on the specified platform. This is the most common target to use.
    • build-what-where-project: Will build the specified test project for the specified platform and target.
    • install-what-where-project: Will install the specified test project on a connected device. There's currently no way to select the device, so ensure you've only one connected (if many devices are connected, it's random which will used).
    • exec-what-where-project: Will run the specified test project in the simulator or on a device.
  • What

    • -ios-: iOS.
    • -tvos-: TVOS.
    • -watchos-: WatchOS

    If "What" is skipped, all variations are executed sequentially.

  • Where

    • -simclassic-: Simulator using the Classic API. Only applicable when platform is iOS.
    • -simunified-: Simulator using Unified API. The build will contain both an i386 and an x86_64 binary. Only applicable to the build-* target, while the -sim32- and -sim64- are only applicable to the exec-* targets. Only applicable when the platform is iOS.
    • -sim32-: 32bits iOS simulator using the Unified API. Not applicable to other platforms.
    • -sim64-: 64bits iOS simulator using the Unified API. Not applicable to other platforms.
    • -sim-:
      • iOS: Both the -simclassic- and -simunified- versions.
      • WatchOS/TVOS: The WatchOS/TVOS simulator.
    • -devclassic-: Device using the Classic API. Only applicable when the platform is iOS.
    • -devunified-: Device using the Unified API. The build will contain both an armv7 and an arm64 binary. It's not possible to select a 32/64bit version, you'll run what your device supports. Only applicable when the platform is iOS.
    • -dev-:
      • iOS: Both the -devclassic- and -devunified- versions.
      • WatchOS/TVOS: A Watch or TV device.
  • Examples

    $ make run-ios-sim32-monotouchtest: This will run monotouch-test using the Unified API in a 32-bit simulator. $ make run-tvos-dev-dont\ link: This will run dont link on an Apple TV device.

Utility run-* targets

These targets will build, install (if applicable) and run the specified project(s).

  • Simulator

    • run-sim-project: Builds and runs the specified test project in the simulator in compat, 32 and 64bit mode.
    • run-sim: Builds and runs all the test projects in the simulator in compat, 32 and 64bit mode.
  • Device

    • run-dev-project: Builds and runs the specified test project on a device in compat and native mode (if it's 32 and 64bit depends on the device; 64bit devices will run in 64bit mode and the same for 32bit devices).
    • run-devcompat: Run all the test projects on device, in compat mode.
    • run-devdual: Run all the test projects on device, in native mode (if it's 32 and 64bit depends on the device; 64bit devices will run in 64bit mode and the same for 32bit devices).
    • run-dev: Run all the test projects on device, in both compat and native mode.