[fuchsia] Add script for Fuchsia integration tests (flutter/engine#35933)
Tested: `run_integration_tests.sh embedder`
This commit is contained in:
@@ -1,84 +1,47 @@
|
||||
# `flutter integration tests`
|
||||
# Flutter runner integration tests
|
||||
|
||||
## Configure and build fuchsia
|
||||
To run the Flutter runner integration tests locally,
|
||||
first start a Fuchsia package server:
|
||||
|
||||
```shell
|
||||
$ cd "$FUCHSIA_DIR"
|
||||
$ fx set terminal.x64
|
||||
$ fx build
|
||||
$ fx serve
|
||||
```
|
||||
|
||||
## Build the test
|
||||
|
||||
You can specify the test's package target to build only the test package, with
|
||||
its dependencies. This will also build the required runner.
|
||||
Then run the integration test:
|
||||
|
||||
```shell
|
||||
$ cd "$ENGINE_DIR/src"
|
||||
$ ./flutter/tools/gn --fuchsia <flags> \
|
||||
# for example: --goma --fuchsia-cpu=x64 --runtime-mode=debug
|
||||
$ ninja -C out/fuchsia_debug_x64 \
|
||||
flutter/shell/platform/fuchsia/flutter/tests/integration
|
||||
$ ENGINE_DIR/flutter/tools/fuchsia/devshell/run_integration_test.sh <integration_test_folder_name> --no-lto
|
||||
```
|
||||
|
||||
|
||||
## Start an emulator
|
||||
For example, to run the `embedder` integration test:
|
||||
|
||||
```shell
|
||||
ffx emu start --net tap
|
||||
$ ENGINE_DIR/flutter/tools/fuchsia/devshell/run_integration_test.sh embedder --no-lto
|
||||
```
|
||||
|
||||
NOTE: Do _not_ run the default package server. The instructions below describe
|
||||
how to launch a flutter-specific package server.
|
||||
Command-line options:
|
||||
|
||||
## Publish the test packages to the Fuchsia package server
|
||||
* Pass `--unoptimized` to disable C++ compiler optimizations.
|
||||
* Add `--fuchsia-cpu x64` or `--fuchsia-cpu arm64` to target a particular architecture.
|
||||
The default is x64.
|
||||
* Add `--runtime-mode debug` or `--runtime-mode profile` to switch between JIT and AOT
|
||||
builds. These correspond to a vanilla Fuchsia build and a `--release` Fuchsia build
|
||||
respectively. The default is debug/JIT builds.
|
||||
* For Googlers, add the `--goma` argument when using goma, and add the `--xcode-symlinks`
|
||||
argument when using goma on macOS.
|
||||
* Remove `--no-lto` if you care about performance or binary size; unfortunately it results
|
||||
in a *much* slower build.
|
||||
|
||||
The tests currently specify the Fuchsia package server's standard domain,
|
||||
`fuchsia.com`, as the server to use to resolve (locate and load) the test
|
||||
packages. So, before running the test, the most recently built `.far` files
|
||||
need to be published to the Fuchsia package repo:
|
||||
## Iterating on tests
|
||||
|
||||
By default, `run_integration_test.sh` will build Fuchsia and start up a Fuchsia emulator
|
||||
to ensure that the test runs on the correct environment.
|
||||
|
||||
However, this is slow for iterating on tests. Once you've run `run_integration_tests.sh`
|
||||
once, you don't need to build Fuchsia or start the emulator anymore, and can pass
|
||||
`--skip-fuchsia-build` and `--skip-fuchsia-emu` to skip those steps.
|
||||
|
||||
```shell
|
||||
$ fx pm publish -a -repo "$(cat $FUCHSIA_DIR/.fx-build-dir)/amber-files/" \
|
||||
-f "$FLUTTER_ENGINE_DIR"/src/out/fuchsia_*64/oot_flutter_jit_runner-0.far
|
||||
$ fx pm publish -a -repo "$(cat $FUCHSIA_DIR/.fx-build-dir)/amber-files/" \
|
||||
-f "$FLUTTER_ENGINE_DIR"/src/out/fuchsia_*64/flutter-embedder-test-0.far
|
||||
$ fx pm publish -a -repo "$(cat $FUCHSIA_DIR/.fx-build-dir)/amber-files/" \
|
||||
-f $(find "$FLUTTER_ENGINE_DIR"/src/out/fuchsia_*64 -name parent-view.far)
|
||||
$ fx pm publish -a -repo "$(cat $FUCHSIA_DIR/.fx-build-dir)/amber-files/" \
|
||||
-f $(find "$FLUTTER_ENGINE_DIR"/src/out/fuchsia_*64 -name child-view.far)
|
||||
$ ENGINE_DIR/flutter/tools/fuchsia/devshell/run_integration_test.sh embedder --no-lto --skip-fuchsia-build --skip-fuchsia-emu
|
||||
```
|
||||
|
||||
## Run the test
|
||||
|
||||
```shell
|
||||
$ ffx test run fuchsia-pkg:://fuchsia.com/flutter-embedder-test#meta/flutter-embedder-test.cm
|
||||
```
|
||||
|
||||
If, for example, you only make a change to the Dart code in `parent-view`, you
|
||||
can rebuild only the parent-view package target, and republish it.
|
||||
|
||||
```shell
|
||||
$ ninja -C out/fuchsia_debug_x64 \
|
||||
flutter/shell/platform/fuchsia/flutter/tests/integration/embedder/parent-view:package
|
||||
$ fx pm publish -a -repo "$(cat $FUCHSIA_DIR/.fx-build-dir)/amber-files/" \
|
||||
-f $(find "$FLUTTER_ENGINE_DIR"/src/out/fuchsia_*64 -name parent-view.far)
|
||||
```
|
||||
|
||||
Then re-run the test as above.
|
||||
|
||||
The tests use a flutter runner with "oot_" prefixed to its package name, to
|
||||
avoid conflicting with any flutter_runner package in the base fuchsia image.
|
||||
After making a change to the flutter_runner you can re-deploy it with:
|
||||
|
||||
```shell
|
||||
$ ninja -C out/fuchsia_debug_x64 \
|
||||
flutter/shell/platform/fuchsia/flutter:oot_flutter_jit_runner
|
||||
$ fx pm publish -a -repo "$(cat $FUCHSIA_DIR/.fx-build-dir)/amber-files/" \
|
||||
-f $(find "$FLUTTER_ENGINE_DIR"/src/out/fuchsia_*64 -name oot_flutter_jit_runner.far)
|
||||
```
|
||||
|
||||
Then re-run the test as above.
|
||||
|
||||
From here, you can modify the Flutter test, rebuild flutter, and usually rerun
|
||||
the test without rebooting, by repeating the commands above.
|
||||
|
||||
188
engine/src/flutter/tools/fuchsia/devshell/run_integration_test.sh
Executable file
188
engine/src/flutter/tools/fuchsia/devshell/run_integration_test.sh
Executable file
@@ -0,0 +1,188 @@
|
||||
#!/bin/bash
|
||||
# Copyright 2013 The Flutter Authors. All rights reserved.
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
|
||||
### Runs a Fuchsia integration test from shell/platform/fuchsia/flutter/tests/integration.
|
||||
###
|
||||
### Usage:
|
||||
### $ENGINE_DIR/flutter/tools/fuchsia/devshell/run_integration_test <integration_test_folder_name>
|
||||
###
|
||||
### Arguments:
|
||||
### --skip-fuchsia-build: Skips configuring and building Fuchsia for the test.
|
||||
### --skip-fuchsia-emu: Skips starting the Fuchsia emulator for the test.
|
||||
### --runtime-mode: The runtime mode to build Flutter in.
|
||||
### Valid values: [debug, profile, release]
|
||||
### Default value: debug
|
||||
### --fuchsia-cpu: The architecture of the Fuchsia device to target.
|
||||
### Valid values: [x64, arm64]
|
||||
### Default value: x64
|
||||
### --unoptimized: Disables C++ compiler optimizations.
|
||||
### --goma: Speeds up builds. For Googlers only, sorry. :(
|
||||
|
||||
set -e # Fail on any error.
|
||||
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"/lib/vars.sh || exit $?
|
||||
|
||||
ensure_fuchsia_dir
|
||||
jiri_bin=$FUCHSIA_DIR/.jiri_root/bin
|
||||
ensure_engine_dir
|
||||
ensure_ninja
|
||||
|
||||
if [[ $# -lt 2 ]]
|
||||
then
|
||||
echo -e "Usage: $0 <integration_test_name>"
|
||||
fi
|
||||
|
||||
# This script currently requires running `fx serve`.
|
||||
if [[ -z "$(pgrep -f 'pm serve')" ]]
|
||||
then
|
||||
engine-error "This script currently requires running 'fx serve' first."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# The first argument is always assumed to be the integration test name.
|
||||
test_name=$1
|
||||
shift # past argument
|
||||
|
||||
# Ensure we know about the test and look up its packages.
|
||||
test_packages=
|
||||
case $test_name in
|
||||
embedder)
|
||||
test_packages=("flutter-embedder-test-0.far" "parent-view.far" "child-view.far")
|
||||
;;
|
||||
*)
|
||||
engine-error "Unknown test name $test_name. You may need to add it to $0"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
# Parse arguments.
|
||||
skip_fuchsia_build=0
|
||||
skip_fuchsia_emu=0
|
||||
runtime_mode="debug"
|
||||
compilation_mode="jit"
|
||||
fuchsia_cpu="x64"
|
||||
goma=0
|
||||
goma_flags=""
|
||||
ninja_cmd="ninja"
|
||||
unoptimized_flags=""
|
||||
unoptimized_suffix=""
|
||||
extra_gn_args=()
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case $1 in
|
||||
--skip-fuchsia-build)
|
||||
shift # past argument
|
||||
skip_fuchsia_build=1
|
||||
;;
|
||||
--skip-fuchsia-emu|--skip-fuchsia-emulator)
|
||||
shift # past argument
|
||||
skip_fuchsia_emu=1
|
||||
;;
|
||||
--runtime-mode)
|
||||
shift # past argument
|
||||
runtime_mode="$1"
|
||||
shift # past value
|
||||
|
||||
if [[ "${runtime_mode}" == debug ]]
|
||||
then
|
||||
compilation_mode="jit"
|
||||
elif [[ "${runtime_mode}" == profile || "${runtime_mode}" == release ]]
|
||||
then
|
||||
compilation_mode="aot"
|
||||
else
|
||||
engine-error "Invalid value for --runtime_mode: ${runtime_mode}"
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
--fuchsia-cpu)
|
||||
shift # past argument
|
||||
fuchsia_cpu="$1"
|
||||
shift # past value
|
||||
|
||||
if [[ "${fuchsia_cpu}" != x64 && "${fuchsia_cpu}" != arm64 ]]
|
||||
then
|
||||
engine-error "Invalid value for --fuchsia-cpu: ${fuchsia_cpu}"
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
--goma)
|
||||
goma=1
|
||||
goma_flags="--goma"
|
||||
ninja_cmd="autoninja"
|
||||
shift # past argument
|
||||
;;
|
||||
--unopt|--unoptimized)
|
||||
unoptimized_flags="--unoptimized"
|
||||
unoptimized_suffix="_unopt"
|
||||
shift # past argument
|
||||
;;
|
||||
*)
|
||||
extra_gn_args+=("$1") # forward argument
|
||||
shift # past argument
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
headless_flags=
|
||||
if [[ -z "$DISPLAY" ]]
|
||||
then
|
||||
engine-warning "You are running a Flutter integration test from a headless environment."
|
||||
engine-warning "This may lead to bugs or the test failing."
|
||||
engine-warning "You may want to switch to a graphical environment and try again, but the script will keep going."
|
||||
|
||||
headless_flags="--headless"
|
||||
fi
|
||||
|
||||
all_gn_args="--fuchsia --fuchsia-cpu="${fuchsia_cpu}" --runtime-mode="${runtime_mode}" ${goma_flags} ${unoptimized_flags} ${extra_gn_args[@]}"
|
||||
engine-info "Building Flutter test with GN args: ${all_gn_args}"
|
||||
|
||||
"$ENGINE_DIR"/flutter/tools/gn ${all_gn_args}
|
||||
|
||||
fuchsia_out_dir_name=fuchsia_${runtime_mode}${unoptimized_suffix}_${fuchsia_cpu}
|
||||
fuchsia_out_dir="$ENGINE_DIR"/out/"${fuchsia_out_dir_name}"
|
||||
engine-info "Building ${fuchsia_out_dir_name}..."
|
||||
${ninja_cmd} -C "${fuchsia_out_dir}" flutter/shell/platform/fuchsia/flutter/tests/integration/$test_name:tests
|
||||
|
||||
engine-info "Registering debug symbols..."
|
||||
"$ENGINE_DIR"/fuchsia/sdk/linux/tools/x64/symbol-index add "${fuchsia_out_dir}"/.build-id "${fuchsia_out_dir}"
|
||||
|
||||
pushd $FUCHSIA_DIR
|
||||
|
||||
if [[ "$skip_fuchsia_build" -eq 0 ]]
|
||||
then
|
||||
engine-info "Building Fuchsia in terminal.x64 mode... (to skip this, run with --skip-fuchsia-build)"
|
||||
if [[ "$runtime_mode" -eq "debug" ]]
|
||||
then
|
||||
"$jiri_bin"/fx set terminal.x64
|
||||
else
|
||||
"$jiri_bin"/fx set terminal.x64 --release
|
||||
fi
|
||||
"$jiri_bin"/fx build
|
||||
fi
|
||||
|
||||
test_package_paths=( "$fuchsia_out_dir"/oot_flutter_jit_runner-0.far )
|
||||
for test_package in "${test_packages[@]}"
|
||||
do
|
||||
test_package_paths+=( $(find "$fuchsia_out_dir" -name "$test_package") )
|
||||
done
|
||||
|
||||
fx_build_dir="$FUCHSIA_DIR/$(cat $FUCHSIA_DIR/.fx-build-dir)"
|
||||
if [[ "$skip_fuchsia_emu" -eq 0 ]]
|
||||
then
|
||||
engine-info "Starting the Fuchsia terminal.x64 emulator... (to skip this, run with --skip-fuchsia-emu)"
|
||||
"$jiri_bin"/ffx emu stop fuchsia-emulator
|
||||
"$jiri_bin"/ffx emu start "file://$fx_build_dir/*.json#terminal.x64" --net tap "${headless_flags}" --name fuchsia-emulator
|
||||
fi
|
||||
|
||||
for test_package_path in "${test_package_paths[@]}"
|
||||
do
|
||||
engine-info "... Publishing $test_package_path to package repository ($fx_build_dir/amber-files)..."
|
||||
"$jiri_bin"/fx pm publish -a -repo "$fx_build_dir/amber-files/" -f "$test_package_path"
|
||||
done
|
||||
|
||||
test_package_name_for_url="$(echo "${test_packages[0]}" | sed "s/\-0.far//")"
|
||||
test_url="fuchsia-pkg://fuchsia.com/${test_package_name_for_url}/0#meta/${test_package_name_for_url}.cm"
|
||||
engine-info "Running the test: $test_url"
|
||||
"$jiri_bin"/ffx test run $test_url
|
||||
|
||||
popd # $FUCHSIA_DIR
|
||||
Reference in New Issue
Block a user