| OLD | NEW |
| (Empty) | |
| 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2010 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. |
| 5 |
| 6 """ |
| 7 This is a script for generating JSON from JUnit XML output (generated by |
| 8 google tests with --gtest_output=xml option). |
| 9 """ |
| 10 import logging |
| 11 import optparse |
| 12 import os |
| 13 import sys |
| 14 import time |
| 15 |
| 16 from xml.dom import minidom |
| 17 |
| 18 from layout_package import json_results_generator |
| 19 from layout_package import path_utils |
| 20 from layout_package import test_expectations |
| 21 |
| 22 # Builder base URL where we have the archived test results. |
| 23 BUILDER_BASE_URL = "http://build.chromium.org/buildbot/" |
| 24 |
| 25 class JSONGeneratorFromXML(object): |
| 26 def __init__(self, options): |
| 27 self._options = options |
| 28 |
| 29 # Check the results directory |
| 30 if not os.path.exists(self._options.results_directory): |
| 31 os.mkdir(self._options.results_directory) |
| 32 |
| 33 results_xml_file = None |
| 34 try: |
| 35 results_xml_file = open(self._options.input_results_xml) |
| 36 except IOError, e: |
| 37 logging.fatal("Cannot open file %s", self._options.input_results_xml) |
| 38 sys.exit(1) |
| 39 |
| 40 summary = self._ParseTestResultsXML( |
| 41 minidom.parse(results_xml_file).documentElement) |
| 42 results_xml_file.close() |
| 43 |
| 44 json_results_generator.JSONResultsGenerator( |
| 45 self._options.builder_name, self._options.build_name, |
| 46 self._options.build_number, self._options.results_directory, |
| 47 self._options.builder_base_url, |
| 48 self._test_timings, |
| 49 self._failures, self._passed_tests, self._skipped_tests, |
| 50 self._tests_list) |
| 51 |
| 52 def _ParseTestResultsXML(self, node): |
| 53 self._tests_list = set() |
| 54 self._passed_tests = set() |
| 55 self._skipped_tests = set() |
| 56 self._test_timings = {} |
| 57 self._failures = {} |
| 58 |
| 59 testcases = node.getElementsByTagName('testcase') |
| 60 for testcase in testcases: |
| 61 name = testcase.getAttribute('name') |
| 62 classname = testcase.getAttribute('classname') |
| 63 test_name = "%s.%s" % (classname, name) |
| 64 |
| 65 status = testcase.getAttribute('status') |
| 66 if status == 'notrun': |
| 67 if name.startswith('DISABLED_'): |
| 68 self._skipped_tests.add(test_name) |
| 69 continue |
| 70 |
| 71 failures = testcase.getElementsByTagName('failure') |
| 72 if failures: |
| 73 self._failures[test_name] = test_expectations.TEXT |
| 74 else: |
| 75 self._passed_tests.add(test_name) |
| 76 |
| 77 self._test_timings[test_name] = float(testcase.getAttribute('time')) |
| 78 self._tests_list.add(test_name) |
| 79 |
| 80 |
| 81 def main(options, args): |
| 82 """Parse the tests results and generate JSON files. |
| 83 |
| 84 Args: |
| 85 options: a dictionary of command line options |
| 86 args: a list of sub directories or files to test |
| 87 """ |
| 88 |
| 89 if not options.test_type: |
| 90 logging.error("--test-type needs to be specified.") |
| 91 sys.exit(1) |
| 92 |
| 93 canon_test_type = options.test_type.replace("-", "_") |
| 94 if not options.input_results_xml: |
| 95 options.input_results_xml = canon_test_type + ".xml" |
| 96 if not options.builder_base_url: |
| 97 options.builder_base_url = BUILDER_BASE_URL + canon_test_type + "_results/" |
| 98 |
| 99 JSONGeneratorFromXML(options) |
| 100 |
| 101 return |
| 102 |
| 103 if '__main__' == __name__: |
| 104 option_parser = optparse.OptionParser() |
| 105 option_parser.add_option("", "--test-type", default="", |
| 106 help="Test type that generated the results XML," |
| 107 " e.g. unit-tests.") |
| 108 option_parser.add_option("", "--results-directory", default="./", |
| 109 help="Output results directory source dir.") |
| 110 option_parser.add_option("", "--input-results-xml", default="", |
| 111 help="Test results xml file (input for us)." |
| 112 " default is TEST_TYPE.xml") |
| 113 option_parser.add_option("", "--builder-base-url", default="", |
| 114 help=("A URL where we have the archived test " |
| 115 "results. (default=%sTEST_TYPE_results/)" |
| 116 % BUILDER_BASE_URL)) |
| 117 option_parser.add_option("", "--builder-name", |
| 118 default="DUMMY_BUILDER_NAME", |
| 119 help="The name of the builder shown on the " |
| 120 "waterfall running this script e.g. WebKit.") |
| 121 option_parser.add_option("", "--build-name", |
| 122 default="DUMMY_BUILD_NAME", |
| 123 help="The name of the builder used in its path, " |
| 124 "e.g. webkit-rel.") |
| 125 option_parser.add_option("", "--build-number", |
| 126 default="DUMMY_BUILD_NUMBER", |
| 127 help="The build number of the builder running" |
| 128 "this script.") |
| 129 options, args = option_parser.parse_args() |
| 130 main(options, args) |
| OLD | NEW |