Adding JUnit build reporting option to test.py

Brian Daniels 2016-05-12 19:01:32 +01:00
parent ec2e4a1d6a
commit bc86aa92a0
2 changed files with 22 additions and 1 deletions

View File

@ -30,6 +30,7 @@ from tools.options import get_default_options_parser
from tools.build_api import build_project, build_library
from tools.targets import TARGET_MAP
from tools.utils import mkdir
from tools.test_exporters import ReportExporter, ResultExporterType
if __name__ == '__main__':
try:
@ -66,6 +67,9 @@ if __name__ == '__main__':
parser.add_option("--test-spec", dest="test_spec",
default=None, help="Destination path for a test spec file that can be used by the Greentea automated test tool")
parser.add_option("--build-report-junit", dest="build_report_junit",
default=None, help="Destination path for a build report in the JUnit xml format")
parser.add_option("-v", "--verbose",
action="store_true",
dest="verbose",
@ -118,16 +122,25 @@ if __name__ == '__main__':
target = TARGET_MAP[options.mcu]
build_report = {}
build_properties = {}
# Build sources
lib_build_res = build_library(base_source_paths, options.build_dir, target, options.tool,
options=options.options,
jobs=options.jobs,
clean=options.clean,
report=build_report,
properties=build_properties,
name="mbed-os",
archive=False)
# Build all the tests
test_build = build_tests(tests, [options.build_dir], options.build_dir, target, options.tool,
options=options.options,
clean=options.clean,
report=build_report,
properties=build_properties,
jobs=options.jobs)
# If a path to a test spec is provided, write it to a file
@ -147,6 +160,10 @@ if __name__ == '__main__':
print "[ERROR] Error writing test spec to file"
print e
# If a path to a JUnit build report spec is provided, write it to a file
if options.build_report_junit:
report_exporter = ReportExporter(ResultExporterType.JUNIT)
report_exporter.report_to_file(build_report, options.build_report_junit, test_suite_properties=build_properties)
sys.exit()
except KeyboardInterrupt, e:

View File

@ -17,7 +17,8 @@ limitations under the License.
Author: Przemyslaw Wirkus <Przemyslaw.wirkus@arm.com>
"""
from tools.utils import construct_enum
from tools.utils import construct_enum, mkdir
import os
ResultExporterType = construct_enum(HTML='Html_Exporter',
@ -97,6 +98,9 @@ class ReportExporter():
def write_to_file(self, report, file_name):
if report is not None:
dirname = os.path.dirname(file_name)
if dirname:
mkdir(dirname)
with open(file_name, 'w') as f:
f.write(report)