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

tests/android: Use adb reverse to access host webserver, allow running on !macos #66

Merged
merged 1 commit into from
Mar 4, 2023

Conversation

MarijnS95
Copy link
Contributor

Instead of chaining a bunch of Unix commands to pry out the IP address of a random adapter, that may not be available on every distro, use the standard adb reverse command to forward a specific port from the Android phone (or emulator) to the host, where the test-webserver is running. This makes the test-script host-independent (should in theory run even on Windows now) and does not require the device at test (which could be a regular Android phone if not having an emulator running) to be connected to / reachable over the same network.

…ing on !macos

Instead of chaining a bunch of Unix commands to pry out the IP address
of a random adapter, that may not be available on every distro, use the
standard `adb reverse` command to forward a specific port from the
Android phone (or emulator) to the host, where the test-webserver is
running.  This makes the test-script host-independent (should in theory
run even on Windows now) and does not require the device at test (which
could be a regular Android phone if not having an emulator running) to
be connected to / reachable over the same network.
@MarijnS95
Copy link
Contributor Author

MarijnS95 commented Mar 2, 2023

Note that we could have also emitted this setup into the app's Cargo.toml like:

[package.metadata.android.reverse_port_forward]
"tcp:{}" = "tcp:{}"

As cargo-apk has native support for it, but calling the command ourselves is just as straightforward.

Note²: we could also use tcp:0 to let adb figure out a free port on the phone side, and route that to the webserver port (which need not necessarily be the same: that's why the tcp:{} argument is passed twice to adb reverse), see also the documentation:

 reverse [--no-rebind] REMOTE LOCAL
     reverse socket connection using:
       tcp:<port> (<remote> may be "tcp:0" to pick any open port)

@amodm
Copy link
Owner

amodm commented Mar 4, 2023

As part of this, let's also then make ubuntu-latest as the default runner for android tests then, instead of macos-latest, as the latter runner is slightly slower (more contention probably) than the linux one.

You can make the change, or I can do it, assuming I have permissions to push on your branch.

@MarijnS95
Copy link
Contributor Author

MarijnS95 commented Mar 4, 2023

@amodm long ago it was pointed out that only MacOS GitHub runners supported hardware acceleration for the Android emulator, and not their Ubuntu machines for some (obscure, iirc) reason. Not sure if that's still the case, but I'd recommend doing it in a separate documented PR and comparing the timings with previous runs to be sure.

amodm added a commit that referenced this pull request Mar 4, 2023
@amodm amodm merged commit 756a609 into amodm:main Mar 4, 2023
@amodm
Copy link
Owner

amodm commented Mar 4, 2023

Yeah, you're right. A quick search doesn't seem to show up HAXM support on Linux. We'll continue to keep the runner on macos-latest for now.

@MarijnS95 MarijnS95 deleted the android-adb-reverse branch March 4, 2023 17:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants