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

gh-116622: Add Android test script #121595

Merged
merged 40 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
103f97e
Update to Android Gradle plugin version 8.4.2
mhsmith Jul 10, 2024
fb1b54a
Separate Python test runner from MainActivity so it can be run from a…
mhsmith Jul 10, 2024
b99b769
Add `android.py test` command
mhsmith Jul 10, 2024
6f07a39
--connected mode working
mhsmith Jul 23, 2024
c71f3cf
--managed mode working, and add instructions to README
mhsmith Jul 23, 2024
cd27b0f
Clarifications
mhsmith Jul 23, 2024
6bbdfda
Restore build command logging, and only require adb when running tests
mhsmith Jul 23, 2024
e738689
Make testbed include only those ABIs which have been built
mhsmith Jul 30, 2024
4561930
Merge branch 'android-2024-07' into android-test-script
mhsmith Jul 30, 2024
b519874
Fix Windows issues
mhsmith Jul 31, 2024
b3ed4c7
Merge branch 'main' into android-test-script
mhsmith Aug 5, 2024
32f79d7
Clarify documentation; remove default `python -m test` arguments
mhsmith Aug 8, 2024
6471512
Link to page about test options; add newlines at end of files
mhsmith Aug 8, 2024
5c3967e
Add `android.py build-testbed` command
mhsmith Aug 8, 2024
cb60cc4
If test script fails before logcat starts, show the Gradle output eve…
mhsmith Aug 11, 2024
b075842
Fix logcat error messages being hidden
mhsmith Aug 11, 2024
2266e82
Improve logging, add timeouts
mhsmith Aug 11, 2024
397d20b
Make the app use the same NDK version as the Python build
mhsmith Aug 11, 2024
8e80dd2
Install platform-tools automatically
mhsmith Aug 11, 2024
709061e
In --connected mode, uninstall app before running Gradle
mhsmith Aug 12, 2024
756bc13
Handle adb logcat returning failure when device disconnects
mhsmith Aug 12, 2024
6b2ed6c
Filter logs by PID rather than UID
mhsmith Aug 12, 2024
05a26cc
Try to terminate subprocesses with SIGTERM before sending SIGKILL
mhsmith Aug 12, 2024
a0dd03b
Handle SIGTERM the same way as SIGINT
mhsmith Aug 12, 2024
2d53549
Fix race condition with pre-run uninstall
mhsmith Aug 12, 2024
c9d5bf5
Fix race condition in a more efficient way
mhsmith Aug 12, 2024
706a1da
Make testbed pick up edits to pure-Python files in the Lib directory
mhsmith Aug 12, 2024
ae3a460
Merge branch 'main' into android-test-script
mhsmith Aug 12, 2024
cf15b99
Remove `boot_completed`, which is unnecessary since we're no longer r…
mhsmith Aug 13, 2024
c56373a
Automatically accept SDK licenses, and log Gradle package installatio…
mhsmith Aug 13, 2024
1e89e58
Stop Gradle test tasks being skipped as up to date
mhsmith Aug 13, 2024
91f356b
Fix CalledProcessError formatting
mhsmith Aug 13, 2024
bdaad24
Add note about testing on Windows
mhsmith Aug 13, 2024
ca2bae2
Implement `fileno` method on stdout and stderr
mhsmith Aug 13, 2024
7a3d674
Correct comment
mhsmith Aug 13, 2024
f4b06f5
Merge branch 'main' into android-test-script
freakboy3742 Aug 13, 2024
47c02a5
Merge branch 'main' into android-test-script
mhsmith Aug 15, 2024
602fbdd
Add note about RAM requirements
mhsmith Aug 15, 2024
305d786
Handle transient failure of pidof
mhsmith Aug 15, 2024
2ad8e4b
Merge branch 'main' into android-test-script
freakboy3742 Aug 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 52 additions & 16 deletions Android/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ you don't already have the SDK, here's how to install it:
The `android.py` script also requires the following commands to be on the `PATH`:

* `curl`
* `java`
* `java` (or set the `JAVA_HOME` environment variable)
* `tar`
* `unzip`

Expand Down Expand Up @@ -80,18 +80,54 @@ call. For example, if you want a pydebug build that also caches the results from

## Testing

To run the Python test suite on Android:

* Install Android Studio, if you don't already have it.
* Follow the instructions in the previous section to build all supported
architectures.
* Run `./android.py setup-testbed` to download the Gradle wrapper.
* Open the `testbed` directory in Android Studio.
* In the *Device Manager* dock, connect a device or start an emulator.
Then select it from the drop-down list in the toolbar.
* Click the "Run" button in the toolbar.
* The testbed app displays nothing on screen while running. To see its output,
open the [Logcat window](https://developer.android.com/studio/debug/logcat).

To run specific tests, or pass any other arguments to the test suite, edit the
command line in testbed/app/src/main/python/main.py.
The tests can be run on Linux, macOS, or Windows, although on Windows you'll
have to build the `cross-build/HOST` subdirectory on one of the other platforms
and copy it over.

The test suite can usually be run on a device with 2 GB of RAM, though for some
configurations or test orders you may need to increase this. As of Android
Studio Koala, 2 GB is the default for all emulators, although the user interface
may indicate otherwise. The effective setting is `hw.ramSize` in
~/.android/avd/*.avd/hardware-qemu.ini, whereas Android Studio displays the
value from config.ini. Changing the value in Android Studio will update both of
these files.

Before running the test suite, follow the instructions in the previous section
to build the architecture you want to test. Then run the test script in one of
the following modes:

* In `--connected` mode, it runs on a device or emulator you have already
connected to the build machine. List the available devices with
`$ANDROID_HOME/platform-tools/adb devices -l`, then pass a device ID to the
script like this:

```sh
./android.py test --connected emulator-5554
freakboy3742 marked this conversation as resolved.
Show resolved Hide resolved
```

* In `--managed` mode, it uses a temporary headless emulator defined in the
`managedDevices` section of testbed/app/build.gradle.kts. This mode is slower,
but more reproducible.

We currently define two devices: `minVersion` and `maxVersion`, corresponding
to our minimum and maximum supported Android versions. For example:

```sh
./android.py test --managed maxVersion
```

By default, the only messages the script will show are Python's own stdout and
stderr. Add the `-v` option to also show Gradle output, and non-Python logcat
messages.
freakboy3742 marked this conversation as resolved.
Show resolved Hide resolved

Any other arguments on the `android.py test` command line will be passed through
to `python -m test` – use `--` to separate them from android.py's own options.
See the [Python Developer's
Guide](https://devguide.python.org/testing/run-write-tests/) for common options
– most of them will work on Android, except for those that involve subprocesses,
such as `-j`.
freakboy3742 marked this conversation as resolved.
Show resolved Hide resolved

Every time you run `android.py test`, changes in pure-Python files in the
repository's `Lib` directory will be picked up immediately. Changes in C files,
and architecture-specific files such as sysconfigdata, will not take effect
until you re-run `android.py make-host` or `build`.
2 changes: 1 addition & 1 deletion Android/android-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ ndk_version=26.2.11394342

ndk=$ANDROID_HOME/ndk/$ndk_version
if ! [ -e $ndk ]; then
log "Installing NDK: this may take several minutes"
log "Installing NDK - this may take several minutes"
yes | $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager "ndk;$ndk_version"
fi

Expand Down
Loading
Loading