From c026c2ed82f5a86d749335f77a2ada84fde42bb2 Mon Sep 17 00:00:00 2001 From: Alberto Escolar Piedras Date: Thu, 21 Jun 2018 09:30:20 +0200 Subject: [PATCH] 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 608778a4de8f1441b86d03147ec61fcf7a0d98ac 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 --- doc/subsystems/test/sanitycheck.rst | 4 +++- scripts/sanitycheck | 19 +++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/doc/subsystems/test/sanitycheck.rst b/doc/subsystems/test/sanitycheck.rst index fe89a6d7da3..d36c812ad7d 100644 --- a/doc/subsystems/test/sanitycheck.rst +++ b/doc/subsystems/test/sanitycheck.rst @@ -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 diff --git a/scripts/sanitycheck b/scripts/sanitycheck index f896f3bcfcf..cbd0a710b75 100755 --- a/scripts/sanitycheck +++ b/scripts/sanitycheck @@ -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, []))