From cdd01f3b9ee0cbe90241276d8413e78d185f0484 Mon Sep 17 00:00:00 2001 From: Derek G Foster Date: Mon, 4 Nov 2024 09:11:55 -0800 Subject: [PATCH] Scripts to generate unit test coverage reports (#708) Signed-off-by: Derek Foster --- scripts/dpdk/report-krnlmon-coverage.sh | 48 +++++++++++++++++++++++++ scripts/dpdk/report-ovsp4rt-coverage.sh | 48 +++++++++++++++++++++++++ scripts/es2k/report-krnlmon-coverage.sh | 48 +++++++++++++++++++++++++ scripts/es2k/report-ovsp4rt-coverage.sh | 48 +++++++++++++++++++++++++ 4 files changed, 192 insertions(+) create mode 100755 scripts/dpdk/report-krnlmon-coverage.sh create mode 100755 scripts/dpdk/report-ovsp4rt-coverage.sh create mode 100755 scripts/es2k/report-krnlmon-coverage.sh create mode 100755 scripts/es2k/report-ovsp4rt-coverage.sh diff --git a/scripts/dpdk/report-krnlmon-coverage.sh b/scripts/dpdk/report-krnlmon-coverage.sh new file mode 100755 index 00000000..8ee61f44 --- /dev/null +++ b/scripts/dpdk/report-krnlmon-coverage.sh @@ -0,0 +1,48 @@ +#!/bin/bash +# +# Copyright 2024 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 +# +# Reports unit test code coverage for KRNLMON on DPDK. +# +# You must build the tests with coverage enabled before +# running this script. For example: +# +# cmake -B build -C dpdk.cmake -DTEST_COVERAGE=ON +# cmake --build build -j5 --target krnlmon-unit-tests +# + +set -e + +# Folder under which to search for .gcda files. +INPUT_DIR=build/krnlmon/krnlmon/ + +# Folder in which the report will be generated. +OUTPUT_DIR=build/Coverage/krnlmon/dpdk + +# Label identifying the tests to report on. +TEST_LABEL=krnlmon + +# Select tests with the specified label, run the tests, +# and compute coverage of the source code. +(cd build; ctest -L ${TEST_LABEL} -T test -T coverage) + +# Make sure the output directory exists. +mkdir -p ${OUTPUT_DIR} + +# Empty it for good measure. +rm -fr ${OUTPUT_DIR:?}/* + +# Capture the coverage data, excluding files in directories +# that don't interest us. +lcov --capture \ + --directory ${INPUT_DIR} \ + --output-file ${OUTPUT_DIR}/coverage.info \ + --exclude '/opt/deps/*' \ + --exclude '/usr/include/*' + +# Generate html coverage report. +genhtml ${OUTPUT_DIR}/coverage.info \ + --output-directory ${OUTPUT_DIR} + +echo "Coverage report is in ${OUTPUT_DIR}." diff --git a/scripts/dpdk/report-ovsp4rt-coverage.sh b/scripts/dpdk/report-ovsp4rt-coverage.sh new file mode 100755 index 00000000..295baef3 --- /dev/null +++ b/scripts/dpdk/report-ovsp4rt-coverage.sh @@ -0,0 +1,48 @@ +#!/bin/bash +# +# Copyright 2024 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 +# +# Reports unit test code coverage for OVSP4RT on DPDK. +# +# You must build the tests with coverage enabled before +# running this script. For example: +# +# cmake -B build -C dpdk.cmake -DTEST_COVERAGE=ON +# cmake --build build -j5 --target ovsp4rt-unit-tests +# + +set -e + +# Folder under which to search for .gcda files. +INPUT_DIR=build/ovs-p4rt/sidecar/ + +# Folder in which the report will be generated. +OUTPUT_DIR=build/Coverage/ovsp4rt/dpdk + +# Label identifying the tests to report on. +TEST_LABEL=ovsp4rt + +# Select tests with the specified label, run the tests, +# and compute coverage of the source code. +(cd build; ctest -L ${TEST_LABEL} -T test -T coverage) + +# Make sure the output directory exists. +mkdir -p ${OUTPUT_DIR} + +# Empty it for good measure. +rm -fr ${OUTPUT_DIR:?}/* + +# Capture the coverage data, excluding files in directories +# that don't interest us. +lcov --capture \ + --directory ${INPUT_DIR} \ + --output-file ${OUTPUT_DIR}/coverage.info \ + --exclude '/opt/deps/*' \ + --exclude '/usr/include/*' + +# Generate html coverage report. +genhtml ${OUTPUT_DIR}/coverage.info \ + --output-directory ${OUTPUT_DIR} + +echo "Coverage report is in ${OUTPUT_DIR}." diff --git a/scripts/es2k/report-krnlmon-coverage.sh b/scripts/es2k/report-krnlmon-coverage.sh new file mode 100755 index 00000000..af410409 --- /dev/null +++ b/scripts/es2k/report-krnlmon-coverage.sh @@ -0,0 +1,48 @@ +#!/bin/bash +# +# Copyright 2024 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 +# +# Reports unit test code coverage for KRNLMON on ES2K. +# +# You must build the tests with coverage enabled before +# running this script. For example: +# +# cmake --preset es2k -DTEST_COVERAGE=ON +# cmake --build build -j5 --target krnlmon-unit-tests +# + +set -e + +# Folder under which to search for .gcda files. +INPUT_DIR=build/krnlmon/krnlmon/ + +# Folder in which the report will be generated. +OUTPUT_DIR=build/Coverage/krnlmon/es2k + +# Label identifying the tests to report on. +TEST_LABEL=krnlmon + +# Select tests with the specified label, run the tests, +# and compute coverage of the source code. +(cd build; ctest -L ${TEST_LABEL} -T test -T coverage) + +# Make sure the output directory exists. +mkdir -p ${OUTPUT_DIR} + +# Empty it for good measure. +rm -fr ${OUTPUT_DIR:?}/* + +# Capture the coverage data, excluding files in directories +# that don't interest us. +lcov --capture \ + --directory ${INPUT_DIR} \ + --output-file ${OUTPUT_DIR}/coverage.info \ + --exclude '/opt/deps/*' \ + --exclude '/usr/include/*' + +# Generate html coverage report. +genhtml ${OUTPUT_DIR}/coverage.info \ + --output-directory ${OUTPUT_DIR} + +echo "Coverage report is in ${OUTPUT_DIR}." diff --git a/scripts/es2k/report-ovsp4rt-coverage.sh b/scripts/es2k/report-ovsp4rt-coverage.sh new file mode 100755 index 00000000..e3795704 --- /dev/null +++ b/scripts/es2k/report-ovsp4rt-coverage.sh @@ -0,0 +1,48 @@ +#!/bin/bash +# +# Copyright 2024 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 +# +# Reports unit test code coverage for OVSP4RT on ES2K. +# +# You must build the tests with coverage enabled before +# running this script. For example: +# +# cmake --preset es2k -DTEST_COVERAGE=ON +# cmake --build build -j5 --target ovsp4rt-unit-tests +# + +set -e + +# Folder under which to search for .gcda files. +INPUT_DIR=build/ovs-p4rt/sidecar/ + +# Folder in which the report will be generated. +OUTPUT_DIR=build/Coverage/ovsp4rt/es2k + +# Label identifying the tests to report on. +TEST_LABEL=ovsp4rt + +# Select tests with the specified label, run the tests, +# and compute coverage of the source code. +(cd build; ctest -L ${TEST_LABEL} -T test -T coverage) + +# Make sure the output directory exists. +mkdir -p ${OUTPUT_DIR} + +# Empty it for good measure. +rm -fr ${OUTPUT_DIR:?}/* + +# Capture the coverage data, excluding files in directories +# that don't interest us. +lcov --capture \ + --directory ${INPUT_DIR} \ + --output-file ${OUTPUT_DIR}/coverage.info \ + --exclude '/opt/deps/*' \ + --exclude '/usr/include/*' + +# Generate html coverage report. +genhtml ${OUTPUT_DIR}/coverage.info \ + --output-directory ${OUTPUT_DIR} + +echo "Coverage report is in ${OUTPUT_DIR}."