From 513fb7f5685b610d367ef88e306c300e6edcc4ff Mon Sep 17 00:00:00 2001 From: Yufeng Wang Date: Thu, 22 Sep 2022 15:29:07 -0700 Subject: [PATCH 1/2] Improve matter gcoverage accuracy by excluding unit test files --- scripts/build/builders/host.py | 4 ++-- scripts/build_coverage.sh | 35 ++++++++++++++++++++++++++++++++-- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/scripts/build/builders/host.py b/scripts/build/builders/host.py index 3e299384e2c3da..5e0161bb2adb91 100644 --- a/scripts/build/builders/host.py +++ b/scripts/build/builders/host.py @@ -365,12 +365,12 @@ def generate(self): def PreBuildCommand(self): if self.app == HostApp.TESTS and self.use_coverage: self._Execute(['ninja', '-C', self.output_dir, 'default'], title="Build-only") - self._Execute(['lcov', '--initial', '--capture', '--directory', os.path.join(self.output_dir, 'obj'), '--exclude', os.path.join(self.chip_dir, 'third_party/*'), '--exclude', '/usr/include/*', + self._Execute(['lcov', '--initial', '--capture', '--directory', os.path.join(self.output_dir, 'obj'), '--exclude', os.path.join(self.chip_dir, 'zzz_generated/*'), '--exclude', os.path.join(self.chip_dir, 'third_party/*'), '--exclude', '/usr/include/*', '--output-file', os.path.join(self.coverage_dir, 'lcov_base.info')], title="Initial coverage baseline") def PostBuildCommand(self): if self.app == HostApp.TESTS and self.use_coverage: - self._Execute(['lcov', '--capture', '--directory', os.path.join(self.output_dir, 'obj'), '--exclude', os.path.join(self.chip_dir, 'third_party/*'), '--exclude', '/usr/include/*', + self._Execute(['lcov', '--capture', '--directory', os.path.join(self.output_dir, 'obj'), '--exclude', os.path.join(self.chip_dir, 'zzz_generated/*'), '--exclude', os.path.join(self.chip_dir, 'third_party/*'), '--exclude', '/usr/include/*', '--output-file', os.path.join(self.coverage_dir, 'lcov_test.info')], title="Update coverage") self._Execute(['lcov', '--add-tracefile', os.path.join(self.coverage_dir, 'lcov_base.info'), '--add-tracefile', os.path.join(self.coverage_dir, 'lcov_test.info'), diff --git a/scripts/build_coverage.sh b/scripts/build_coverage.sh index b7223ce2e4aa0b..67961cc43e119b 100755 --- a/scripts/build_coverage.sh +++ b/scripts/build_coverage.sh @@ -92,8 +92,39 @@ if [ "$skip_gn" == false ]; then ninja -C "$OUTPUT_ROOT" check fi +echo "PWD:$PWD" +echo "CHIP_ROOT:$CHIP_ROOT" +echo "OUTPUT_ROOT:$OUTPUT_ROOT" + +rm -rf "$OUTPUT_ROOT/obj/src/access/tests" +rm -rf "$OUTPUT_ROOT/obj/src/app/tests" +rm -rf "$OUTPUT_ROOT/obj/src/ble/tests" +rm -rf "$OUTPUT_ROOT/obj/src/controller/tests" +rm -rf "$OUTPUT_ROOT/obj/src/credentials/tests" +rm -rf "$OUTPUT_ROOT/obj/src/crypto/tests" +rm -rf "$OUTPUT_ROOT/obj/src/inet/tests" +rm -rf "$OUTPUT_ROOT/obj/src/lib/asn1/tests" +rm -rf "$OUTPUT_ROOT/obj/src/lib/core/tests" +rm -rf "$OUTPUT_ROOT/obj/src/lib/dnssd/minimal_mdns/tests" +rm -rf "$OUTPUT_ROOT/obj/src/lib/dnssd/minimal_mdns/core/tests" +rm -rf "$OUTPUT_ROOT/obj/src/lib/dnssd/minimal_mdns/records/tests" +rm -rf "$OUTPUT_ROOT/obj/src/lib/dnssd/minimal_mdns/responders/tests" +rm -rf "$OUTPUT_ROOT/obj/src/lib/dnssd/tests" +rm -rf "$OUTPUT_ROOT/obj/src/lib/shell/tests" +rm -rf "$OUTPUT_ROOT/obj/src/lib/support/tests" +rm -rf "$OUTPUT_ROOT/obj/src/messaging/tests" +rm -rf "$OUTPUT_ROOT/obj/src/platform/tests" +rm -rf "$OUTPUT_ROOT/obj/src/protocols/bdx/tests" +rm -rf "$OUTPUT_ROOT/obj/src/protocols/secure_channel/tests" +rm -rf "$OUTPUT_ROOT/obj/src/protocols/user_directed_commissioning/tests" +rm -rf "$OUTPUT_ROOT/obj/src/setup_payload/tests" +rm -rf "$OUTPUT_ROOT/obj/src/system/tests" +rm -rf "$OUTPUT_ROOT/obj/src/transport/tests" +rm -rf "$OUTPUT_ROOT/obj/src/transport/raw/tests" +rm -rf "$OUTPUT_ROOT/obj/src/transport/retransmit/tests" + mkdir -p "$COVERAGE_ROOT" -lcov --initial --capture --directory "$OUTPUT_ROOT/obj/src" --exclude="$CHIP_ROOT/third_party/*" --exclude=/usr/include/* --output-file "$COVERAGE_ROOT/lcov_base.info" -lcov --capture --directory "$OUTPUT_ROOT/obj/src" --exclude="$CHIP_ROOT/third_party/*" --exclude=/usr/include/* --output-file "$COVERAGE_ROOT/lcov_test.info" +lcov --initial --capture --directory "$OUTPUT_ROOT/obj/src" --exclude="$PWD"/zzz_generated/* --exclude="$PWD"/third_party/* --exclude=/usr/include/* --output-file "$COVERAGE_ROOT/lcov_base.info" +lcov --capture --directory "$OUTPUT_ROOT/obj/src" --exclude="$PWD"/zzz_generated/* --exclude="$PWD"/third_party/* --exclude=/usr/include/* --output-file "$COVERAGE_ROOT/lcov_test.info" lcov --add-tracefile "$COVERAGE_ROOT/lcov_base.info" --add-tracefile "$COVERAGE_ROOT/lcov_test.info" --output-file "$COVERAGE_ROOT/lcov_final.info" genhtml "$COVERAGE_ROOT/lcov_final.info" --output-directory "$COVERAGE_ROOT/html" From 4bbf94568b7b452dc580b5740b4f719d858e4871 Mon Sep 17 00:00:00 2001 From: Yufeng Wang Date: Fri, 23 Sep 2022 12:24:37 -0700 Subject: [PATCH 2/2] Address review comment --- scripts/build/builders/host.py | 2 ++ scripts/build_coverage.sh | 32 ++------------------------------ 2 files changed, 4 insertions(+), 30 deletions(-) diff --git a/scripts/build/builders/host.py b/scripts/build/builders/host.py index 5e0161bb2adb91..a599b0f6e6c3cf 100644 --- a/scripts/build/builders/host.py +++ b/scripts/build/builders/host.py @@ -365,6 +365,8 @@ def generate(self): def PreBuildCommand(self): if self.app == HostApp.TESTS and self.use_coverage: self._Execute(['ninja', '-C', self.output_dir, 'default'], title="Build-only") + self._Execute(['find', os.path.join(self.output_dir, 'obj/src/'), '-depth', + '-name', 'tests', '-exec', 'rm -rf {} \;'], title="Cleanup unit tests") self._Execute(['lcov', '--initial', '--capture', '--directory', os.path.join(self.output_dir, 'obj'), '--exclude', os.path.join(self.chip_dir, 'zzz_generated/*'), '--exclude', os.path.join(self.chip_dir, 'third_party/*'), '--exclude', '/usr/include/*', '--output-file', os.path.join(self.coverage_dir, 'lcov_base.info')], title="Initial coverage baseline") diff --git a/scripts/build_coverage.sh b/scripts/build_coverage.sh index 67961cc43e119b..91f5e7f4f0e2a0 100755 --- a/scripts/build_coverage.sh +++ b/scripts/build_coverage.sh @@ -92,36 +92,8 @@ if [ "$skip_gn" == false ]; then ninja -C "$OUTPUT_ROOT" check fi -echo "PWD:$PWD" -echo "CHIP_ROOT:$CHIP_ROOT" -echo "OUTPUT_ROOT:$OUTPUT_ROOT" - -rm -rf "$OUTPUT_ROOT/obj/src/access/tests" -rm -rf "$OUTPUT_ROOT/obj/src/app/tests" -rm -rf "$OUTPUT_ROOT/obj/src/ble/tests" -rm -rf "$OUTPUT_ROOT/obj/src/controller/tests" -rm -rf "$OUTPUT_ROOT/obj/src/credentials/tests" -rm -rf "$OUTPUT_ROOT/obj/src/crypto/tests" -rm -rf "$OUTPUT_ROOT/obj/src/inet/tests" -rm -rf "$OUTPUT_ROOT/obj/src/lib/asn1/tests" -rm -rf "$OUTPUT_ROOT/obj/src/lib/core/tests" -rm -rf "$OUTPUT_ROOT/obj/src/lib/dnssd/minimal_mdns/tests" -rm -rf "$OUTPUT_ROOT/obj/src/lib/dnssd/minimal_mdns/core/tests" -rm -rf "$OUTPUT_ROOT/obj/src/lib/dnssd/minimal_mdns/records/tests" -rm -rf "$OUTPUT_ROOT/obj/src/lib/dnssd/minimal_mdns/responders/tests" -rm -rf "$OUTPUT_ROOT/obj/src/lib/dnssd/tests" -rm -rf "$OUTPUT_ROOT/obj/src/lib/shell/tests" -rm -rf "$OUTPUT_ROOT/obj/src/lib/support/tests" -rm -rf "$OUTPUT_ROOT/obj/src/messaging/tests" -rm -rf "$OUTPUT_ROOT/obj/src/platform/tests" -rm -rf "$OUTPUT_ROOT/obj/src/protocols/bdx/tests" -rm -rf "$OUTPUT_ROOT/obj/src/protocols/secure_channel/tests" -rm -rf "$OUTPUT_ROOT/obj/src/protocols/user_directed_commissioning/tests" -rm -rf "$OUTPUT_ROOT/obj/src/setup_payload/tests" -rm -rf "$OUTPUT_ROOT/obj/src/system/tests" -rm -rf "$OUTPUT_ROOT/obj/src/transport/tests" -rm -rf "$OUTPUT_ROOT/obj/src/transport/raw/tests" -rm -rf "$OUTPUT_ROOT/obj/src/transport/retransmit/tests" +# Remove unit test itself from coverage statistics +find "$OUTPUT_ROOT/obj/src/" -depth -name 'tests' -exec rm -rf {} \; mkdir -p "$COVERAGE_ROOT" lcov --initial --capture --directory "$OUTPUT_ROOT/obj/src" --exclude="$PWD"/zzz_generated/* --exclude="$PWD"/third_party/* --exclude=/usr/include/* --output-file "$COVERAGE_ROOT/lcov_base.info"