Skip to content

Commit

Permalink
[#407] Unit test coverage (#433)
Browse files Browse the repository at this point in the history
* [#407] Added Sample coverage singular test

* [#407] Added on-push trigger for testing

* [#407] Remove make debug from sample CI

* [#407] Source Env Vars from Makefile

* [#407] Added make coverage-sample

* [#407] Initial gcov test

* [#407] Run update to install lcov

* [#407] Remove sudo call

* [#407] Add lcov coverage report generation and upload

* [#407] remove genhtml install

* [#407] Add make coverage

* [#407] Modify lcov commands

* [#407] Missing separator fix

* [#407] Remove coverage from makefile

* [#407] Read coverage for whole directory

* [#407] Switch lcov directory to sample

* [#407] Try build

* [#407] Alternative coverage flags

* [#407] Add coverage flags to build-test make command

* [#407] Modify Cmake flags

* [#407] Modify coverage report path

* [#407] Modify coverage report path

* [#407] Modify upload-artifact to v4

* [#407] Modify coverage test file regex

* [#407] Attempt uploading report to codecov

* [#407] Use cFE code coverage workflow

* [#407] Rerun CI

* [#407] Exclude io_lib

* [#407] Exclude io_lib 2

* [#407] Exclude io_lib 3

* [#407] Exclude io_lib 4

* [#407] Exclude io_lib 5

* [#407] Exclude io_lib 6

* [#407] Cleanup makefile and removed extra flags from component settings;

* [#407] Changed CI to run on push only and removed a number of unit tests from SC due to segfault (to address in another issue);

* [#407] Attempt to set additional ITC_C_FLAGS during coverage CI runs to create .,gcda files;

* [#407] Combine make coverage and gcov

* [#407] Updates to new container 20241219, hwlib to include gcov, io_lib to remove old artifacts, and make gcov to simplify CI;

* [#407] Update Workflow For Coverage

* [#407] Fix Coverage Flags

* Update coverage badges

* [#407] Update Build Tests Step

* [#407] Ignore Parse Errors GCov

* Update coverage badges

* [#407] Updates for Badges

* [#407] Update Artifact Action to v4

* [#407] Update to submodules after code reviews and merge requests;

* [#407] Change to run CI only on pull request;

---------

Co-authored-by: Donnie-Ice <[email protected]>
Co-authored-by: NDC\rjbrown6 <[email protected]>
Co-authored-by: github-actions <[email protected]>
  • Loading branch information
4 people authored Jan 8, 2025
1 parent 246a693 commit 3c61261
Show file tree
Hide file tree
Showing 12 changed files with 80 additions and 12 deletions.
60 changes: 58 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
fsw:
runs-on: ubuntu-latest
container:
image: ivvitc/nos3-64:20241010
image: ivvitc/nos3-64:20241219
steps:
- uses: actions/checkout@v4
with:
Expand All @@ -26,7 +26,7 @@ jobs:
sim:
runs-on: ubuntu-latest
container:
image: ivvitc/nos3-64:20241010
image: ivvitc/nos3-64:20241219
steps:
- uses: actions/checkout@v4
with:
Expand All @@ -36,3 +36,59 @@ jobs:
run: make config
- name: build
run: make build-sim

coverage:
runs-on: ubuntu-latest
container:
image: ivvitc/nos3-64:20241219
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 1
submodules: recursive
- name: Configure Safe Directory
run: git config --global --add safe.directory $GITHUB_WORKSPACE
- name: Update
run: apt-get update
- name: install dependencies
run: apt-get install -y gcc lcov gcovr bc
- name: config
run: make config
- name: build-test
run: |
export CFLAGS="-fprofile-arcs -ftest-coverage -g"
make build-test
make test-fsw
# - name: Generate Coverage Report
# run: make gcov
- name: Generate Coverage Report and Badges
run: |
mkdir -p docs/coverage
gcovr --gcov-ignore-parse-errors --branches --xml-pretty --exclude-unreachable-branches -o docs/coverage/coverage_report.xml
gcovr --gcov-ignore-parse-errors --branches --html --html-details -o docs/coverage/coverage_report.html
LINE_COVERAGE=$(grep -oP '(?<=<coverage line-rate=")[0-9.]+(?=")' docs/coverage/coverage_report.xml | head -n 1)
BRANCH_COVERAGE=$(grep -oP '(?<=branch-rate=")[0-9.]+(?=")' docs/coverage/coverage_report.xml | head -n 1)
LINE_COVERAGE_PERCENT=$(printf "%.0f" $(echo "$LINE_COVERAGE * 100" | bc))
BRANCH_COVERAGE_PERCENT=$(printf "%.0f" $(echo "$BRANCH_COVERAGE * 100" | bc))
if [ "$LINE_COVERAGE_PERCENT" -ge 80 ]; then LINE_COLOR="brightgreen"; elif [ "$LINE_COVERAGE_PERCENT" -ge 50 ]; then LINE_COLOR="yellow"; else LINE_COLOR="red"; fi
if [ "$BRANCH_COVERAGE_PERCENT" -ge 80 ]; then BRANCH_COLOR="brightgreen"; elif [ "$BRANCH_COVERAGE_PERCENT" -ge 50 ]; then BRANCH_COLOR="yellow"; else BRANCH_COLOR="red"; fi
curl -o docs/coverage/line-coverage-badge.svg "https://img.shields.io/badge/line%20coverage-${LINE_COVERAGE_PERCENT}%25-${LINE_COLOR}"
curl -o docs/coverage/branch-coverage-badge.svg "https://img.shields.io/badge/branch%20coverage-${BRANCH_COVERAGE_PERCENT}%25-${BRANCH_COLOR}"
- name: Commit Coverage Badges
run: |
git config user.name "github-actions"
git config user.email "[email protected]"
git add docs/coverage/line-coverage-badge.svg
git add docs/coverage/branch-coverage-badge.svg
git commit -m "Update coverage badges" || echo "No changes to commit"
git push origin HEAD
- name: Archive Coverage Directory
uses: actions/upload-artifact@v4
with:
name: coverage-artifacts
path: docs/coverage
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v5
with:
token: 040717d0-b624-470e-be41-d08720135088
14 changes: 11 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ INSTALLPREFIX ?= exe
FSWBUILDDIR ?= $(CURDIR)/fsw/build
GSWBUILDDIR ?= $(CURDIR)/gsw/build
SIMBUILDDIR ?= $(CURDIR)/sims/build
COVERAGEDIR ?= $(CURDIR)/fsw/build/amd64-posix/default_cpu1

export CFS_APP_PATH = ../components
export MISSION_DEFS = ../cfg/build/
export MISSIONCONFIG = ../cfg/build/nos3

# The "prep" step requires extra options that are specified via enviroment variables.

# The "prep" step requires extra options that are specified via environment variables.
# Certain special ones should be passed via cache (-D) options to CMake.
# These are only needed for the "prep" target but they are computed globally anyway.
PREP_OPTS :=
Expand All @@ -28,9 +30,10 @@ ifneq ($(BUILDTYPE),)
PREP_OPTS += -DCMAKE_BUILD_TYPE=$(BUILDTYPE)
endif


# The "LOCALTGTS" defines the top-level targets that are implemented in this makefile
# Any other target may also be given, in that case it will simply be passed through.
LOCALTGTS := all checkout clean clean-fsw clean-sim clean-gsw config debug fsw gsw launch log prep sim stop stop-gsw uninstall
LOCALTGTS := all checkout clean clean-fsw clean-sim clean-gsw config debug fsw gcov gsw launch log prep sim stop stop-gsw uninstall
OTHERTGTS := $(filter-out $(LOCALTGTS),$(MAKECMDGOALS))

# As this makefile does not build any real files, treat everything as a PHONY target
Expand Down Expand Up @@ -107,6 +110,11 @@ debug:
fsw:
./cfg/build/fsw_build.sh

gcov:
cd $(COVERAGEDIR) && ctest -O ctest.log
lcov -c --directory . --output-file $(COVERAGEDIR)/coverage.info
genhtml $(COVERAGEDIR)/coverage.info --output-directory $$(COVERAGEDIR)/results

gsw:
./scripts/gsw/build_cryptolib.sh
./cfg/build/gsw_build.sh
Expand Down Expand Up @@ -145,7 +153,7 @@ stop-gsw:
./scripts/gsw/stop_gsw.sh

test-fsw:
cd $(FSWBUILDDIR)/amd64-posix/default_cpu1 && ctest -O ctest.log
cd $(COVERAGEDIR) && ctest -O ctest.log

uninstall:
$(MAKE) clean
Expand Down
2 changes: 2 additions & 0 deletions components/ComponentSettings.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ set(ITC_C_FLAGS "${ITC_C_FLAGS}"
#"-fstack-check"
#"-Weverything"
"-pedantic-errors"
"-fprofile-arcs" # code coverage
"-ftest-coverage" # ^
)

#if(${TGTNAME} STREQUAL cpu1)
Expand Down
1 change: 1 addition & 0 deletions docs/coverage/branch-coverage-badge.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions docs/coverage/line-coverage-badge.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion fsw/apps/hwlib
Submodule hwlib updated 1 files
+1 −1 sim/CMakeLists.txt
2 changes: 1 addition & 1 deletion fsw/apps/io_lib
Submodule io_lib updated 320 files
2 changes: 1 addition & 1 deletion fsw/apps/sbn
Submodule sbn updated 0 files
2 changes: 1 addition & 1 deletion fsw/apps/sc
Submodule sc updated 1 files
+2 −0 unit-test/sc_loads_tests.c
2 changes: 1 addition & 1 deletion fsw/fprime/fprime-nos3
Submodule fprime-nos3 updated 0 files
2 changes: 1 addition & 1 deletion scripts/env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ INFLUXDB_ADMIN_PASSWORD=admin_password
DNETWORK="docker network"
#fi

DBOX="ivvitc/nos3-64:20241010"
DBOX="ivvitc/nos3-64:20241219"

# Debugging
#echo "Script directory = " $SCRIPT_DIR
Expand Down

0 comments on commit 3c61261

Please sign in to comment.