Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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())