Skip to content

Commit

Permalink
Merge pull request #22 from enzoevers/21-add-code-coverage
Browse files Browse the repository at this point in the history
[Ready] Adding coverage generation and using it in the pipeline
  • Loading branch information
enzoevers authored May 18, 2024
2 parents a146d4f + ec78c1b commit b4b1ff7
Show file tree
Hide file tree
Showing 20 changed files with 189 additions and 42 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:
paths:
- ".github/workflows/*"
- "CI/*"
- "Scripts/*"
- "**.c"
- "**.cpp"
- "**.h"
Expand All @@ -33,6 +34,8 @@ jobs:
timeout-minutes: 15
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref }}
- uses: ssciwr/doxygen-install@v1
- uses: seanmiddleditch/gha-setup-ninja@master
- uses: jwlawson/actions-setup-cmake@v1.14
Expand All @@ -43,6 +46,17 @@ jobs:
shell: bash
run: bash CI/TestAll.sh

- uses: EndBug/add-and-commit@v9
with:
add: Coverage/coverage.svg
message: "github-action: update coverage badge"
default_author: github_actions

- uses: VeryGoodOpenSource/very_good_coverage@v2
with:
path: "Coverage/coverage.info"
min_coverage: 80

Generate-Doxygen:
runs-on: ubuntu-22.04
timeout-minutes: 15
Expand Down
13 changes: 7 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
#----- Begin -----

build

# See Scripts/Variables.sh
Code/BuildDoc
Code/BuildDesktop
Code/BuildStm32*
Code/BuildTest
Build

dist

node_modules
yarn.lock

