From 16d501236198d8b4c52a473abea76e105652478a Mon Sep 17 00:00:00 2001 From: Alexander Biggs Date: Thu, 29 Sep 2022 12:57:05 -0700 Subject: [PATCH] [fuchsia] Add --gtest-filter flag for unit tests. (flutter/engine#36509) --- .../shell/platform/fuchsia/unit_tests.md | 6 ++++ .../tools/fuchsia/devshell/run_unit_tests.sh | 18 ++++++++--- .../devshell/test/test_run_unit_tests.sh | 30 +++++++++++++++++++ 3 files changed, 50 insertions(+), 4 deletions(-) create mode 100755 engine/src/flutter/tools/fuchsia/devshell/test/test_run_unit_tests.sh diff --git a/engine/src/flutter/shell/platform/fuchsia/unit_tests.md b/engine/src/flutter/shell/platform/fuchsia/unit_tests.md index 1cd20a5a5b..938ba1b772 100644 --- a/engine/src/flutter/shell/platform/fuchsia/unit_tests.md +++ b/engine/src/flutter/shell/platform/fuchsia/unit_tests.md @@ -30,3 +30,9 @@ $ENGINE_DIR/flutter/tools/fuchsia/devshell/run_unit_tests.sh ```sh $ENGINE_DIR/flutter/tools/fuchsia/devshell/run_unit_tests.sh --package-filter flow_tests-0.far ``` + +- Pass `--gtest-filter` to run specific tests from the test package instead of all the tests. For example: + + ```sh + $ENGINE_DIR/flutter/tools/fuchsia/devshell/run_unit_tests.sh --package-filter flutter_runner_tests-0.far --gtest-filter "*FlatlandConnection*" + ``` diff --git a/engine/src/flutter/tools/fuchsia/devshell/run_unit_tests.sh b/engine/src/flutter/tools/fuchsia/devshell/run_unit_tests.sh index 736d6e50e4..30364cb28c 100755 --- a/engine/src/flutter/tools/fuchsia/devshell/run_unit_tests.sh +++ b/engine/src/flutter/tools/fuchsia/devshell/run_unit_tests.sh @@ -7,6 +7,9 @@ ### ### Arguments: ### --package-filter: Only runs tests in packages that match the given `find` statement. +### --gtest-filter: In the packages, only runs tests that match the given filter. +### For example: --gtest-filter "*FlatlandConnection*" to run any tests +### that have the phrase FlatlandConnection in them. ### --unoptimized: Disables C++ compiler optimizations. ### --count: Number of times to run the test. By default runs 1 time. ### See `ffx test run --count`. @@ -27,19 +30,20 @@ goma=0 goma_flags="" ninja_cmd="ninja" package_filter="*tests-0.far" +test_filter_flags="" unoptimized_flags="" unoptimized_suffix="" -count_flag="" +count_flags="" while [[ $# -gt 0 ]]; do case $1 in - --package-filter) + --package_filter|--package-filter) shift # past argument package_filter="$1" shift # past value ;; --count) shift # past argument - count_flag="--count $1" + count_flags="--count $1" shift # past value ;; --goma) @@ -53,6 +57,11 @@ while [[ $# -gt 0 ]]; do unoptimized_suffix="_unopt" shift # past argument ;; + --gtest_filter|--gtest-filter) + shift # past argument + test_filter_flags="-- --gtest_filter=$1" + shift # past value + ;; *) engine-error "Unknown argument: $1" exit 1 @@ -98,7 +107,8 @@ do 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}" + # ${test_filter_flags} must come last below because it includes " -- " to start program arguments. + test_cmd="${FUCHSIA_DIR}/.jiri_root/bin/ffx test run fuchsia-pkg://fuchsia.com/${test_name}#meta/${test_name}.cm ${count_flags} ${test_filter_flags}" engine-info "... $test_cmd ..." $test_cmd diff --git a/engine/src/flutter/tools/fuchsia/devshell/test/test_run_unit_tests.sh b/engine/src/flutter/tools/fuchsia/devshell/test/test_run_unit_tests.sh new file mode 100755 index 0000000000..adba2f1488 --- /dev/null +++ b/engine/src/flutter/tools/fuchsia/devshell/test/test_run_unit_tests.sh @@ -0,0 +1,30 @@ +#!/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. +# +### Tests run_unit_tests.sh by running it with various arguments. +### This script doesn't assert the results but just checks that the script runs +### successfully every time. +### +### This script doesn't run on CQ, it's only used for local testing. + +source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"/../lib/vars.sh || exit $? + +ensure_engine_dir + +set -e # Fail on any error. + +engine-info "Testing run_unit_tests.sh --package-filter flutter_runner_tests-0.far..." +"$ENGINE_DIR"/flutter/tools/fuchsia/devshell/run_unit_tests.sh --package-filter "flutter_runner_tests-0.far" + +engine-info "Testing run_unit_tests.sh --package-filter flutter_runner_tests-0.far --count 2..." +"$ENGINE_DIR"/flutter/tools/fuchsia/devshell/run_unit_tests.sh --package-filter "flutter_runner_tests-0.far" --count 2 + + +engine-info "Testing run_unit_tests.sh --package-filter flutter_runner_tests-0.far --gtest-filter *FlatlandConnection*..." +"$ENGINE_DIR"/flutter/tools/fuchsia/devshell/run_unit_tests.sh --package-filter "flutter_runner_tests-0.far" --gtest-filter "*FlatlandConnection*" + +engine-info "Testing run_unit_tests.sh with no args..." +"$ENGINE_DIR"/flutter/tools/fuchsia/devshell/run_unit_tests.sh +