[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
This commit is contained in:
parent
c20915566d
commit
ed3b8da5e8
@ -12,13 +12,11 @@
|
|||||||
# Use of this source code is governed by a BSD-style license that can be found
|
# Use of this source code is governed by a BSD-style license that can be found
|
||||||
# in the LICENSE file.
|
# in the LICENSE file.
|
||||||
|
|
||||||
import argparse
|
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from subprocess import CompletedProcess
|
from typing import Any, Iterable, List, Mapping, Set
|
||||||
from typing import Any, Iterable, List, Mapping, NamedTuple, Set
|
|
||||||
|
|
||||||
# The import is coming from vpython wheel and pylint cannot find it.
|
# The import is coming from vpython wheel and pylint cannot find it.
|
||||||
import yaml # pylint: disable=import-error
|
import yaml # pylint: disable=import-error
|
||||||
@ -33,10 +31,9 @@ sys.path.insert(
|
|||||||
)
|
)
|
||||||
|
|
||||||
# pylint: disable=import-error, wrong-import-position
|
# 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 common import DIR_SRC_ROOT
|
||||||
from run_executable_test import ExecutableTestRunner
|
from compatible_utils import force_running_unattended
|
||||||
from test_runner import TestRunner
|
|
||||||
|
|
||||||
if len(sys.argv) == 2:
|
if len(sys.argv) == 2:
|
||||||
VARIANT = sys.argv[1]
|
VARIANT = sys.argv[1]
|
||||||
@ -48,36 +45,6 @@ else:
|
|||||||
OUT_DIR = os.path.join(DIR_SRC_ROOT, 'out', VARIANT)
|
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
|
# Visible for testing
|
||||||
def resolve_packages(tests: Iterable[Mapping[str, Any]]) -> Set[str]:
|
def resolve_packages(tests: Iterable[Mapping[str, Any]]) -> Set[str]:
|
||||||
packages = set()
|
packages = set()
|
||||||
@ -121,8 +88,15 @@ def build_test_cases(tests: Iterable[Mapping[str, Any]]) -> List[TestCase]:
|
|||||||
return test_cases
|
return test_cases
|
||||||
|
|
||||||
|
|
||||||
def _bundled_test_runner_of(target_id: str) -> _BundledTestRunner:
|
def main() -> int:
|
||||||
log_dir = os.environ.get('FLUTTER_LOGS_DIR', '/tmp/log')
|
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:
|
with open(os.path.join(os.path.dirname(__file__), 'test_suites.yaml'), 'r') as file:
|
||||||
tests = yaml.safe_load(file)
|
tests = yaml.safe_load(file)
|
||||||
# TODO(zijiehe-google-com): Run all tests in release build,
|
# 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
|
return 'variant' not in test or test['variant'] in VARIANT
|
||||||
|
|
||||||
tests = [t for t in tests if variant(t)]
|
tests = [t for t in tests if variant(t)]
|
||||||
return _BundledTestRunner(target_id, resolve_packages(tests), build_test_cases(tests), log_dir)
|
for package in resolve_packages(tests):
|
||||||
|
sys.argv.append('--packages=' + package)
|
||||||
|
return run_tests(build_test_cases(tests))
|
||||||
def _get_test_runner(runner_args: argparse.Namespace, *_) -> TestRunner:
|
|
||||||
return _bundled_test_runner_of(runner_args.target_id)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
logging.basicConfig(level=logging.INFO)
|
sys.exit(main())
|
||||||
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())
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user