-
Notifications
You must be signed in to change notification settings - Fork 41
Add C API tests for error handling, indexing, and search parameters #306
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3c5d004
Add comprehensive C API tests for error handling, index building, sea…
rfsaliev b9020f1
Refactor CMake configuration for C API tests
rfsaliev 4f918b6
Enhance C API tests with dynamic index functionality and coverage rep…
rfsaliev c6e70de
Address code review comments
rfsaliev 540a9db
Code review: fix CMake configuration and dynamic index
rfsaliev 93013a9
Update CMake configuration for C API tests
rfsaliev 70c02b3
revert svs_c.cpp to the base branch state
rfsaliev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| # Copyright 2026 Intel Corporation | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| set(TARGET_NAME svs_c_api_test) | ||
|
|
||
| # Check if Catch2 is available | ||
| find_package(Catch2 3 QUIET) | ||
|
|
||
| if(NOT Catch2_FOUND) | ||
| message(STATUS "Catch2 not found, fetching from GitHub...") | ||
| include(FetchContent) | ||
|
|
||
| # Do wide printing for the console logger for Catch2 | ||
| set(CATCH_CONFIG_CONSOLE_WIDTH "100" CACHE STRING "" FORCE) | ||
| set(CATCH_BUILD_TESTING OFF CACHE BOOL "" FORCE) | ||
| set(CATCH_CONFIG_ENABLE_BENCHMARKING OFF CACHE BOOL "" FORCE) | ||
| set(CATCH_CONFIG_FAST_COMPILE OFF CACHE BOOL "" FORCE) | ||
| set(CATCH_CONFIG_PREFIX_ALL ON CACHE BOOL "" FORCE) | ||
|
|
||
|
rfsaliev marked this conversation as resolved.
|
||
| set(PRESET_CMAKE_CXX_STANDARD ${CMAKE_CXX_STANDARD}) | ||
| if(DEFINED SVS_CXX_STANDARD) | ||
| set(CMAKE_CXX_STANDARD ${SVS_CXX_STANDARD}) | ||
| endif() | ||
| FetchContent_Declare( | ||
| Catch2 | ||
| GIT_REPOSITORY https://github.com/catchorg/Catch2.git | ||
| GIT_TAG v3.4.0 | ||
| ) | ||
| FetchContent_MakeAvailable(Catch2) | ||
| set(CMAKE_CXX_STANDARD ${PRESET_CMAKE_CXX_STANDARD}) | ||
| endif() | ||
|
|
||
| # Define test sources | ||
| set(C_API_TEST_SOURCES | ||
| c_api_error.cpp | ||
| c_api_algorithm.cpp | ||
| c_api_storage.cpp | ||
| c_api_search_params.cpp | ||
| c_api_index_builder.cpp | ||
| c_api_index.cpp | ||
| c_api_dynamic_index.cpp | ||
| ) | ||
|
|
||
| # Create test executable | ||
| add_executable(${TARGET_NAME} ${C_API_TEST_SOURCES}) | ||
|
|
||
| # Link with C API library and Catch2 | ||
| target_link_libraries(${TARGET_NAME} PRIVATE | ||
| svs_c_api | ||
| Catch2::Catch2WithMain | ||
| ) | ||
|
|
||
| # Set C++ standard | ||
| target_compile_features(${TARGET_NAME} PRIVATE cxx_std_20) | ||
| set_target_properties(${TARGET_NAME} PROPERTIES | ||
| CXX_STANDARD 20 | ||
| CXX_STANDARD_REQUIRED ON | ||
| CXX_EXTENSIONS OFF | ||
| ) | ||
|
|
||
| # Include directories | ||
| target_include_directories(${TARGET_NAME} PRIVATE | ||
| ${CMAKE_CURRENT_SOURCE_DIR}/../include | ||
| ) | ||
|
|
||
| # Add test to CTest | ||
| include(CTest) | ||
| enable_testing() | ||
|
|
||
| # Add Catch2 CMake module path | ||
| if(NOT Catch2_FOUND) | ||
| # Catch2 was fetched, use its source directory | ||
| list(APPEND CMAKE_MODULE_PATH ${catch2_SOURCE_DIR}/extras) | ||
| else() | ||
| # Catch2 was found via find_package, use its module directory | ||
| list(APPEND CMAKE_MODULE_PATH ${Catch2_DIR}) | ||
| endif() | ||
|
|
||
| include(Catch) | ||
| catch_discover_tests(${TARGET_NAME} PROPERTIES LABELS "c_api") | ||
|
|
||
| # Add a custom target to run tests | ||
| add_custom_target(run_c_api_test | ||
| COMMAND ${TARGET_NAME} | ||
| DEPENDS ${TARGET_NAME} | ||
| WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} | ||
| COMMENT "Running C API tests..." | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,164 @@ | ||
| # C API Tests | ||
|
|
||
| This directory contains comprehensive tests for the SVS C API using the Catch2 testing framework. | ||
|
|
||
| ## Test Structure | ||
|
|
||
| The tests are organized into separate files by functionality: | ||
|
|
||
| - **c_api_error.cpp**: Tests for error handling functionality | ||
| - **c_api_algorithm.cpp**: Tests for algorithm creation and configuration (Vamana) | ||
| - **c_api_storage.cpp**: Tests for storage configurations (Simple, LeanVec, LVQ, SQ) | ||
| - **c_api_search_params.cpp**: Tests for search parameter creation and configuration | ||
| - **c_api_index_builder.cpp**: Tests for index builder creation and configuration | ||
| - **c_api_index.cpp**: Tests for index building, searching, and basic operations | ||
| - **c_api_dynamic_index.cpp**: Tests for dynamic index operations (add, delete, consolidate, compact) | ||
|
|
||
| Note: The main() function is provided by Catch2::Catch2WithMain automatically. | ||
|
|
||
| ## Building the Tests | ||
|
|
||
| The tests are built as part of the C API build process. To build them: | ||
|
|
||
| ```bash | ||
| # From the build directory | ||
| cmake -DSVS_BUILD_C_API_TESTS=ON .. | ||
| make svs_c_api_test | ||
| ``` | ||
|
rfsaliev marked this conversation as resolved.
|
||
|
|
||
| To disable building tests: | ||
|
|
||
| ```bash | ||
| cmake -DSVS_BUILD_C_API_TESTS=OFF .. | ||
| ``` | ||
|
|
||
| ## Running the Tests | ||
|
|
||
| ### Run all tests | ||
|
|
||
| ```bash | ||
| ./svs_c_api_test | ||
| ``` | ||
|
|
||
| ### Run specific test cases | ||
|
|
||
| ```bash | ||
| # Run error handling tests only | ||
| ./svs_c_api_test "[c_api][error]" | ||
|
|
||
| # Run algorithm tests only | ||
| ./svs_c_api_test "[c_api][algorithm]" | ||
|
|
||
| # Run all index tests | ||
| ./svs_c_api_test "[c_api][index]" | ||
|
|
||
| # Run dynamic index tests | ||
| ./svs_c_api_test "[c_api][dynamic]" | ||
| ``` | ||
|
|
||
| ### Run with verbose output | ||
|
|
||
| ```bash | ||
| ./svs_c_api_test -s | ||
| ``` | ||
|
|
||
| ### List all available tests | ||
|
|
||
| ```bash | ||
| ./svs_c_api_test --list-tests | ||
| ``` | ||
|
|
||
| ### Run with CTest | ||
|
|
||
| ```bash | ||
| ctest -R svs_c_api_test | ||
| ``` | ||
|
|
||
| ## Test Coverage | ||
|
|
||
| The tests cover the following aspects of the C API: | ||
|
|
||
| ### Error Handling | ||
|
|
||
| - Error handle creation and cleanup | ||
| - Error state checking | ||
| - Error codes and messages | ||
| - NULL error handle support | ||
|
|
||
| ### Algorithm Configuration | ||
|
|
||
| - Vamana algorithm creation | ||
| - Parameter getters and setters (graph_degree, build_window_size, alpha, search_history) | ||
| - Invalid parameter handling | ||
|
|
||
| ### Storage Configuration | ||
|
|
||
| - Simple storage (Float32, Float16, Int8, Uint8) | ||
| - LeanVec storage (various primary/secondary combinations) | ||
| - LVQ storage (with and without residual) | ||
| - Scalar Quantization storage | ||
|
|
||
| ### Search Parameters | ||
|
|
||
| - Vamana search parameter creation | ||
| - Various window sizes | ||
|
|
||
| ### Index Builder | ||
|
|
||
| - Index builder creation with different metrics (Euclidean, Cosine, Dot Product) | ||
| - Storage configuration | ||
| - Thread pool configuration (Native, OMP, Custom) | ||
|
|
||
| ### Index Operations | ||
|
|
||
| - Index building from data | ||
| - Searching with queries | ||
| - Different K values | ||
| - Distance calculation | ||
| - Vector reconstruction | ||
| - Thread count management | ||
|
|
||
| ### Dynamic Index Operations | ||
|
|
||
| - Dynamic index building with/without explicit IDs | ||
| - Adding points | ||
| - Deleting points | ||
| - ID existence checking | ||
| - Index consolidation | ||
| - Index compaction | ||
| - Search after modifications | ||
|
|
||
| ## Test Patterns | ||
|
|
||
| The tests follow the patterns established in the SVS project: | ||
|
|
||
| 1. Use `CATCH_TEST_CASE` for test case definitions | ||
| 2. Use `CATCH_SECTION` for test subsections | ||
| 3. Use `CATCH_REQUIRE` for assertions | ||
| 4. Clean up all resources (free handles) after each test | ||
| 5. Test both success and error paths | ||
| 6. Test with and without NULL error handles | ||
|
|
||
| ## Adding New Tests | ||
|
|
||
| When adding new tests: | ||
|
|
||
| 1. Create a new `.cpp` file or add to an existing one | ||
| 2. Follow the existing structure and naming conventions | ||
| 3. Include proper copyright header | ||
| 4. Use appropriate test tags: `[c_api][functionality]` | ||
| 5. Add the new test file to `CMakeLists.txt` if needed | ||
| 6. Clean up all allocated resources | ||
| 7. Test both success and error conditions | ||
|
|
||
| ## Dependencies | ||
|
|
||
| - Catch2 v3.x (automatically fetched if not found) | ||
| - SVS C API library | ||
| - C++20 or later compiler | ||
|
|
||
| ## Notes | ||
|
|
||
| - Tests use a simple sequential thread pool for deterministic behavior | ||
| - Test data is generated programmatically for repeatability | ||
| - Some tests may be skipped if optional features are not enabled (e.g., LVQ/LeanVec) | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.