Skip to content

Commit 42624d0

Browse files
committed
Merge pull request #89 from bridadan/test-build-reporting
Test build reporting
2 parents 61fb65b + bc86aa9 commit 42624d0

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
lines changed

tools/build_api.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,10 @@ def build_project(src_path, build_path, target, toolchain_name,
109109

110110
if report != None:
111111
start = time()
112-
id_name = project_id.upper()
113-
description = project_description
112+
113+
# If project_id is specified, use that over the default name
114+
id_name = project_id.upper() if project_id else name.upper()
115+
description = project_description if project_description else name
114116
vendor_label = target.extra_labels[0]
115117
cur_result = None
116118
prep_report(report, target.name, toolchain_name, id_name)
@@ -190,7 +192,8 @@ def build_project(src_path, build_path, target, toolchain_name,
190192
def build_library(src_paths, build_path, target, toolchain_name,
191193
dependencies_paths=None, options=None, name=None, clean=False, archive=True,
192194
notify=None, verbose=False, macros=None, inc_dirs=None, inc_dirs_ext=None,
193-
jobs=1, silent=False, report=None, properties=None, extra_verbose=False):
195+
jobs=1, silent=False, report=None, properties=None, extra_verbose=False,
196+
project_id=None):
194197
""" src_path: the path of the source directory
195198
build_path: the path of the build directory
196199
target: ['LPC1768', 'LPC11U24', 'LPC2368']
@@ -213,7 +216,9 @@ def build_library(src_paths, build_path, target, toolchain_name,
213216

214217
if report != None:
215218
start = time()
216-
id_name = name.upper()
219+
220+
# If project_id is specified, use that over the default name
221+
id_name = project_id.upper() if project_id else name.upper()
217222
description = name
218223
vendor_label = target.extra_labels[0]
219224
cur_result = None

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)