diff --git a/.github/workflows/L1-Test.yml b/.github/workflows/L1-Test.yml index 0756ec47b..5c1c88769 100644 --- a/.github/workflows/L1-Test.yml +++ b/.github/workflows/L1-Test.yml @@ -2,7 +2,7 @@ name: L1 Unit Tests Remote Debugger on: pull_request: - branches: [ develop, main, feature/RDK-49894 ] + branches: [ develop ] env: AUTOMATICS_UNAME: ${{ secrets.AUTOMATICS_UNAME }} diff --git a/.github/workflows/code-coverage.yml b/.github/workflows/code-coverage.yml new file mode 100644 index 000000000..a53bd33cc --- /dev/null +++ b/.github/workflows/code-coverage.yml @@ -0,0 +1,54 @@ +name: Code Coverage + +on: + pull_request: + branches: [ main ] + +jobs: + execute-unit-code-coverage-report-on-release: + name: Test coverage report for release + runs-on: ubuntu-latest + container: + image: ghcr.io/rdkcentral/docker-rdk-ci:latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Run unit tests with coverage flags enabled + run: | + sh run_ut.sh --enable-cov + - name: Caculate the code coverage summary + run: | + cd ./src/unittest + lcov --list coverage.info | grep "Lines\|Total" > /tmp/coverage_summary.txt + cd - + + - name: Update the coverage report to Pull request using actions + uses: actions/github-script@v4 + with: + script: | + const fs = require('fs'); + const lcov_result = fs.readFileSync('/tmp/coverage_summary.txt', 'utf8'); + + github.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: + '## Code Coverage Summary \n' + + ' ' + + '```' + + lcov_result + + '```' + }); + - name: Generate the html report + run: | + cd ./src/unittest + genhtml coverage.info --output-directory /tmp/coverage_report + cd - + - name: Upload the coverage report to Pull request using actions + uses: actions/upload-artifact@v4 + with: + name: coverage-report + path: /tmp/coverage_report diff --git a/run_ut.sh b/run_ut.sh index 1297ca3eb..6fb0576ce 100644 --- a/run_ut.sh +++ b/run_ut.sh @@ -16,6 +16,17 @@ # SPDX-License-Identifier: Apache-2.0 # +ENABLE_COV=false + +if [ "x$1" = "x--enable-cov" ]; then + echo "Enabling coverage options" + export CXXFLAGS="-g -O0 -fprofile-arcs -ftest-coverage" + export CFLAGS="-g -O0 -fprofile-arcs -ftest-coverage" + export LDFLAGS="-lgcov --coverage" + ENABLE_COV=true +fi + +export TOP_DIR=`pwd` cd ./src/unittest/ echo "********************" @@ -44,10 +55,14 @@ fi echo "********************" echo "**** CAPTURE RDK REMOTE DEBUGGER COVERAGE DATA ****" echo "********************" -lcov --capture --directory . --output-file coverage.info -lcov --remove coverage.info '/usr/*' --output-file coverage.filtered.info -genhtml coverage.filtered.info --output-directory out +if [ "$ENABLE_COV" = true ]; then + echo "Generating coverage report" + lcov --capture --directory . --output-file coverage.info + lcov --remove coverage.info '/usr/*' --output-file coverage.info + lcov --list coverage.info +fi +cd $TOP_DIR echo "********************" echo "**** RUNNING UT ENDS ****" echo "********************"