From be4847abacff3066eb9b6bc706ea731978b6361d Mon Sep 17 00:00:00 2001 From: David Iglesias Date: Wed, 11 May 2022 14:34:15 -0700 Subject: [PATCH] [cross_file] Add run_tests.dart (and remove install_chromium_for_benchmarks.sh) (#1756) --- .ci/scripts/custom_package_tests.sh | 8 +++- .cirrus.yml | 35 +++++++++------- packages/cross_file/dart_test.yaml | 6 +++ packages/cross_file/pubspec.yaml | 1 + packages/cross_file/tool/run_tests.dart | 49 +++++++++++++++++++++++ script/install_chromium.sh | 34 ++++++++++------ script/install_chromium_for_benchmarks.sh | 24 ----------- 7 files changed, 105 insertions(+), 52 deletions(-) create mode 100644 packages/cross_file/dart_test.yaml create mode 100644 packages/cross_file/tool/run_tests.dart delete mode 100755 script/install_chromium_for_benchmarks.sh diff --git a/.ci/scripts/custom_package_tests.sh b/.ci/scripts/custom_package_tests.sh index bde44fbe0d52..236300eaa052 100755 --- a/.ci/scripts/custom_package_tests.sh +++ b/.ci/scripts/custom_package_tests.sh @@ -3,5 +3,11 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. +# Exclusions +# +# cross_file +# Custom tests need Chrome. (They run in linux-custom_package_tests) + dart pub global run flutter_plugin_tools custom-test \ - --packages-for-branch --log-timing + --packages-for-branch --log-timing \ + --exclude=cross_file diff --git a/.cirrus.yml b/.cirrus.yml index 96b88ef188de..686e67e51ee7 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -6,6 +6,18 @@ only_if: $CIRRUS_TAG == '' && $CIRRUS_BRANCH != 'master' env: CHANNEL: "master" # Default to master when not explicitly set by a task. +install_chrome_linux_template: &INSTALL_CHROME_LINUX + env: + CHROME_NO_SANDBOX: true + CHROME_DOWNLOAD_DIR: /tmp/chromium + CHROME_EXECUTABLE: $CHROME_DOWNLOAD_DIR/chrome-linux/chrome + CHROMEDRIVER_EXECUTABLE: $CHROME_DOWNLOAD_DIR/chromedriver/chromedriver + PATH: $PATH:$CHROME_DOWNLOAD_DIR/chrome-linux + install_chromium_script: + # Install a pinned version of Chromium and its corresponding ChromeDriver. + # Setting CHROME_EXECUTABLE above causes this version to be used for tests. + - ./script/install_chromium.sh "$CHROME_DIR" + tool_setup_template: &TOOL_SETUP_TEMPLATE tool_setup_script: - .ci/scripts/prepare_tool.sh @@ -128,6 +140,7 @@ task: matrix: CHANNEL: "master" CHANNEL: "stable" + << : *INSTALL_CHROME_LINUX local_tests_script: # pigeon tests currently don't support Linux: # https://github.com/flutter/flutter/issues/100386 @@ -158,16 +171,9 @@ task: matrix: CHANNEL: "master" CHANNEL: "stable" - CHROME_NO_SANDBOX: true - CHROME_DIR: /tmp/web_chromium/ - CHROME_EXECUTABLE: $CHROME_DIR/chrome-linux/chrome - install_script: - # Install a pinned version of Chromium and its corresponding ChromeDriver. - # Setting CHROME_EXECUTABLE above causes this version to be used for tests. - - ./script/install_chromium.sh "$CHROME_DIR" + << : *INSTALL_CHROME_LINUX chromedriver_background_script: - - cd "$CHROME_DIR" - - ./chromedriver/chromedriver --port=4444 + - $CHROMEDRIVER_EXECUTABLE --port=4444 build_script: - ./script/tool_runner.sh build-examples --web drive_script: @@ -177,11 +183,8 @@ task: matrix: CHROMIUM_BUILD: "768968" # Chromium 84.0.4147.0 CHROMIUM_BUILD: "950363" # Chromium 98.0.4758.0 - CHROME_NO_SANDBOX: true - install_chromium_script: - - ./script/install_chromium_for_benchmarks.sh + << : *INSTALL_CHROME_LINUX script: - - export CHROME_EXECUTABLE=$(pwd)/.chromium/chrome-linux/chrome - cd packages/web_benchmarks/testing/test_app - flutter packages get - cd ../.. @@ -226,10 +229,12 @@ task: local_tests_script: # flutter_image # https://github.com/flutter/flutter/issues/100387 + # cross_file + # Custom tests need Chrome. (They run in linux-custom_package_tests) - if [[ "$CHANNEL" == "master" ]]; then - - ./script/tool_runner.sh custom-test + - ./script/tool_runner.sh custom-test --exclude=cross_file - else - - ./script/tool_runner.sh custom-test --exclude=flutter_image + - ./script/tool_runner.sh custom-test --exclude=cross_file,flutter_image - fi ### macOS desktop tasks ### - name: macos-platform_tests diff --git a/packages/cross_file/dart_test.yaml b/packages/cross_file/dart_test.yaml new file mode 100644 index 000000000000..cdb656dbb689 --- /dev/null +++ b/packages/cross_file/dart_test.yaml @@ -0,0 +1,6 @@ +# See https://github.com/dart-lang/test/blob/master/pkgs/test/doc/configuration.md#arguments +override_platforms: + chrome: + settings: + executable: chrome + arguments: --no-sandbox diff --git a/packages/cross_file/pubspec.yaml b/packages/cross_file/pubspec.yaml index 53420a391d0b..8fcf77240bb3 100644 --- a/packages/cross_file/pubspec.yaml +++ b/packages/cross_file/pubspec.yaml @@ -12,4 +12,5 @@ dependencies: meta: ^1.3.0 dev_dependencies: + path: ^1.8.1 test: ^1.21.1 diff --git a/packages/cross_file/tool/run_tests.dart b/packages/cross_file/tool/run_tests.dart new file mode 100644 index 000000000000..ef094ef1936e --- /dev/null +++ b/packages/cross_file/tool/run_tests.dart @@ -0,0 +1,49 @@ +// 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 `dart test -p chrome` in the root of the cross_file package. +// +// Called from the custom-tests CI action. +// +// usage: dart run tool/run_tests.dart +// (needs a `chrome` executable in $PATH, or a tweak to dart_test.yaml) +import 'dart:io'; +import 'package:path/path.dart' as p; + +Future main(List args) async { + final Directory workingDir = + Directory(p.dirname(Platform.script.path)).parent; + + final int status = await _runProcess( + 'dart', + [ + 'test', + '-p', + 'chrome', + ], + workingDirectory: workingDir.path, + ); + + exit(status); +} + +Future _streamOutput(Future processFuture) async { + final Process process = await processFuture; + stdout.addStream(process.stdout); + stderr.addStream(process.stderr); + return process; +} + +Future _runProcess( + String command, + List arguments, { + String? workingDirectory, +}) async { + final Process process = await _streamOutput(Process.start( + command, + arguments, + workingDirectory: workingDirectory, + )); + return process.exitCode; +} diff --git a/script/install_chromium.sh b/script/install_chromium.sh index b7d787626d55..ed55776a5c19 100755 --- a/script/install_chromium.sh +++ b/script/install_chromium.sh @@ -2,41 +2,51 @@ # 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. + +# This script may be run as: +# $ CHROME_DOWNLOAD_DIR=./whatever script/install_chromium.sh set -e set -x -readonly TARGET_DIR=$1 +# The target directory where chromium is going to be downloaded +: "${CHROME_DOWNLOAD_DIR:=/tmp/chromium}" # Default value for the CHROME_DOWNLOAD_DIR env. # The build of Chromium used to test web functionality. # # Chromium builds can be located here: https://commondatastorage.googleapis.com/chromium-browser-snapshots/index.html?prefix=Linux_x64/ # # Check: https://github.com/flutter/engine/blob/master/lib/web_ui/dev/browser_lock.yaml -readonly CHROMIUM_BUILD=929514 +: "${CHROMIUM_BUILD:=950363}" # Default value for the CHROMIUM_BUILD env. + +# Convenience defaults for CHROME_EXECUTABLE and CHROMEDRIVER_EXECUTABLE. These +# two values should be set in the environment from CI, so this script can validate +# that it has completed downloading chrome and driver successfully (and the expected +# files are executable) +: "${CHROME_EXECUTABLE:=$CHROME_DOWNLOAD_DIR/chrome-linux/chrome}" +: "${CHROMEDRIVER_EXECUTABLE:=$CHROME_DOWNLOAD_DIR/chromedriver/chromedriver}" # The correct ChromeDriver is distributed alongside the chromium build above, as # `chromedriver_linux64.zip`, so no need to hardcode any extra info about it. readonly DOWNLOAD_ROOT="https://www.googleapis.com/download/storage/v1/b/chromium-browser-snapshots/o/Linux_x64%2F${CHROMIUM_BUILD}%2F" # Install Chromium. -mkdir "$TARGET_DIR" -readonly CHROMIUM_ZIP_FILE="$TARGET_DIR/chromium.zip" +mkdir "$CHROME_DOWNLOAD_DIR" +readonly CHROMIUM_ZIP_FILE="$CHROME_DOWNLOAD_DIR/chromium.zip" wget --no-verbose "${DOWNLOAD_ROOT}chrome-linux.zip?alt=media" -O "$CHROMIUM_ZIP_FILE" -unzip -q "$CHROMIUM_ZIP_FILE" -d "$TARGET_DIR/" +unzip -q "$CHROMIUM_ZIP_FILE" -d "$CHROME_DOWNLOAD_DIR/" # Install ChromeDriver. -readonly DRIVER_ZIP_FILE="$TARGET_DIR/chromedriver.zip" +readonly DRIVER_ZIP_FILE="$CHROME_DOWNLOAD_DIR/chromedriver.zip" wget --no-verbose "${DOWNLOAD_ROOT}chromedriver_linux64.zip?alt=media" -O "$DRIVER_ZIP_FILE" -unzip -q "$DRIVER_ZIP_FILE" -d "$TARGET_DIR/" -# Rename TARGET_DIR/chromedriver_linux64 to the expected TARGET_DIR/chromedriver -mv -T "$TARGET_DIR/chromedriver_linux64" "$TARGET_DIR/chromedriver" - -export CHROME_EXECUTABLE="$TARGET_DIR/chrome-linux/chrome" +unzip -q "$DRIVER_ZIP_FILE" -d "$CHROME_DOWNLOAD_DIR/" +# Rename CHROME_DOWNLOAD_DIR/chromedriver_linux64 to the expected CHROME_DOWNLOAD_DIR/chromedriver +mv -T "$CHROME_DOWNLOAD_DIR/chromedriver_linux64" "$CHROME_DOWNLOAD_DIR/chromedriver" # Echo info at the end for ease of debugging. +# +# exports from this script cannot be used elsewhere in the .cirrus.yml file. set +x echo -readonly CHROMEDRIVER_EXECUTABLE="$TARGET_DIR/chromedriver/chromedriver" echo "$CHROME_EXECUTABLE" "$CHROME_EXECUTABLE" --version echo "$CHROMEDRIVER_EXECUTABLE" diff --git a/script/install_chromium_for_benchmarks.sh b/script/install_chromium_for_benchmarks.sh deleted file mode 100755 index 8e6505dd310f..000000000000 --- a/script/install_chromium_for_benchmarks.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/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. -set -e -set -x - -# TODO(stuartmorgan): merge this with install_chromium.sh - -# The build of Chromium used to test web functionality. -# -# Chromium builds can be located here: https://commondatastorage.googleapis.com/chromium-browser-snapshots/index.html?prefix=Linux_x64/ -# -# Set CHROMIUM_BUILD env-var to let the script know what to download. - -: "${CHROMIUM_BUILD:=950363}" # Default value for the CHROMIUM_BUILD env. -echo "Downloading CHROMIUM_BUILD=${CHROMIUM_BUILD}" - -mkdir .chromium -wget "https://www.googleapis.com/download/storage/v1/b/chromium-browser-snapshots/o/Linux_x64%2F${CHROMIUM_BUILD}%2Fchrome-linux.zip?alt=media" -O .chromium/chromium.zip -unzip .chromium/chromium.zip -d .chromium/ -export CHROME_EXECUTABLE=$(pwd)/.chromium/chrome-linux/chrome -echo $CHROME_EXECUTABLE -$CHROME_EXECUTABLE --version