mirror of
https://github.com/emqx/neuron.git
synced 2026-10-28 14:07:20 +08:00
Merge pull request #1186 from hxy7yx/main
Introduce coverage statistics for testing
This commit is contained in:
@@ -51,13 +51,25 @@ jobs:
|
||||
run: |
|
||||
git config --global --add safe.directory $(pwd)
|
||||
mkdir -p build && cd build
|
||||
cmake .. -DCMAKE_TOOLCHAIN_FILE=../cmake/x86_64-linux-gnu.cmake
|
||||
cmake -DUSE_GCOV=1 .. -DCMAKE_TOOLCHAIN_FILE=../cmake/x86_64-linux-gnu.cmake
|
||||
make -j4
|
||||
|
||||
- name: unit test
|
||||
run: |
|
||||
cd build
|
||||
ctest --output-on-failure
|
||||
sudo apt install -y lcov
|
||||
ctest --output-on-failure -O tests/reports/ut.log --output-junit tests/reports/output.xml
|
||||
lcov --capture --directory . --output-file testneuron.info --test-name testneuron
|
||||
genhtml -o result testneuron.info
|
||||
|
||||
- uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: ut_result
|
||||
path: |
|
||||
build/tests/reports/ut.log
|
||||
build/tests/reports/output.xml
|
||||
build/result/index.html
|
||||
build/neuron.log
|
||||
|
||||
ft:
|
||||
runs-on: ubuntu-20.04
|
||||
|
||||
@@ -31,6 +31,14 @@ if(NOT DISABLE_WERROR)
|
||||
set(CMAKE_C_FLAGS "$ENV{CFLAGS} -Werror")
|
||||
endif()
|
||||
|
||||
if(USE_GCOV)
|
||||
message(STATUS "using gcov")
|
||||
SET(GCC_COVERAGE_COMPILE_FLAGS "-fprofile-arcs -ftest-coverage")
|
||||
SET(GCC_COVERAGE_LINK_FLAGS "-lgcov")
|
||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_COVERAGE_COMPILE_FLAGS}")
|
||||
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_LINKER_FLAGS} ${GCC_COVERAGE_LINK_FLAGS}")
|
||||
endif(USE_GCOV)
|
||||
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -g")
|
||||
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS} -O1")
|
||||
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
# Test
|
||||
|
||||
To run all unit testers
|
||||
|
||||
```shell
|
||||
$ cd build
|
||||
$ ctest --output-on-failure
|
||||
```
|
||||
|
||||
Introducing coverage statistics using LCOV
|
||||
|
||||
Adding parameter -DUSE_GCOV=1 during compilation.
|
||||
|
||||
Generate image files .gcno and data files .gcda under build/tests/CMakeFiles/.dir
|
||||
|
||||
Execute the following command in the build folder to generate an intermediate file for HTML:
|
||||
|
||||
```shell
|
||||
$ lcov --capture --directory . -- output-file testneuron.info --test-name testneuron
|
||||
```
|
||||
|
||||
Execute the following command in the build folder to generate an HTML file in the result folder under the build folder:
|
||||
|
||||
```shell
|
||||
$ genhtml -o result testneuron.info
|
||||
```
|
||||
|
||||
Open build/result index.html to view coverage statistics report.
|
||||
Reference in New Issue
Block a user