[refactor] More post-NSS WebCrypto cleanups (utility functions).
[chromium-blink-merge.git] / testing / scripts / run_telemetry_as_googletest.py
blobe6c90cf9b4d590b08271825a90e79510559304e1
1 #!/usr/bin/env python
2 # Copyright 2015 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
6 """Runs isolate bundled Telemetry unittests.
8 This script attempts to emulate the contract of gtest-style tests
9 invoked via recipes. The main contract is that the caller passes the
10 argument:
12 --test-launcher-summary-output=[FILENAME]
14 json is written to that file in the format produced by
15 common.parse_common_test_results.
17 This script is intended to be the base command invoked by the isolate,
18 followed by a subsequent Python script. It could be generalized to
19 invoke an arbitrary executable.
20 """
22 import argparse
23 import json
24 import os
25 import sys
28 import common
31 def main():
32 parser = argparse.ArgumentParser()
33 parser.add_argument(
34 '--test-launcher-summary-output',
35 type=argparse.FileType('w'),
36 required=True)
37 args, rest_args = parser.parse_known_args()
38 with common.temporary_file() as tempfile_path:
39 rc = common.run_command([sys.executable] + rest_args + [
40 '--write-full-results-to', tempfile_path,
42 with open(tempfile_path) as f:
43 results = json.load(f)
44 parsed_results = common.parse_common_test_results(results,
45 test_separator='.')
46 failures = parsed_results['unexpected_failures']
48 json.dump({
49 'valid': bool(rc <= common.MAX_FAILURES_EXIT_STATUS and
50 ((rc == 0) or failures)),
51 'failures': failures.keys(),
52 }, args.test_launcher_summary_output)
54 return rc
57 # This is not really a "script test" so does not need to manually add
58 # any additional compile targets.
59 def main_compile_targets(args):
60 json.dump([], args.output)
63 if __name__ == '__main__':
64 # Conform minimally to the protocol defined by ScriptTest.
65 if 'compile_targets' in sys.argv:
66 funcs = {
67 'run': None,
68 'compile_targets': main_compile_targets,
70 sys.exit(common.run_script(sys.argv[1:], funcs))
71 sys.exit(main())