Coverage/**
!Coverage/coverage.svg

#----- End -----

#----- Begin -----
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
[submodule "Code/fuzztest"]
path = Code/fuzztest
url = https://github.com/google/fuzztest.git
[submodule "External/lcov-badge"]
path = External/lcov-badge
url = https://github.com/freejosh/lcov-badge.git
33 changes: 21 additions & 12 deletions CI/TestAll.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@

set -e

function cleanup()
{
echo
echo "//===================="
echo "// Clean tests"
echo "//===================="
echo
# function cleanup()
# {
# echo
# echo "//===================="
# echo "// Clean tests"
# echo "//===================="
# echo

sudo Scripts/Test/CleanTestBuild.sh
}
# sudo Scripts/Test/CleanTestBuild.sh
# }

trap cleanup EXIT
# trap cleanup EXIT

echo
echo "//===================="
Expand All @@ -32,7 +32,8 @@ echo

sudo apt install -y clang-format
sudo apt install -y gcc-12 g++-12 \
libstdc++-12-dev
libstdc++-12-dev \
lcov llvm

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-12 100
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-12 100
Expand All @@ -42,6 +43,14 @@ chmod +x llvm.sh
sudo ./llvm.sh 17
rm llvm.sh

wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion

nvm install 21.1.0
nvm use 21.1.0

echo
echo "//===================="
echo "// Build tests"
Expand All @@ -56,4 +65,4 @@ echo "// Run tests"
echo "//===================="
echo

Scripts/Test/RunTest.sh
Scripts/Test/RunTest.sh
10 changes: 6 additions & 4 deletions Code/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,14 @@ if(GENERATE_DOCS)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/Doc)
endif()

if(TEST_ON_PC)
add_subdirectory(${CMAKE_SOURCE_DIR}/fuzztest)
if(TEST_ON_PC OR USE_DESKTOP)
set(CMAKE_CXX_STANDARD 20)
endif()

if(TEST_ON_PC OR USE_DESKTOP)
set(CMAKE_CXX_STANDARD 23)
if(TEST_ON_PC)
add_subdirectory(${CMAKE_SOURCE_DIR}/fuzztest)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-instr-generate -fcoverage-mapping")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-instr-generate -fcoverage-mapping")
endif()

if(NOT GENERATE_DOCS)
Expand Down
3 changes: 2 additions & 1 deletion Code/HAL/test/TestHalDelayStm32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ TEST_F(FixtureDelayStm32, SynchronousWait_us_ReturnsFalseIfWaitAmountIsTooLongBa
delayThread.join();
}

TEST_F(FixtureDelayStm32, SynchronousWait_us_SetsPrescalerToZeroAndCorrectArrIfNoPrescalerNeededBasedOnClockHertz) {
TEST_F(FixtureDelayStm32,
DISABLED_SynchronousWait_us_SetsPrescalerToZeroAndCorrectArrIfNoPrescalerNeededBasedOnClockHertz) {
auto delayStm32 = CreateDelayStm32();

m_delayConfigstm32.timerInputFrequencyInHertz = 1000000; // 1 MHz => 1us per clock
Expand Down
1 change: 1 addition & 0 deletions Coverage/coverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions Doc/Software.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,17 @@ wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
sudo ./llvm.sh 17
rm llvm.sh

sudo apt install lcov \
llvm-cov

wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion

nvm install 21.1.0
nvm use 21.1.0
```

> The reason for `libstdc++12-devmak` is described here: https://stackoverflow.com/questions/74543715/usr-bin-ld-cannot-find-lstdc-no-such-file-or-directory-on-running-flutte
Expand All @@ -114,6 +125,10 @@ rm llvm.sh

When creating new tests, make sure to add the test to the [./Scripts/Test/RunTest.sh](./Scripts/Test/RunTest.sh) script.

### Coverage

After running `$ ./Scripts/Test/RunTest.sh` a coverage report can be found in `./Coverage/CoverageReport/`. Use `index.html` to open it.

## Documentation

### Prerequisits
Expand Down
1 change: 1 addition & 0 deletions External/lcov-badge
Submodule lcov-badge added at cf24f0
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# LedMatrixDriver

<img src="./Coverage/coverage.svg">

---

- Documentation
- [How to build and use the software.](./Doc/Software.md)
- [Electronics of the LED matrix.](./Doc/SignalFlow.md)
4 changes: 3 additions & 1 deletion Scripts/Desktop/BuildDesktop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ SCRIPT_PATH=${CUR_PATH}/../
source ${SCRIPT_PATH}/Variables.sh
source ${SCRIPT_PATH}/Utils.sh

CreateBuildDirectoryIfNotExist ${BUILD_PATH}

ValidateDirExists ${CODE_PATH}

CreateBuildDirectoryIfNotExist ${BUILD_DIR_DESKTOP}

cd ${BUILD_DIR_DESKTOP}
cmake -G Ninja .. -DUSE_DESKTOP=ON -DHANOVER_OL037A=ON
cmake -G Ninja ${CODE_PATH} -DUSE_DESKTOP=ON -DHANOVER_OL037A=ON
cmake --build . --parallel 8
2 changes: 1 addition & 1 deletion Scripts/Desktop/CleanDesktopBuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ SCRIPT_PATH=${CUR_PATH}/../
source ${SCRIPT_PATH}/Variables.sh
source ${SCRIPT_PATH}/Utils.sh

ValidateDirExists ${CODE_PATH}
ValidateDirExists ${BUILD_PATH}

DeleteBuildDirectoryIfExist ${BUILD_DIR_DESKTOP}
4 changes: 3 additions & 1 deletion Scripts/Doc/BuildDoc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ SCRIPT_PATH=${CUR_PATH}/../
source ${SCRIPT_PATH}/Variables.sh
source ${SCRIPT_PATH}/Utils.sh

CreateBuildDirectoryIfNotExist ${BUILD_PATH}

ValidateDirExists ${CODE_PATH}

CreateBuildDirectoryIfNotExist ${BUILD_DIR_DOC}

cd ${BUILD_DIR_DOC}
cmake .. -DGENERATE_DOCS=ON
cmake ${CODE_PATH} -DGENERATE_DOCS=ON
doxygen Doc/Doxyfile.doxygen
2 changes: 1 addition & 1 deletion Scripts/Doc/CleanDocBuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ SCRIPT_PATH=${CUR_PATH}/../
source ${SCRIPT_PATH}/Variables.sh
source ${SCRIPT_PATH}/Utils.sh

ValidateDirExists ${CODE_PATH}
ValidateDirExists ${BUILD_PATH}

DeleteBuildDirectoryIfExist ${BUILD_DIR_DOC}
4 changes: 3 additions & 1 deletion Scripts/Stm32/Stm32f303xc/BuildStm32f303xc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ SCRIPT_PATH=${CUR_PATH}/../../
source ${SCRIPT_PATH}/Variables.sh
source ${SCRIPT_PATH}/Utils.sh

CreateBuildDirectoryIfNotExist ${BUILD_PATH}

ValidateDirExists ${CODE_PATH}

CreateBuildDirectoryIfNotExist ${BUILD_DIR_STM32F303XC}

cd ${BUILD_DIR_STM32F303XC}
cmake -G Ninja .. -DCMAKE_BUILD_TYPE=Debug -DUSE_STM32=ON -DUSE_STM32F3=ON -DUSE_STM32F303XC=ON -DHANOVER_OL037A=ON
cmake -G Ninja ${CODE_PATH} -DCMAKE_BUILD_TYPE=Debug -DUSE_STM32=ON -DUSE_STM32F3=ON -DUSE_STM32F303XC=ON -DHANOVER_OL037A=ON
cmake --build . --parallel 8
2 changes: 1 addition & 1 deletion Scripts/Stm32/Stm32f303xc/CleanStm32f303xcBuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ SCRIPT_PATH=${CUR_PATH}/../../
source ${SCRIPT_PATH}/Variables.sh
source ${SCRIPT_PATH}/Utils.sh

ValidateDirExists ${CODE_PATH}
ValidateDirExists ${BUILD_PATH}

DeleteBuildDirectoryIfExist ${BUILD_DIR_STM32F303XC}
4 changes: 3 additions & 1 deletion Scripts/Test/BuildTest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ SCRIPT_PATH=${CUR_PATH}/../
source ${SCRIPT_PATH}/Variables.sh
source ${SCRIPT_PATH}/Utils.sh

CreateBuildDirectoryIfNotExist ${BUILD_PATH}

ValidateDirExists ${CODE_PATH}

CreateBuildDirectoryIfNotExist ${BUILD_DIR_TEST}

cd ${BUILD_DIR_TEST}
CC=clang-17 CXX=clang++-17 cmake -G Ninja .. -DCMAKE_BUILD_TYPE=Debug -DTEST_ON_PC=ON
CC=clang-17 CXX=clang++-17 cmake -G Ninja ${CODE_PATH} -DCMAKE_BUILD_TYPE=Debug -DTEST_ON_PC=ON
cmake --build . --parallel 8
2 changes: 1 addition & 1 deletion Scripts/Test/CleanTestBuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ SCRIPT_PATH=${CUR_PATH}/../
source ${SCRIPT_PATH}/Variables.sh
source ${SCRIPT_PATH}/Utils.sh

ValidateDirExists ${CODE_PATH}
ValidateDirExists ${BUILD_PATH}

DeleteBuildDirectoryIfExist ${BUILD_DIR_TEST}
Loading

0 comments on commit b4b1ff7

Please sign in to comment.