Skip to content

Commit

Permalink
[fuchsia] Use BundledTestRunner from test-scripts (flutter#54404)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
zijiehe-google-com authored Aug 13, 2024
1 parent 019f9e3 commit cd1e0d9
Showing 1 changed file with 16 additions and 53 deletions.
69 changes: 16 additions & 53 deletions testing/fuchsia/run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -33,10 +31,9 @@
)

# 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]
Expand All @@ -48,36 +45,6 @@
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()
Expand Down Expand Up @@ -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,
Expand All @@ -131,21 +105,10 @@ def variant(test) -> bool:
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())

0 comments on commit cd1e0d9

Please sign in to comment.