Skip to content

Commit

Permalink
Add c++ tests to github actions
Browse files Browse the repository at this point in the history
  • Loading branch information
markkohdev committed Aug 19, 2024
1 parent 598e9e6 commit a875599
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 13 deletions.
25 changes: 20 additions & 5 deletions .github/workflows/all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -228,17 +228,32 @@ jobs:
# TODO: Switch back to macos-latest once https://github.com/actions/python-versions/pull/114 is fixed
os:
- 'ubuntu-latest'
- windows-latest
# TODO: Fix failing CMake build on windows:
# Error: `cl : command line error D8016: '/O2' and '/RTC1' command-line options are incompatible [D:\a\voyager\voyager\cpp\test\test.vcxproj]`
# I've tried passing CXX flags, but windows doesn't seem to respect disabling runtime checks with /RTC1 or disabling optimizations with /O2
# - windows-latest
- macos-12
name: Test C++ on ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- name: Install Linux dependencies
if: runner.os == 'Linux'
run: sudo apt-get update && sudo apt-get install -y pkg-config
- name: Build voyager locally
- name: Install CMake (Windows)
if: matrix.os == 'windows-latest'
run: |
choco install cmake --installargs 'ADD_CMAKE_TO_PATH=System'
choco install ninja
- name: Install CMake (MacOS)
if: matrix.os == 'macos-12'
run: brew install cmake
- name: Install CMake (Ubuntu)
if: matrix.os == 'ubuntu-latest'
run: sudo apt-get install -y cmake
- name: Configure CMake
run: cmake .
- name: Build with CMake
run: make
- name: Run Tests (if any)
run: make test

build-python-wheels:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ compile_commands.json
CTestTestfile.cmake
_deps
DartConfiguration.tcl
VoyagerTests
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ To run the C++ tests, use the following commands:
cd cpp
git submodule update --init --recursive
cmake .
make
make test
./test/test
```

## Style
Expand Down
13 changes: 13 additions & 0 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@ set(CMAKE_CXX_STANDARD 17)
set(LLVM_CXX_STD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

if (MSVC)
# Set /RTC1 only for Debug builds
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /RTC1")

# Ensure /RTC1 is not used in Release builds
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /O2")

# Optionally, remove /RTC1 from the global CXX flags to avoid conflicts
string(REGEX REPLACE "/RTC1" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
endif()

add_subdirectory(include)
add_subdirectory(src)
add_subdirectory(test)
Expand All @@ -25,3 +36,5 @@ add_custom_target(format
COMMAND ${FORMAT_COMMAND} `${FIND_COMMAND}`
COMMENT "Running C++ formatter"
)

enable_testing()
15 changes: 10 additions & 5 deletions cpp/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
add_executable(test doctest_setup.cpp test_main.cpp)
# List the test source files
set(TEST_FILES test_main.cpp doctest_setup.cpp) # Add any test files here

target_link_libraries(test
# Create an executable for the tests
add_executable(VoyagerTests ${TEST_FILES})

# Link the test executable with the main project and Doctest
# target_link_libraries(MyProjectTests PRIVATE MyProject doctest::doctest)
target_link_libraries(VoyagerTests
PUBLIC
VoyagerLib
PRIVATE
doctest
)

target_compile_options(test PRIVATE -O2 -g)

include(CTest)
# Add the tests
add_test(NAME VoyagerTests COMMAND VoyagerTests)
6 changes: 4 additions & 2 deletions cpp/test/test_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ TEST_CASE("Test combinations of different instantiations and sizes") {
std::vector<StorageDataType> storageTypesSet = {
StorageDataType::Float8, StorageDataType::Float32, StorageDataType::E4M3};

auto count = 0;

for (auto spaceType : spaceTypesSet) {
for (auto numDimensions : numDimensionsSet) {
for (auto numElements : numElementsSet) {
for (auto storageType : storageTypesSet) {
SUBCASE("Combination test") {
SUBCASE("Test instantiation ") {
CAPTURE(spaceType);
CAPTURE(numDimensions);
CAPTURE(numElements);
Expand All @@ -41,7 +43,7 @@ TEST_CASE("Test combinations of different instantiations and sizes") {
testCombination(index, spaceType, numDimensions, storageType);
} else if (storageType == StorageDataType::E4M3) {
auto index = TypedIndex<float, E4M3>(spaceType, numDimensions);
testCombination(index, spaceType, 20, storageType);
testCombination(index, spaceType, numDimensions, storageType);
}
}
}
Expand Down

0 comments on commit a875599

Please sign in to comment.