Skip to content

Commit

Permalink
Enable test coverage report
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-rabault committed Jun 7, 2023
1 parent e7f274f commit cfff594
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 3 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,24 @@ jobs:
# Run Unit tests
platformio test -vvv
- if: matrix.os == 'ubuntu-latest'
run: |
sudo apt-get install -y lcov
lcov -d .pio/build/native/ -c -o lcov.info
lcov --remove lcov.info '*/usr/*' '*/Platforms/*' '*/bootloader/*' '*/.pio/*' '*/HAL/*' '*/test/*' -o lcov.info
- if: matrix.os == 'ubuntu-latest'
name: Coveralls
uses: coverallsapp/github-action@v2

unit-tests:
name: Unit tests
needs: tests-run
runs-on: ubuntu-latest
steps:
- run: echo "Tests succeed!"


code-format:
name: Code format
runs-on: ubuntu-latest
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
**/.gitignore
*.out
*.log
*.info
*.profraw
cov/*
/examples/projects/NUCLEO-G431KB/button/.mxproject
/examples/projects/NUCLEO-G431KB/button/Button.gpdsc
/examples/projects/NUCLEO-L432KC/button/Button.gpdsc
Expand Down
3 changes: 2 additions & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ lib_extra_dirs = $PROJECT_DIR/../

build_unflags = -Os
build_flags =
-O1
-O0
-include ./test/_resources/node_config.h
-DUNIT_TEST
-D LUOSHAL=STUB
--coverage

build_type = debug
test_build_src = true
Expand Down
9 changes: 7 additions & 2 deletions source_filter_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@
if resources.is_dir():
env.Append(CPPPATH=[(resources.path)])

if (current_os == 'Darwin'):
env.Append(LINKFLAGS=["--coverage"])

if (current_os == 'Linux') or (current_os == 'Windows'):
env.Append(LINKFLAGS=["-lgcov", "--coverage", "-fprofile-arcs"])
# CODE COVERAGE WILL BE ADDED SOON
# if (current_os == 'Linux') or (current_os == 'Darwin') or (current_os == 'Windows'):
# env.Append(LINKFLAGS=["-lgcov"])
Expand All @@ -136,9 +141,9 @@
# env.Execute(".pio/build/native/program test/"+file)
# env.Execute("lcov -d .pio/build/native/ -c -o lcov.info")
# env.Execute(
# "lcov --remove lcov.info '*/tool-unity/*' '*/test/*' -o filtered_lcov.info")
# "lcov --remove lcov.info '*/Platforms/*' '*/bootloader/*' '*/.pio/*' '*/HAL/*' '*/test/*' -o filtered_lcov.info")
# env.Execute(
# "genhtml -o cov/ --demangle-cpp filtered_lcov.info")
# "genhtml filtered_lcov.info -o cov/ --demangle-cpp")

# Generate code coverage when testing workflow is ended
# env.AddPostAction(".pio/build/native/program", generateCoverageInfo)
Expand Down
5 changes: 5 additions & 0 deletions test/code_coverage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env python
import os
os.system("lcov -d .pio/build/native/ -c -o lcov.info")
os.system("lcov --remove lcov.info '*/Platforms/*' '*/bootloader/*' '*/.pio/*' '*/HAL/*' '*/test/*' -o filtered_lcov.info")
os.system("genhtml filtered_lcov.info -o cov/ --demangle-cpp")

0 comments on commit cfff594

Please sign in to comment.