Skip to content

Commit

Permalink
Improve matter gcoverage accuracy by excluding unit test files
Browse files Browse the repository at this point in the history
  • Loading branch information
yufengwangca committed Sep 22, 2022
1 parent 7189344 commit 513fb7f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
4 changes: 2 additions & 2 deletions scripts/build/builders/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
35 changes: 33 additions & 2 deletions scripts/build_coverage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit 513fb7f

Please sign in to comment.