• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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"""Runs isolate bundled Telemetry unittests.
6
7If optional argument --isolated-script-test-output=[FILENAME] is passed
8to the script, json is written to that file in the format detailed in
9//docs/testing/json-test-results-format.md.
10
11If optional argument --isolated-script-test-filter=[TEST_NAMES] is passed to
12the script, it should be a  double-colon-separated ("::") list of test names,
13to run just that subset of tests.
14
15This script is intended to be the base command invoked by the isolate,
16followed by a subsequent Python script. It could be generalized to
17invoke an arbitrary executable.
18"""
19
20import json
21import sys
22
23import common
24
25
26class TelemetryUnittestAdapter(common.BaseIsolatedScriptArgsAdapter):
27
28  def generate_test_output_args(self, output):
29    return ['--write-full-results-to', output]
30
31  def generate_test_also_run_disabled_tests_args(self):
32    return ['--also-run-disabled-tests']
33
34  def generate_test_filter_args(self, test_filter_str):
35    return ['--test-filter', test_filter_str]
36
37  def generate_sharding_args(self, total_shards, shard_index):
38    return [
39        '--total-shards=%d' % total_shards,
40        '--shard-index=%d' % shard_index
41    ]
42
43  def generate_test_launcher_retry_limit_args(self, retry_limit):
44    return ['--retry-limit=%d' % retry_limit]
45
46  def generate_test_repeat_args(self, repeat_count):
47    return ['--repeat=%d' % repeat_count]
48
49
50def main():
51  adapter = TelemetryUnittestAdapter()
52  return adapter.run_test()
53
54
55# This is not really a "script test" so does not need to manually add
56# any additional compile targets.
57def main_compile_targets(args):
58  json.dump([], args.output)
59
60
61if __name__ == '__main__':
62  # Conform minimally to the protocol defined by ScriptTest.
63  if 'compile_targets' in sys.argv:
64    funcs = {
65        'run': None,
66        'compile_targets': main_compile_targets,
67    }
68    sys.exit(common.run_script(sys.argv[1:], funcs))
69  sys.exit(main())
70