xref: /aosp_15_r20/external/cronet/testing/scripts/run_telemetry_as_googletest.py (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1#!/usr/bin/env vpython3
2# Copyright 2015 The Chromium Authors
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6"""Runs isolate bundled Telemetry unittests.
7
8If optional argument --isolated-script-test-output=[FILENAME] is passed
9to the script, json is written to that file in the format detailed in
10//docs/testing/json-test-results-format.md.
11
12If optional argument --isolated-script-test-filter=[TEST_NAMES] is passed to
13the script, it should be a  double-colon-separated ("::") list of test names,
14to run just that subset of tests.
15
16This script is intended to be the base command invoked by the isolate,
17followed by a subsequent Python script. It could be generalized to
18invoke an arbitrary executable.
19"""
20
21import argparse
22import json
23import os
24import sys
25
26# Add src/testing/ into sys.path for importing common without pylint errors.
27sys.path.append(
28    os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir)))
29from scripts import common
30
31
32class TelemetryUnittestAdapter(common.BaseIsolatedScriptArgsAdapter):
33
34  def generate_test_output_args(self, output):
35    return ['--write-full-results-to', output]
36
37  def generate_test_also_run_disabled_tests_args(self):
38    return ['--also-run-disabled-tests']
39
40  def generate_test_filter_args(self, test_filter_str):
41    return ['--test-filter', test_filter_str]
42
43  def generate_sharding_args(self, total_shards, shard_index):
44    return ['--total-shards=%d' % total_shards,
45            '--shard-index=%d' % shard_index]
46
47  def generate_test_launcher_retry_limit_args(self, retry_limit):
48    return ['--retry-limit=%d' % retry_limit]
49
50  def generate_test_repeat_args(self, repeat_count):
51    return ['--repeat=%d' % repeat_count]
52
53
54def main():
55  adapter = TelemetryUnittestAdapter()
56  return adapter.run_test()
57
58
59# This is not really a "script test" so does not need to manually add
60# any additional compile targets.
61def main_compile_targets(args):
62  json.dump([], args.output)
63
64
65if __name__ == '__main__':
66  # Conform minimally to the protocol defined by ScriptTest.
67  if 'compile_targets' in sys.argv:
68    funcs = {
69      'run': None,
70      'compile_targets': main_compile_targets,
71    }
72    sys.exit(common.run_script(sys.argv[1:], funcs))
73  sys.exit(main())
74