diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index bb98faf8..d5c79afe 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -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 diff --git a/CMakeLists.txt b/CMakeLists.txt index 375d97dd..118ed0ff 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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") diff --git a/tests/README.md b/tests/README.md new file mode 100644 index 00000000..f1c2e211 --- /dev/null +++ b/tests/README.md @@ -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. \ No newline at end of file