Skip to content

Commit e7e421b

Browse files
committed
extra unit tests infrastructure and first workflow job to test it
1 parent 19c9a73 commit e7e421b

File tree

3 files changed

+154
-38
lines changed

3 files changed

+154
-38
lines changed

.github/workflows/build-unit-tests-external.yml

Lines changed: 96 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,49 +2,117 @@ name: build-unit-tests-external
22

33
on: [push, pull_request]
44

5-
jobs:
6-
release_extra_unit_tests:
7-
runs-on: windows-2019
5+
jobs:
6+
release_extra_only:
7+
runs-on: ${{ matrix.os }}
8+
strategy:
9+
matrix:
10+
os: [ubuntu-latest]
811

912
steps:
1013
- uses: actions/checkout@v4
1114

12-
- name: Create Build Environment
13-
run: cmake -E make_directory ${{runner.workspace}}/build
14-
1515
- name: Clone extra unit tests repo
16-
working-directory: ${{runner.workspace}}/build
17-
run: git clone https://github.com/galabovaa/highs-unit-tests.git
16+
shell: bash
17+
working-directory: ${{runner.workspace}}
18+
run: |
19+
git clone https://github.com/galabovaa/highs-unit-tests.git
1820
1921
- name: Create symlink
2022
shell: bash
21-
working-directory: $GITHUB_WORKSPACE/check
22-
run: mklink /d highs-unit-tests ${{runner.workspace}}/highs-unit-tests
23+
working-directory: ${{runner.workspace}}
24+
working-directory:
25+
run: ln -s ${{runner.workspace}}/highs-unit-tests $GITHUB_WORKSPACE/check
26+
27+
- name: Create Build Environment
28+
run: cmake -E make_directory ${{runner.workspace}}/build
2329

24-
- name: Configure CMake
25-
# Use a bash shell so we can use the same syntax for environment variable
26-
# access regardless of the host operating system
30+
- name: Configure CMake All
2731
shell: bash
2832
working-directory: ${{runner.workspace}}/build
29-
# Note the current convention is to use the -S and -B options here to specify source
30-
# and build directories, but this is only available with CMake 3.13 and higher.
31-
# The CMake binaries on the Github Actions machines are (as of this writing) 3.12
32-
run: cmake $GITHUB_WORKSPACE -DALL_TESTS=ON -DBUILD_EXTRA_UNIT_TESTS=ON
33+
run: cmake $GITHUB_WORKSPACE -DBUILD_EXTRA_UNIT_TESTS=ON -DBUILD_EXTRA_UNIT_ONLY=ON -DBUILD_CXX=OFF
3334

34-
- name: Build
35+
- name: Build All
3536
working-directory: ${{runner.workspace}}/build
3637
shell: bash
37-
# Execute the build. You can specify a specific target with "--target <NAME>"
38-
run: cmake --build . --config Release --parallel
38+
run: |
39+
cmake --build . --parallel
3940
40-
- name: Unit Test Extra
41+
- name: Test Extra Only
4142
working-directory: ${{runner.workspace}}/build
4243
shell: bash
43-
run: ./bin/Release/unit_tests.exe highs-names-extra
44+
run: ctest --parallel --timeout 300 --output-on-failure
4445

