From 538d967f7cacaf647c406e10fdf2b7c66a090f15 Mon Sep 17 00:00:00 2001 From: "zijiehe@" <68449066+zijiehe-google-com@users.noreply.github.com> Date: Thu, 25 Jan 2024 03:58:03 -0800 Subject: [PATCH] [Fuchsia] Redo - Use chromium test-scripts to download images and execute tests (flutter/engine#49940) This change is a redo of https://github.com/flutter/engine/pull/49847. https://github.com/zijiehe-google-com/engine/compare/4530942..main should show the diff between this and the original change; mainly fixes the https://github.com/flutter/flutter/issues/141907. Following paragraph is copied from the original change. This change can be executed from buildroot by ``` python3 flutter/tools/fuchsia/with_envs.py flutter/testing/fuchsia/run_tests.py ``` Bug: https://github.com/flutter/flutter/issues/140179 - [V] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [V] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [V] I read and followed the [Flutter Style Guide] and the [C++, Objective-C, Java style guides]. - [V] I listed at least one issue that this PR fixes in the description above. - [V] I added new tests to check the change I am making or feature I am adding, or the PR is [test-exempt]. See [testing the engine] for instructions on writing and running engine tests. - [V] I updated/added relevant documentation (doc comments with `///`). - [V] I signed the [CLA]. - [V] All existing and new tests are passing. --- DEPS | 32 +++++++++- engine/src/flutter/.ci.yaml | 2 + engine/src/flutter/.gitignore | 3 + .../flutter/ci/builders/linux_fuchsia.json | 16 ++++- .../src/flutter/testing/fuchsia/run_tests.py | 59 +++++++++++++++++++ engine/src/flutter/tools/fuchsia/with_envs.py | 54 +++++++++++++++++ 6 files changed, 162 insertions(+), 4 deletions(-) create mode 100755 engine/src/flutter/testing/fuchsia/run_tests.py create mode 100644 engine/src/flutter/tools/fuchsia/with_envs.py diff --git a/DEPS b/DEPS index d0ce99c3c2..362539660d 100644 --- a/DEPS +++ b/DEPS @@ -109,6 +109,9 @@ vars = { # local development. 'download_fuchsia_sdk': False, 'fuchsia_sdk_path': '', + # Whether to download and run the Fuchsia emulator locally to test Fuchsia + # builds. + 'run_fuchsia_emu': False, # An LLVM backend needs LLVM binaries and headers. To avoid build time # increases we can use prebuilts. We don't want to download this on every @@ -247,6 +250,11 @@ vars = { "upstream_yaml": "https://github.com/dart-lang/yaml.git", "upstream_yapf": "https://github.com/google/yapf.git", "upstream_zlib": "https://github.com/madler/zlib.git", + + # The version / instance id of the cipd:chromium/fuchsia/test-scripts which + # will be used altogether with fuchsia-sdk to setup the build / test + # environment. + 'fuchsia_test_scripts_version': 'MXOVCk7s_1bZ8hJZ5M5DgS_9i8FeSjYojkSGY8zpnxQC', } gclient_gn_args_file = 'src/third_party/dart/build/config/gclient_args.gni' @@ -976,7 +984,7 @@ deps = { # Get the SDK from https://chrome-infra-packages.appspot.com/p/fuchsia/sdk/core at the 'latest' tag # Get the toolchain from https://chrome-infra-packages.appspot.com/p/fuchsia/clang at the 'goma' tag - 'src/fuchsia/sdk/linux': { + 'src/fuchsia/sdk/linux': { 'packages': [ { 'package': 'fuchsia/sdk/core/linux-amd64', @@ -987,6 +995,17 @@ deps = { 'dep_type': 'cipd', }, + 'src/flutter/tools/fuchsia/test_scripts': { + 'packages': [ + { + 'package': 'chromium/fuchsia/test-scripts', + 'version': Var('fuchsia_test_scripts_version'), + } + ], + 'condition': 'run_fuchsia_emu', + 'dep_type': 'cipd', + }, + 'src/third_party/impeller-cmake-example': { 'url': Var('flutter_git') + '/third_party/impeller-cmake-example.git' + '@' + 'd1a26a51dc6890e5f851749e3d8e048703f24f51', 'condition': 'download_impeller_cmake_example', @@ -1148,5 +1167,16 @@ hooks = [ 'third_party/impeller-cmake-example', '--setup', ] + }, + { + 'name': 'Download Fuchsia system images', + 'pattern': '.', + 'condition': 'run_fuchsia_emu', + 'action': [ + 'python3', + 'src/flutter/tools/fuchsia/with_envs.py', + 'src/flutter/tools/fuchsia/test_scripts/update_product_bundles.py', + 'terminal.x64', + ] } ] diff --git a/engine/src/flutter/.ci.yaml b/engine/src/flutter/.ci.yaml index 487a0a6add..37aaf3daad 100644 --- a/engine/src/flutter/.ci.yaml +++ b/engine/src/flutter/.ci.yaml @@ -198,6 +198,8 @@ targets: config_name: linux_fuchsia drone_dimensions: - os=Linux + dimensions: + kvm: "1" # TODO(https://github.com/flutter/flutter/issues/138559): Re-enable/delete. # runIfNot: # - lib/web_ui/** diff --git a/engine/src/flutter/.gitignore b/engine/src/flutter/.gitignore index 59a4590b1a..e589f08937 100644 --- a/engine/src/flutter/.gitignore +++ b/engine/src/flutter/.gitignore @@ -136,3 +136,6 @@ app.*.symbols # RBE support configurations and scripts vended from CIPD /build/rbe + +# The test-scripts from Chromium and managed by DEPS and gclient. +/tools/fuchsia/test_scripts diff --git a/engine/src/flutter/ci/builders/linux_fuchsia.json b/engine/src/flutter/ci/builders/linux_fuchsia.json index 6388b1e9b1..011a13618a 100644 --- a/engine/src/flutter/ci/builders/linux_fuchsia.json +++ b/engine/src/flutter/ci/builders/linux_fuchsia.json @@ -77,7 +77,7 @@ { "name": "Upload to Symbol Server for arch: arm64", "language": "python3", - "contexts": ["depot_tools_on_path"], + "contexts": ["depot_tools_on_path"], "script": "flutter/tools/fuchsia/upload_to_symbol_server.py", "parameters": [ "--symbol-dir", @@ -138,10 +138,12 @@ { "drone_dimensions": [ "device_type=none", + "kvm=1", "os=Linux" ], "gclient_variables": { - "download_android_deps": false + "download_android_deps": false, + "run_fuchsia_emu": true }, "gn": [ "--fuchsia", @@ -163,7 +165,7 @@ { "name": "Upload to Symbol Server for arch: x64", "language": "python3", - "contexts": ["depot_tools_on_path"], + "contexts": ["depot_tools_on_path"], "script": "flutter/tools/fuchsia/upload_to_symbol_server.py", "parameters": [ "--symbol-dir", @@ -172,6 +174,14 @@ "${REVISION}", "--upload" ] + }, + { + "name": "x64 emulator based tests", + "language": "python3", + "script": "flutter/tools/fuchsia/with_envs.py", + "parameters": [ + "testing/fuchsia/run_tests.py" + ] } ] } diff --git a/engine/src/flutter/testing/fuchsia/run_tests.py b/engine/src/flutter/testing/fuchsia/run_tests.py new file mode 100755 index 0000000000..2a301c8282 --- /dev/null +++ b/engine/src/flutter/testing/fuchsia/run_tests.py @@ -0,0 +1,59 @@ +#!/usr/bin/env python3 +# Copyright (c) 2013, the Flutter project authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be found +# in the LICENSE file. + +import argparse +import os +import sys + +# The imports are coming from fuchsia/test_scripts and pylint cannot find them +# without setting a global init-hook which is less favorable. +# But this file will be executed as part of the CI, its correctness of importing +# is guaranteed. + +sys.path.insert( + 0, + os.path.join( + os.path.dirname(__file__), '../../tools/fuchsia/test_scripts/test/' + ) +) + +# pylint: disable=import-error, wrong-import-position +import run_test +from common import DIR_SRC_ROOT +from run_executable_test import ExecutableTestRunner +from test_runner import TestRunner + +# TODO(https://github.com/flutter/flutter/issues/140179): Respect build +# configurations. +OUT_DIR = os.path.join(DIR_SRC_ROOT, 'out/fuchsia_debug_x64') + + +# TODO(https://github.com/flutter/flutter/issues/140179): Execute all the tests +# in +# https://github.com/flutter/engine/blob/main/testing/fuchsia/test_suites.yaml +# and avoid hardcoded paths. +def _get_test_runner(runner_args: argparse.Namespace, *_) -> TestRunner: + return ExecutableTestRunner( + OUT_DIR, [], + 'fuchsia-pkg://fuchsia.com/dart_runner_tests#meta/dart_runner_tests.cm', + runner_args.target_id, None, '/tmp/log', + [os.path.join(OUT_DIR, 'dart_runner_tests.far')], None + ) + + +if __name__ == '__main__': + try: + os.remove(os.path.join(OUT_DIR, 'dart_runner_tests.far')) + except FileNotFoundError: + pass + os.symlink( + 'dart_runner_tests-0.far', os.path.join(OUT_DIR, 'dart_runner_tests.far') + ) + sys.argv.append('--out-dir=' + OUT_DIR) + # The 'flutter-test-type' is a place holder and has no specific meaning; the + # _get_test_runner is overrided. + sys.argv.append('flutter-test-type') + run_test._get_test_runner = _get_test_runner # pylint: disable=protected-access + sys.exit(run_test.main()) diff --git a/engine/src/flutter/tools/fuchsia/with_envs.py b/engine/src/flutter/tools/fuchsia/with_envs.py new file mode 100644 index 0000000000..5dc951dd1c --- /dev/null +++ b/engine/src/flutter/tools/fuchsia/with_envs.py @@ -0,0 +1,54 @@ +#!/usr/bin/env python3 +# Copyright (c) 2013, the Flutter project authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be found +# in the LICENSE file. + +import os +import platform +import subprocess +import sys + +sys.path.insert( + 0, + os.path.abspath( + os.path.join(os.path.dirname(__file__), 'test_scripts/test/') + ) +) + +from common import catch_sigterm, wait_for_sigterm + + +def Main(): + """ + Executes the test-scripts with required environment variables. It acts like + /usr/bin/env, but provides some extra functionality to dynamically set up + the environment variables. + """ + # Ensures the signals can be correctly forwarded to the subprocesses. + catch_sigterm() + + os.environ['SRC_ROOT'] = os.path.abspath( + os.path.join(os.path.dirname(__file__), '../../../') + ) + # Flutter uses a different repo structure and fuchsia sdk is not in the + # third_party/, so images root and sdk root need to be explicitly set. + os.environ['FUCHSIA_IMAGES_ROOT'] = os.path.join( + os.environ['SRC_ROOT'], 'fuchsia/images/' + ) + + assert platform.system() == 'Linux', 'Unsupported OS ' + platform.system() + os.environ['FUCHSIA_SDK_ROOT'] = os.path.join( + os.environ['SRC_ROOT'], 'fuchsia/sdk/linux/' + ) + + with subprocess.Popen(sys.argv[1:]) as proc: + try: + proc.wait() + except: + # Use terminate / SIGTERM to allow the subprocess exiting cleanly. + proc.terminate() + return proc.returncode + + +if __name__ == '__main__': + sys.exit(Main())