[bazel] Add android_gm_test macro.
This CL defines the android_gm_test macro, which can be used to run GMs on an Android device and download any PNG and JSON files produced by the GMs to the machine where Bazel is invoked.
Like the android_unit_test macro, android_gm_test delegates to the "base" android_test macro. This CL adds a new boolean save_output_files argument to android_test. When set to True, android_test will download any files produced by the C++ binary running on the device, and will make them available on the machine where Bazel was invoked as undeclared test outputs (via the TEST_UNDECLARED_OUTPUTS_DIR mechanism, see https://bazel.build/reference/test-encyclopedia#initial-conditions).
This CL also adds some android_gm_test targets in //gm/BUILD.bazel. Sample invocation:
$ bazel test --config=linux_rbe //gm:cpu_android_test --config=pixel_5
To inspect the PNG and JSON files produced by the test:
$ unzip -l bazel-testlogs/gm/cpu_android_test/test.outputs/outputs.zip
How this works:
1. adb_test_runner.go now takes a new, optional --output-dir flag, which specifies the directory in the host system (that is, the machine running Bazel) where to download from the device any files produced by the test.
2. When --output-dir is set, adb_test_runner.go creates a directory on the device where the test should store any output files. This directory is communicated by the test via the ADB_TEST_OUTPUT_DIR environment variable.
3. When the test on the device finishes running, adb_test_runner.go uses "adb pull" to copy the contents of ADB_TEST_OUTPUT_DIR into the --output-dir.
4. The adb_test Bazel rule, which delegates to adb_test_runner.go, now takes an optional save_output_files boolean attribute. When set to True, adb_test will invoke adb_test_runner.go with --output-dir set to $TEST_UNDECLARED_OUTPUTS_DIR.
5. The android_test Bazel macro, which delegates to the adb_test rule, now takes a save_output_files boolean attribute which is passed directly to adb_test.
6. The android_gm_test Bazel macro delegates to android_test, and sets the extra_args argument so that the C++ binary is invoked with the --outputDir flag (defined in //gm/BazelGMRunner.cpp) set to $ADB_TEST_OUTPUT_DIR.
7. To recap, the C++ binary on device saves any PNG and JSON files produced by GMs in $ADB_TEST_OUTPUT_DIR on the device, and adb_test_runner.go downloads the contents of that directory into $TEST_UNDECLARED_OUTPUTS_DIR on the machine where Bazel is running. The downloaded files will then be available to the user as a ZIP file inside the //bazel-testlogs directory (see example above).
How we can run Bazel-built Android GMs on CI: We can use the same mechanism as with Bazel-built Android unit tests. That is, one task to compile them on RBE, and a separate task to run the compiled artifact on a phone attached to a Raspberry Pi. The difference is that the task driver running on the RPi will have to set the TEST_UNDECLARED_OUTPUTS_DIR environment variable before executing the runner script produced by Bazel, and that it will have to upload the PNGs to Gold. We can do this with goldctl, but it will require some changes. Specifically, goldctl's image hashing logic is different from that of BazelGMRunner.cpp (and DM.cpp, both of which delegate to HashAndEncode.cpp); therefore we need to add support to goldctl for specifying an externally computed MD5 hash.
Other changes:
- //gm/BazelGMRunner.cpp no longer uses std::filesystem because it's not supported by the hermetic NDK C++ toolchain, and uses SkOSPath instead.
- Small syntactic changes on various C++ files to appease the hermetic NDK C++ toolchain.
Recommended review order:
- //bazel/adb_test_runner/adb_test_runner.go
- //bazel/adb_test.bzl
- //bazel/android_test.bzl
- //gm/android_gm_test.bzl
- //tests/android_unit_test.bzl
- //gm/BUILD.bazel
- Everything else
Bug: skia:14227
Change-Id: I881c8838c78f9110dc78177397298c3a6e99b800
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/718236
Reviewed-by: Kevin Lubick <kjlubick@google.com>
Commit-Queue: Leandro Lovisolo <lovisolo@google.com>
12 files changed