0

[Fuchsia] Generate <test_target_name> Wrapper in Output Directory

Allow fuchsia_test_runner template to create an executable wrapper with
same name as test target itself.

When building a test target, in addition to the test component
<test_target_name>_component, three wrapper scripts are created:
1. deploy_<test_target_name>, for deploying the Fuchsia package onto a
   device
2. run_<test_target_name>, for running the Fuchsia package on the device
3. <test_target_name>, for running the Fuchsia package on the device
The first two executables will be found in ${OUTPUT_DIR}/bin whereas
%package% will be found directly in the output directory.

This change also allows ninja to identify which test target to build
in the case of duplicate target names (e.g. unit_tests) since ninja
prioritizes executable targets.

Bug: 1268956
Change-Id: I582ab0d22a1b19b0e8df1bb96e0c8d207b021a2c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3296401
Auto-Submit: Chong Gu <chonggu@google.com>
Reviewed-by: David Dorwin <ddorwin@chromium.org>
Commit-Queue: Chong Gu <chonggu@google.com>
Cr-Commit-Position: refs/heads/main@{#950169}
This commit is contained in:
Chong Gu
2021-12-09 18:16:49 +00:00
committed by Chromium LUCI CQ
parent a2c06811b1
commit bb94e0f01e
3 changed files with 40 additions and 29 deletions

@ -151,6 +151,17 @@ template("fuchsia_run_script_with_packages") {
]
}
}
# Create a wrapper script rather than using a group() in order to ensure
# "ninja $target_name" always works.
if (defined(invoker.executable_wrapper)) {
generate_wrapper(invoker.executable_wrapper) {
forward_variables_from(invoker, TESTONLY_AND_VISIBILITY)
executable = _generated_script_path
wrapper_script = "$root_build_dir/${invoker.executable_wrapper}"
deps = [ ":${invoker._run_target}" ]
}
}
}
# Generates a script which deploys a package to the TUF repo of a Fuchsia
@ -203,6 +214,7 @@ template("fuchsia_test_runner") {
executable_args = []
}
output_name_format = "run_%package%"
executable_wrapper = invoker.target_name
# Populate the arguments used by the test runner, defined at build-time.
executable_args += [
@ -251,14 +263,6 @@ template("fuchsia_test_runner") {
testonly = invoker.testonly
include_fuchsia_build_dir = true
}
group(target_name) {
forward_variables_from(invoker, TESTONLY_AND_VISIBILITY)
deps = [
":${_install_target}",
":${_run_target}",
]
}
}
# Transitional target that aliases "fuchsia_package_runner" to an installer

@ -268,13 +268,11 @@ that make working with both Fuchsia and Chromium checkouts easier.
* `default_fuchsia_build_dir_for_installation`. Point this to an output
directory in Fuchsia. For instance. `/path/to/src/fuchsia/out/qemu-x64`. This
will automatically add the `--fuchsia-out-dir` flag to most `run_*` and
`deploy_*` scripts.
will automatically add the `--fuchsia-out-dir` flag to wrapper scripts.
* `default_fuchsia_device_node_name`. Set this to a Fuchsia device node name.
This will automatically add the `--node-name` flag to most `run_*` and
`deploy_*` scripts.
* Finally, use the `-d` flag to `run_*` scripts to execute them on an already
running device or emulator, rather than starting an ephemeral emulator
instance. This speeds up subsequent runs since the runner script does not need
to wait for the emulator instance to boot and only differential changes are
pushed to the device.
This will automatically add the `--node-name` flag to most wrapper scripts.
* Finally, use the `-d` flag when running the <test_target_name> wrappers to
execute them on an already running device or emulator, rather than starting an
ephemeral emulator instance. This speeds up subsequent runs since the runner
script does not need to wait for the emulator instance to boot and only
differential changes are pushed to the device.

@ -1,10 +1,19 @@
# Deploying and running gtests on Fuchsia.
Fuchsia gtest binaries are deployed and executed via scripts that are
automatically generated by the `test()` GN target.
The binaries can deploy to either emulators started by the runner script,
an existing emulator instance, or a physical device. To build a gtest binary,
check this [documentation](build_instructions.md).
automatically generated by the `test()` GN target. For each test, three wrapper
scripts are created:
1. deploy_<test_target_name>, for deploying the Fuchsia package onto a device
2. run_<test_target_name>, for running the Fuchsia package on the device
3. <test_target_name>, for running the Fuchsia package on the device
The first two executables are found in ${OUTPUT_DIR}/bin whereas the last one
will be found directly in the output directory.
The aforementioned devices can be either emulators started by the scripts
themselves, an existing emulator instance, or a physical device. To build a
gtest binary, check this [documentation](build_instructions.md).
For the sake of this example, we will be using `base_unittests` as the package
we wish to install and/or execute.
@ -14,7 +23,7 @@ we wish to install and/or execute.
The test script brings up an emulator, runs the tests on it, and
shuts the emulator down when finished.
```bash
$ out/fuchsia/bin/run_base_unittests
$ out/fuchsia/base_unittests
```
The flag `--custom-image` can be used to specify the Fuchsia boot image used
@ -27,7 +36,7 @@ workstation image.
Note the `-d` flag, which is an alias for `--device`.
```bash
$ out/fuchsia/bin/run_base_unittests -d
$ out/fuchsia/base_unittests -d
```
## Run on a device paved with Fuchsia built from source
@ -36,7 +45,7 @@ Make sure that the CPU architecture of your Chromium output directory matches
the architecture of the Fuchsia output directory (x64==x64, arm64==arm64, etc.).
```bash
$ out/fuchsia/bin/run_base_unittests -d
$ out/fuchsia/base_unittests -d
--fuchsia-out-dir=/path/to/fuchsia/outdir
```
@ -48,17 +57,17 @@ default_fuchsia_build_dir_for_installation = "/path/to/fuchsia/outdir"
```
With this flag in place, the `--fuchsia-out-dir` flag will automatically be
used whenever you `run_` or `install_` Fuchsia packages, making your command
lines much shorter:
used whenever you use the wrapper scripts to run or deploy Fuchsia packages,
making your command lines much shorter:
```bash
$ out/fuchsia/bin/run_base_unittests -d
$ out/fuchsia/base_unittests -d
```
## Install on a device running Fuchsia built from source
```bash
$ out/fuchsia/bin/install_base_unittests
$ out/fuchsia/bin/deploy_base_unittests
--fuchsia-out-dir=/path/to/fuchsia/outdir
```
@ -75,7 +84,7 @@ Note the `--ssh-config` flag, which should point to the config file used to set
up the connection between the host and the remote device.
```bash
$ out/fuchsia/bin/run_base_unittests -d
$ out/fuchsia/base_unittests -d
--host=localhost --ssh-config=/path/to/ssh/config
```