Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
galabovaa committed Jan 8, 2025
1 parent 01361bc commit dcf7f0a
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 91 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/code-coverage.yml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ pip-log.txt

# Unit test / coverage reports
.coverage
cov.info
.tox

#Translations
Expand Down
102 changes: 40 additions & 62 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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()
Expand Down
38 changes: 21 additions & 17 deletions check/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 14 additions & 12 deletions cmake/cpp-highs.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit dcf7f0a

Please sign in to comment.