From dcf7f0aad9729212355244b939582676abe482ae Mon Sep 17 00:00:00 2001 From: Ivet Galabova Date: Wed, 8 Jan 2025 17:52:00 +0000 Subject: [PATCH] clean up --- .github/workflows/code-coverage.yml | 51 ++++++++++++++ .gitignore | 1 + CMakeLists.txt | 102 +++++++++++----------------- check/CMakeLists.txt | 38 ++++++----- cmake/cpp-highs.cmake | 26 +++---- 5 files changed, 127 insertions(+), 91 deletions(-) create mode 100644 .github/workflows/code-coverage.yml diff --git a/.github/workflows/code-coverage.yml b/.github/workflows/code-coverage.yml new file mode 100644 index 0000000000..e4f073ca67 --- /dev/null +++ b/.github/workflows/code-coverage.yml @@ -0,0 +1,51 @@ +name: code-coverage + +on: [push, pull_request] + +jobs: + debug: + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest] + + steps: + - uses: actions/checkout@v4 + + - name: install + run: sudo apt-get update && sudo apt-get install lcov + + - name: Create Build Environment + run: cmake -E make_directory ${{runner.workspace}}/build + + - name: Configure CMake + shell: bash + working-directory: ${{runner.workspace}}/build + run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=Debug -DHIGHS_COVERAGE=ON -DALL_TESTS=ON -DBUILD_SHARED_LIBS=OFF + + - name: Build + working-directory: ${{runner.workspace}}/build + shell: bash + run: | + cmake --build . --parallel --config Debug + + - name: Test + working-directory: ${{runner.workspace}}/build + shell: bash + run: ctest --parallel --timeout 300 --output-on-failure + + - name: Generate report with lcov + working-directory: ${{runner.workspace}}/build + shell: bash + run: | + lcov -d . -c -o cov.info --ignore-errors empty + lcov --remove cov.info "/usr/include/*" -o cov.info + lcov --remove cov.info "/usr/include/*" -o cov.info + lcov --remove cov.info "extern/pdqsort/*" -o cov.info + lcov --remove cov.info "extern/zstr/*" -o cov.info + lcov --remove cov.info "app/cxxopts*" -o cov.info + lcov --remove cov.info "/usr/lib/*" -o cov.info + lcov --list cov.info + + + diff --git a/.gitignore b/.gitignore index 096bc893e1..c36222e48d 100644 --- a/.gitignore +++ b/.gitignore @@ -230,6 +230,7 @@ pip-log.txt # Unit test / coverage reports .coverage +cov.info .tox #Translations diff --git a/CMakeLists.txt b/CMakeLists.txt index 90eda6bea4..3409278e60 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -103,6 +103,8 @@ if (PYTHON_BUILD_SETUP) set(ZLIB OFF) endif() +option(HIGHS_COVERAGE "Activate the code coverage compilation" OFF) + # Address | Thread | Leak # Linux atm # Only Debug is theted atm @@ -328,16 +330,18 @@ if(NOT FAST_BUILD) endif() include(CheckCXXCompilerFlag) -if(CMAKE_SYSTEM_PROCESSOR MATCHES "^(ppc64|powerpc64)" AND NOT APPLE) - check_cxx_compiler_flag("-mpopcntd" COMPILER_SUPPORTS_POPCNTD) - if(COMPILER_SUPPORTS_POPCNTD) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mpopcntd") - endif() -else() - check_cxx_compiler_flag("-mpopcnt" COMPILER_SUPPORTS_POPCNT) - if(COMPILER_SUPPORTS_POPCNT) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mpopcnt") - endif() +if (NOT HIGHS_COVERAGE) + if(CMAKE_SYSTEM_PROCESSOR MATCHES "^(ppc64|powerpc64)" AND NOT APPLE) + check_cxx_compiler_flag("-mpopcntd" COMPILER_SUPPORTS_POPCNTD) + if(COMPILER_SUPPORTS_POPCNTD) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mpopcntd") + endif() + else() + check_cxx_compiler_flag("-mpopcnt" COMPILER_SUPPORTS_POPCNT) + if(COMPILER_SUPPORTS_POPCNT) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mpopcnt") + endif() + endif() endif() option(DEBUGSOL "check the debug solution" OFF) @@ -474,37 +478,24 @@ elseif (DEBUG_MEMORY STREQUAL "Leak") endif() # HiGHS coverage update in progress - -# For the moment keep above coverage part in case we are testing at CI. -# option(CI_COV "CI extended tests" ON) - -# Coverage part -# 'make coverage' to start the coverage process -option(HIGHS_COVERAGE "Activate the code coverage compilation" OFF) - -if(HIGHS_COVERAGE) - if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0 --coverage") - set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 --coverage") - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -O0 --coverage") +if(FAST_BUILD AND HIGHS_COVERAGE) + if(WIN32) + message(FATAL_ERROR "Error: code coverage analysis is only available under Linux for now.") endif() - if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") - set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -fprofile-arcs -ftest-coverage -Xclang -coverage-cfg-checksum -Xclang -coverage-no-function-names-in-data -Xclang -coverage-version='408*'") - set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fprofile-arcs -ftest-coverage -Xclang -coverage-cfg-checksum -Xclang -coverage-no-function-names-in-data -Xclang -coverage-version='408*'") + if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug") + message(FATAL_ERROR "Warning: to enable coverage, you must compile in Debug mode") endif() -endif() -if(HIGHS_COVERAGE) - if(NOT CMAKE_BUILD_TYPE STREQUAL "DEBUG") - message(FATAL_ERROR "Warning: to enable coverage, you must compile in DEBUG mode") - endif() -endif() + # Disable IPO + set(CMAKE_INTERPROCEDURAL_OPTIMIZATION OFF) + message(STATUS "Building in coverage mode") -if(HIGHS_COVERAGE) - if(WIN32) - message(FATAL_ERROR "Error: code coverage analysis is only available under Linux for now.") - endif() + # Enable coverage flags + add_compile_options(-O0) + add_compile_options(--coverage) + add_link_options(-O0) + add_link_options(--coverage) # Ensure coverage data is linked correctly find_program(GCOV_PATH gcov) find_program(LCOV_PATH lcov) @@ -522,31 +513,18 @@ if(HIGHS_COVERAGE) message(FATAL_ERROR "genhtml not found! Please install lcov and gcov. Aborting...") endif() - # Capturing lcov counters and generating report - # if(NOT CI) - add_custom_target(coverage - COMMAND ${LCOV_PATH} --directory ${CMAKE_BINARY_DIR} --zerocounters - COMMAND ${LCOV_PATH} --capture --initial --directory ${CMAKE_BINARY_DIR}/bin --output-file ${CMAKE_BINARY_DIR}/coverage.info - COMMAND ${CMAKE_COMMAND} -E chdir ${CMAKE_BINARY_DIR} ${CMAKE_CTEST_COMMAND} -LE "(LONG|FAIL)" || true - COMMAND ${LCOV_PATH} --capture --directory ${CMAKE_BINARY_DIR}/bin --directory ${CMAKE_BINARY_DIR}/src --directory ${CMAKE_BINARY_DIR}/app --directory ${CMAKE_BINARY_DIR}/check --output-file ${CMAKE_BINARY_DIR}/coverage.info - COMMAND ${LCOV_PATH} --remove "*/usr/include/*" --output-file ${CMAKE_BINARY_DIR}/coverage.info.cleaned - COMMAND ${GENHTML_PATH} -o ${CMAKE_BINARY_DIR}/coverage ${CMAKE_BINARY_DIR}/coverage.info.cleaned - COMMAND ${CMAKE_COMMAND} -E remove ${CMAKE_BINARY_DIR}/coverage.info.cleaned - VERBATIM - WORKING_DIRECTORY ${CMAKE_BINARY_DIR} - COMMENT "Resetting code coverage counters to zero. - Processing code coverage counters and generating report. - You can zip the directory ${CMAKE_BINARY_DIR}/coverage and upload the content to a web server.") - # else() - # add_custom_target(ci_cov - # COMMAND ${LCOV_PATH} --directory ${CMAKE_BINARY_DIR} --zerocounters - # COMMAND ${LCOV_PATH} --capture --initial --directory ${CMAKE_BINARY_DIR}/bin --output-file ${CMAKE_BINARY_DIR}/coverage.info - # COMMAND ${CMAKE_COMMAND} -E chdir ${CMAKE_BINARY_DIR} ${CMAKE_CTEST_COMMAND} -LE "(LONG|FAIL)" || true - # COMMAND ${LCOV_PATH} --capture --directory ${CMAKE_BINARY_DIR}/bin --directory ${CMAKE_BINARY_DIR}/src --directory ${CMAKE_BINARY_DIR}/app --directory ${CMAKE_BINARY_DIR}/check --output-file ${CMAKE_BINARY_DIR}/coverage.info - # VERBATIM - # WORKING_DIRECTORY ${CMAKE_BINARY_DIR} - # COMMENT "Resetting code coverage counters to zero.") - # endif() + # add_custom_target(coverage + # COMMAND ${LCOV_PATH} -d bin -c -o cov.info --ignore-errors empty + # COMMAND ${LCOV_PATH} --remove "*/usr/include/*" -o ${CMAKE_BINARY_DIR}/cov.info.cleaned + # COMMAND ${LCOV_PATH} --remove "*/usr/lib/*" -o ${CMAKE_BINARY_DIR}/cov.info.cleaned + # COMMAND ${LCOV_PATH} --remove "extern/pdqsort/*" -o ${CMAKE_BINARY_DIR}/cov.info.cleaned + # COMMAND ${LCOV_PATH} --remove "extern/zstr/*" -o ${CMAKE_BINARY_DIR}/cov.info.cleaned + # COMMAND ${LCOV_PATH} --remove "app/cxxopts*" -o ${CMAKE_BINARY_DIR}/cov.info.cleaned + # COMMAND ${GENHTML_PATH} ${CMAKE_BINARY_DIR}/cov.info.cleaned -o ${CMAKE_BINARY_DIR}/cov_report + # VERBATIM + # WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + # COMMENT "Generating code coverage report v2025.") + endif() if(NOT FAST_BUILD) @@ -571,7 +549,7 @@ if(NOT FAST_BUILD) endif() if(HIGHS_COVERAGE) - if(NOT CMAKE_BUILD_TYPE STREQUAL "DEBUG") + if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug") message(FATAL_ERROR "Warning: to enable coverage, you must compile in DEBUG mode") endif() endif() diff --git a/check/CMakeLists.txt b/check/CMakeLists.txt index b1076e1825..4ba1f995eb 100644 --- a/check/CMakeLists.txt +++ b/check/CMakeLists.txt @@ -129,25 +129,29 @@ if ((NOT FAST_BUILD OR ALL_TESTS) AND NOT (BUILD_EXTRA_UNIT_ONLY)) add_test(NAME capi_unit_tests COMMAND capi_unit_tests) # Check whether test executable builds OK. - add_test(NAME unit-test-build - COMMAND ${CMAKE_COMMAND} - --build ${HIGHS_BINARY_DIR} - --target unit_tests - # --config ${CMAKE_BUILD_TYPE} - ) - + if (NOT HIGHS_COVERAGE) + add_test(NAME unit-test-build + COMMAND ${CMAKE_COMMAND} + --build ${HIGHS_BINARY_DIR} + --target unit_tests + # --config ${CMAKE_BUILD_TYPE} + ) - # Avoid that several build jobs try to concurretly build. - set_tests_properties(unit-test-build - PROPERTIES - RESOURCE_LOCK unittestbin) + # Avoid that several build jobs try to concurretly build. + set_tests_properties(unit-test-build + PROPERTIES + RESOURCE_LOCK unittestbin) - # create a binary running all the tests in the executable - add_test(NAME unit_tests_all COMMAND unit_tests --success) - set_tests_properties(unit_tests_all - PROPERTIES - DEPENDS unit-test-build) - set_tests_properties(unit_tests_all PROPERTIES TIMEOUT 10000) + # create a binary running all the tests in the executable + add_test(NAME unit_tests_all COMMAND unit_tests --success) + set_tests_properties(unit_tests_all + PROPERTIES + DEPENDS unit-test-build) + set_tests_properties(unit_tests_all PROPERTIES TIMEOUT 10000) + else() + add_test(NAME unit_tests_all COMMAND unit_tests --success) + set_tests_properties(unit_tests_all PROPERTIES TIMEOUT 10000) + endif() # An individual test can be added with the command below but the approach # above with a single add_test for all the unit tests automatically detects all diff --git a/cmake/cpp-highs.cmake b/cmake/cpp-highs.cmake index 88a529a6f3..3e25a3e601 100644 --- a/cmake/cpp-highs.cmake +++ b/cmake/cpp-highs.cmake @@ -57,18 +57,20 @@ install(TARGETS highs PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/highs) # Add library targets to the build-tree export set -export(TARGETS highs - NAMESPACE ${PROJECT_NAMESPACE}::highs - FILE "${HIGHS_BINARY_DIR}/highs-targets.cmake") - -install(EXPORT ${lower}-targets - NAMESPACE ${PROJECT_NAMESPACE}:: - FILE highs-targets.cmake - DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${lower}) -# install(FILES "${HIGHS_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/highs-config.cmake" -# DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/highs) -# install(FILES "${HIGHS_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/highs.pc" -# DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) +if (NOT HIGHS_COVERAGE) + export(TARGETS highs + NAMESPACE ${PROJECT_NAMESPACE}::highs + FILE "${HIGHS_BINARY_DIR}/highs-targets.cmake") + + install(EXPORT ${lower}-targets + NAMESPACE ${PROJECT_NAMESPACE}:: + FILE highs-targets.cmake + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${lower}) + # install(FILES "${HIGHS_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/highs-config.cmake" + # DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/highs) + # install(FILES "${HIGHS_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/highs.pc" + # DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) +endif() include(CMakePackageConfigHelpers)