Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 548f978

Browse files
authored
[fuchsia] Add script for Fuchsia integration tests (#35933)
Tested: `run_integration_tests.sh embedder`
1 parent 24779c3 commit 548f978

File tree

2 files changed

+214
-63
lines changed

2 files changed

+214
-63
lines changed
Lines changed: 26 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,47 @@
1-
# `flutter integration tests`
1+
# Flutter runner integration tests
22

3-
## Configure and build fuchsia
3+
To run the Flutter runner integration tests locally,
4+
first start a Fuchsia package server:
45

56
```shell
67
$ cd "$FUCHSIA_DIR"
7-
$ fx set terminal.x64
8-
$ fx build
8+
$ fx serve
99
```
1010

11-
## Build the test
12-
13-
You can specify the test's package target to build only the test package, with
14-
its dependencies. This will also build the required runner.
11+
Then run the integration test:
1512

1613
```shell
17-
$ cd "$ENGINE_DIR/src"
18-
$ ./flutter/tools/gn --fuchsia <flags> \
19-
# for example: --goma --fuchsia-cpu=x64 --runtime-mode=debug
20-
$ ninja -C out/fuchsia_debug_x64 \
21-
flutter/shell/platform/fuchsia/flutter/tests/integration
14+
$ ENGINE_DIR/flutter/tools/fuchsia/devshell/run_integration_test.sh <integration_test_folder_name> --no-lto
2215
```
2316

24-
25-
## Start an emulator
17+
For example, to run the `embedder` integration test:
2618

2719
```shell
28-
ffx emu start --net tap
20+
$ ENGINE_DIR/flutter/tools/fuchsia/devshell/run_integration_test.sh embedder --no-lto
2921
```
3022

31-
NOTE: Do _not_ run the default package server. The instructions below describe
32-
how to launch a flutter-specific package server.
33-
34-
## Publish the test packages to the Fuchsia package server
35-
36-
The tests currently specify the Fuchsia package server's standard domain,
37-
`fuchsia.com`, as the server to use to resolve (locate and load) the test
38-
packages. So, before running the test, the most recently built `.far` files
39-
need to be published to the Fuchsia package repo:
23+
Command-line options:
4024

41-
```shell
42-
$ fx pm publish -a -repo "$(cat $FUCHSIA_DIR/.fx-build-dir)/amber-files/" \
43-
-f "$FLUTTER_ENGINE_DIR"/src/out/fuchsia_*64/oot_flutter_jit_runner-0.far
44-
$ fx pm publish -a -repo "$(cat $FUCHSIA_DIR/.fx-build-dir)/amber-files/" \
45-
-f "$FLUTTER_ENGINE_DIR"/src/out/fuchsia_*64/flutter-embedder-test-0.far
46-
$ fx pm publish -a -repo "$(cat $FUCHSIA_DIR/.fx-build-dir)/amber-files/" \
47-
-f $(find "$FLUTTER_ENGINE_DIR"/src/out/fuchsia_*64 -name parent-view.far)
48-
$ fx pm publish -a -repo "$(cat $FUCHSIA_DIR/.fx-build-dir)/amber-files/" \
49-
-f $(find "$FLUTTER_ENGINE_DIR"/src/out/fuchsia_*64 -name child-view.far)
50-
```
25+
* Pass `--unoptimized` to disable C++ compiler optimizations.
26+
* Add `--fuchsia-cpu x64` or `--fuchsia-cpu arm64` to target a particular architecture.
27+
The default is x64.
28+
* Add `--runtime-mode debug` or `--runtime-mode profile` to switch between JIT and AOT
29+
builds. These correspond to a vanilla Fuchsia build and a `--release` Fuchsia build
30+
respectively. The default is debug/JIT builds.
31+
* For Googlers, add the `--goma` argument when using goma, and add the `--xcode-symlinks`
32+
argument when using goma on macOS.
33+
* Remove `--no-lto` if you care about performance or binary size; unfortunately it results
34+
in a *much* slower build.
5135

52-
## Run the test
36+
## Iterating on tests
5337

54-
```shell
55-
$ ffx test run fuchsia-pkg:://fuchsia.com/flutter-embedder-test#meta/flutter-embedder-test.cm
56-
```
38+
By default, `run_integration_test.sh` will build Fuchsia and start up a Fuchsia emulator
39+
to ensure that the test runs on the correct environment.
5740

58-
If, for example, you only make a change to the Dart code in `parent-view`, you
59-
can rebuild only the parent-view package target, and republish it.
41+
However, this is slow for iterating on tests. Once you've run `run_integration_tests.sh`
42+
once, you don't need to build Fuchsia or start the emulator anymore, and can pass
43+
`--skip-fuchsia-build` and `--skip-fuchsia-emu` to skip those steps.
6044

6145
```shell
62-
$ ninja -C out/fuchsia_debug_x64 \
63-
flutter/shell/platform/fuchsia/flutter/tests/integration/embedder/parent-view:package
64-
$ fx pm publish -a -repo "$(cat $FUCHSIA_DIR/.fx-build-dir)/amber-files/" \
65-
-f $(find "$FLUTTER_ENGINE_DIR"/src/out/fuchsia_*64 -name parent-view.far)
46+
$ ENGINE_DIR/flutter/tools/fuchsia/devshell/run_integration_test.sh embedder --no-lto --skip-fuchsia-build --skip-fuchsia-emu
6647
```
67-
68-
Then re-run the test as above.
69-
70-
The tests use a flutter runner with "oot_" prefixed to its package name, to
71-
avoid conflicting with any flutter_runner package in the base fuchsia image.
72-
After making a change to the flutter_runner you can re-deploy it with:
73-
74-
```shell
75-
$ ninja -C out/fuchsia_debug_x64 \
76-
flutter/shell/platform/fuchsia/flutter:oot_flutter_jit_runner
77-
$ fx pm publish -a -repo "$(cat $FUCHSIA_DIR/.fx-build-dir)/amber-files/" \
78-
-f $(find "$FLUTTER_ENGINE_DIR"/src/out/fuchsia_*64 -name oot_flutter_jit_runner.far)
79-
```
80-
81-
Then re-run the test as above.
82-
83-
From here, you can modify the Flutter test, rebuild flutter, and usually rerun
84-
the test without rebooting, by repeating the commands above.
Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
#!/bin/bash
2+
# Copyright 2013 The Flutter Authors. All rights reserved.
3+
# Use of this source code is governed by a BSD-style license that can be
4+
# found in the LICENSE file.
5+
6+
### Runs a Fuchsia integration test from shell/platform/fuchsia/flutter/tests/integration.
7+
###
8+
### Usage:
9+
### $ENGINE_DIR/flutter/tools/fuchsia/devshell/run_integration_test <integration_test_folder_name>
10+
###
11+
### Arguments:
12+
### --skip-fuchsia-build: Skips configuring and building Fuchsia for the test.
13+
### --skip-fuchsia-emu: Skips starting the Fuchsia emulator for the test.
14+
### --runtime-mode: The runtime mode to build Flutter in.
15+
### Valid values: [debug, profile, release]
16+
### Default value: debug
17+
### --fuchsia-cpu: The architecture of the Fuchsia device to target.
18+
### Valid values: [x64, arm64]
19+
### Default value: x64
20+
### --unoptimized: Disables C++ compiler optimizations.
21+
### --goma: Speeds up builds. For Googlers only, sorry. :(
22+
23+
set -e # Fail on any error.
24+
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"/lib/vars.sh || exit $?
25+
26+
ensure_fuchsia_dir
27+
jiri_bin=$FUCHSIA_DIR/.jiri_root/bin
28+
ensure_engine_dir
29+
ensure_ninja
30+
31+
if [[ $# -lt 2 ]]
32+
then
33+
echo -e "Usage: $0 <integration_test_name>"
34+
fi
35+
36+
# This script currently requires running `fx serve`.
37+
if [[ -z "$(pgrep -f 'pm serve')" ]]
38+
then
39+
engine-error "This script currently requires running 'fx serve' first."
40+
exit 1
41+
fi
42+
43+
# The first argument is always assumed to be the integration test name.
44+
test_name=$1
45+
shift # past argument
46+
47+
# Ensure we know about the test and look up its packages.
48+
test_packages=
49+
case $test_name in
50+
embedder)
51+
test_packages=("flutter-embedder-test-0.far" "parent-view.far" "child-view.far")
52+
;;
53+
*)
54+
engine-error "Unknown test name $test_name. You may need to add it to $0"
55+
exit 1
56+
;;
57+
esac
58+
59+
# Parse arguments.
60+
skip_fuchsia_build=0
61+
skip_fuchsia_emu=0
62+
runtime_mode="debug"
63+
compilation_mode="jit"
64+
fuchsia_cpu="x64"
65+
goma=0
66+
goma_flags=""
67+
ninja_cmd="ninja"
68+
unoptimized_flags=""
69+
unoptimized_suffix=""
70+
extra_gn_args=()
71+
while [[ $# -gt 0 ]]; do
72+
case $1 in
73+
--skip-fuchsia-build)
74+
shift # past argument
75+
skip_fuchsia_build=1
76+
;;
77+
--skip-fuchsia-emu|--skip-fuchsia-emulator)
78+
shift # past argument
79+
skip_fuchsia_emu=1
80+
;;
81+
--runtime-mode)
82+
shift # past argument
83+
runtime_mode="$1"
84+
shift # past value
85+
86+
if [[ "${runtime_mode}" == debug ]]
87+
then
88+
compilation_mode="jit"
89+
elif [[ "${runtime_mode}" == profile || "${runtime_mode}" == release ]]
90+
then
91+
compilation_mode="aot"
92+
else
93+
engine-error "Invalid value for --runtime_mode: ${runtime_mode}"
94+
exit 1
95+
fi
96+
;;
97+
--fuchsia-cpu)
98+
shift # past argument
99+
fuchsia_cpu="$1"
100+
shift # past value
101+
102+
if [[ "${fuchsia_cpu}" != x64 && "${fuchsia_cpu}" != arm64 ]]
103+
then
104+
engine-error "Invalid value for --fuchsia-cpu: ${fuchsia_cpu}"
105+
exit 1
106+
fi
107+
;;
108+
--goma)
109+
goma=1
110+
goma_flags="--goma"
111+
ninja_cmd="autoninja"
112+
shift # past argument
113+
;;
114+
--unopt|--unoptimized)
115+
unoptimized_flags="--unoptimized"
116+
unoptimized_suffix="_unopt"
117+
shift # past argument
118+
;;
119+
*)
120+
extra_gn_args+=("$1") # forward argument
121+
shift # past argument
122+
;;
123+
esac
124+
done
125+
126+
headless_flags=
127+
if [[ -z "$DISPLAY" ]]
128+
then
129+
engine-warning "You are running a Flutter integration test from a headless environment."
130+
engine-warning "This may lead to bugs or the test failing."
131+
engine-warning "You may want to switch to a graphical environment and try again, but the script will keep going."
132+
133+
headless_flags="--headless"
134+
fi
135+
136+
all_gn_args="--fuchsia --fuchsia-cpu="${fuchsia_cpu}" --runtime-mode="${runtime_mode}" ${goma_flags} ${unoptimized_flags} ${extra_gn_args[@]}"
137+
engine-info "Building Flutter test with GN args: ${all_gn_args}"
138+
139+
"$ENGINE_DIR"/flutter/tools/gn ${all_gn_args}
140+
141+
fuchsia_out_dir_name=fuchsia_${runtime_mode}${unoptimized_suffix}_${fuchsia_cpu}
142+
fuchsia_out_dir="$ENGINE_DIR"/out/"${fuchsia_out_dir_name}"
143+
engine-info "Building ${fuchsia_out_dir_name}..."
144+
${ninja_cmd} -C "${fuchsia_out_dir}" flutter/shell/platform/fuchsia/flutter/tests/integration/$test_name:tests
145+
146+
engine-info "Registering debug symbols..."
147+
"$ENGINE_DIR"/fuchsia/sdk/linux/tools/x64/symbol-index add "${fuchsia_out_dir}"/.build-id "${fuchsia_out_dir}"
148+
149+
pushd $FUCHSIA_DIR
150+
151+
if [[ "$skip_fuchsia_build" -eq 0 ]]
152+
then
153+
engine-info "Building Fuchsia in terminal.x64 mode... (to skip this, run with --skip-fuchsia-build)"
154+
if [[ "$runtime_mode" -eq "debug" ]]
155+
then
156+
"$jiri_bin"/fx set terminal.x64
157+
else
158+
"$jiri_bin"/fx set terminal.x64 --release
159+
fi
160+
"$jiri_bin"/fx build
161+
fi
162+
163+
test_package_paths=( "$fuchsia_out_dir"/oot_flutter_jit_runner-0.far )
164+
for test_package in "${test_packages[@]}"
165+
do
166+
test_package_paths+=( $(find "$fuchsia_out_dir" -name "$test_package") )
167+
done
168+
169+
fx_build_dir="$FUCHSIA_DIR/$(cat $FUCHSIA_DIR/.fx-build-dir)"
170+
if [[ "$skip_fuchsia_emu" -eq 0 ]]
171+
then
172+
engine-info "Starting the Fuchsia terminal.x64 emulator... (to skip this, run with --skip-fuchsia-emu)"
173+
"$jiri_bin"/ffx emu stop fuchsia-emulator
174+
"$jiri_bin"/ffx emu start "file://$fx_build_dir/*.json#terminal.x64" --net tap "${headless_flags}" --name fuchsia-emulator
175+
fi
176+
177+
for test_package_path in "${test_package_paths[@]}"
178+
do
179+
engine-info "... Publishing $test_package_path to package repository ($fx_build_dir/amber-files)..."
180+
"$jiri_bin"/fx pm publish -a -repo "$fx_build_dir/amber-files/" -f "$test_package_path"
181+
done
182+
183+
test_package_name_for_url="$(echo "${test_packages[0]}" | sed "s/\-0.far//")"
184+
test_url="fuchsia-pkg://fuchsia.com/${test_package_name_for_url}/0#meta/${test_package_name_for_url}.cm"
185+
engine-info "Running the test: $test_url"
186+
"$jiri_bin"/ffx test run $test_url
187+
188+
popd # $FUCHSIA_DIR

0 commit comments

Comments
 (0)