|
1 | | -#!/usr/bin/env vpython3 |
2 | | - |
3 | | -# [VPYTHON:BEGIN] |
4 | | -# python_version: "3.8" |
5 | | -# wheel < |
6 | | -# name: "infra/python/wheels/pyyaml/${platform}_${py_python}_${py_abi}" |
7 | | -# version: "version:5.4.1.chromium.1" |
8 | | -# > |
9 | | -# [VPYTHON:END] |
10 | | - |
| 1 | +#!/usr/bin/env python3 |
11 | 2 | # Copyright (c) 2013, the Flutter project authors. All rights reserved. |
12 | 3 | # Use of this source code is governed by a BSD-style license that can be found |
13 | 4 | # in the LICENSE file. |
14 | 5 |
|
15 | 6 | import argparse |
16 | | -import logging |
17 | 7 | import os |
18 | 8 | import sys |
19 | 9 |
|
20 | | -from subprocess import CompletedProcess |
21 | | -from typing import List |
22 | | - |
23 | | -# The import is coming from vpython wheel and pylint cannot find it. |
24 | | -import yaml # pylint: disable=import-error |
25 | | - |
26 | 10 | # The imports are coming from fuchsia/test_scripts and pylint cannot find them |
27 | 11 | # without setting a global init-hook which is less favorable. |
28 | 12 | # But this file will be executed as part of the CI, its correctness of importing |
|
41 | 25 | from run_executable_test import ExecutableTestRunner |
42 | 26 | from test_runner import TestRunner |
43 | 27 |
|
44 | | -if len(sys.argv) == 2: |
45 | | - VARIANT = sys.argv[1] |
46 | | - sys.argv.pop() |
47 | | -elif len(sys.argv) == 1: |
48 | | - VARIANT = 'fuchsia_debug_x64' |
49 | | -else: |
50 | | - assert False, 'Expect only one parameter as the compile output directory.' |
51 | | -OUT_DIR = os.path.join(DIR_SRC_ROOT, 'out', VARIANT) |
52 | | - |
53 | | - |
54 | | -class BundledTestRunner(TestRunner): |
55 | | - |
56 | | - # private, use bundled_test_runner_of function instead. |
57 | | - def __init__( |
58 | | - self, target_id: str, package_deps: List[str], tests: List[str], |
59 | | - logs_dir: str |
60 | | - ): |
61 | | - super().__init__(OUT_DIR, [], None, target_id, package_deps) |
62 | | - self.tests = tests |
63 | | - self.logs_dir = logs_dir |
64 | | - |
65 | | - def run_test(self) -> CompletedProcess: |
66 | | - returncode = 0 |
67 | | - for test in self.tests: |
68 | | - # pylint: disable=protected-access |
69 | | - test_runner = ExecutableTestRunner( |
70 | | - OUT_DIR, [], test, self._target_id, None, self.logs_dir, [], None |
71 | | - ) |
72 | | - test_runner._package_deps = self._package_deps |
73 | | - result = test_runner.run_test().returncode |
74 | | - logging.info('Result of test %s is %s', test, result) |
75 | | - if result != 0: |
76 | | - returncode = result |
77 | | - return CompletedProcess(args='', returncode=returncode) |
78 | | - |
79 | | - |
80 | | -def bundled_test_runner_of(target_id: str) -> BundledTestRunner: |
81 | | - log_dir = os.environ.get('FLUTTER_LOGS_DIR', '/tmp/log') |
82 | | - with open(os.path.join(os.path.dirname(__file__), 'test_suites.yaml'), |
83 | | - 'r') as file: |
84 | | - tests = yaml.safe_load(file) |
85 | | - # TODO(zijiehe-google-com): Run tests with multiple packages or with extra |
86 | | - # test arguments, https://github.com/flutter/flutter/issues/140179. |
87 | | - tests = list( |
88 | | - filter( |
89 | | - lambda test: test['test_command'].startswith('test run ') and test[ |
90 | | - 'test_command'].endswith('.cm'), tests |
91 | | - ) |
92 | | - ) |
93 | | - tests = list( |
94 | | - filter( |
95 | | - lambda test: 'package' in test and test['package'].endswith('-0.far'), |
96 | | - tests |
97 | | - ) |
98 | | - ) |
99 | | - tests = list( |
100 | | - filter( |
101 | | - lambda test: not 'variant' in test or VARIANT == test['variant'], |
102 | | - tests |
103 | | - ) |
104 | | - ) |
105 | | - for test in tests: |
106 | | - original_package = test['package'] |
107 | | - test['package'] = os.path.join( |
108 | | - OUT_DIR, test['package'].replace('-0.far', '.far') |
109 | | - ) |
110 | | - try: |
111 | | - os.remove(test['package']) |
112 | | - except FileNotFoundError: |
113 | | - pass |
114 | | - os.symlink(original_package, test['package']) |
115 | | - return BundledTestRunner( |
116 | | - target_id, [test['package'] for test in tests], |
117 | | - [test['test_command'][len('test run '):] for test in tests], log_dir |
118 | | - ) |
| 28 | +# TODO(https://github.com/flutter/flutter/issues/140179): Respect build |
| 29 | +# configurations. |
| 30 | +OUT_DIR = os.path.join(DIR_SRC_ROOT, 'out/fuchsia_debug_x64') |
119 | 31 |
|
120 | 32 |
|
| 33 | +# TODO(https://github.com/flutter/flutter/issues/140179): Execute all the tests |
| 34 | +# in |
| 35 | +# https://github.com/flutter/engine/blob/main/testing/fuchsia/test_suites.yaml |
| 36 | +# and avoid hardcoded paths. |
121 | 37 | def _get_test_runner(runner_args: argparse.Namespace, *_) -> TestRunner: |
122 | | - return bundled_test_runner_of(runner_args.target_id) |
| 38 | + return ExecutableTestRunner( |
| 39 | + OUT_DIR, [], |
| 40 | + 'fuchsia-pkg://fuchsia.com/dart_runner_tests#meta/dart_runner_tests.cm', |
| 41 | + runner_args.target_id, None, '/tmp/log', |
| 42 | + [os.path.join(OUT_DIR, 'dart_runner_tests.far')], None |
| 43 | + ) |
123 | 44 |
|
124 | 45 |
|
125 | 46 | if __name__ == '__main__': |
126 | | - logging.info('Running tests in %s', OUT_DIR) |
| 47 | + try: |
| 48 | + os.remove(os.path.join(OUT_DIR, 'dart_runner_tests.far')) |
| 49 | + except FileNotFoundError: |
| 50 | + pass |
| 51 | + os.symlink( |
| 52 | + 'dart_runner_tests-0.far', os.path.join(OUT_DIR, 'dart_runner_tests.far') |
| 53 | + ) |
127 | 54 | sys.argv.append('--out-dir=' + OUT_DIR) |
128 | 55 | # The 'flutter-test-type' is a place holder and has no specific meaning; the |
129 | 56 | # _get_test_runner is overrided. |
|
0 commit comments