[PATCH] tester: Add basic support to generate JUnit test reports

Hesham Almatary Hesham.Almatary at cl.cam.ac.uk
Wed Nov 20 15:01:07 UTC 2019


---
 tester/rt/test.py | 29 ++++++++++++++++++++++++++++-
 1 file changed, 28 insertions(+), 1 deletion(-)

diff --git a/tester/rt/test.py b/tester/rt/test.py
index 3cd9b48..db83b77 100644
--- a/tester/rt/test.py
+++ b/tester/rt/test.py
@@ -285,8 +285,35 @@ def generate_json_report(args, reports, start_time, end_time,
         json.dump(json_log, outfile, sort_keys=True, indent=4)
 
 
+def generate_junit_report(args, reports, start_time, end_time,
+                         total, junit_file):
+
+    from junit_xml import TestSuite, TestCase
+    import sys
+    junit_log = []
+
+    for name in reports.results:
+        result_type = reports.results[name]['result']
+        test_parts = name.split("/")
+        test_category = test_parts[-2]
+        test_name = test_parts[-1]
+
+        junit_result = TestCase(test_name.split('.')[0])
+        junit_result.category = test_category
+        if result_type == "failed" or result_type == "timeout":
+            junit_result. add_failure_info(None, reports.results[name]["output"], result_type)
+
+        junit_log.append(junit_result)
+
+    ts = TestSuite("RTEMS Test Suite", junit_log)
+
+    # write out junit log
+    with open(junit_file, 'w') as f:
+        TestSuite.to_file(f, [ts], prettyprint=True)
+
 report_formatters = {
-        'json': generate_json_report
+        'json': generate_json_report,
+        'junit': generate_junit_report
 }
 
 
-- 
2.17.1



More information about the devel mailing list