From 196197bba0a208cefc18e4f63ab757d6d1795b99 Mon Sep 17 00:00:00 2001 From: Hzj_jie Date: Thu, 8 Feb 2024 14:01:06 -0800 Subject: [PATCH 01/18] test filter --- testing/fuchsia/run_tests.py | 80 +++++++++++++++++++++++------------- 1 file changed, 51 insertions(+), 29 deletions(-) diff --git a/testing/fuchsia/run_tests.py b/testing/fuchsia/run_tests.py index e99c722f68262..b8d7697c5913b 100755 --- a/testing/fuchsia/run_tests.py +++ b/testing/fuchsia/run_tests.py @@ -18,7 +18,7 @@ import sys from subprocess import CompletedProcess -from typing import List, Set +from typing import Any, List, NamedTuple, Set # The import is coming from vpython wheel and pylint cannot find it. import yaml # pylint: disable=import-error @@ -51,11 +51,16 @@ OUT_DIR = os.path.join(DIR_SRC_ROOT, 'out', VARIANT) +class TestCase(NamedTuple): + package: str = None + 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[str], + self, target_id: str, package_deps: Set[str], tests: List[TestCase], logs_dir: str ): super().__init__(OUT_DIR, [], None, target_id, list(package_deps)) @@ -67,7 +72,7 @@ def run_test(self) -> CompletedProcess: for test in self.tests: # pylint: disable=protected-access test_runner = ExecutableTestRunner( - OUT_DIR, [], test, self._target_id, None, self.logs_dir, [], None + OUT_DIR, test.args.split(), test.package, self._target_id, None, self.logs_dir, [], None ) test_runner._package_deps = self._package_deps result = test_runner.run_test().returncode @@ -77,6 +82,47 @@ def run_test(self) -> CompletedProcess: return CompletedProcess(args='', returncode=returncode) +def extract_packages(tests: List[Any]) -> Set[str]: + packages = set() + for test in tests: + if 'package' in test: + packages.add(test['package']) + else: + assert 'packages' in test, \ + 'Expect either one package or a list of packages' + packages.update(test['packages']) + resolved_packages = set() + for package in packages: + if package.endswith('-0.far'): + # Make a symbolic link to match the name of the package itself without the + # '-0.far' suffix. + new_package = os.path.join(OUT_DIR, package.replace('-0.far', '.far')) + try: + # Remove the old one if it exists, usually happen on the devbox, so + # ignore the FileNotFoundError. + os.remove(new_package) + except FileNotFoundError: + pass + os.symlink(package, new_package) + resolved_packages.add(new_package) + else: + resolved_packages.add(os.path.join(OUT_DIR, package)) + return resolved_packages + + +def build_test_cases(tests: List[Any]) -> List[TestCase]: + test_cases = [] + for test in tests: + assert test.startswith('test run ') + test = test[len('test run '):] + if ' -- ' in test: + index = test.index(' -- ') + test_cases.append(TestCase(package=test[:index], args=test[index + len(' -- '):])) + else: + test_cases.append(TestCase(package=test)) + return test_cases + + def bundled_test_runner_of(target_id: str) -> BundledTestRunner: log_dir = os.environ.get('FLUTTER_LOGS_DIR', '/tmp/log') with open(os.path.join(os.path.dirname(__file__), 'test_suites.yaml'), @@ -104,33 +150,9 @@ def bundled_test_runner_of(target_id: str) -> BundledTestRunner: tests ) ) - packages = set() - for test in tests: - if 'package' in test: - packages.add(test['package']) - else: - assert 'packages' in test, \ - 'Expect either one package or a list of packages' - packages.update(test['packages']) - resolved_packages = set() - for package in packages: - if package.endswith('-0.far'): - # Make a symbolic link to match the name of the package itself without the - # '-0.far' suffix. - new_package = os.path.join(OUT_DIR, package.replace('-0.far', '.far')) - try: - # Remove the old one if it exists, usually happen on the devbox, so - # ignore the FileNotFoundError. - os.remove(new_package) - except FileNotFoundError: - pass - os.symlink(package, new_package) - resolved_packages.add(new_package) - else: - resolved_packages.add(os.path.join(OUT_DIR, package)) return BundledTestRunner( - target_id, resolved_packages, - [test['test_command'][len('test run '):] for test in tests], log_dir + target_id, extract_packages(tests), + build_test_cases(tests), log_dir ) From 43cda29823a19a9a6b659b0ba35a3ee22b46eed4 Mon Sep 17 00:00:00 2001 From: Hzj_jie Date: Thu, 8 Feb 2024 14:01:19 -0800 Subject: [PATCH 02/18] format --- testing/fuchsia/run_tests.py | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/testing/fuchsia/run_tests.py b/testing/fuchsia/run_tests.py index b8d7697c5913b..691634597698f 100755 --- a/testing/fuchsia/run_tests.py +++ b/testing/fuchsia/run_tests.py @@ -52,8 +52,8 @@ class TestCase(NamedTuple): - package: str = None - args: str = '' + package: str = None + args: str = '' class BundledTestRunner(TestRunner): @@ -72,7 +72,8 @@ def run_test(self) -> CompletedProcess: for test in self.tests: # pylint: disable=protected-access test_runner = ExecutableTestRunner( - OUT_DIR, test.args.split(), test.package, self._target_id, None, self.logs_dir, [], None + OUT_DIR, test.args.split(), test.package, self._target_id, None, + self.logs_dir, [], None ) test_runner._package_deps = self._package_deps result = test_runner.run_test().returncode @@ -113,13 +114,15 @@ def extract_packages(tests: List[Any]) -> Set[str]: def build_test_cases(tests: List[Any]) -> List[TestCase]: test_cases = [] for test in tests: - assert test.startswith('test run ') - test = test[len('test run '):] - if ' -- ' in test: - index = test.index(' -- ') - test_cases.append(TestCase(package=test[:index], args=test[index + len(' -- '):])) - else: - test_cases.append(TestCase(package=test)) + assert test.startswith('test run ') + test = test[len('test run '):] + if ' -- ' in test: + index = test.index(' -- ') + test_cases.append( + TestCase(package=test[:index], args=test[index + len(' -- '):]) + ) + else: + test_cases.append(TestCase(package=test)) return test_cases @@ -151,8 +154,7 @@ def bundled_test_runner_of(target_id: str) -> BundledTestRunner: ) ) return BundledTestRunner( - target_id, extract_packages(tests), - build_test_cases(tests), log_dir + target_id, extract_packages(tests), build_test_cases(tests), log_dir ) From e3063aff1361d28697fa10a5f686154bc57f8078 Mon Sep 17 00:00:00 2001 From: Hzj_jie Date: Thu, 8 Feb 2024 15:28:46 -0800 Subject: [PATCH 03/18] Run tests with extra test arguments --- testing/fuchsia/run_tests.py | 19 ++++++------------- testing/fuchsia/test_suites.yaml | 1 + 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/testing/fuchsia/run_tests.py b/testing/fuchsia/run_tests.py index 691634597698f..0a1cf557a08f5 100755 --- a/testing/fuchsia/run_tests.py +++ b/testing/fuchsia/run_tests.py @@ -70,11 +70,12 @@ def __init__( def run_test(self) -> CompletedProcess: returncode = 0 for test in self.tests: - # pylint: disable=protected-access + 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) @@ -83,7 +84,7 @@ def run_test(self) -> CompletedProcess: return CompletedProcess(args='', returncode=returncode) -def extract_packages(tests: List[Any]) -> Set[str]: +def resolve_packages(tests: List[Any]) -> Set[str]: packages = set() for test in tests: if 'package' in test: @@ -111,9 +112,9 @@ def extract_packages(tests: List[Any]) -> Set[str]: return resolved_packages -def build_test_cases(tests: List[Any]) -> List[TestCase]: +def build_test_cases(tests: dict) -> List[TestCase]: test_cases = [] - for test in tests: + for test in [t['test_command'] for t in tests]: assert test.startswith('test run ') test = test[len('test run '):] if ' -- ' in test: @@ -131,14 +132,6 @@ def bundled_test_runner_of(target_id: str) -> BundledTestRunner: 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 tests with extra test arguments, - # https://github.com/flutter/flutter/issues/140179. - tests = list( - filter( - lambda test: test['test_command'].startswith('test run ') and test[ - 'test_command'].endswith('.cm'), tests - ) - ) # TODO(zijiehe-google-com): Run tests with dart aot, # https://github.com/flutter/flutter/issues/140179. tests = list( @@ -154,7 +147,7 @@ def bundled_test_runner_of(target_id: str) -> BundledTestRunner: ) ) return BundledTestRunner( - target_id, extract_packages(tests), build_test_cases(tests), log_dir + target_id, resolve_packages(tests), build_test_cases(tests), log_dir ) diff --git a/testing/fuchsia/test_suites.yaml b/testing/fuchsia/test_suites.yaml index e1ed249563b6d..c315a8aadf8cd 100644 --- a/testing/fuchsia/test_suites.yaml +++ b/testing/fuchsia/test_suites.yaml @@ -27,6 +27,7 @@ package: testing_tests-0.far - test_command: test run fuchsia-pkg://fuchsia.com/txt_tests#meta/txt_tests.cm -- --gtest_filter=-ParagraphTest.* package: txt_tests-0.far + variant: fuchsia_debug_x64 - test_command: test run fuchsia-pkg://fuchsia.com/ui_tests#meta/ui_tests.cm package: ui_tests-0.far variant: fuchsia_debug_x64 From 1b8f2f436bf85888725ae4606ad70f8205358f58 Mon Sep 17 00:00:00 2001 From: Hzj_jie Date: Mon, 12 Feb 2024 12:20:47 -0800 Subject: [PATCH 04/18] address review comments --- testing/fuchsia/run_tests.py | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/testing/fuchsia/run_tests.py b/testing/fuchsia/run_tests.py index 0a1cf557a08f5..71b241e5a32a6 100755 --- a/testing/fuchsia/run_tests.py +++ b/testing/fuchsia/run_tests.py @@ -18,7 +18,7 @@ import sys from subprocess import CompletedProcess -from typing import Any, List, NamedTuple, Set +from typing import Any, Iterable, List, Mapping, NamedTuple, Set # The import is coming from vpython wheel and pylint cannot find it. import yaml # pylint: disable=import-error @@ -52,7 +52,7 @@ class TestCase(NamedTuple): - package: str = None + package: str args: str = '' @@ -84,7 +84,7 @@ def run_test(self) -> CompletedProcess: return CompletedProcess(args='', returncode=returncode) -def resolve_packages(tests: List[Any]) -> Set[str]: +def resolve_packages(tests: Iterable[Mapping[str, Any]]) -> Set[str]: packages = set() for test in tests: if 'package' in test: @@ -112,16 +112,14 @@ def resolve_packages(tests: List[Any]) -> Set[str]: return resolved_packages -def build_test_cases(tests: dict) -> List[TestCase]: +def build_test_cases(tests: Iterable[Mapping[str, Any]]) -> List[TestCase]: test_cases = [] for test in [t['test_command'] for t in tests]: assert test.startswith('test run ') test = test[len('test run '):] if ' -- ' in test: - index = test.index(' -- ') - test_cases.append( - TestCase(package=test[:index], args=test[index + len(' -- '):]) - ) + package, args = test.split(' -- ', 1) + test_cases.append(TestCase(package=package, args=args)) else: test_cases.append(TestCase(package=test)) return test_cases @@ -134,18 +132,13 @@ def bundled_test_runner_of(target_id: str) -> BundledTestRunner: tests = yaml.safe_load(file) # TODO(zijiehe-google-com): Run tests with dart aot, # https://github.com/flutter/flutter/issues/140179. - tests = list( - filter( - lambda test: 'run_with_dart_aot' not in test or test[ - 'run_with_dart_aot'] != 'true', tests - ) - ) - tests = list( - filter( - lambda test: 'variant' not in test or VARIANT == test['variant'], - tests - ) - ) + def dart_jit(test) -> bool: + return 'run_with_dart_aot' not in test or test['run_with_dart_aot'] != 'true' + # TODO(zijiehe-google-com): Run all tests in release build, + # https://github.com/flutter/flutter/issues/140179. + def variant(test) -> bool: + return 'variant' not in test or test['variant'] == VARIANT + tests = [t for t in tests if dart_jit(t) and variant(t)] return BundledTestRunner( target_id, resolve_packages(tests), build_test_cases(tests), log_dir ) From b122d5a0e1369f8ced1940535fb688fa5f4c455c Mon Sep 17 00:00:00 2001 From: Hzj_jie Date: Mon, 12 Feb 2024 12:21:16 -0800 Subject: [PATCH 05/18] format --- testing/fuchsia/run_tests.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/testing/fuchsia/run_tests.py b/testing/fuchsia/run_tests.py index 71b241e5a32a6..a7d6f7b7a6ae9 100755 --- a/testing/fuchsia/run_tests.py +++ b/testing/fuchsia/run_tests.py @@ -134,10 +134,12 @@ def bundled_test_runner_of(target_id: str) -> BundledTestRunner: # https://github.com/flutter/flutter/issues/140179. def dart_jit(test) -> bool: return 'run_with_dart_aot' not in test or test['run_with_dart_aot'] != 'true' + # TODO(zijiehe-google-com): Run all tests in release build, # https://github.com/flutter/flutter/issues/140179. def variant(test) -> bool: return 'variant' not in test or test['variant'] == VARIANT + tests = [t for t in tests if dart_jit(t) and variant(t)] return BundledTestRunner( target_id, resolve_packages(tests), build_test_cases(tests), log_dir From b878c85e48c128491e52e29cafd1dfcf221396bc Mon Sep 17 00:00:00 2001 From: Hzj_jie Date: Mon, 12 Feb 2024 12:21:41 -0800 Subject: [PATCH 06/18] format --- testing/fuchsia/run_tests.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/testing/fuchsia/run_tests.py b/testing/fuchsia/run_tests.py index a7d6f7b7a6ae9..b57d1e1a782c0 100755 --- a/testing/fuchsia/run_tests.py +++ b/testing/fuchsia/run_tests.py @@ -133,7 +133,8 @@ def bundled_test_runner_of(target_id: str) -> BundledTestRunner: # TODO(zijiehe-google-com): Run tests with dart aot, # https://github.com/flutter/flutter/issues/140179. def dart_jit(test) -> bool: - return 'run_with_dart_aot' not in test or test['run_with_dart_aot'] != 'true' + return 'run_with_dart_aot' not in test or + test['run_with_dart_aot'] != 'true' # TODO(zijiehe-google-com): Run all tests in release build, # https://github.com/flutter/flutter/issues/140179. From c0262262067fb3a2d40e8aa673f66387eb08bbcd Mon Sep 17 00:00:00 2001 From: Hzj_jie Date: Mon, 12 Feb 2024 12:22:05 -0800 Subject: [PATCH 07/18] format --- testing/fuchsia/run_tests.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/testing/fuchsia/run_tests.py b/testing/fuchsia/run_tests.py index b57d1e1a782c0..9499903d8bf97 100755 --- a/testing/fuchsia/run_tests.py +++ b/testing/fuchsia/run_tests.py @@ -133,8 +133,8 @@ def bundled_test_runner_of(target_id: str) -> BundledTestRunner: # TODO(zijiehe-google-com): Run tests with dart aot, # https://github.com/flutter/flutter/issues/140179. def dart_jit(test) -> bool: - return 'run_with_dart_aot' not in test or - test['run_with_dart_aot'] != 'true' + return 'run_with_dart_aot' not in test or test[ + 'run_with_dart_aot'] != 'true' # TODO(zijiehe-google-com): Run all tests in release build, # https://github.com/flutter/flutter/issues/140179. From 41e1ed7ba70df3847b37a9978e48fe44c81c2fa9 Mon Sep 17 00:00:00 2001 From: Hzj_jie Date: Mon, 12 Feb 2024 12:22:23 -0800 Subject: [PATCH 08/18] format --- testing/fuchsia/run_tests.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/testing/fuchsia/run_tests.py b/testing/fuchsia/run_tests.py index 9499903d8bf97..a7d6f7b7a6ae9 100755 --- a/testing/fuchsia/run_tests.py +++ b/testing/fuchsia/run_tests.py @@ -133,8 +133,7 @@ def bundled_test_runner_of(target_id: str) -> BundledTestRunner: # TODO(zijiehe-google-com): Run tests with dart aot, # https://github.com/flutter/flutter/issues/140179. def dart_jit(test) -> bool: - return 'run_with_dart_aot' not in test or test[ - 'run_with_dart_aot'] != 'true' + return 'run_with_dart_aot' not in test or test['run_with_dart_aot'] != 'true' # TODO(zijiehe-google-com): Run all tests in release build, # https://github.com/flutter/flutter/issues/140179. From f5e4c19f7780cf38650f35b41b1711cb87d252c8 Mon Sep 17 00:00:00 2001 From: Hzj_jie Date: Mon, 12 Feb 2024 12:23:02 -0800 Subject: [PATCH 09/18] format --- testing/fuchsia/run_tests.py | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/testing/fuchsia/run_tests.py b/testing/fuchsia/run_tests.py index a7d6f7b7a6ae9..f9e6e1359a34e 100755 --- a/testing/fuchsia/run_tests.py +++ b/testing/fuchsia/run_tests.py @@ -29,10 +29,7 @@ # is guaranteed. sys.path.insert( - 0, - os.path.join( - os.path.dirname(__file__), '../../tools/fuchsia/test_scripts/test/' - ) + 0, os.path.join(os.path.dirname(__file__), '../../tools/fuchsia/test_scripts/test/') ) # pylint: disable=import-error, wrong-import-position @@ -59,10 +56,7 @@ class TestCase(NamedTuple): 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 - ): + 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 @@ -72,8 +66,7 @@ def run_test(self) -> CompletedProcess: 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 + 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 @@ -127,8 +120,7 @@ def build_test_cases(tests: Iterable[Mapping[str, Any]]) -> List[TestCase]: def bundled_test_runner_of(target_id: str) -> BundledTestRunner: log_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) # TODO(zijiehe-google-com): Run tests with dart aot, # https://github.com/flutter/flutter/issues/140179. @@ -141,9 +133,7 @@ def variant(test) -> bool: return 'variant' not in test or test['variant'] == VARIANT tests = [t for t in tests if dart_jit(t) and variant(t)] - return BundledTestRunner( - target_id, resolve_packages(tests), build_test_cases(tests), log_dir - ) + return BundledTestRunner(target_id, resolve_packages(tests), build_test_cases(tests), log_dir) def _get_test_runner(runner_args: argparse.Namespace, *_) -> TestRunner: From 1a20e1cb1fde6c1379e43613da8f41dc5297f173 Mon Sep 17 00:00:00 2001 From: Hzj_jie Date: Mon, 12 Feb 2024 13:19:19 -0800 Subject: [PATCH 10/18] private --- testing/fuchsia/run_tests.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/testing/fuchsia/run_tests.py b/testing/fuchsia/run_tests.py index f9e6e1359a34e..e833329925f1a 100755 --- a/testing/fuchsia/run_tests.py +++ b/testing/fuchsia/run_tests.py @@ -48,12 +48,13 @@ OUT_DIR = os.path.join(DIR_SRC_ROOT, 'out', VARIANT) +# Visible for testing class TestCase(NamedTuple): package: str args: str = '' -class BundledTestRunner(TestRunner): +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): @@ -77,6 +78,7 @@ def run_test(self) -> CompletedProcess: return CompletedProcess(args='', returncode=returncode) +# Visible for testing def resolve_packages(tests: Iterable[Mapping[str, Any]]) -> Set[str]: packages = set() for test in tests: @@ -105,6 +107,7 @@ def resolve_packages(tests: Iterable[Mapping[str, Any]]) -> Set[str]: return resolved_packages +# Visible for testing def build_test_cases(tests: Iterable[Mapping[str, Any]]) -> List[TestCase]: test_cases = [] for test in [t['test_command'] for t in tests]: @@ -118,7 +121,7 @@ def build_test_cases(tests: Iterable[Mapping[str, Any]]) -> List[TestCase]: return test_cases -def bundled_test_runner_of(target_id: str) -> BundledTestRunner: +def _bundled_test_runner_of(target_id: str) -> _BundledTestRunner: log_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) @@ -133,11 +136,11 @@ def variant(test) -> bool: return 'variant' not in test or test['variant'] == VARIANT tests = [t for t in tests if dart_jit(t) and variant(t)] - return BundledTestRunner(target_id, resolve_packages(tests), build_test_cases(tests), log_dir) + 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) + return _bundled_test_runner_of(runner_args.target_id) if __name__ == '__main__': From 187b09114fcdcdd35cbba1e520f91ff5ab146407 Mon Sep 17 00:00:00 2001 From: Hzj_jie Date: Mon, 12 Feb 2024 13:43:31 -0800 Subject: [PATCH 11/18] run_tests_test.py --- testing/fuchsia/run_tests_test.py | 49 +++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100755 testing/fuchsia/run_tests_test.py diff --git a/testing/fuchsia/run_tests_test.py b/testing/fuchsia/run_tests_test.py new file mode 100755 index 0000000000000..0283b19737b88 --- /dev/null +++ b/testing/fuchsia/run_tests_test.py @@ -0,0 +1,49 @@ +#!/usr/bin/env python3 +# +# Copyright 2013 The Flutter 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 shutil +import unittest + +from pathlib import Path + +import run_tests + +run_tests.OUT_DIR='/tmp/out/fuchsia_debug_x64' +os.makedirs(run_tests.OUT_DIR, exist_ok=True) + +class RunTestsTest(unittest.TestCase): + def test_resolve_both_package_and_packages(self): + packages = run_tests.resolve_packages([ + {'package': 'abc'}, + {'packages': ['abc', 'def']} + ]) + self.assertEqual(packages, {os.path.join(run_tests.OUT_DIR, 'abc'), os.path.join(run_tests.OUT_DIR, 'def')}) + + + def test_resolve_package_make_symbolic_link(self): + Path(os.path.join(run_tests.OUT_DIR, 'abc-0.far')).touch() + packages = run_tests.resolve_packages([ + {'package': 'abc-0.far'}, + ]) + self.assertEqual(packages, {os.path.join(run_tests.OUT_DIR, 'abc.far')}) + self.assertTrue(os.path.islink(os.path.join(run_tests.OUT_DIR, 'abc.far'))) + + + def test_build_test_cases_with_arguments(self): + test_cases = run_tests.build_test_cases([ + {'test_command': 'test run abc'}, + {'test_command': 'test run def -- --args'}, + ]) + self.assertEqual(test_cases, [run_tests.TestCase(package='abc'), run_tests.TestCase(package='def', args='--args')]) + + +if __name__ == '__main__': + try: + unittest.main() + finally: + # Clean up the temporary files. Since it's in /tmp/, ignore the errors. + shutil.rmtree(run_tests.OUT_DIR, ignore_errors=True) From 7b748c02c98cc85b009f0e7fd12b02561f636298 Mon Sep 17 00:00:00 2001 From: Hzj_jie Date: Mon, 12 Feb 2024 13:45:43 -0800 Subject: [PATCH 12/18] format --- ci/builders/linux_fuchsia.json | 5 ++++ testing/fuchsia/run_tests_test.py | 38 +++++++++++++++++-------------- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/ci/builders/linux_fuchsia.json b/ci/builders/linux_fuchsia.json index 50a58b1436412..8b3f687bb8b17 100644 --- a/ci/builders/linux_fuchsia.json +++ b/ci/builders/linux_fuchsia.json @@ -192,6 +192,11 @@ "--upload" ] }, + { + "name": "run_tests test", + "language": "python3", + "script": "flutter/testing/fuchsia/run_tests_test.py" + }, { "name": "x64 emulator based debug tests", "language": "python3", diff --git a/testing/fuchsia/run_tests_test.py b/testing/fuchsia/run_tests_test.py index 0283b19737b88..ce972c7645660 100755 --- a/testing/fuchsia/run_tests_test.py +++ b/testing/fuchsia/run_tests_test.py @@ -12,38 +12,42 @@ import run_tests -run_tests.OUT_DIR='/tmp/out/fuchsia_debug_x64' +run_tests.OUT_DIR = '/tmp/out/fuchsia_debug_x64' os.makedirs(run_tests.OUT_DIR, exist_ok=True) + class RunTestsTest(unittest.TestCase): - def test_resolve_both_package_and_packages(self): - packages = run_tests.resolve_packages([ - {'package': 'abc'}, - {'packages': ['abc', 'def']} - ]) - self.assertEqual(packages, {os.path.join(run_tests.OUT_DIR, 'abc'), os.path.join(run_tests.OUT_DIR, 'def')}) + def test_resolve_both_package_and_packages(self): + packages = run_tests.resolve_packages([{'package': 'abc'}, {'packages': ['abc', 'def']}]) + self.assertEqual( + packages, {os.path.join(run_tests.OUT_DIR, 'abc'), + os.path.join(run_tests.OUT_DIR, 'def')} + ) def test_resolve_package_make_symbolic_link(self): Path(os.path.join(run_tests.OUT_DIR, 'abc-0.far')).touch() packages = run_tests.resolve_packages([ - {'package': 'abc-0.far'}, + {'package': 'abc-0.far'}, ]) self.assertEqual(packages, {os.path.join(run_tests.OUT_DIR, 'abc.far')}) self.assertTrue(os.path.islink(os.path.join(run_tests.OUT_DIR, 'abc.far'))) - def test_build_test_cases_with_arguments(self): test_cases = run_tests.build_test_cases([ - {'test_command': 'test run abc'}, - {'test_command': 'test run def -- --args'}, + {'test_command': 'test run abc'}, + {'test_command': 'test run def -- --args'}, ]) - self.assertEqual(test_cases, [run_tests.TestCase(package='abc'), run_tests.TestCase(package='def', args='--args')]) + self.assertEqual( + test_cases, + [run_tests.TestCase(package='abc'), + run_tests.TestCase(package='def', args='--args')] + ) if __name__ == '__main__': - try: - unittest.main() - finally: - # Clean up the temporary files. Since it's in /tmp/, ignore the errors. - shutil.rmtree(run_tests.OUT_DIR, ignore_errors=True) + try: + unittest.main() + finally: + # Clean up the temporary files. Since it's in /tmp/, ignore the errors. + shutil.rmtree(run_tests.OUT_DIR, ignore_errors=True) From 92573973efa216c3bfd8e3e2ce6c52973723c1de Mon Sep 17 00:00:00 2001 From: Hzj_jie Date: Mon, 12 Feb 2024 14:01:36 -0800 Subject: [PATCH 13/18] vpython3 --- ci/builders/linux_fuchsia.json | 2 +- testing/fuchsia/run_tests_test.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ci/builders/linux_fuchsia.json b/ci/builders/linux_fuchsia.json index 8b3f687bb8b17..04ac40ce8b9de 100644 --- a/ci/builders/linux_fuchsia.json +++ b/ci/builders/linux_fuchsia.json @@ -194,7 +194,7 @@ }, { "name": "run_tests test", - "language": "python3", + "language": "vpython3", "script": "flutter/testing/fuchsia/run_tests_test.py" }, { diff --git a/testing/fuchsia/run_tests_test.py b/testing/fuchsia/run_tests_test.py index ce972c7645660..bc5d876415a2d 100755 --- a/testing/fuchsia/run_tests_test.py +++ b/testing/fuchsia/run_tests_test.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python3 +#!/usr/bin/env vpython3 # # Copyright 2013 The Flutter Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be From cc3aaf41fae4b1296a924fbc2333f5335bb07d8a Mon Sep 17 00:00:00 2001 From: Hzj_jie Date: Mon, 12 Feb 2024 14:12:13 -0800 Subject: [PATCH 14/18] script --- ci/builders/linux_fuchsia.json | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ci/builders/linux_fuchsia.json b/ci/builders/linux_fuchsia.json index 04ac40ce8b9de..77368872998b5 100644 --- a/ci/builders/linux_fuchsia.json +++ b/ci/builders/linux_fuchsia.json @@ -194,8 +194,10 @@ }, { "name": "run_tests test", - "language": "vpython3", - "script": "flutter/testing/fuchsia/run_tests_test.py" + "script": "vpython3", + "parameters": [ + "flutter/testing/fuchsia/run_tests_test.py" + ] }, { "name": "x64 emulator based debug tests", From fd2b95e5b06d8ff79c4e09428be19f04da4d3c12 Mon Sep 17 00:00:00 2001 From: Hzj_jie Date: Mon, 12 Feb 2024 14:22:06 -0800 Subject: [PATCH 15/18] remove vpython3 --- ci/builders/linux_fuchsia.json | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/ci/builders/linux_fuchsia.json b/ci/builders/linux_fuchsia.json index 77368872998b5..ca1c999c09d56 100644 --- a/ci/builders/linux_fuchsia.json +++ b/ci/builders/linux_fuchsia.json @@ -194,10 +194,7 @@ }, { "name": "run_tests test", - "script": "vpython3", - "parameters": [ - "flutter/testing/fuchsia/run_tests_test.py" - ] + "script": "flutter/testing/fuchsia/run_tests_test.py" }, { "name": "x64 emulator based debug tests", From 8b76efaddc7035c03845c750e989074268f38ef3 Mon Sep 17 00:00:00 2001 From: Hzj_jie Date: Mon, 12 Feb 2024 15:00:04 -0800 Subject: [PATCH 16/18] vpython --- testing/fuchsia/run_tests.py | 4 ++++ testing/fuchsia/run_tests_test.py | 10 +++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/testing/fuchsia/run_tests.py b/testing/fuchsia/run_tests.py index e833329925f1a..321ca5ec691e4 100755 --- a/testing/fuchsia/run_tests.py +++ b/testing/fuchsia/run_tests.py @@ -79,6 +79,7 @@ def run_test(self) -> CompletedProcess: # Visible for testing +@staticmethod def resolve_packages(tests: Iterable[Mapping[str, Any]]) -> Set[str]: packages = set() for test in tests: @@ -108,6 +109,7 @@ def resolve_packages(tests: Iterable[Mapping[str, Any]]) -> Set[str]: # Visible for testing +@staticmethod def build_test_cases(tests: Iterable[Mapping[str, Any]]) -> List[TestCase]: test_cases = [] for test in [t['test_command'] for t in tests]: @@ -121,6 +123,7 @@ def build_test_cases(tests: Iterable[Mapping[str, Any]]) -> List[TestCase]: return test_cases +@staticmethod def _bundled_test_runner_of(target_id: str) -> _BundledTestRunner: log_dir = os.environ.get('FLUTTER_LOGS_DIR', '/tmp/log') with open(os.path.join(os.path.dirname(__file__), 'test_suites.yaml'), 'r') as file: @@ -139,6 +142,7 @@ def variant(test) -> bool: return _BundledTestRunner(target_id, resolve_packages(tests), build_test_cases(tests), log_dir) +@staticmethod def _get_test_runner(runner_args: argparse.Namespace, *_) -> TestRunner: return _bundled_test_runner_of(runner_args.target_id) diff --git a/testing/fuchsia/run_tests_test.py b/testing/fuchsia/run_tests_test.py index bc5d876415a2d..9c533d7426f44 100755 --- a/testing/fuchsia/run_tests_test.py +++ b/testing/fuchsia/run_tests_test.py @@ -1,5 +1,13 @@ #!/usr/bin/env vpython3 -# + +# [VPYTHON:BEGIN] +# python_version: "3.8" +# wheel < +# name: "infra/python/wheels/pyyaml/${platform}_${py_python}_${py_abi}" +# version: "version:5.4.1.chromium.1" +# > +# [VPYTHON:END] + # Copyright 2013 The Flutter Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. From af5ef74fffd7c052bf5a727196abdd1ed5a76501 Mon Sep 17 00:00:00 2001 From: Hzj_jie Date: Mon, 12 Feb 2024 15:17:18 -0800 Subject: [PATCH 17/18] remove static --- testing/fuchsia/run_tests.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/testing/fuchsia/run_tests.py b/testing/fuchsia/run_tests.py index 321ca5ec691e4..e833329925f1a 100755 --- a/testing/fuchsia/run_tests.py +++ b/testing/fuchsia/run_tests.py @@ -79,7 +79,6 @@ def run_test(self) -> CompletedProcess: # Visible for testing -@staticmethod def resolve_packages(tests: Iterable[Mapping[str, Any]]) -> Set[str]: packages = set() for test in tests: @@ -109,7 +108,6 @@ def resolve_packages(tests: Iterable[Mapping[str, Any]]) -> Set[str]: # Visible for testing -@staticmethod def build_test_cases(tests: Iterable[Mapping[str, Any]]) -> List[TestCase]: test_cases = [] for test in [t['test_command'] for t in tests]: @@ -123,7 +121,6 @@ def build_test_cases(tests: Iterable[Mapping[str, Any]]) -> List[TestCase]: return test_cases -@staticmethod def _bundled_test_runner_of(target_id: str) -> _BundledTestRunner: log_dir = os.environ.get('FLUTTER_LOGS_DIR', '/tmp/log') with open(os.path.join(os.path.dirname(__file__), 'test_suites.yaml'), 'r') as file: @@ -142,7 +139,6 @@ def variant(test) -> bool: return _BundledTestRunner(target_id, resolve_packages(tests), build_test_cases(tests), log_dir) -@staticmethod def _get_test_runner(runner_args: argparse.Namespace, *_) -> TestRunner: return _bundled_test_runner_of(runner_args.target_id) From b153e24bbb9a8a2378c782c9f08a0eacf79fd0b4 Mon Sep 17 00:00:00 2001 From: Hzj_jie Date: Mon, 12 Feb 2024 15:22:51 -0800 Subject: [PATCH 18/18] no-member --- testing/fuchsia/run_tests_test.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/testing/fuchsia/run_tests_test.py b/testing/fuchsia/run_tests_test.py index 9c533d7426f44..82b5d5aae433e 100755 --- a/testing/fuchsia/run_tests_test.py +++ b/testing/fuchsia/run_tests_test.py @@ -18,6 +18,8 @@ from pathlib import Path +# pylint is looking for a wrong //testing/run_tests.py. +# pylint: disable=no-member import run_tests run_tests.OUT_DIR = '/tmp/out/fuchsia_debug_x64'