diff --git a/scripts/sanity_chk/sanitylib.py b/scripts/sanity_chk/sanitylib.py index 65ccf481c02678..ac5b4877b948f0 100644 --- a/scripts/sanity_chk/sanitylib.py +++ b/scripts/sanity_chk/sanitylib.py @@ -1854,6 +1854,8 @@ def setup_handler(self): elif instance.testcase.type == "unit": instance.handler = BinaryHandler(instance, "unit") instance.handler.binary = os.path.join(instance.build_dir, "testbinary") + if self.coverage: + args.append("COVERAGE=1") elif instance.platform.type == "native": handler = BinaryHandler(instance, "native") diff --git a/subsys/testsuite/unittest.cmake b/subsys/testsuite/unittest.cmake index 89cdd9da62d4fb..c3fa7dae11c70d 100644 --- a/subsys/testsuite/unittest.cmake +++ b/subsys/testsuite/unittest.cmake @@ -71,6 +71,10 @@ if(COVERAGE) -fprofile-arcs -ftest-coverage ) + + target_link_libraries(testbinary PRIVATE + -lgcov + ) endif() if(LIBS)