sanitycheck: control coverage from command line

Added a new command line options to sanitycheck:
--enable-coverage which will compile for native_posix
with CONFIG_COVERAGE set, and unit tests accordingly.
+
Now -C --coverage implies also --enable-coverage.

Background:
After 608778a4de
it is possible to add Kconfig options from command
line during the cmake invocation.
So we can use it to set CONFIG_COVERAGE for the native_posix
target when we need to instead of relaying on it always
being compiled with coverage enabled.

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
This commit is contained in:
Alberto Escolar Piedras 2018-06-21 09:30:20 +02:00 committed by Anas Nashif
commit c026c2ed82
2 changed files with 20 additions and 3 deletions

View file

@ -160,8 +160,10 @@ The sanitycheck script accepts the following optional arguments:
to CMake. E.g "sanitycheck -x=USE_CCACHE=0" will
translate to "cmake -DUSE_CCACHE=0" which will
ultimately disable ccache.
--enable-coverage Enable code coverage when building unit tests and when
targeting the native_posix board
-C, --coverage Generate coverage report for unit tests, and tests and
samples run in native_posix.
samples run in native_posix. Implies --enable-coverage.
Board Configuration

View file

@ -1042,7 +1042,8 @@ class MakeGenerator:
run_logfile = os.path.join(outdir, "run.log")
handler_logfile = os.path.join(outdir, "handler.log")
args += ["COVERAGE=1", "EXTRA_LDFLAGS=--coverage"]
if options.enable_coverage:
args += ["COVERAGE=1", "EXTRA_LDFLAGS=--coverage"]
# we handle running in the UnitHandler class
text = (self._get_rule_header(name) +
@ -1065,6 +1066,9 @@ class MakeGenerator:
run_logfile = os.path.join(outdir, "run.log")
handler_logfile = os.path.join(outdir, "handler.log")
if options.enable_coverage:
args += ["CONFIG_COVERAGE=y"]
# we handle running in the NativeHandler class
text = (self._get_rule_header(name) +
self._get_sub_make(name, "building", directory,
@ -1877,6 +1881,9 @@ class TestSuite:
# each other since they all try to build them
# simultaneously
if plat.type == "native" and options.enable_coverage:
args.append("CONFIG_COVERAGE=y")
o = os.path.join(self.outdir, plat.name, tc.path)
dlist[tc, plat, tc.name.split(
"/")[-1]] = os.path.join(o, "zephyr", ".config")
@ -2544,9 +2551,14 @@ def parse_arguments():
"""
)
parser.add_argument("--enable-coverage", action="store_true",
help="Enable code coverage when building unit tests and"
" when targeting the native_posix board")
parser.add_argument("-C", "--coverage", action="store_true",
help="Generate coverage report for unit tests, and"
" tests and samples run in native_posix.")
" tests and samples run in native_posix. Implies"
" --enable_coverage")
return parser.parse_args()
@ -2689,6 +2701,9 @@ def main():
global options
options = parse_arguments()
if options.coverage:
options.enable_coverage = True
if options.size:
for fn in options.size:
size_report(SizeCalculator(fn, []))