From ed3b8da5e81ff73d16a6870e900e8524ffbb054b Mon Sep 17 00:00:00 2001 From: "zijiehe@" <68449066+zijiehe-google-com@users.noreply.github.com> Date: Tue, 13 Aug 2024 13:55:33 -0700 Subject: [PATCH] [fuchsia] Use BundledTestRunner from test-scripts (flutter/engine#54404) The BundledTestRunner has been moved to chromium already, flutter can now use it without needing to reimplement the same logic. The logic of parsing yaml file is still flutter specific and keeps as-is. Bug: http://crbug.com/356463343 [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style --- .../src/flutter/testing/fuchsia/run_tests.py | 69 +++++-------------- 1 file changed, 16 insertions(+), 53 deletions(-) diff --git a/engine/src/flutter/testing/fuchsia/run_tests.py b/engine/src/flutter/testing/fuchsia/run_tests.py index f315a6887c..b289ad5fb4 100755 --- a/engine/src/flutter/testing/fuchsia/run_tests.py +++ b/engine/src/flutter/testing/fuchsia/run_tests.py @@ -12,13 +12,11 @@ # Use of this source code is governed by a BSD-style license that can be found # in the LICENSE file. -import argparse import logging import os import sys -from subprocess import CompletedProcess -from typing import Any, Iterable, List, Mapping, NamedTuple, Set +from typing import Any, Iterable, List, Mapping, Set # The import is coming from vpython wheel and pylint cannot find it. import yaml # pylint: disable=import-error @@ -33,10 +31,9 @@ sys.path.insert( ) # pylint: disable=import-error, wrong-import-position -import run_test +from bundled_test_runner import run_tests, TestCase from common import DIR_SRC_ROOT -from run_executable_test import ExecutableTestRunner -from test_runner import TestRunner +from compatible_utils import force_running_unattended if len(sys.argv) == 2: VARIANT = sys.argv[1] @@ -48,36 +45,6 @@ else: OUT_DIR = os.path.join(DIR_SRC_ROOT, 'out', VARIANT) -# Visible for testing -class TestCase(NamedTuple): - package: str - args: str = '' - - -class _BundledTestRunner(TestRunner): - - # private, use bundled_test_runner_of function instead. - def __init__(self, target_id: str, package_deps: Set[str], tests: List[TestCase], logs_dir: str): - super().__init__(OUT_DIR, [], None, target_id, list(package_deps)) - self.tests = tests - self.logs_dir = logs_dir - - def run_test(self) -> CompletedProcess: - returncode = 0 - for test in self.tests: - assert test.package.endswith('.cm') - test_runner = ExecutableTestRunner( - OUT_DIR, test.args.split(), test.package, self._target_id, None, self.logs_dir, [], None - ) - # pylint: disable=protected-access - test_runner._package_deps = self._package_deps - result = test_runner.run_test().returncode - logging.info('Result of test %s is %s', test, result) - if result != 0: - returncode = result - return CompletedProcess(args='', returncode=returncode) - - # Visible for testing def resolve_packages(tests: Iterable[Mapping[str, Any]]) -> Set[str]: packages = set() @@ -121,8 +88,15 @@ def build_test_cases(tests: Iterable[Mapping[str, Any]]) -> List[TestCase]: return test_cases -def _bundled_test_runner_of(target_id: str) -> _BundledTestRunner: - log_dir = os.environ.get('FLUTTER_LOGS_DIR', '/tmp/log') +def main() -> int: + logging.basicConfig(level=logging.INFO) + logging.info('Running tests in %s', OUT_DIR) + force_running_unattended() + sys.argv.append('--out-dir=' + OUT_DIR) + if VARIANT.endswith('_arm64') or VARIANT.endswith('_arm64_tester'): + sys.argv.append('--product=terminal.qemu-arm64') + + sys.argv.append('--logs-dir=' + os.environ.get('FLUTTER_LOGS_DIR', '/tmp/log')) with open(os.path.join(os.path.dirname(__file__), 'test_suites.yaml'), 'r') as file: tests = yaml.safe_load(file) # TODO(zijiehe-google-com): Run all tests in release build, @@ -131,21 +105,10 @@ def _bundled_test_runner_of(target_id: str) -> _BundledTestRunner: return 'variant' not in test or test['variant'] in VARIANT tests = [t for t in tests if variant(t)] - return _BundledTestRunner(target_id, resolve_packages(tests), build_test_cases(tests), log_dir) - - -def _get_test_runner(runner_args: argparse.Namespace, *_) -> TestRunner: - return _bundled_test_runner_of(runner_args.target_id) + for package in resolve_packages(tests): + sys.argv.append('--packages=' + package) + return run_tests(build_test_cases(tests)) if __name__ == '__main__': - logging.basicConfig(level=logging.INFO) - logging.info('Running tests in %s', OUT_DIR) - sys.argv.append('--out-dir=' + OUT_DIR) - if VARIANT.endswith('_arm64') or VARIANT.endswith('_arm64_tester'): - sys.argv.append('--product=terminal.qemu-arm64') - # 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()) + sys.exit(main())