OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/python -u |
| 2 # |
| 3 # Copyright (c) 2011 The Chromium OS Authors. All rights reserved. |
| 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. |
| 6 # |
| 7 # Site extension of the default parser. Generates a JSON report of test results. |
| 8 # |
| 9 # This site parser is used to generate a JSON report of test failures, crashes, |
| 10 # and the associated logs for later consumption by an Email generator. |
| 11 # |
| 12 # The parser uses the test report generator which comes bundled with the Chrome |
| 13 # OS source tree in order to maintain consistency. As well as not having to keep |
| 14 # track of any secondary failure white lists. |
| 15 # |
| 16 # The path to the Chrome OS source tree is defined in global_config under the |
| 17 # CROS section as 'source_tree'. |
| 18 # |
| 19 # Existing parse behavior is kept completely intact. If the site parser is not |
| 20 # configured it will print a debug message and exit after default parser is |
| 21 # called. |
| 22 # |
| 23 |
| 24 import os, json, sys |
| 25 |
| 26 import common |
| 27 from autotest_lib.tko import parse, utils as tko_utils |
| 28 from autotest_lib.client.common_lib import global_config, utils |
| 29 |
| 30 |
| 31 # Name of the report file to produce upon completion. |
| 32 _JSON_REPORT_FILE = 'results.json' |
| 33 |
| 34 # Number of log lines to include with each test. |
| 35 _LOG_LIMIT = 25 |
| 36 |
| 37 |
| 38 def main(): |
| 39 # Call the original parser. |
| 40 parse.main() |
| 41 |
| 42 # Results directory should be the last argument passed in. |
| 43 results_dir = sys.argv[-1] |
| 44 |
| 45 # Load the Chrome OS source tree location. |
| 46 cros_src_dir = global_config.global_config.get_config_value( |
| 47 'CROS', 'source_tree', default='') |
| 48 |
| 49 # We want the standard Autotest parser to keep working even if we haven't |
| 50 # been setup properly. |
| 51 if not cros_src_dir: |
| 52 tko_utils.dprint( |
| 53 'Unable to load required components for site parser. Falling back' |
| 54 ' to default parser.') |
| 55 return |
| 56 |
| 57 # Load ResultCollector from the Chrome OS source tree. |
| 58 sys.path.append(os.path.join( |
| 59 cros_src_dir, 'src/platform/crostestutils/utils_py')) |
| 60 from generate_test_report import ResultCollector |
| 61 |
| 62 # Collect results using the standard Chrome OS test report generator. Doing |
| 63 # so allows us to use the same crash white list and reporting standards the |
| 64 # VM based test instances use. |
| 65 results = ResultCollector().CollectResults(results_dir) |
| 66 |
| 67 # We don't care about successful tests. We only want failed or crashing. |
| 68 # Note: .items() generates a copy of the dictionary, so it's safe to delete. |
| 69 for k, v in results.items(): |
| 70 if v['status'] == 'PASS' and not v['crashes']: |
| 71 del results[k] |
| 72 |
| 73 # Filter results and collect logs. If we can't find a log for the test, skip |
| 74 # it. The Emailer will fill in the blanks using Database data later. |
| 75 filtered_results = {} |
| 76 for test in results: |
| 77 test_name = os.path.basename(test) |
| 78 log = os.path.join(test, 'debug', '%s.ERROR' % test_name) |
| 79 |
| 80 # If a log doesn't exist, we don't care about this test. |
| 81 if not os.path.exists(log): |
| 82 continue |
| 83 |
| 84 # Pull out only the last _LOG_LIMIT lines of the file. |
| 85 short_log = utils.system_output('tail -n %d %s' % (_LOG_LIMIT, log)) |
| 86 |
| 87 # Let the reader know we've trimmed the log. |
| 88 if len(short_log.splitlines()) == _LOG_LIMIT: |
| 89 short_log = ( |
| 90 '[...displaying only the last 25 log lines...]\n' + short_log) |
| 91 |
| 92 filtered_results[test_name] = results[test] |
| 93 filtered_results[test_name]['log'] = short_log |
| 94 |
| 95 # Generate JSON dump of results. Store in results dir. |
| 96 json_file = open(os.path.join(results_dir, _JSON_REPORT_FILE), 'w') |
| 97 json.dump(filtered_results, json_file) |
| 98 json_file.close() |
| 99 |
| 100 |
| 101 if __name__ == '__main__': |
| 102 main() |
OLD | NEW |