Skip to content

Commit

Permalink
[fuchsia] Add run_unit_tests.sh script. (flutter#36308)
Browse files Browse the repository at this point in the history
This is a convenience script for running unit tests locally.

To make this script work, I had to move several test exclusions
from test_suites.yaml (which controls running tests on CQ)
to the tests themselves. I think this is for the best because
it makes running the tests locally with behavior that matches
CQ easier.

Also added fuchsia_tests to build_and_copy_to_fuchsia.sh
so it builds the unit tests .far packages by default.

Tested: Ran `run_unit_tests.sh`, all tests pass. Ran
`build_and_copy_to_fuchsia.sh`, it still builds.
  • Loading branch information
akbiggs authored Sep 21, 2022
1 parent 3a28e8a commit c67b332
Show file tree
Hide file tree
Showing 8 changed files with 185 additions and 10 deletions.
24 changes: 23 additions & 1 deletion fml/message_loop_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,11 @@ TEST(MessageLoop, CheckRunsTaskOnCurrentThread) {
}

TEST(MessageLoop, TIMESENSITIVE(SingleDelayedTaskByDelta)) {
#if defined(OS_FUCHSIA)
GTEST_SKIP()
<< "This test does not work on Fuchsia. https://fxbug.dev/110020 ";
#endif // OS_FUCHSIA

bool checked = false;
std::thread thread([&checked]() {
fml::MessageLoop::EnsureInitializedForCurrentThread();
Expand All @@ -178,6 +183,11 @@ TEST(MessageLoop, TIMESENSITIVE(SingleDelayedTaskByDelta)) {
}

TEST(MessageLoop, TIMESENSITIVE(SingleDelayedTaskForTime)) {
#if defined(OS_FUCHSIA)
GTEST_SKIP()
<< "This test does not work on Fuchsia. https://fxbug.dev/110020 ";
#endif // OS_FUCHSIA

bool checked = false;
std::thread thread([&checked]() {
fml::MessageLoop::EnsureInitializedForCurrentThread();
Expand All @@ -200,6 +210,11 @@ TEST(MessageLoop, TIMESENSITIVE(SingleDelayedTaskForTime)) {
}

TEST(MessageLoop, TIMESENSITIVE(MultipleDelayedTasksWithIncreasingDeltas)) {
#if defined(OS_FUCHSIA)
GTEST_SKIP()
<< "This test does not work on Fuchsia. https://fxbug.dev/110020 ";
#endif // OS_FUCHSIA

const auto count = 10;
int checked = false;
std::thread thread(PLATFORM_SPECIFIC_CAPTURE(&checked)() {
Expand Down Expand Up @@ -227,6 +242,11 @@ TEST(MessageLoop, TIMESENSITIVE(MultipleDelayedTasksWithIncreasingDeltas)) {
}

TEST(MessageLoop, TIMESENSITIVE(MultipleDelayedTasksWithDecreasingDeltas)) {
#if defined(OS_FUCHSIA)
GTEST_SKIP()
<< "This test does not work on Fuchsia. https://fxbug.dev/110020 ";
#endif // OS_FUCHSIA

const auto count = 10;
int checked = false;
std::thread thread(PLATFORM_SPECIFIC_CAPTURE(&checked)() {
Expand Down Expand Up @@ -262,7 +282,9 @@ TEST(MessageLoop, TaskObserverFire) {
auto& loop = fml::MessageLoop::GetCurrent();
size_t task_count = 0;
size_t obs_count = 0;
auto obs = PLATFORM_SPECIFIC_CAPTURE(&obs_count)() { obs_count++; };
auto obs = PLATFORM_SPECIFIC_CAPTURE(&obs_count)() {
obs_count++;
};
for (size_t i = 0; i < count; i++) {
loop.GetTaskRunner()->PostTask(
PLATFORM_SPECIFIC_CAPTURE(&terminated, i, &task_count)() {
Expand Down
15 changes: 11 additions & 4 deletions shell/common/shell_fuchsia_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,13 @@ class FuchsiaShellTest : public ShellTest {
}

~FuchsiaShellTest() {
// Restore the time zone that matche that of the test harness. This is
// Restore the time zone that matches that of the test harness. This is
// the default.
const std::string local_timezone = GetLocalTimezone();
SetTimezone(local_timezone);
AssertTimezone(local_timezone, GetSettings());
// TODO(https://fxbug.dev/110019): This crashes right now.

// const std::string local_timezone = GetLocalTimezone();
// SetTimezone(local_timezone);
// AssertTimezone(local_timezone, GetSettings());
}

// Gets the international settings from this Fuchsia realm.
Expand Down Expand Up @@ -160,6 +162,11 @@ static void RunCoroutineWithRetry(int retries,
// timestamp rounded down to whole hour should match the timestamp we got
// in the initial step.
TEST_F(FuchsiaShellTest, LocaltimesVaryOnTimezoneChanges) {
#if defined(OS_FUCHSIA)
GTEST_SKIP()
<< "This test fails after the CF V2 migration. https://fxbug.dev/110019 ";
#endif // OS_FUCHSIA

// See fixtures/shell_test.dart, the callback NotifyLocalTime is declared
// there.
fml::AutoResetWaitableEvent latch;
Expand Down
4 changes: 4 additions & 0 deletions shell/common/shell_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,10 @@ TEST_F(ShellTest, LastEntrypointArgs) {
}

TEST_F(ShellTest, DisallowedDartVMFlag) {
#if defined(OS_FUCHSIA)
GTEST_SKIP() << "This test flakes on Fuchsia. https://fxbug.dev/110006 ";
#endif // OS_FUCHSIA

// Run this test in a thread-safe manner, otherwise gtest will complain.
::testing::FLAGS_gtest_death_test_style = "threadsafe";

Expand Down
4 changes: 4 additions & 0 deletions shell/platform/embedder/tests/embedder_a11y_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ namespace testing {
using EmbedderA11yTest = testing::EmbedderTest;

TEST_F(EmbedderA11yTest, A11yTreeIsConsistent) {
#if defined(OS_FUCHSIA)
GTEST_SKIP() << "This test crashes on Fuchsia. https://fxbug.dev/87493 ";
#endif // OS_FUCHSIA

auto& context = GetEmbedderContext(EmbedderTestContextType::kOpenGLContext);

fml::AutoResetWaitableEvent latch;
Expand Down
32 changes: 32 additions & 0 deletions shell/platform/fuchsia/unit_tests.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Running the Fuchsia unit tests locally

These instructions assume you have set `$FUCHSIA_DIR` to your Fuchsia checkout
and `$ENGINE_DIR` to the `src/` folder of your Engine checkout. For example for
zsh, add these lines to your `~/.zprofile`:

```sh
export FUCHSIA_DIR=~/fuchsia
export ENGINE_DIR=~/engine/src
```

1. In a separate terminal, start a Fuchsia package server:

```sh
cd "$FUCHSIA_DIR"
fx serve
```

2. Run the unit tests:

```sh
$ENGINE_DIR/flutter/tools/fuchsia/devshell/run_unit_tests.sh
```

- Pass `--unopt` to turn off C++ compiler optimizations.
- Pass `--count N` to do N test runs. Useful for testing for flakes.
- Pass `--goma` to accelerate the build if you're a Googler.
- Pass `--package-filter` to run a specific test package instead of all the test packages. For example:

```sh
$ENGINE_DIR/flutter/tools/fuchsia/devshell/run_unit_tests.sh --package-filter flow_tests-0.far
```
7 changes: 3 additions & 4 deletions testing/fuchsia/test_suites.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
package: flutter_runner_tzdata_tests-0.far
- test_command: run-test-suite fuchsia-pkg://fuchsia.com/flutter_runner_tzdata_missing_tests#meta/flutter_runner_tzdata_missing_tests.cm
package: flutter_runner_tzdata_missing_tests-0.far
- test_command: run-test-suite fuchsia-pkg://fuchsia.com/fml_tests#meta/fml_tests.cm -- --gtest_filter=-MessageLoop.TimeSensitiveTest_*
- test_command: run-test-suite fuchsia-pkg://fuchsia.com/fml_tests#meta/fml_tests.cm
package: fml_tests-0.far
- test_command: run-test-suite fuchsia-pkg://fuchsia.com/display_list_tests#meta/display_list_tests.cm
package: display_list_tests-0.far
Expand All @@ -25,16 +25,15 @@
package: flow_tests-0.far
- test_command: run-test-suite fuchsia-pkg://fuchsia.com/runtime_tests#meta/runtime_tests.cm
package: runtime_tests-0.far
- test_command: run-test-suite fuchsia-pkg://fuchsia.com/shell_tests#meta/shell_tests.cm -- --gtest_filter=-ShellTest.ReportTimingsIsCalledLaterInReleaseMode:ShellTest.ReportTimingsIsCalledSoonerInNonReleaseMode:ShellTest.DisallowedDartVMFlag:FuchsiaShellTest.LocaltimesVaryOnTimezoneChanges
- test_command: run-test-suite fuchsia-pkg://fuchsia.com/shell_tests#meta/shell_tests.cm
package: shell_tests-0.far
- test_command: run-test-suite fuchsia-pkg://fuchsia.com/testing_tests#meta/testing_tests.cm
package: testing_tests-0.far
- test_command: run-test-suite fuchsia-pkg://fuchsia.com/txt_tests#meta/txt_tests.cm -- --gtest_filter=-ParagraphTest.*
package: txt_tests-0.far
- test_command: run-test-suite fuchsia-pkg://fuchsia.com/ui_tests#meta/ui_tests.cm
package: ui_tests-0.far
# TODO(fxb/87493): re-enable A11yTreeIsConsistent when it doesn't crash.
- test_command: run-test-suite fuchsia-pkg://fuchsia.com/embedder_tests#meta/embedder_tests.cm -- --gtest_filter=-EmbedderA11yTest.A11yTreeIsConsistent
- test_command: run-test-suite fuchsia-pkg://fuchsia.com/embedder_tests#meta/embedder_tests.cm
package: embedder_tests-0.far
- test_command: run-test-suite fuchsia-pkg://fuchsia.com/dart_utils_tests#meta/dart_utils_tests.cm
package: dart_utils_tests-0.far
2 changes: 1 addition & 1 deletion tools/fuchsia/devshell/build_and_copy_to_fuchsia.sh
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ engine-info "GN args: ${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
${ninja_cmd} -C "${fuchsia_out_dir}" flutter/shell/platform/fuchsia fuchsia_tests

engine-info "Making Fuchsia's Flutter prebuilts writable..."
chmod -R +w "$FUCHSIA_DIR"/prebuilt/third_party/flutter
Expand Down
107 changes: 107 additions & 0 deletions tools/fuchsia/devshell/run_unit_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
#!/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 the Fuchsia unit tests in the debug configuration.
###
### Arguments:
### --package-filter: Only runs tests in packages that match the given `find` statement.
### --unoptimized: Disables C++ compiler optimizations.
### --count: Number of times to run the test. By default runs 1 time.
### See `ffx test run --count`.
### --goma: Speeds up builds for Googlers. 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
ensure_engine_dir
ensure_ninja

# Parse arguments.
runtime_mode="debug"
compilation_mode="jit"
fuchsia_cpu="x64"
goma=0
goma_flags=""
ninja_cmd="ninja"
package_filter="*tests-0.far"
unoptimized_flags=""
unoptimized_suffix=""
count_flag=""
while [[ $# -gt 0 ]]; do
case $1 in
--package-filter)
shift # past argument
package_filter="$1"
shift # past value
;;
--count)
shift # past argument
count_flag="--count $1"
shift # past value
;;
--goma)
goma=1
goma_flags="--goma"
ninja_cmd="autoninja"
shift # past argument
;;
--unopt|--unoptimized)
unoptimized_flags="--unoptimized"
unoptimized_suffix="_unopt"
shift # past argument
;;
*)
engine-error "Unknown argument: $1"
exit 1
;;
esac
done

all_gn_args="--fuchsia --no-lto --fuchsia-cpu="${fuchsia_cpu}" --runtime-mode="${runtime_mode}" ${goma_flags} ${unoptimized_flags}"
engine-info "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}" fuchsia_tests

engine-info "Registering debug symbols..."
"${ENGINE_DIR}"/fuchsia/sdk/linux/tools/x64/symbol-index add "${fuchsia_out_dir}"/.build-id "${fuchsia_out_dir}"

test_packages="$(find ${fuchsia_out_dir} -name "${package_filter}")"

engine-info "Publishing test packages..."
test_names=()
for test_package in $test_packages
do
engine-info "... publishing ${test_package} ..."
$ENGINE_DIR/fuchsia/sdk/linux/tools/x64/pm publish -a -r $FUCHSIA_DIR/$(cat $FUCHSIA_DIR/.fx-build-dir)/amber-files -f "${test_package}"
test_names+=("$(basename ${test_package} | sed -e "s/-0.far//")")
done

# .jiri_root/bin/ffx needs to run from $FUCHSIA_DIR.

pushd $FUCHSIA_DIR

# TODO(akbiggs): Match the behavior of this script more closely with test_suites.yaml.
engine-info "Running tests... (if this fails because of Launch(InstanceCannotResolve), run fx serve and try again)"
for test_name in "${test_names[@]}"
do
# ParagraphTest.* fails in txt_tests.
if [[ "${test_name}" == "txt_tests" ]]
then
engine-warning "Skipping txt_tests because I don't know how to filter out ParagraphTests.*"
continue
fi
test_cmd="${FUCHSIA_DIR}/.jiri_root/bin/ffx test run fuchsia-pkg://fuchsia.com/${test_name}#meta/${test_name}.cm ${count_flag}"

engine-info "... $test_cmd ..."
$test_cmd
done

popd # $FUCHSIA_DIR

0 comments on commit c67b332

Please sign in to comment.