45-
- name: Test
46-
working-directory: ${{runner.workspace}}/build
47-
shell: bash
48-
# Execute tests defined by the CMake configuration.
49-
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
50-
run: ctest --timeout 300 --output-on-failure -C Release
46+
# release_all_tests:
47+
# runs-on: ${{ matrix.os }}
48+
# strategy:
49+
# matrix:
50+
# os: [ubuntu-latest]
51+
52+
# steps:
53+
# - uses: actions/checkout@v4
54+
55+
# - name: Create Build Environment
56+
# run: cmake -E make_directory ${{runner.workspace}}/build
57+
58+
# - name: Configure CMake All
59+
# shell: bash
60+
# working-directory: ${{runner.workspace}}/build
61+
# run: cmake $GITHUB_WORKSPACE -DALL_TESTS=ON -DBUILD_EXTRA_UNIT_TESTS=ON
62+
63+
# - name: Build All
64+
# working-directory: ${{runner.workspace}}/build
65+
# shell: bash
66+
# run: |
67+
# cmake --build . --parallel
68+
69+
# - name: Test All
70+
# working-directory: ${{runner.workspace}}/build
71+
# shell: bash
72+
# run: ctest --parallel --timeout 300 --output-on-failure
73+
74+
# release__windows_extra_unit_tests:
75+
# runs-on: windows-2019
76+
77+
# steps:
78+
# - uses: actions/checkout@v4
79+
80+
# - name: Create Build Environment
81+
# run: cmake -E make_directory ${{runner.workspace}}/build
82+
83+
# - name: Clone extra unit tests repo
84+
# working-directory: ${{runner.workspace}}/build
85+
# run: git clone https://github.com/galabovaa/highs-unit-tests.git
86+
87+
# - name: Create symlink
88+
# shell: bash
89+
# working-directory: $GITHUB_WORKSPACE/check
90+
# run: mklink /d highs-unit-tests ${{runner.workspace}}/highs-unit-tests
91+
92+
# - name: Configure CMake
93+
# # Use a bash shell so we can use the same syntax for environment variable
94+
# # access regardless of the host operating system
95+
# shell: bash
96+
# working-directory: ${{runner.workspace}}/build
97+
# # Note the current convention is to use the -S and -B options here to specify source
98+
# # and build directories, but this is only available with CMake 3.13 and higher.
99+
# # The CMake binaries on the Github Actions machines are (as of this writing) 3.12
100+
# run: cmake $GITHUB_WORKSPACE -DALL_TESTS=ON -DBUILD_EXTRA_UNIT_TESTS=ON
101+
102+
# - name: Build
103+
# working-directory: ${{runner.workspace}}/build
104+
# shell: bash
105+
# # Execute the build. You can specify a specific target with "--target <NAME>"
106+
# run: cmake --build . --config Release --parallel
107+
108+
# - name: Unit Test Extra
109+
# working-directory: ${{runner.workspace}}/build
110+
# shell: bash
111+
# run: ./bin/Release/unit_tests.exe highs-names-extra
112+
113+
# - name: Test
114+
# working-directory: ${{runner.workspace}}/build
115+
# shell: bash
116+
# # Execute tests defined by the CMake configuration.
117+
# # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
118+
# run: ctest --timeout 300 --output-on-failure -C Release

CMakeLists.txt

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ cmake_minimum_required(VERSION 3.15...3.27)
99
# set preference for clang compiler and intel compiler over gcc and other compilers
1010
include(Platform/${CMAKE_SYSTEM_NAME}-Determine-C OPTIONAL)
1111
include(Platform/${CMAKE_SYSTEM_NAME}-C OPTIONAL)
12-
set(CMAKE_C_COMPILER_NAMES clang icc cc ${CMAKE_C_COMPILER_NAMES})
12+
set(CMAKE_C_COMPILER_NAMES clang gcc icx cc ${CMAKE_C_COMPILER_NAMES})
1313

1414
include(Platform/${CMAKE_SYSTEM_NAME}-Determine-CXX OPTIONAL)
1515
include(Platform/${CMAKE_SYSTEM_NAME}-CXX OPTIONAL)
16-
set(CMAKE_CXX_COMPILER_NAMES clang++ icpc c++ ${CMAKE_CXX_COMPILER_NAMES})
16+
set(CMAKE_CXX_COMPILER_NAMES clang++ g++ icpx c++ ${CMAKE_CXX_COMPILER_NAMES})
1717

1818
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
1919

@@ -82,11 +82,16 @@ include(CMakeDependentOption)
8282
CMAKE_DEPENDENT_OPTION(ALL_TESTS "Build all tests" OFF "BUILD_TESTING;BUILD_CXX" OFF)
8383
message(STATUS "Build all tests: ${ALL_TESTS}")
8484

85-
CMAKE_DEPENDENT_OPTION(BUILD_EXTRA_UNIT_TESTS "Build extra unit tests" OFF "ALL_TESTS" OFF)
85+
option(BUILD_EXTRA_UNIT_TESTS "Build extra unit tests" OFF)
8686
if (BUILD_EXTRA_UNIT_TESTS)
8787
message(STATUS "Build extra unit tests: ON")
8888
endif()
8989

