diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml new file mode 100644 index 00000000..296d0727 --- /dev/null +++ b/.github/workflows/coverage.yml @@ -0,0 +1,49 @@ +name: Coverage + +on: + push: + branches: [ main ] + pull_request: + +jobs: + coverage: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Install tools + run: sudo apt-get update && sudo apt-get install -y lcov gcovr + + # ---- BUILD ---- + - name: Configure + run: cmake -DCOVERAGE=ON -DCMAKE_BUILD_TYPE=Debug -DBUILD_TESTING=ON . + + - name: Build + run: make -j + + # ---- RUN TESTS ---- + - name: Run tests + run: | + if [ -f "CTestTestfile.cmake" ]; then + ctest --output-on-failure + else + bin/all_tests + fi + + # ---- GENERATE COVERAGE ---- + - name: Generate coverage + run: | + gcovr \ + --root . \ + --xml-pretty \ + --output coverage.xml \ + --exclude 'test/*' \ + --exclude 'build/*' + + # ---- SEND TO COVERALLS ---- + - name: Upload to Coveralls + uses: coverallsapp/github-action@v2 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + path-to-lcov: coverage.xml diff --git a/CMakeLists.txt b/CMakeLists.txt index afcec394..9e4a5afa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,6 @@ -#CMakeLists.txt file for cvx_presolver cmake_minimum_required(VERSION 3.20) project(PSLP - LANGUAGES C CXX + LANGUAGES C CXX # The library is written in C, but we also have some C++ test files VERSION 0.1.0 DESCRIPTION "PSLP — A Lightweight C Presolver for Linear Programs" ) @@ -95,7 +94,7 @@ else() endif() # Create PSLP library -add_library(PSLP ${CORE_SOURCES})# ${PRIVATE_HEADERS}) +add_library(PSLP ${CORE_SOURCES}) target_include_directories(PSLP PUBLIC $ @@ -126,7 +125,7 @@ else() endif() # Testing -option(BUILD_TESTING "Build tests" ON) +option(BUILD_TESTING "Build tests" OFF) if(BUILD_TESTING) include(CTest) enable_testing() @@ -158,6 +157,15 @@ else() message(STATUS "Testing disabled") endif() +option(COVERAGE "Enable coverage reporting" OFF) + +if(COVERAGE) + message(STATUS "Building with coverage flags") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0 -g --coverage") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage") + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} --coverage") +endif() + add_executable(test_cpp EXCLUDE_FROM_ALL tests/test_cpp.cpp) target_link_libraries(test_cpp PRIVATE PSLP) diff --git a/include/core/debug_macros.h b/include/core/debug_macros.h index 49abe928..748c5a2d 100644 --- a/include/core/debug_macros.h +++ b/include/core/debug_macros.h @@ -35,8 +35,6 @@ #define HUGE_BOUND_ARG , huge_bound_ok #endif -// OBS: The macros should be wrapped inside a DEBUG when use - #ifndef NDEBUG #define DEBUG(code) \ do \