summaryrefslogtreecommitdiff
path: root/buildscripts/promote_silent_failures.py
diff options
context:
space:
mode:
authorEddie Louie <eddie.louie@mongodb.com>2017-05-23 13:25:40 -0400
committerEddie Louie <eddie.louie@mongodb.com>2017-05-30 12:06:39 -0400
commit50ea467d27c8ec98ee25d8298d61e0d5edfc560e (patch)
treeafaaf62d44e96b6c3f4070fd2d2aeae5722a9a3e /buildscripts/promote_silent_failures.py
parentfad590916a30ff34dc8c3b37afcfffa2c4e5c8bc (diff)
downloadmongo-50ea467d27c8ec98ee25d8298d61e0d5edfc560e.tar.gz
SERVER-29061 Add buildscripts/promote_silent_failures.py script to convert silent
test failures into non-silent test failures
Diffstat (limited to 'buildscripts/promote_silent_failures.py')
-rw-r--r--buildscripts/promote_silent_failures.py68
1 files changed, 68 insertions, 0 deletions
diff --git a/buildscripts/promote_silent_failures.py b/buildscripts/promote_silent_failures.py
new file mode 100644
index 00000000000..2865fa5aa96
--- /dev/null
+++ b/buildscripts/promote_silent_failures.py
@@ -0,0 +1,68 @@
+#!/usr/bin/env python
+"""
+Converts silent test failures into non-silent failures.
+
+Any test files with at least 2 executions in the report.json file that have a "silentfail" status,
+this script will change the outputted report to have a "fail" status instead.
+"""
+
+from __future__ import absolute_import
+from __future__ import print_function
+
+import collections
+import json
+import optparse
+import os
+import sys
+
+
+# Get relative imports to work when the package is not installed on the PYTHONPATH.
+if __name__ == "__main__" and __package__ is None:
+ sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
+ from buildscripts.resmokelib.testing import report
+
+
+def read_json_file(json_file):
+ with open(json_file) as json_data:
+ return json.load(json_data)
+
+
+def main():
+
+ usage = "usage: %prog [options] report.json"
+ parser = optparse.OptionParser(usage=usage)
+ parser.add_option("-o", "--output-file",
+ dest="outfile",
+ default="-",
+ help="If '-', then the report file is written to stdout."
+ " Any other value is treated as the output file name. By default,"
+ " output is written to stdout.")
+
+ (options, args) = parser.parse_args()
+
+ if len(args) != 1:
+ parser.error("Requires a single report.json file.")
+
+ report_file_json = read_json_file(args[0])
+ test_report = report.TestReport.from_dict(report_file_json)
+
+ # Count number of "silentfail" per test file.
+ status_dict = collections.defaultdict(int)
+ for test_info in test_report.test_infos:
+ if test_info.status == "silentfail":
+ status_dict[test_info.test_id] += 1
+
+ # For test files with more than 1 "silentfail", convert status to "fail".
+ for test_info in test_report.test_infos:
+ if status_dict[test_info.test_id] >= 2:
+ test_info.status = "fail"
+
+ result_report = test_report.as_dict();
+ if options.outfile != "-":
+ with open(options.outfile, "w") as fp:
+ json.dump(result_report, fp)
+ else:
+ print(json.dumps(result_report))
+
+if __name__ == "__main__":
+ main()