90+
CMAKE_DEPENDENT_OPTION(BUILD_EXTRA_UNIT_ONLY "Build extra unit tests ONLY" OFF "BUILD_EXTRA_UNIT_TESTS" OFF)
91+
if (BUILD_EXTRA_UNIT_ONLY)
92+
message(STATUS "Build only extra unit tests: ON")
93+
endif()
94+
9095
CMAKE_DEPENDENT_OPTION(BUILD_EXTRA_PROBLEM_SET "Build extra instance tests" OFF "BUILD_TESTING" OFF)
9196
if (BUILD_EXTRA_PROBLEM_SET)
9297
message(STATUS "Build extra instance tests: ON")
@@ -592,14 +597,14 @@ else(FAST_BUILD)
592597

593598
if(BUILD_CXX)
594599
add_subdirectory(app)
595-
if(BUILD_TESTING)
596-
enable_testing()
597-
add_subdirectory(check)
598-
endif()
599-
# Add tests in examples/tests
600600
add_subdirectory(examples)
601601
endif()
602602

603+
if(BUILD_TESTING)
604+
enable_testing()
605+
add_subdirectory(check)
606+
endif()
607+
603608
include(python-highs)
604609

605610
option(USE_DOTNET_STD_21 "Use .Net Standard 2.1 support" ON)

check/CMakeLists.txt

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
include(CTest)
22

3-
if (FORTRAN)
3+
if (FORTRAN AND NOT BUILD_EXTRA_UNIT_ONLY)
44
set(CMAKE_Fortran_MODULE_DIRECTORY ${HIGHS_BINARY_DIR}/modules)
55
add_executable(fortrantest TestFortranAPI.f90)
66
if (NOT FAST_BUILD)
@@ -13,7 +13,7 @@ if (FORTRAN)
1313
${HIGHS_SOURCE_DIR}/check)
1414
endif()
1515

16-
if (NOT FAST_BUILD OR ALL_TESTS)
16+
if ((NOT FAST_BUILD OR ALL_TESTS) AND NOT (BUILD_EXTRA_UNIT_ONLY))
1717
# prepare Catch library
1818
set(CATCH_INCLUDE_DIR ${HIGHS_SOURCE_DIR}/extern)
1919
add_library(Catch INTERFACE)
@@ -413,3 +413,46 @@ if (BUILD_EXTRA_PROBLEM_SET)
413413
message(STATUS "${HIGHS_SOURCE_DIR}/check/highs-problem-set")
414414
include(highs-problem-set)
415415
endif()
416+
417+
if (BUILD_EXTRA_UNIT_TESTS AND BUILD_EXTRA_UNIT_ONLY)
418+
# prepare Catch library
419+
set(CATCH_INCLUDE_DIR ${HIGHS_SOURCE_DIR}/extern)
420+
add_library(Catch INTERFACE)
421+
target_include_directories(Catch INTERFACE ${CATCH_INCLUDE_DIR})
422+
423+
424+
list(APPEND CMAKE_MODULE_PATH "${HIGHS_SOURCE_DIR}/check/highs-unit-tests")
425+
message(STATUS "${HIGHS_SOURCE_DIR}/check/highs-unit-tests")
426+
include(highs-unit-tests)
427+
428+
set(TEST_SOURCES TestMain.cpp ${HIGHS_EXTRA_UNIT_TESTS})
429+
message(STATUS ${TEST_SOURCES})
430+
431+
add_executable(unit_tests_extra ${TEST_SOURCES})
432+
target_link_libraries(unit_tests_extra Catch)
433+
434+
if (BUILD_CXX)
435+
configure_file(${HIGHS_SOURCE_DIR}/check/HCheckConfig.h.in ${HIGHS_BINARY_DIR}/HCheckConfig.h)
436+
target_link_libraries(unit_tests_extra highs)
437+
endif()
438+
439+
add_test(NAME unit-test-extra-build
440+
COMMAND ${CMAKE_COMMAND}
441+
--build ${HIGHS_BINARY_DIR}
442+
--target unit_tests_extra
443+
# --config ${CMAKE_BUILD_TYPE}
444+
)
445+
446+
# Avoid that several build jobs try to concurretly build.
447+
set_tests_properties(unit-test-extra-build
448+
PROPERTIES
449+
RESOURCE_LOCK unittestbin)
450+
451+
# create a binary running all the tests in the executable
452+
add_test(NAME unit_tests_extra COMMAND unit_tests_extra --success)
453+
set_tests_properties(unit_tests_extra
454+
PROPERTIES
455+
DEPENDS unit-test-extra-build)
456+
set_tests_properties(unit_tests_extra PROPERTIES TIMEOUT 10000)
457+
458+
endif()

0 commit comments

Comments
 (0)