xref: /aosp_15_r20/external/cronet/build/fuchsia/test/run_telemetry_test.py (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1# Copyright 2022 The Chromium Authors
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4"""Implements commands for running GPU tests."""
5
6import argparse
7import os
8import subprocess
9
10from typing import List, Optional
11
12from common import DIR_SRC_ROOT
13from test_runner import TestRunner
14
15_GPU_TEST_SCRIPT = os.path.join(DIR_SRC_ROOT, 'content', 'test', 'gpu',
16                                'run_gpu_integration_test.py')
17_PERF_TEST_SCRIPT = os.path.join(DIR_SRC_ROOT, 'tools', 'perf',
18                                 'run_benchmark')
19
20
21class TelemetryTestRunner(TestRunner):
22    """Test runner for running GPU tests."""
23
24    def __init__(self, test_type: str, out_dir: str, test_args: List[str],
25                 target_id: Optional[str]) -> None:
26        parser = argparse.ArgumentParser()
27        parser.add_argument(
28            '--browser', help='The browser to use for Telemetry based tests.')
29        args, _ = parser.parse_known_args(test_args)
30
31        if args.browser == 'web-engine-shell':
32            packages = ['web_engine_shell']
33        elif args.browser == 'fuchsia-chrome':
34            packages = ['chrome']
35        elif args.browser == 'cast-streaming-shell':
36            packages = ['cast_streaming_shell']
37        else:
38            raise Exception('Unknown browser %s' % args.browser)
39
40        if test_type == 'gpu':
41            self._test_script = _GPU_TEST_SCRIPT
42        elif test_type == 'perf':
43            self._test_script = _PERF_TEST_SCRIPT
44        else:
45            raise ValueError('Test type can only be |gpu| or |perf|.')
46
47        super().__init__(out_dir, test_args, packages, target_id)
48
49    # TODO(crbug.com/1345390): Remove when Telemetry tests use CFv2 components.
50    @staticmethod
51    def is_cfv2() -> bool:
52        return False
53
54    def run_test(self):
55        test_cmd = [self._test_script]
56        if self._test_args:
57            test_cmd.extend(self._test_args)
58        test_cmd.extend(['--chromium-output-directory', self._out_dir])
59        if self._target_id:
60            test_cmd.extend(['--fuchsia-target-id', self._target_id])
61        return subprocess.run(test_cmd, check=True)
62