diff --git a/.github/workflows/build-firmware.yaml b/.github/workflows/build-firmware.yaml index 17b169b0..252e2d6c 100644 --- a/.github/workflows/build-firmware.yaml +++ b/.github/workflows/build-firmware.yaml @@ -1,6 +1,13 @@ name: Build Firmware -on: [push, pull_request, workflow_dispatch] +on: + push: + branches: + - master + - prod-* + pull_request: + workflow_dispatch: + jobs: build-firmware: diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 5474b39e..95654c4e 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -1,6 +1,12 @@ name: Unit Tests -on: [push,pull_request] +on: + push: + branches: + - master + - prod-* + pull_request: + workflow_dispatch: jobs: build: @@ -24,7 +30,8 @@ jobs: if: ${{ matrix.os != 'macos-latest' }} run: | sudo apt-get update - sudo apt-get install valgrind + sudo apt-get install valgrind python3-pip + pip install gcovr==8.5 - name: Print Compiler version # NOTE: on mac, this is actually symlink'd to clang, not gcc, but that's ok - we want to build on both @@ -32,6 +39,12 @@ jobs: run: gcc -v - name: Build Tests + if: ${{ matrix.os != 'macos-latest' }} + working-directory: test + run: make -j4 SANITIZE=yes COVERAGE=yes + + - name: Build Tests + if: ${{ matrix.os == 'macos-latest' }} working-directory: test run: make -j4 SANITIZE=yes @@ -39,6 +52,18 @@ jobs: working-directory: test run: ASAN_OPTIONS=detect_stack_use_after_return=1 build/wideband_test + - name: Generate Code Coverage + if: ${{ matrix.os != 'macos-latest' }} + working-directory: ./test/ + run: ./ci_gcov.sh + + - name: Upload code coverage artifacts + if: ${{ matrix.os != 'macos-latest' }} + uses: actions/upload-artifact@v6 + with: + name: rusefi_wideband_code_coverage + path: ./test/gcov_working_area/gcov + - name: Rebuild Tests For Valgrind # Valgrind isn't compatible with address sanitizer, so we have to rebuild the code if: ${{ matrix.os != 'macos-latest' }} diff --git a/test/Makefile b/test/Makefile index e90319e9..a1d2ff26 100644 --- a/test/Makefile +++ b/test/Makefile @@ -50,6 +50,19 @@ ifeq ($(SANITIZE),) endif endif +ifeq ($(COVERAGE),yes) + ifeq ($(IS_CLANG),1) + COVERAGE_FLAGS := -fprofile-instr-generate -fcoverage-mapping + $(info Detected Clang: using LLVM-style coverage flags) + else + COVERAGE_FLAGS := --coverage + $(info Detected GCC: using GCC-style coverage flags) + endif + USE_COPT += $(COVERAGE_FLAGS) + USE_CPPOPT += $(COVERAGE_FLAGS) +endif + + IS_MAC = no ifneq ($(OS),Windows_NT) UNAME_S := $(shell uname -s) @@ -198,6 +211,10 @@ ifeq ($(SANITIZE),yes) ULIBS += -fsanitize=address -fsanitize=undefined endif +ifeq ($(COVERAGE),yes) + ULIBS += $(COVERAGE_FLAGS) +endif + # # End of user defines ############################################################################## diff --git a/test/ci_gcov.sh b/test/ci_gcov.sh new file mode 100755 index 00000000..80144725 --- /dev/null +++ b/test/ci_gcov.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +# +# this script is used by github actions +# + +rm -rf gcov_working_area + +mkdir gcov_working_area +cd gcov_working_area +mkdir gcov + +echo -e "\nGenerating rusEFI wideband unit test coverage" + +# for debug use --html-details --html-single-page --verbose to generate a single html +gcovr --exclude-throw-branches --exclude-unreachable-branches --decisions --merge-mode-functions=separate \ + --exclude '/.*/googletest/' \ + -j4 -r ../.. --html-nested gcov/index.html \ No newline at end of file