Skip to content

Commit 4f918b6

Browse files
committed
Enhance C API tests with dynamic index functionality and coverage reporting
- Refactor CMake configuration to support coverage options for C API tests. - Update test build options to allow dynamic index testing with configurable block sizes. - Introduce a utility for managing temporary directories in tests. - Improve dynamic index tests to include save/load functionality and multi-threading support. - Update README and test commands for consistency with new test target names.
1 parent b9020f1 commit 4f918b6

6 files changed

Lines changed: 349 additions & 135 deletions

File tree

bindings/c/CMakeLists.txt

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,6 @@ set_target_properties(${TARGET_NAME} PROPERTIES VERSION ${PROJECT_VERSION} SOVER
6969
target_link_libraries(${TARGET_NAME} PRIVATE
7070
svs::svs
7171
)
72-
if (SVS_EXPERIMENTAL_LINK_STATIC_MKL)
73-
link_mkl_static(${TARGET_NAME})
74-
endif()
7572

7673
if (SVS_RUNTIME_ENABLE_LVQ_LEANVEC)
7774
message(STATUS "Enabling LVQ/LeanVec support in C API")
@@ -95,7 +92,9 @@ if (SVS_RUNTIME_ENABLE_LVQ_LEANVEC)
9592
svs::svs
9693
svs_compile_options
9794
)
98-
link_mkl_static(${TARGET_NAME})
95+
if(SVS_EXPERIMENTAL_LINK_STATIC_MKL)
96+
link_mkl_static(${TARGET_NAME})
97+
endif()
9998
elseif(TARGET svs::svs)
10099
message(FATAL_ERROR
101100
"Pre-built LVQ/LeanVec SVS library cannot be used in SVS main build. "
@@ -191,8 +190,34 @@ install(FILES
191190
)
192191

193192
# Build tests if requested
194-
option(SVS_BUILD_C_API_TESTS "Build C API tests" ON)
193+
if(DEFINED SVS_BUILD_TESTS)
194+
option(SVS_BUILD_C_API_TESTS "Build C API tests" ${SVS_BUILD_TESTS})
195+
else()
196+
option(SVS_BUILD_C_API_TESTS "Build C API tests" OFF)
197+
endif()
198+
199+
195200
if(SVS_BUILD_C_API_TESTS)
201+
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
202+
target_compile_options(${TARGET_NAME} PRIVATE --coverage)
203+
target_link_libraries(${TARGET_NAME} PRIVATE --coverage)
204+
# add coverage target
205+
add_custom_target(clean_coverage
206+
COMMAND ${CMAKE_COMMAND} -E echo "Cleaning coverage data..."
207+
COMMAND ${CMAKE_COMMAND} -E chdir ${CMAKE_BINARY_DIR} find . -name "*.gcda" -delete
208+
COMMAND ${CMAKE_COMMAND} -E remove -f ${CMAKE_BINARY_DIR}/coverage.info
209+
COMMENT "Cleaning coverage data..."
210+
)
211+
add_custom_target(coverage
212+
COMMAND ${CMAKE_COMMAND} -E echo "Generating coverage report..."
213+
COMMAND ${CMAKE_COMMAND} -E env GCOV_PREFIX=${CMAKE_BINARY_DIR}/coverage GCOV_PREFIX_STRIP=1 ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/coverage
214+
COMMAND ${CMAKE_COMMAND} -E chdir ${CMAKE_BINARY_DIR} lcov --capture --directory . --output-file coverage.info
215+
COMMAND ${CMAKE_COMMAND} -E chdir ${CMAKE_BINARY_DIR} lcov --remove coverage.info '/usr/*' --output-file coverage.info
216+
COMMAND ${CMAKE_COMMAND} -E chdir ${CMAKE_BINARY_DIR} lcov --remove coverage.info '*/_deps/*' --output-file coverage.info
217+
COMMAND ${CMAKE_COMMAND} -E chdir ${CMAKE_BINARY_DIR} lcov --list coverage.info
218+
COMMENT "Generating code coverage report..."
219+
)
220+
endif()
196221
add_subdirectory(tests)
197222
endif()
198223

bindings/c/tests/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ if(NOT Catch2_FOUND)
2929
set(CATCH_CONFIG_PREFIX_ALL ON CACHE BOOL "" FORCE)
3030

3131
set(PRESET_CMAKE_CXX_STANDARD ${CMAKE_CXX_STANDARD})
32-
set(CMAKE_CXX_STANDARD 20)
32+
set(CMAKE_CXX_STANDARD ${SVS_CXX_STANDARD})
3333
FetchContent_Declare(
3434
Catch2
3535
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
36-
GIT_TAG v3.11.0
36+
GIT_TAG v3.4.0
3737
)
3838
FetchContent_MakeAvailable(Catch2)
3939
set(CMAKE_CXX_STANDARD ${PRESET_CMAKE_CXX_STANDARD})
@@ -97,7 +97,7 @@ include(Catch)
9797
catch_discover_tests(${TARGET_NAME})
9898

9999
# Add a custom target to run tests
100-
add_custom_target(run_c_api_tests
100+
add_custom_target(run_c_api_test
101101
COMMAND ${TARGET_NAME}
102102
DEPENDS ${TARGET_NAME}
103103
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}

bindings/c/tests/README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ The tests are built as part of the C API build process. To build them:
2323
```bash
2424
# From the build directory
2525
cmake -DSVS_BUILD_C_API_TESTS=ON ..
26-
make svs_c_api_tests
26+
make svs_c_api_test
2727
```
2828

2929
To disable building tests:
@@ -37,41 +37,41 @@ cmake -DSVS_BUILD_C_API_TESTS=OFF ..
3737
### Run all tests
3838

3939
```bash
40-
./svs_c_api_tests
40+
./svs_c_api_test
4141
```
4242

4343
### Run specific test cases
4444

4545
```bash
4646
# Run error handling tests only
47-
./svs_c_api_tests "[c_api][error]"
47+
./svs_c_api_test "[c_api][error]"
4848

4949
# Run algorithm tests only
50-
./svs_c_api_tests "[c_api][algorithm]"
50+
./svs_c_api_test "[c_api][algorithm]"
5151

5252
# Run all index tests
53-
./svs_c_api_tests "[c_api][index]"
53+
./svs_c_api_test "[c_api][index]"
5454

5555
# Run dynamic index tests
56-
./svs_c_api_tests "[c_api][dynamic]"
56+
./svs_c_api_test "[c_api][dynamic]"
5757
```
5858

5959
### Run with verbose output
6060

6161
```bash
62-
./svs_c_api_tests -s
62+
./svs_c_api_test -s
6363
```
6464

6565
### List all available tests
6666

6767
```bash
68-
./svs_c_api_tests --list-tests
68+
./svs_c_api_test --list-tests
6969
```
7070

7171
### Run with CTest
7272

7373
```bash
74-
ctest -R svs_c_api_tests
74+
ctest -R svs_c_api_test
7575
```
7676

7777
## Test Coverage

0 commit comments

Comments
 (0)