Skip to content

Commit bc86aa9

Browse files
committed
Adding JUnit build reporting option to test.py
1 parent ec2e4a1 commit bc86aa9

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

tools/test.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
from tools.build_api import build_project, build_library
3131
from tools.targets import TARGET_MAP
3232
from tools.utils import mkdir
33+
from tools.test_exporters import ReportExporter, ResultExporterType
3334

3435
if __name__ == '__main__':
3536
try:
@@ -66,6 +67,9 @@
6667
parser.add_option("--test-spec", dest="test_spec",
6768
default=None, help="Destination path for a test spec file that can be used by the Greentea automated test tool")
6869

70+
parser.add_option("--build-report-junit", dest="build_report_junit",
71+
default=None, help="Destination path for a build report in the JUnit xml format")
72+
6973
parser.add_option("-v", "--verbose",
7074
action="store_true",
7175
dest="verbose",
@@ -118,16 +122,25 @@
118122

119123
target = TARGET_MAP[options.mcu]
120124

125+
build_report = {}
126+
build_properties = {}
127+
128+
# Build sources
121129
lib_build_res = build_library(base_source_paths, options.build_dir, target, options.tool,
122130
options=options.options,
123131
jobs=options.jobs,
124132
clean=options.clean,
133+
report=build_report,
134+
properties=build_properties,
135+
name="mbed-os",
125136
archive=False)
126137

127138
# Build all the tests
128139
test_build = build_tests(tests, [options.build_dir], options.build_dir, target, options.tool,
129140
options=options.options,
130141
clean=options.clean,
142+
report=build_report,
143+
properties=build_properties,
131144
jobs=options.jobs)
132145

133146
# If a path to a test spec is provided, write it to a file
@@ -147,6 +160,10 @@
147160
print "[ERROR] Error writing test spec to file"
148161
print e
149162

163+
# If a path to a JUnit build report spec is provided, write it to a file
164+
if options.build_report_junit:
165+
report_exporter = ReportExporter(ResultExporterType.JUNIT)
166+
report_exporter.report_to_file(build_report, options.build_report_junit, test_suite_properties=build_properties)
150167
sys.exit()
151168

152169
except KeyboardInterrupt, e:

tools/test_exporters.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
Author: Przemyslaw Wirkus <[email protected]>
1818
"""
1919

20-
from tools.utils import construct_enum
20+
from tools.utils import construct_enum, mkdir
21+
import os
2122

2223

2324
ResultExporterType = construct_enum(HTML='Html_Exporter',
@@ -97,6 +98,9 @@ def report_to_file(self, test_summary_ext, file_name, test_suite_properties=None
9798

9899
def write_to_file(self, report, file_name):
99100
if report is not None:
101+
dirname = os.path.dirname(file_name)
102+
if dirname:
103+
mkdir(dirname)
100104
with open(file_name, 'w') as f:
101105
f.write(report)
102106

0 commit comments

Comments
 (0)