Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support passing environment variables to iOS apps launched by xharness, and support separate install, run-test, and uninstall subcommands #493

Closed
imhameed opened this issue Mar 3, 2021 · 8 comments
Assignees
Labels
apple iOS/tvOS/WatchOS/Mac Catalyst area enhancement New feature or request

Comments

@imhameed
Copy link

imhameed commented Mar 3, 2021

I'm working on getting CoreCLR's runtime tests working with Mono on iOS devices. In dotnet/runtime#43954, I'm bundling multiple runtime test assemblies (with one entry point each) together into a single iOS app bundle, similar to what we currently do on Android. I'm passing the entry point assembly to run through an environment variable (unlike Android, which uses a command line argument): https://github.com/dotnet/runtime/pull/43954/files#diff-6cef647106df3b37e45599e150f97a7dc3678f2606723b1967dbda7d1f0a42b9R268-R273

I've verified that doing this works locally when launching runtime test assemblies (via their containing iOS app bundle) via mlaunch. To make this run for real on CI I'll need to do this with xharness.

xharness doesn't appear to have a way to add passthrough environment variables, although it does appear to support mlaunch's --setenv option internally:
https://github.com/dotnet/xharness/blob/main/src/Microsoft.DotNet.XHarness.iOS.Shared/Execution/Arguments.cs#L199-L222

There was also a request in #397 to add separate install, run-test, and uninstall commands to xharness for Android. That will also be necessary for iOS, because a single iOS runtime test app bundle will contain multiple entry points.

@premun
Copy link
Member

premun commented Mar 4, 2021

@imhameed sure, this should be a piece of cake!

I have some questions:

  1. Are env variables fine or do you need to pass arguments to the app directly as well (we support this already but not sure it works on the mlaunch side)?
  2. For the run-test, install/uninstall flows, I can follow the flow from Android?
  3. I know that for Simulators there's no install/uninstall, we just run the app so we won't need to get the device ID but I need to look into whether we can just run the app without having to have to copy it there repeatedly. I imagine we might keep the same flow for device/Simulator though so that it's not confusing where in/uninstall will be a no-op

@premun premun added enhancement New feature or request apple iOS/tvOS/WatchOS/Mac Catalyst area labels Mar 4, 2021
@premun premun self-assigned this Mar 4, 2021
@premun
Copy link
Member

premun commented Mar 4, 2021

@imhameed can you also please provide me with a test application and some instructions on how you would like to run the tests using it so that I have a good picture of things should work?

@imhameed
Copy link
Author

imhameed commented Mar 4, 2021

@imhameed sure, this should be a piece of cake!

Great!

I have some questions:

  1. Are env variables fine or do you need to pass arguments to the app directly as well (we support this already but not sure it works on the mlaunch side)?

  2. For the run-test, install/uninstall flows, I can follow the flow from Android?

  3. I know that for Simulators there's no install/uninstall, we just run the app so we won't need to get the device ID but I need to look into whether we can just run the app without having to have to copy it there repeatedly. I imagine we might keep the same flow for device/Simulator though so that it's not confusing where in/uninstall will be a no-op

  1. I don't need to pass arguments to the app right now. And I think mlaunch does support this.
  2. Yes.
  3. Sounds fine; the goal is to avoid burning time on redundant data transfer/install/verification work.

@imhameed can you also please provide me with a test application and some instructions on how you would like to run the tests using it so that I have a good picture of things should work?

Sure. I don't have one handy right now but I'll send you something shortly.

@premun
Copy link
Member

premun commented Mar 5, 2021

@imhameed I opened a pull request (#496) for the first part where we also set the environmental variables.
(please note that these were passed as regular arguments already before)

premun added a commit that referenced this issue Mar 19, 2021
The extra arguments added after the `--` verbatim string are now also passed as environmental variables:
```
xharness apple test -a=some.app -o=o -t=ios-simulator-64 --set-env=bar=xyz -- --foo=bar
```
ends up as (mlaunch output):
```
Launching net.dot.System.Numerics.Vectors.Tests async on 'iOS 14.2 (18B79) - iPhone X' with: {
    arguments =     (
        "--foo=bar",
        foo3
    );
    environment =     {
        NSUnbufferedIO = YES;
        "NUNIT_AUTOEXIT" = true;
        "NUNIT_ENABLE_XML_OUTPUT" = true;
        "NUNIT_HOSTNAME" = "127.0.0.1";
        "NUNIT_HOSTPORT" = 53423;
        "NUNIT_XML_VERSION" = xUnit;
        "OS_ACTIVITY_DT_MODE" = YES;
        bar = xyz;
    };
}
```

Same for `apple run` and for MacCatalyst apps.

Related to #493
@premun
Copy link
Member

premun commented Mar 26, 2021

Variables are not passed (#521 (comment))

@premun
Copy link
Member

premun commented Apr 13, 2021

Blocked, waiting for new mlaunch

premun added a commit that referenced this issue Apr 15, 2021
In order to introduce the new `install` / `run-test` / `uninstall` commands (#493), we need to separate installation from running the app which is currently happening via 1 mlaunch command for Simulators.

We unify the approach for Simulators and devices and do the install separately. This will also help with diagnosis of issues when simulators freeze and we don't know at which stage.

The code was refactored out of the `Command` classes into the `Orchestrator` classes so that it can be tested later too.
We can also now test passing args to the `Commands` and how they get parsed.
premun added a commit that referenced this issue Apr 20, 2021
Adds new commands that only spawn the application and skip installation/uninstallation (#493)
@premun
Copy link
Member

premun commented Apr 20, 2021

@imhameed you can use XHarness 1.0.0-prerelease.21220.1 and newer to control how the app is installed used and uninstalled.

I noticed one thing using the app you've sent me - the app should run the test and quit so that things work well.

The commands that you want to use:

xharness apple install ...
xharness apple just-run ...
xharness apple just-run ...
xharness apple just-run ...
xharness apple uninstall ...

This will be faster as it won't reinstall the app at each run. This will then immensely speed up scenarios with real devices where these operations take more time.

Please note that uninstall accepts the the app arg too but it should be the bundle id rather than path to the app package.

@premun
Copy link
Member

premun commented Apr 20, 2021

Closing as it is now implemented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
apple iOS/tvOS/WatchOS/Mac Catalyst area enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants