mirror of https://github.com/ARMmbed/mbed-os.git
Unit tests: improve argument checking in coverage.py
parent
04c98b0223
commit
00397b232c
|
@ -25,12 +25,15 @@ import re
|
||||||
|
|
||||||
from .utils import execute_program
|
from .utils import execute_program
|
||||||
from .get_tools import get_gcov_program, \
|
from .get_tools import get_gcov_program, \
|
||||||
get_gcovr_program
|
get_gcovr_program
|
||||||
|
from .settings import COVERAGE_OUTPUT_TYPES
|
||||||
|
|
||||||
|
|
||||||
class CoverageAPI(object):
|
class CoverageAPI(object):
|
||||||
"""
|
"""
|
||||||
Generate code coverage reports for unit tests.
|
Generate code coverage reports for unit tests.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, mbed_os_root=None, build_dir=None):
|
def __init__(self, mbed_os_root=None, build_dir=None):
|
||||||
self.root = mbed_os_root
|
self.root = mbed_os_root
|
||||||
|
|
||||||
|
@ -62,6 +65,8 @@ class CoverageAPI(object):
|
||||||
args.extend(["-x",
|
args.extend(["-x",
|
||||||
"-o",
|
"-o",
|
||||||
"./coverage.xml"])
|
"./coverage.xml"])
|
||||||
|
else:
|
||||||
|
logging.error("Invalid coverage output type: %s" % coverage_type)
|
||||||
|
|
||||||
# Add exclude filters:
|
# Add exclude filters:
|
||||||
for path in excludes:
|
for path in excludes:
|
||||||
|
@ -103,9 +108,11 @@ class CoverageAPI(object):
|
||||||
build_path - build path
|
build_path - build path
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# Check for the tool
|
||||||
if get_gcovr_program() is None:
|
if get_gcovr_program() is None:
|
||||||
logging.error("No gcovr tool found in path. \
|
logging.error(
|
||||||
Cannot generate coverage reports.")
|
"No gcovr tool found in path. " +
|
||||||
|
"Cannot generate coverage reports.")
|
||||||
return
|
return
|
||||||
|
|
||||||
if build_path is None:
|
if build_path is None:
|
||||||
|
@ -118,19 +125,24 @@ class CoverageAPI(object):
|
||||||
excludes = []
|
excludes = []
|
||||||
|
|
||||||
for output in outputs:
|
for output in outputs:
|
||||||
|
# Skip if invalid/unsupported output type
|
||||||
|
if output not in COVERAGE_OUTPUT_TYPES:
|
||||||
|
logging.warning(
|
||||||
|
"Invalid output type. " +
|
||||||
|
"Skip coverage report for type: %s." % output.upper())
|
||||||
|
continue
|
||||||
|
|
||||||
if output == "html":
|
if output == "html":
|
||||||
# Create build directory if not exist.
|
# Create a build directory if not exist
|
||||||
coverage_path = os.path.join(build_path, "coverage")
|
coverage_path = os.path.join(build_path, "coverage")
|
||||||
if not os.path.exists(coverage_path):
|
if not os.path.exists(coverage_path):
|
||||||
os.mkdir(coverage_path)
|
os.mkdir(coverage_path)
|
||||||
|
|
||||||
|
# Generate the command
|
||||||
args = self._gen_cmd(output, excludes, filter_regex)
|
args = self._gen_cmd(output, excludes, filter_regex)
|
||||||
|
|
||||||
if output == "html":
|
# Run the coverage tool
|
||||||
execute_program(args,
|
execute_program(
|
||||||
"HTML code coverage report generation failed.",
|
args,
|
||||||
"HTML code coverage report created.")
|
"%s code coverage report generation failed." % output.upper(),
|
||||||
elif output == "xml":
|
"%s code coverage report created." % output.upper())
|
||||||
execute_program(args,
|
|
||||||
"XML code coverage report generation failed.",
|
|
||||||
"XML code coverage report created.")
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ UNIT TEST OPTIONS
|
||||||
import argparse
|
import argparse
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from .settings import CMAKE_GENERATORS, MAKE_PROGRAMS, COVERAGE_TYPES
|
from .settings import CMAKE_GENERATORS, MAKE_PROGRAMS, COVERAGE_ARGS
|
||||||
from .get_tools import get_make_tool
|
from .get_tools import get_make_tool
|
||||||
|
|
||||||
def get_options_parser():
|
def get_options_parser():
|
||||||
|
@ -71,7 +71,7 @@ def get_options_parser():
|
||||||
dest="debug_build")
|
dest="debug_build")
|
||||||
|
|
||||||
parser.add_argument("--coverage",
|
parser.add_argument("--coverage",
|
||||||
choices=COVERAGE_TYPES,
|
choices=COVERAGE_ARGS,
|
||||||
help="Generate code coverage report",
|
help="Generate code coverage report",
|
||||||
dest="coverage")
|
dest="coverage")
|
||||||
|
|
||||||
|
|
|
@ -29,10 +29,12 @@ DEFAULT_CMAKE_GENERATORS = {
|
||||||
"ninja": "Ninja"
|
"ninja": "Ninja"
|
||||||
}
|
}
|
||||||
|
|
||||||
COVERAGE_TYPES = ["html",
|
COVERAGE_ARGS = ["html",
|
||||||
"xml",
|
"xml",
|
||||||
"both"]
|
"both"]
|
||||||
|
|
||||||
|
COVERAGE_OUTPUT_TYPES = ["html", "xml"]
|
||||||
|
|
||||||
CXX_COMPILERS = ["g++-6", "g++-8", "g++-7", "g++-5", "g++-4.9", "g++"]
|
CXX_COMPILERS = ["g++-6", "g++-8", "g++-7", "g++-5", "g++-4.9", "g++"]
|
||||||
|
|
||||||
C_COMPILERS = ["gcc-6", "gcc-8", "gcc-7", "gcc-5", "gcc-4.9", "gcc"]
|
C_COMPILERS = ["gcc-6", "gcc-8", "gcc-7", "gcc-5", "gcc-4.9", "gcc"]
|
||||||
|
|
Loading…
Reference in New Issue