diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..ac24f1f8 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,93 @@ +{ + "files.associations": { + "cctype": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "csetjmp": "cpp", + "csignal": "cpp", + "cstdarg": "cpp", + "cstddef": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cstring": "cpp", + "ctime": "cpp", + "cwchar": "cpp", + "cwctype": "cpp", + "any": "cpp", + "array": "cpp", + "atomic": "cpp", + "strstream": "cpp", + "barrier": "cpp", + "bit": "cpp", + "bitset": "cpp", + "cfenv": "cpp", + "charconv": "cpp", + "chrono": "cpp", + "cinttypes": "cpp", + "codecvt": "cpp", + "compare": "cpp", + "complex": "cpp", + "concepts": "cpp", + "condition_variable": "cpp", + "coroutine": "cpp", + "cstdint": "cpp", + "cuchar": "cpp", + "deque": "cpp", + "forward_list": "cpp", + "list": "cpp", + "map": "cpp", + "set": "cpp", + "string": "cpp", + "unordered_map": "cpp", + "unordered_set": "cpp", + "vector": "cpp", + "exception": "cpp", + "algorithm": "cpp", + "functional": "cpp", + "iterator": "cpp", + "memory": "cpp", + "memory_resource": "cpp", + "numeric": "cpp", + "optional": "cpp", + "random": "cpp", + "ratio": "cpp", + "regex": "cpp", + "source_location": "cpp", + "string_view": "cpp", + "system_error": "cpp", + "tuple": "cpp", + "type_traits": "cpp", + "utility": "cpp", + "fstream": "cpp", + "future": "cpp", + "initializer_list": "cpp", + "iomanip": "cpp", + "iosfwd": "cpp", + "iostream": "cpp", + "istream": "cpp", + "latch": "cpp", + "limits": "cpp", + "mutex": "cpp", + "new": "cpp", + "numbers": "cpp", + "ostream": "cpp", + "ranges": "cpp", + "scoped_allocator": "cpp", + "semaphore": "cpp", + "shared_mutex": "cpp", + "span": "cpp", + "sstream": "cpp", + "stdexcept": "cpp", + "stop_token": "cpp", + "streambuf": "cpp", + "syncstream": "cpp", + "thread": "cpp", + "typeindex": "cpp", + "typeinfo": "cpp", + "valarray": "cpp", + "variant": "cpp", + "expected": "cpp", + "spanstream": "cpp", + "stacktrace": "cpp" + } +} \ No newline at end of file diff --git a/Test/CMakeLists.txt b/Test/CMakeLists.txt index 52f4168a..0700188f 100644 --- a/Test/CMakeLists.txt +++ b/Test/CMakeLists.txt @@ -2,29 +2,38 @@ # Licensed under the MIT License. if (NOT LIBRARYONLY) - if(NOT WIN32) - ADD_DEFINITIONS(-DBOOST_TEST_DYN_LINK) - message (STATUS "BOOST_TEST_DYN_LINK") - endif() + find_package(Boost 1.66 COMPONENTS system thread serialization wserialization regex filesystem) + if (Boost_FOUND) + include_directories (${Boost_INCLUDE_DIR}) + link_directories (${Boost_LIBRARY_DIR}) + message (STATUS "Found Boost.") + message (STATUS "Include Path: ${Boost_INCLUDE_DIRS}") + message (STATUS "Library Path: ${Boost_LIBRARY_DIRS}") + message (STATUS "Library: ${Boost_LIBRARIES}") + else() + message (FATAL_ERROR "Could not find Boost 1.67!") + endif() - find_package(Boost 1.66 COMPONENTS system thread serialization wserialization regex filesystem unit_test_framework) - if (Boost_FOUND) - include_directories (${Boost_INCLUDE_DIR}) - link_directories (${Boost_LIBRARY_DIR}) - message (STATUS "Found Boost.") - message (STATUS "Include Path: ${Boost_INCLUDE_DIRS}") - message (STATUS "Library Path: ${Boost_LIBRARY_DIRS}") - message (STATUS "Library: ${Boost_LIBRARIES}") - else() - message (FATAL_ERROR "Could not find Boost 1.67!") - endif() + # GoogleTest + include(FetchContent) + find_package(GTest QUIET) + if (NOT GTest_FOUND) + message(STATUS "GTest not found; fetching googletest via FetchContent...") + FetchContent_Declare( + googletest + URL https://github.com/google/googletest/archive/refs/tags/v1.14.0.zip + ) + # For Windows: prevent overriding the parent project's compiler/linker settings + set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) + FetchContent_MakeAvailable(googletest) + endif() include_directories(${PROJECT_SOURCE_DIR}/AnnService ${PROJECT_SOURCE_DIR}/Test ${PROJECT_SOURCE_DIR}/ThirdParty/spdk/build/include) file(GLOB TEST_HDR_FILES ${PROJECT_SOURCE_DIR}/Test/inc/Test.h) file(GLOB TEST_SRC_FILES ${PROJECT_SOURCE_DIR}/Test/src/*.cpp) add_executable(SPTAGTest ${TEST_SRC_FILES} ${TEST_HDR_FILES}) - target_link_libraries(SPTAGTest SPTAGLibStatic ssdservingLib ${Boost_LIBRARIES}) + target_link_libraries(SPTAGTest PRIVATE SPTAGLibStatic ssdservingLib ${Boost_LIBRARIES} GTest::gtest GTest::gtest_main) install(TARGETS SPTAGTest RUNTIME DESTINATION bin diff --git a/Test/cuda/cuda_tests.cpp b/Test/cuda/cuda_tests.cpp index 40c6cfd4..144d624b 100644 --- a/Test/cuda/cuda_tests.cpp +++ b/Test/cuda/cuda_tests.cpp @@ -1,44 +1,42 @@ -//#include "test_kernels.cu" - -#define BOOST_TEST_MODULE GPU +// #include "test_kernels.cu" #include #include +#include "inc/Test.h" #include -#include #include int GPUBuildKNNTest(); -BOOST_AUTO_TEST_CASE(RandomTests) +TEST(GPUTest, RandomTests) { - BOOST_CHECK(1 == 1); + EXPECT_EQ(1, 1); int errors = GPUBuildKNNTest(); printf("outside\n"); - BOOST_CHECK(errors == 0); + EXPECT_EQ(errors, 0); } /* int GPUTestDistance_All(); -BOOST_AUTO_TEST_CASE(DistanceTests) { +// TEST(GPUTest, DistanceTests) { int errs = GPUTestDistance_All(); - BOOST_CHECK(errs == 0); -} + EXPECT_EQ(errs, 0); +// } int GPUBuildTPTTest(); -BOOST_AUTO_TEST_CASE(TPTreeTests) { +// TEST(GPUTest, TPTreeTests) { int errs = GPUBuildTPTTest(); - BOOST_CHECK(errs == 0); -} + EXPECT_EQ(errs, 0); +// } int GPUBuildSSDTest_All(); -BOOST_AUTO_TEST_CASE(BuildSSDTests) { +// TEST(GPUTest, BuildSSDTests) { int errs = GPUBuildSSDTest_All(); - BOOST_CHECK(errs == 0); -} + EXPECT_EQ(errs, 0); +// } */ diff --git a/Test/cuda/pq_perf.cpp b/Test/cuda/pq_perf.cpp index c256f3b1..a2aca646 100644 --- a/Test/cuda/pq_perf.cpp +++ b/Test/cuda/pq_perf.cpp @@ -1,12 +1,10 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -//#include "../inc/Test.h" - -#define BOOST_TEST_MODULE GPU +// #include "../inc/Test.h" +#include "inc/Test.h" #include -#include #include #include @@ -82,8 +80,8 @@ std::shared_ptr& meta, std::shared_ptr& queryset, int k, std::string out, std::shared_ptr quantizer) { std::shared_ptr vecIndex = SPTAG::VectorIndex::CreateInstance(algo, SPTAG::GetEnumValueType()); - vecIndex->SetQuantizer(quantizer); - BOOST_CHECK(nullptr != vecIndex); + vecIndex->SetQuantizer(quantizer); + ASSERT_NE(nullptr, vecIndex); if (algo == IndexAlgoType::KDT) vecIndex->SetParameter("KDTNumber", "2"); vecIndex->SetParameter("DistCalcMethod", distCalcMethod); @@ -92,8 +90,8 @@ std::string out, std::shared_ptr quantizer) vecIndex->SetParameter("MaxCheck", "4096"); vecIndex->SetParameter("MaxCheckForRefineGraph", "8192"); - BOOST_CHECK(SPTAG::ErrorCode::Success == vecIndex->BuildIndex(vec, meta, true)); - BOOST_CHECK(SPTAG::ErrorCode::Success == vecIndex->SaveIndex(out)); + ASSERT_EQ(SPTAG::ErrorCode::Success, vecIndex->BuildIndex(vec, meta, true)); + ASSERT_EQ(SPTAG::ErrorCode::Success, vecIndex->SaveIndex(out)); //Search(vecIndex, queryset, k, truth); return vecIndex; } @@ -199,10 +197,10 @@ void GenerateReconstructData(std::shared_ptr &real_vecset, std::share auto ptr = SPTAG::f_createIO(); if (ptr == nullptr || !ptr->Initialize(CODEBOOK_FILE.c_str(), std::ios::binary | std::ios::in)) { - BOOST_ASSERT("Canot Open CODEBOOK_FILE to read!" == "Error"); + GTEST_FAIL() << "Cannot open CODEBOOK_FILE to read!"; } quantizer->LoadIQuantizer(ptr); - BOOST_ASSERT(quantizer); + ASSERT_TRUE(quantizer != nullptr); std::shared_ptr options( new Helper::ReaderOptions(GetEnumValueType(), m, VectorFileType::DEFAULT)); @@ -293,17 +291,17 @@ void GenerateReconstructData(std::shared_ptr &real_vecset, std::share auto ptr = SPTAG::f_createIO(); if (ptr == nullptr || !ptr->Initialize(CODEBOOK_FILE.c_str(), std::ios::binary | std::ios::out)) { - BOOST_ASSERT("Canot Open CODEBOOK_FILE to write!" == "Error"); + GTEST_FAIL() << "Cannot open CODEBOOK_FILE to write!"; } // quantizer->SaveQuantizer(ptr); ptr->ShutDown(); if (!ptr->Initialize(CODEBOOK_FILE.c_str(), std::ios::binary | std::ios::in)) { - BOOST_ASSERT("Canot Open CODEBOOK_FILE to read!" == "Error"); + GTEST_FAIL() << "Cannot open CODEBOOK_FILE to read!"; } quantizer->LoadIQuantizer(ptr); - BOOST_ASSERT(quantizer); + ASSERT_TRUE(quantizer != nullptr); rec_vecset.reset(new BasicVectorSet(ByteArray::Alloc(sizeof(R) * n * m), GetEnumValueType(), m, n)); quan_vecset.reset( @@ -659,9 +657,10 @@ template void DistancePerfRandomized(IndexAlgoType algo, DistCalcMe SPTAGLIB_LOG(SPTAG::Helper::LogLevel::LL_Info, "GPU time - baseline:%0.3lf, PQ:%0.3lf\n", GPU_baseline_t, GPU_PQ_t); } -BOOST_AUTO_TEST_SUITE(GPUPQPerfTest) +namespace GPUPQPerfTestSuite +{ -BOOST_AUTO_TEST_CASE(GPUPQCosineTest) +TEST(GPUPQPerfTest, GPUPQCosineTest) { DistancePerfSuite(IndexAlgoType::BKT, DistCalcMethod::L2); @@ -669,4 +668,4 @@ BOOST_AUTO_TEST_CASE(GPUPQCosineTest) DistancePerfRandomized(IndexAlgoType::BKT, DistCalcMethod::L2); } -BOOST_AUTO_TEST_SUITE_END() +} // namespace GPUPQPerfTestSuite diff --git a/Test/inc/Test.h b/Test/inc/Test.h index da6c096b..f9a5ea9b 100644 --- a/Test/inc/Test.h +++ b/Test/inc/Test.h @@ -4,4 +4,4 @@ #pragma once #include -#include +#include diff --git a/Test/src/AlgoTest.cpp b/Test/src/AlgoTest.cpp index 6adcea67..4c438a0a 100644 --- a/Test/src/AlgoTest.cpp +++ b/Test/src/AlgoTest.cpp @@ -16,7 +16,7 @@ void Build(SPTAG::IndexAlgoType algo, std::string distCalcMethod, std::shared_pt std::shared_ptr vecIndex = SPTAG::VectorIndex::CreateInstance(algo, SPTAG::GetEnumValueType()); - BOOST_CHECK(nullptr != vecIndex); + ASSERT_NE(nullptr, vecIndex); if (algo != SPTAG::IndexAlgoType::SPANN) { @@ -45,8 +45,8 @@ void Build(SPTAG::IndexAlgoType algo, std::string distCalcMethod, std::shared_pt vecIndex->SetParameter("SearchInternalResultNum", "64", "BuildSSDIndex"); } - BOOST_CHECK(SPTAG::ErrorCode::Success == vecIndex->BuildIndex(vec, meta)); - BOOST_CHECK(SPTAG::ErrorCode::Success == vecIndex->SaveIndex(out)); + ASSERT_EQ(SPTAG::ErrorCode::Success, vecIndex->BuildIndex(vec, meta)); + ASSERT_EQ(SPTAG::ErrorCode::Success, vecIndex->SaveIndex(out)); } template @@ -56,7 +56,7 @@ void BuildWithMetaMapping(SPTAG::IndexAlgoType algo, std::string distCalcMethod, std::shared_ptr vecIndex = SPTAG::VectorIndex::CreateInstance(algo, SPTAG::GetEnumValueType()); - BOOST_CHECK(nullptr != vecIndex); + ASSERT_NE(nullptr, vecIndex); if (algo != SPTAG::IndexAlgoType::SPANN) { @@ -85,15 +85,15 @@ void BuildWithMetaMapping(SPTAG::IndexAlgoType algo, std::string distCalcMethod, vecIndex->SetParameter("SearchInternalResultNum", "64", "BuildSSDIndex"); } - BOOST_CHECK(SPTAG::ErrorCode::Success == vecIndex->BuildIndex(vec, meta, true)); - BOOST_CHECK(SPTAG::ErrorCode::Success == vecIndex->SaveIndex(out)); + ASSERT_EQ(SPTAG::ErrorCode::Success, vecIndex->BuildIndex(vec, meta, true)); + ASSERT_EQ(SPTAG::ErrorCode::Success, vecIndex->SaveIndex(out)); } template void Search(const std::string folder, T *vec, SPTAG::SizeType n, int k, std::string *truthmeta) { std::shared_ptr vecIndex; - BOOST_CHECK(SPTAG::ErrorCode::Success == SPTAG::VectorIndex::LoadIndex(folder, vecIndex)); - BOOST_CHECK(nullptr != vecIndex); + ASSERT_EQ(SPTAG::ErrorCode::Success, SPTAG::VectorIndex::LoadIndex(folder, vecIndex)); + ASSERT_NE(nullptr, vecIndex); for (SPTAG::SizeType i = 0; i < n; i++) { @@ -109,7 +109,7 @@ template void Search(const std::string folder, T *vec, SPTAG::SizeT std::cout << std::endl; for (int j = 0; j < k; j++) { - BOOST_CHECK(resmeta.find(truthmeta[i * k + j]) != resmeta.end()); + EXPECT_NE(resmeta.end(), resmeta.find(truthmeta[i * k + j])); } vec += vecIndex->GetFeatureDim(); } @@ -121,11 +121,11 @@ void Add(const std::string folder, std::shared_ptr &vec, std:: const std::string out) { std::shared_ptr vecIndex; - BOOST_CHECK(SPTAG::ErrorCode::Success == SPTAG::VectorIndex::LoadIndex(folder, vecIndex)); - BOOST_CHECK(nullptr != vecIndex); + ASSERT_EQ(SPTAG::ErrorCode::Success, SPTAG::VectorIndex::LoadIndex(folder, vecIndex)); + ASSERT_NE(nullptr, vecIndex); - BOOST_CHECK(SPTAG::ErrorCode::Success == vecIndex->AddIndex(vec, meta)); - BOOST_CHECK(SPTAG::ErrorCode::Success == vecIndex->SaveIndex(out)); + ASSERT_EQ(SPTAG::ErrorCode::Success, vecIndex->AddIndex(vec, meta)); + ASSERT_EQ(SPTAG::ErrorCode::Success, vecIndex->SaveIndex(out)); vecIndex.reset(); } @@ -135,7 +135,7 @@ void AddOneByOne(SPTAG::IndexAlgoType algo, std::string distCalcMethod, std::sha { std::shared_ptr vecIndex = SPTAG::VectorIndex::CreateInstance(algo, SPTAG::GetEnumValueType()); - BOOST_CHECK(nullptr != vecIndex); + ASSERT_NE(nullptr, vecIndex); vecIndex->SetParameter("DistCalcMethod", distCalcMethod); vecIndex->SetParameter("NumberOfThreads", "16"); @@ -158,21 +158,21 @@ void AddOneByOne(SPTAG::IndexAlgoType algo, std::string distCalcMethod, std::sha Sleep(10000); - BOOST_CHECK(SPTAG::ErrorCode::Success == vecIndex->SaveIndex(out)); + ASSERT_EQ(SPTAG::ErrorCode::Success, vecIndex->SaveIndex(out)); } template void Delete(const std::string folder, T *vec, SPTAG::SizeType n, const std::string out) { std::shared_ptr vecIndex; - BOOST_CHECK(SPTAG::ErrorCode::Success == SPTAG::VectorIndex::LoadIndex(folder, vecIndex)); - BOOST_CHECK(nullptr != vecIndex); + ASSERT_EQ(SPTAG::ErrorCode::Success, SPTAG::VectorIndex::LoadIndex(folder, vecIndex)); + ASSERT_NE(nullptr, vecIndex); - BOOST_CHECK(SPTAG::ErrorCode::Success == vecIndex->DeleteIndex((const void *)vec, n)); - BOOST_CHECK(SPTAG::ErrorCode::Success == vecIndex->SaveIndex(out)); + ASSERT_EQ(SPTAG::ErrorCode::Success, vecIndex->DeleteIndex((const void *)vec, n)); + ASSERT_EQ(SPTAG::ErrorCode::Success, vecIndex->SaveIndex(out)); vecIndex.reset(); } -template void Test(SPTAG::IndexAlgoType algo, std::string distCalcMethod) +template void RunTest(SPTAG::IndexAlgoType algo, std::string distCalcMethod) { SPTAG::SizeType n = 2000, q = 3; SPTAG::DimensionType m = 10; @@ -244,21 +244,22 @@ template void Test(SPTAG::IndexAlgoType algo, std::string distCalcM } } -BOOST_AUTO_TEST_SUITE(AlgoTest) +namespace AlgoTest +{ -BOOST_AUTO_TEST_CASE(KDTTest) +TEST(AlgoTest, KDTTest) { - Test(SPTAG::IndexAlgoType::KDT, "L2"); + RunTest(SPTAG::IndexAlgoType::KDT, "L2"); } -BOOST_AUTO_TEST_CASE(BKTTest) +TEST(AlgoTest, BKTTest) { - Test(SPTAG::IndexAlgoType::BKT, "L2"); + RunTest(SPTAG::IndexAlgoType::BKT, "L2"); } -BOOST_AUTO_TEST_CASE(SPANNTest) +TEST(AlgoTest, SPANNTest) { - Test(SPTAG::IndexAlgoType::SPANN, "L2"); + RunTest(SPTAG::IndexAlgoType::SPANN, "L2"); } -BOOST_AUTO_TEST_SUITE_END() +} // namespace AlgoTest diff --git a/Test/src/Base64HelperTest.cpp b/Test/src/Base64HelperTest.cpp index 1878ed01..5a165bab 100644 --- a/Test/src/Base64HelperTest.cpp +++ b/Test/src/Base64HelperTest.cpp @@ -6,9 +6,10 @@ #include -BOOST_AUTO_TEST_SUITE(Base64Test) +namespace Base64Test +{ -BOOST_AUTO_TEST_CASE(Base64EncDec) +TEST(Base64Test, Base64EncDec) { using namespace SPTAG::Helper::Base64; @@ -25,19 +26,19 @@ BOOST_AUTO_TEST_CASE(Base64EncDec) } size_t encBufLen = CapacityForEncode(inputSize); - BOOST_CHECK(encBufLen < bufferSize); + EXPECT_LT(encBufLen, bufferSize); size_t encOutLen = 0; - BOOST_CHECK(Encode(rawBuffer.get(), inputSize, encBuffer.get(), encOutLen)); - BOOST_CHECK(encBufLen >= encOutLen); + EXPECT_TRUE(Encode(rawBuffer.get(), inputSize, encBuffer.get(), encOutLen)); + EXPECT_GE(encBufLen, encOutLen); size_t decBufLen = CapacityForDecode(encOutLen); - BOOST_CHECK(decBufLen < bufferSize); + EXPECT_LT(decBufLen, bufferSize); size_t decOutLen = 0; - BOOST_CHECK(Decode(encBuffer.get(), encOutLen, rawBuffer.get(), decOutLen)); - BOOST_CHECK(decBufLen >= decOutLen); + EXPECT_TRUE(Decode(encBuffer.get(), encOutLen, rawBuffer.get(), decOutLen)); + EXPECT_GE(decBufLen, decOutLen); } } -BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file +} // namespace Base64Test \ No newline at end of file diff --git a/Test/src/CommonHelperTest.cpp b/Test/src/CommonHelperTest.cpp index 281bf052..8d99276b 100644 --- a/Test/src/CommonHelperTest.cpp +++ b/Test/src/CommonHelperTest.cpp @@ -6,13 +6,14 @@ #include -BOOST_AUTO_TEST_SUITE(CommonHelperTest) +namespace CommonHelperTest +{ -BOOST_AUTO_TEST_CASE(ToLowerInPlaceTest) +TEST(CommonHelperTest, ToLowerInPlaceTest) { auto runTestCase = [](std::string p_input, const std::string &p_expected) { SPTAG::Helper::StrUtils::ToLowerInPlace(p_input); - BOOST_CHECK(p_input == p_expected); + EXPECT_EQ(p_input, p_expected); }; runTestCase("abc", "abc"); @@ -22,19 +23,19 @@ BOOST_AUTO_TEST_CASE(ToLowerInPlaceTest) runTestCase("123!-=aBc", "123!-=abc"); } -BOOST_AUTO_TEST_CASE(SplitStringTest) +TEST(CommonHelperTest, SplitStringTest) { std::string input("seg1 seg2 seg3 seg4"); const auto &segs = SPTAG::Helper::StrUtils::SplitString(input, " "); - BOOST_CHECK(segs.size() == 4); - BOOST_CHECK(segs[0] == "seg1"); - BOOST_CHECK(segs[1] == "seg2"); - BOOST_CHECK(segs[2] == "seg3"); - BOOST_CHECK(segs[3] == "seg4"); + EXPECT_EQ(segs.size(), 4u); + EXPECT_EQ(segs[0], "seg1"); + EXPECT_EQ(segs[1], "seg2"); + EXPECT_EQ(segs[2], "seg3"); + EXPECT_EQ(segs[3], "seg4"); } -BOOST_AUTO_TEST_CASE(FindTrimmedSegmentTest) +TEST(CommonHelperTest, FindTrimmedSegmentTest) { using namespace SPTAG::Helper::StrUtils; std::string input("\t Space End \r\n\t"); @@ -42,40 +43,40 @@ BOOST_AUTO_TEST_CASE(FindTrimmedSegmentTest) const auto &pos = FindTrimmedSegment(input.c_str(), input.c_str() + input.size(), [](char p_val) -> bool { return std::isspace(p_val) > 0; }); - BOOST_CHECK(pos.first == input.c_str() + 2); - BOOST_CHECK(pos.second == input.c_str() + 13); + EXPECT_EQ(pos.first, input.c_str() + 2); + EXPECT_EQ(pos.second, input.c_str() + 13); } -BOOST_AUTO_TEST_CASE(StartsWithTest) +TEST(CommonHelperTest, StartsWithTest) { using namespace SPTAG::Helper::StrUtils; - BOOST_CHECK(StartsWith("Abcd", "A")); - BOOST_CHECK(StartsWith("Abcd", "Ab")); - BOOST_CHECK(StartsWith("Abcd", "Abc")); - BOOST_CHECK(StartsWith("Abcd", "Abcd")); - - BOOST_CHECK(!StartsWith("Abcd", "a")); - BOOST_CHECK(!StartsWith("Abcd", "F")); - BOOST_CHECK(!StartsWith("Abcd", "AF")); - BOOST_CHECK(!StartsWith("Abcd", "AbF")); - BOOST_CHECK(!StartsWith("Abcd", "AbcF")); - BOOST_CHECK(!StartsWith("Abcd", "Abcde")); + EXPECT_TRUE(StartsWith("Abcd", "A")); + EXPECT_TRUE(StartsWith("Abcd", "Ab")); + EXPECT_TRUE(StartsWith("Abcd", "Abc")); + EXPECT_TRUE(StartsWith("Abcd", "Abcd")); + + EXPECT_FALSE(StartsWith("Abcd", "a")); + EXPECT_FALSE(StartsWith("Abcd", "F")); + EXPECT_FALSE(StartsWith("Abcd", "AF")); + EXPECT_FALSE(StartsWith("Abcd", "AbF")); + EXPECT_FALSE(StartsWith("Abcd", "AbcF")); + EXPECT_FALSE(StartsWith("Abcd", "Abcde")); } -BOOST_AUTO_TEST_CASE(StrEqualIgnoreCaseTest) +TEST(CommonHelperTest, StrEqualIgnoreCaseTest) { using namespace SPTAG::Helper::StrUtils; - BOOST_CHECK(StrEqualIgnoreCase("Abcd", "Abcd")); - BOOST_CHECK(StrEqualIgnoreCase("Abcd", "abcd")); - BOOST_CHECK(StrEqualIgnoreCase("Abcd", "abCD")); - BOOST_CHECK(StrEqualIgnoreCase("Abcd-123", "abcd-123")); - BOOST_CHECK(StrEqualIgnoreCase(" ZZZ", " zzz")); + EXPECT_TRUE(StrEqualIgnoreCase("Abcd", "Abcd")); + EXPECT_TRUE(StrEqualIgnoreCase("Abcd", "abcd")); + EXPECT_TRUE(StrEqualIgnoreCase("Abcd", "abCD")); + EXPECT_TRUE(StrEqualIgnoreCase("Abcd-123", "abcd-123")); + EXPECT_TRUE(StrEqualIgnoreCase(" ZZZ", " zzz")); - BOOST_CHECK(!StrEqualIgnoreCase("abcd", "abcd1")); - BOOST_CHECK(!StrEqualIgnoreCase("Abcd", " abcd")); - BOOST_CHECK(!StrEqualIgnoreCase("000", "OOO")); + EXPECT_FALSE(StrEqualIgnoreCase("abcd", "abcd1")); + EXPECT_FALSE(StrEqualIgnoreCase("Abcd", " abcd")); + EXPECT_FALSE(StrEqualIgnoreCase("000", "OOO")); } -BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file +} // namespace CommonHelperTest diff --git a/Test/src/ConcurrentTest.cpp b/Test/src/ConcurrentTest.cpp index b137037d..9caac683 100644 --- a/Test/src/ConcurrentTest.cpp +++ b/Test/src/ConcurrentTest.cpp @@ -17,7 +17,7 @@ void ConcurrentAddSearchSave(SPTAG::IndexAlgoType algo, std::string distCalcMeth { std::shared_ptr vecIndex = SPTAG::VectorIndex::CreateInstance(algo, SPTAG::GetEnumValueType()); - BOOST_CHECK(nullptr != vecIndex); + ASSERT_NE(nullptr, vecIndex); vecIndex->SetParameter("DistCalcMethod", distCalcMethod); vecIndex->SetParameter("NumberOfThreads", "16"); @@ -133,16 +133,17 @@ template void CTest(SPTAG::IndexAlgoType algo, std::string distCalc ConcurrentAddSearchSave(algo, distCalcMethod, vecset, metaset, "testindices"); } -BOOST_AUTO_TEST_SUITE(ConcurrentTest) +namespace ConcurrentTest +{ -BOOST_AUTO_TEST_CASE(BKTTest) +TEST(ConcurrentTest, BKTTest) { CTest(SPTAG::IndexAlgoType::BKT, "L2"); } -BOOST_AUTO_TEST_CASE(KDTTest) +TEST(ConcurrentTest, KDTTest) { CTest(SPTAG::IndexAlgoType::KDT, "L2"); } -BOOST_AUTO_TEST_SUITE_END() +} // namespace ConcurrentTest diff --git a/Test/src/DistanceTest.cpp b/Test/src/DistanceTest.cpp index d95dd46d..21b9d9f5 100644 --- a/Test/src/DistanceTest.cpp +++ b/Test/src/DistanceTest.cpp @@ -38,18 +38,18 @@ template void test(int high) { SPTAG::DimensionType dimension = random(256, 2); T *X = new T[dimension], *Y = new T[dimension]; - BOOST_ASSERT(X != nullptr && Y != nullptr); + ASSERT_TRUE(X != nullptr && Y != nullptr); for (SPTAG::DimensionType i = 0; i < dimension; i++) { X[i] = random(high, -high); Y[i] = random(high, -high); } - BOOST_CHECK_CLOSE_FRACTION( - ComputeL2Distance(X, Y, dimension), - SPTAG::COMMON::DistanceUtils::ComputeDistance(X, Y, dimension, SPTAG::DistCalcMethod::L2), 1e-5); - BOOST_CHECK_CLOSE_FRACTION( - high * high - ComputeCosineDistance(X, Y, dimension), - SPTAG::COMMON::DistanceUtils::ComputeDistance(X, Y, dimension, SPTAG::DistCalcMethod::Cosine), 1e-5); + EXPECT_NEAR(ComputeL2Distance(X, Y, dimension), + SPTAG::COMMON::DistanceUtils::ComputeDistance(X, Y, dimension, SPTAG::DistCalcMethod::L2), + 1e-5 * ComputeL2Distance(X, Y, dimension)); + EXPECT_NEAR(high * high - ComputeCosineDistance(X, Y, dimension), + SPTAG::COMMON::DistanceUtils::ComputeDistance(X, Y, dimension, SPTAG::DistCalcMethod::Cosine), + 1e-5 * (std::abs(high * high - ComputeCosineDistance(X, Y, dimension)))); delete[] X; delete[] Y; @@ -109,16 +109,17 @@ void test_dist_calc_performance(int high, SPTAG::DimensionType dimension = 256, delete[] Y; } -BOOST_AUTO_TEST_SUITE(DistanceTest) +namespace DistanceTest +{ -BOOST_AUTO_TEST_CASE(TestDistanceComputation) +TEST(DistanceTest, TestDistanceComputation) { test(1); test(127); test(32767); } -BOOST_AUTO_TEST_CASE(TestDistanceComputationPerformance) +TEST(DistanceTest, TestDistanceComputationPerformance) { std::vector dimensions{128, 256, 512, 1024}; std::vector nums_threads{1, 16, 40}; @@ -140,4 +141,4 @@ BOOST_AUTO_TEST_CASE(TestDistanceComputationPerformance) } } -BOOST_AUTO_TEST_SUITE_END() +} // namespace DistanceTest diff --git a/Test/src/FilterTest.cpp b/Test/src/FilterTest.cpp index 285df5b4..cd3c8124 100644 --- a/Test/src/FilterTest.cpp +++ b/Test/src/FilterTest.cpp @@ -16,21 +16,21 @@ void BuildWithMetaMapping(SPTAG::IndexAlgoType algo, std::string distCalcMethod, std::shared_ptr vecIndex = SPTAG::VectorIndex::CreateInstance(algo, SPTAG::GetEnumValueType()); - BOOST_CHECK(nullptr != vecIndex); + ASSERT_NE(nullptr, vecIndex); vecIndex->SetParameter("DistCalcMethod", distCalcMethod); vecIndex->SetParameter("NumberOfThreads", "16"); - BOOST_CHECK(SPTAG::ErrorCode::Success == vecIndex->BuildIndex(vec, meta, true)); - BOOST_CHECK(SPTAG::ErrorCode::Success == vecIndex->SaveIndex(out)); + ASSERT_EQ(SPTAG::ErrorCode::Success, vecIndex->BuildIndex(vec, meta, true)); + ASSERT_EQ(SPTAG::ErrorCode::Success, vecIndex->SaveIndex(out)); } template void SearchWithFilter(const std::string folder, T *vec, SPTAG::SizeType n, int k) { std::cout << "start search with filter" << std::endl; std::shared_ptr vecIndex; - BOOST_CHECK(SPTAG::ErrorCode::Success == SPTAG::VectorIndex::LoadIndex(folder, vecIndex)); - BOOST_CHECK(nullptr != vecIndex); + ASSERT_EQ(SPTAG::ErrorCode::Success, SPTAG::VectorIndex::LoadIndex(folder, vecIndex)); + ASSERT_NE(nullptr, vecIndex); std::string value = "2"; std::function filterFunction = [value](const SPTAG::ByteArray &meta) -> bool { std::string metaValue((char *)meta.Data(), meta.Length()); @@ -51,7 +51,7 @@ template void SearchWithFilter(const std::string folder, T *vec, SP std::cout << std::endl; for (int j = 0; j < k; j++) { - BOOST_CHECK(resmeta.find("2") == resmeta.end()); + EXPECT_EQ(resmeta.end(), resmeta.find("2")); } vec += vecIndex->GetFeatureDim(); } @@ -104,11 +104,12 @@ template void FTest(SPTAG::IndexAlgoType algo, std::string distCalc SearchWithFilter("testindices", query.data(), q, k); } -BOOST_AUTO_TEST_SUITE(FilterTest) +namespace FilterTest +{ -BOOST_AUTO_TEST_CASE(BKTTest) +TEST(FilterTest, BKTTest) { FTest(SPTAG::IndexAlgoType::BKT, "L2"); } -BOOST_AUTO_TEST_SUITE_END() +} // namespace FilterTest diff --git a/Test/src/IniReaderTest.cpp b/Test/src/IniReaderTest.cpp index 9386a35a..27fd9153 100644 --- a/Test/src/IniReaderTest.cpp +++ b/Test/src/IniReaderTest.cpp @@ -6,9 +6,10 @@ #include -BOOST_AUTO_TEST_SUITE(IniReaderTest) +namespace IniReaderTest +{ -BOOST_AUTO_TEST_CASE(IniReaderLoadTest) +TEST(IniReaderTest, IniReaderLoadTest) { std::ofstream tmpIni("temp.ini"); tmpIni << "[Common]" << std::endl; @@ -19,22 +20,21 @@ BOOST_AUTO_TEST_CASE(IniReaderLoadTest) tmpIni.close(); SPTAG::Helper::IniReader reader; - BOOST_CHECK(SPTAG::ErrorCode::Success == reader.LoadIniFile("temp.ini")); + ASSERT_EQ(SPTAG::ErrorCode::Success, reader.LoadIniFile("temp.ini")); - BOOST_CHECK(reader.DoesSectionExist("Common")); - BOOST_CHECK(reader.DoesParameterExist("Common", "Param1")); - BOOST_CHECK(reader.DoesParameterExist("Common", "Param2")); + EXPECT_TRUE(reader.DoesSectionExist("Common")); + EXPECT_TRUE(reader.DoesParameterExist("Common", "Param1")); + EXPECT_TRUE(reader.DoesParameterExist("Common", "Param2")); - BOOST_CHECK(!reader.DoesSectionExist("NotExist")); - BOOST_CHECK(!reader.DoesParameterExist("NotExist", "Param1")); - BOOST_CHECK(!reader.DoesParameterExist("Common", "ParamNotExist")); + EXPECT_FALSE(reader.DoesSectionExist("NotExist")); + EXPECT_FALSE(reader.DoesParameterExist("NotExist", "Param1")); + EXPECT_FALSE(reader.DoesParameterExist("Common", "ParamNotExist")); - BOOST_CHECK(1 == reader.GetParameter("Common", "Param1", 0)); - BOOST_CHECK(0 == reader.GetParameter("Common", "ParamNotExist", 0)); + EXPECT_EQ(1, reader.GetParameter("Common", "Param1", 0)); + EXPECT_EQ(0, reader.GetParameter("Common", "ParamNotExist", 0)); - BOOST_CHECK(std::string("Exp=2") == reader.GetParameter("Common", "Param2", std::string())); - BOOST_CHECK(std::string("1") == reader.GetParameter("Common", "Param1", std::string())); - BOOST_CHECK(std::string() == reader.GetParameter("Common", "ParamNotExist", std::string())); + EXPECT_EQ(std::string("Exp=2"), reader.GetParameter("Common", "Param2", std::string())); + EXPECT_EQ(std::string("1"), reader.GetParameter("Common", "Param1", std::string())); + EXPECT_EQ(std::string(), reader.GetParameter("Common", "ParamNotExist", std::string())); } - -BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file +} // namespace IniReaderTest \ No newline at end of file diff --git a/Test/src/IterativeScanTest.cpp b/Test/src/IterativeScanTest.cpp index 938ed328..b1d46103 100644 --- a/Test/src/IterativeScanTest.cpp +++ b/Test/src/IterativeScanTest.cpp @@ -17,14 +17,16 @@ template void BuildIndex(IndexAlgoType algo, std::string distCalcMethod, std::shared_ptr &vec, std::shared_ptr &meta, const std::string out) { - std::shared_ptr vecIndex = - VectorIndex::CreateInstance(algo, GetEnumValueType()); - BOOST_CHECK(nullptr != vecIndex); + + std::shared_ptr vecIndex = + SPTAG::VectorIndex::CreateInstance(algo, SPTAG::GetEnumValueType()); + ASSERT_NE(nullptr, vecIndex); if (algo != IndexAlgoType::SPANN) { vecIndex->SetParameter("DistCalcMethod", distCalcMethod); vecIndex->SetParameter("NumberOfThreads", "16"); + vecIndex->SetParameter("MaxCheck", "5"); } else { @@ -49,19 +51,16 @@ void BuildIndex(IndexAlgoType algo, std::string distCalcMethod, std::shared_ptr< vecIndex->SetParameter("MaxCheck", "8192", "BuildSSDIndex"); } - BOOST_CHECK(ErrorCode::Success == vecIndex->BuildIndex(vec, meta)); - BOOST_CHECK(ErrorCode::Success == vecIndex->SaveIndex(out)); + ASSERT_EQ(SPTAG::ErrorCode::Success, vecIndex->BuildIndex(vec, meta)); + ASSERT_EQ(SPTAG::ErrorCode::Success, vecIndex->SaveIndex(out)); } -template -void SearchIterativeBatch(const std::string folder, T *vec, SizeType n, std::string *truthmeta) +template void SearchIterativeBatch(const std::string folder, T *vec, SizeType n, std::string *truthmeta) { std::shared_ptr vecIndex; - BOOST_CHECK(ErrorCode::Success == VectorIndex::LoadIndex(folder, vecIndex)); - BOOST_CHECK(nullptr != vecIndex); - vecIndex->SetParameter("MaxCheck", "5", "BuildSSDIndex"); - vecIndex->UpdateIndex(); + ASSERT_EQ(SPTAG::ErrorCode::Success, SPTAG::VectorIndex::LoadIndex(folder, vecIndex)); + ASSERT_NE(nullptr, vecIndex); std::shared_ptr resultIterator = vecIndex->GetIterator(vec); // std::cout << "relaxedMono:" << resultIterator->GetRelaxedMono() << std::endl; @@ -73,13 +72,13 @@ void SearchIterativeBatch(const std::string folder, T *vec, SizeType n, std::str int resultCount = results->GetResultNum(); if (resultCount <= 0) break; - BOOST_CHECK(resultCount == batch); + ASSERT_EQ(resultCount, batch); for (int j = 0; j < resultCount; j++) { - BOOST_CHECK(std::string((char *)((results->GetMetadata(j)).Data()), (results->GetMetadata(j)).Length()) == - truthmeta[ri]); - BOOST_CHECK(results->GetResult(j)->RelaxedMono == true); + EXPECT_EQ(std::string((char *)((results->GetMetadata(j)).Data()), (results->GetMetadata(j)).Length()), + truthmeta[ri]); + EXPECT_TRUE(results->GetResult(j)->RelaxedMono == true); std::cout << "Result[" << ri << "] VID:" << results->GetResult(j)->VID << " Dist:" << results->GetResult(j)->Dist << " RelaxedMono:" << results->GetResult(j)->RelaxedMono << std::endl; @@ -134,6 +133,9 @@ template void TestIterativeScan(IndexAlgoType algo, std::string dis SearchIterativeBatch("testindices", query.data(), q, truthmeta1); } +namespace IterativeScanTest +{ + template float EvaluateRecall(const std::vector &res, std::shared_ptr &vecIndex, std::shared_ptr &queryset, std::shared_ptr &truth, @@ -186,8 +188,8 @@ template void TestIterativeScanRandom(IndexAlgoType algo, std::stri BuildIndex(algo, distCalcMethod, vecset, metaset, "testindices"); std::shared_ptr vecIndex; - BOOST_CHECK(ErrorCode::Success == VectorIndex::LoadIndex("testindices", vecIndex)); - BOOST_CHECK(nullptr != vecIndex); + ASSERT_EQ(ErrorCode::Success, VectorIndex::LoadIndex("testindices", vecIndex)); + ASSERT_NE(nullptr, vecIndex); std::vector res(queryset->Count(), QueryResult(nullptr, k, true)); std::vector resiter(queryset->Count(), QueryResult(nullptr, k, true)); @@ -206,12 +208,14 @@ template void TestIterativeScanRandom(IndexAlgoType algo, std::stri { auto results = resultIterator->Next(batch); int resultCount = results->GetResultNum(); - if (resultCount <= 0) break; - BOOST_CHECK(resultCount == batch); + if (resultCount <= 0) + break; + EXPECT_EQ(resultCount, batch); for (int j = 0; j < resultCount; j++) { relaxMono = results->GetResult(j)->RelaxedMono; - ((COMMON::QueryResultSet *)(&resiter[i]))->AddPoint(results->GetResult(j)->VID, results->GetResult(j)->Dist); + ((COMMON::QueryResultSet *)(&resiter[i])) + ->AddPoint(results->GetResult(j)->VID, results->GetResult(j)->Dist); } ri += resultCount; iterscanned = results->GetScanned(); @@ -224,21 +228,19 @@ template void TestIterativeScanRandom(IndexAlgoType algo, std::stri << " Iterator Recall:" << EvaluateRecall(resiter, vecIndex, queryset, truth, vecset, k) << std::endl; } -BOOST_AUTO_TEST_SUITE(IterativeScanTest) - -BOOST_AUTO_TEST_CASE(BKTTest) +TEST(IterativeScanTest, BKTTest) { TestIterativeScan(IndexAlgoType::BKT, "L2"); } -BOOST_AUTO_TEST_CASE(BKTRandomTest) +TEST(IterativeScanTest, BKTRandomTest) { TestIterativeScanRandom(IndexAlgoType::BKT, "L2"); } -BOOST_AUTO_TEST_CASE(SPANNRandomTest) +TEST(IterativeScanTest, SPANNRandomTest) { TestIterativeScanRandom(IndexAlgoType::SPANN, "L2"); } -BOOST_AUTO_TEST_SUITE_END() +} // namespace IterativeScanTest diff --git a/Test/src/KVTest.cpp b/Test/src/KVTest.cpp index 9c49d4ae..320fd957 100644 --- a/Test/src/KVTest.cpp +++ b/Test/src/KVTest.cpp @@ -49,7 +49,7 @@ void Search(std::shared_ptr db, int internalResultNum, int t std::cout << "avg get time: " << (latency / (float)(times)) << "us" << std::endl; } -void Test(std::string path, std::string type, bool debug = false) +void RunTest(std::string path, std::string type, bool debug = false) { int internalResultNum = 64; int totalNum = 1024; @@ -130,27 +130,28 @@ void Test(std::string path, std::string type, bool debug = false) // } } -BOOST_AUTO_TEST_SUITE(KVTest) +namespace KVTest +{ -BOOST_AUTO_TEST_CASE(RocksDBTest) +TEST(KVTest, RocksDBTest) { if (!direxists("tmp_rocksdb")) mkdir("tmp_rocksdb"); - Test(std::string("tmp_rocksdb") + FolderSep + "test", "RocksDB", false); + RunTest(std::string("tmp_rocksdb") + FolderSep + "test", "RocksDB", false); } -BOOST_AUTO_TEST_CASE(SPDKTest) +TEST(KVTest, SPDKTest) { if (!direxists("tmp_spdk")) mkdir("tmp_spdk"); - Test(std::string("tmp_spdk") + FolderSep + "test", "SPDK", false); + RunTest(std::string("tmp_spdk") + FolderSep + "test", "SPDK", false); } -BOOST_AUTO_TEST_CASE(FileTest) +TEST(KVTest, FileTest) { if (!direxists("tmp_file")) mkdir("tmp_file"); - Test(std::string("tmp_file") + FolderSep + "test", "File", false); + RunTest(std::string("tmp_file") + FolderSep + "test", "File", false); } -BOOST_AUTO_TEST_SUITE_END() +} // namespace KVTest diff --git a/Test/src/MultiIndexExperiment.cpp b/Test/src/MultiIndexExperiment.cpp index 60b3c87c..5b4db1b7 100644 --- a/Test/src/MultiIndexExperiment.cpp +++ b/Test/src/MultiIndexExperiment.cpp @@ -45,13 +45,13 @@ void BuildIndex(SPTAG::IndexAlgoType algo, std::string distCalcMethod, std::shar std::shared_ptr vecIndex = SPTAG::VectorIndex::CreateInstance(algo, SPTAG::GetEnumValueType()); - BOOST_CHECK(nullptr != vecIndex); + ASSERT_NE(nullptr, vecIndex); vecIndex->SetParameter("DistCalcMethod", distCalcMethod); vecIndex->SetParameter("NumberOfThreads", "16"); - BOOST_CHECK(SPTAG::ErrorCode::Success == vecIndex->BuildIndex(vec, meta)); - BOOST_CHECK(SPTAG::ErrorCode::Success == vecIndex->SaveIndex(out)); + ASSERT_EQ(SPTAG::ErrorCode::Success, vecIndex->BuildIndex(vec, meta)); + ASSERT_EQ(SPTAG::ErrorCode::Success, vecIndex->SaveIndex(out)); } float sumFunc(std::vector in) @@ -194,8 +194,8 @@ template void TestMultiIndexScanN(SPTAG::IndexAlgoType algo, std::s for (unsigned int i = 0; i < n; i++) { std::shared_ptr vecIndex; - BOOST_CHECK(SPTAG::ErrorCode::Success == SPTAG::VectorIndex::LoadIndex(indexName(i).c_str(), vecIndex)); - BOOST_CHECK(nullptr != vecIndex); + ASSERT_EQ(SPTAG::ErrorCode::Success, SPTAG::VectorIndex::LoadIndex(indexName(i).c_str(), vecIndex)); + ASSERT_NE(nullptr, vecIndex); vecIndices.push_back(vecIndex); p_targets.push_back(query_current[i].data()); } @@ -233,11 +233,12 @@ template void TestMultiIndexScanN(SPTAG::IndexAlgoType algo, std::s } } -BOOST_AUTO_TEST_SUITE(MultiIndexExperiment) +namespace MultiIndexExperimentTest +{ -BOOST_AUTO_TEST_CASE(BKTTest) +TEST(MultiIndexExperiment, BKTTest) { TestMultiIndexScanN(SPTAG::IndexAlgoType::BKT, "InnerProduct", 2); } -BOOST_AUTO_TEST_SUITE_END() +} // namespace MultiIndexExperimentTest diff --git a/Test/src/MultiIndexScanTest.cpp b/Test/src/MultiIndexScanTest.cpp index 3fca5ea0..2196bc1b 100644 --- a/Test/src/MultiIndexScanTest.cpp +++ b/Test/src/MultiIndexScanTest.cpp @@ -22,13 +22,13 @@ void BuildIndex(SPTAG::IndexAlgoType algo, std::string distCalcMethod, std::shar std::shared_ptr vecIndex = SPTAG::VectorIndex::CreateInstance(algo, SPTAG::GetEnumValueType()); - BOOST_CHECK(nullptr != vecIndex); + ASSERT_NE(nullptr, vecIndex); vecIndex->SetParameter("DistCalcMethod", distCalcMethod); vecIndex->SetParameter("NumberOfThreads", "16"); - BOOST_CHECK(SPTAG::ErrorCode::Success == vecIndex->BuildIndex(vec, meta)); - BOOST_CHECK(SPTAG::ErrorCode::Success == vecIndex->SaveIndex(out)); + ASSERT_EQ(SPTAG::ErrorCode::Success, vecIndex->BuildIndex(vec, meta)); + ASSERT_EQ(SPTAG::ErrorCode::Success, vecIndex->SaveIndex(out)); } float rankFunc(std::vector in) @@ -45,8 +45,8 @@ void MultiIndexSearch(unsigned int n, std::vector> &queries, int for (unsigned int i = 0; i < n; i++) { std::shared_ptr vecIndex; - BOOST_CHECK(SPTAG::ErrorCode::Success == SPTAG::VectorIndex::LoadIndex(indexName(i).c_str(), vecIndex)); - BOOST_CHECK(nullptr != vecIndex); + ASSERT_EQ(SPTAG::ErrorCode::Success, SPTAG::VectorIndex::LoadIndex(indexName(i).c_str(), vecIndex)); + ASSERT_NE(nullptr, vecIndex); vecIndices.push_back(vecIndex); p_targets.push_back(queries[i].data()); } @@ -125,11 +125,12 @@ template void TestMultiIndexScanN(SPTAG::IndexAlgoType algo, std::s MultiIndexSearch(n, queries, k, false, 10); } -BOOST_AUTO_TEST_SUITE(MultiIndexScanTest) +namespace MultiIndexScanTest +{ -BOOST_AUTO_TEST_CASE(BKTTest) +TEST(MultiIndexScanTest, BKTTest) { TestMultiIndexScanN(SPTAG::IndexAlgoType::BKT, "L2", 2); } -BOOST_AUTO_TEST_SUITE_END() +} // namespace MultiIndexScanTest diff --git a/Test/src/PerfTest.cpp b/Test/src/PerfTest.cpp index 4a69830a..0df541e3 100644 --- a/Test/src/PerfTest.cpp +++ b/Test/src/PerfTest.cpp @@ -61,7 +61,7 @@ void PerfAdd(IndexAlgoType algo, std::string distCalcMethod, std::shared_ptr &truth, std::string out) { std::shared_ptr vecIndex = VectorIndex::CreateInstance(algo, GetEnumValueType()); - BOOST_CHECK(nullptr != vecIndex); + ASSERT_NE(nullptr, vecIndex); if (algo == IndexAlgoType::KDT) vecIndex->SetParameter("KDTNumber", "2"); @@ -92,9 +92,9 @@ void PerfAdd(IndexAlgoType algo, std::string distCalcMethod, std::shared_ptr(vecIndex, queryset, k, truth); - BOOST_CHECK(ErrorCode::Success == vecIndex->SaveIndex(out)); - BOOST_CHECK(ErrorCode::Success == VectorIndex::LoadIndex(out, vecIndex)); - BOOST_CHECK(nullptr != vecIndex); + ASSERT_EQ(ErrorCode::Success, vecIndex->SaveIndex(out)); + ASSERT_EQ(ErrorCode::Success, VectorIndex::LoadIndex(out, vecIndex)); + ASSERT_NE(nullptr, vecIndex); Search(vecIndex, queryset, k, truth); } @@ -104,7 +104,7 @@ void PerfBuild(IndexAlgoType algo, std::string distCalcMethod, std::shared_ptr &truth, std::string out) { std::shared_ptr vecIndex = SPTAG::VectorIndex::CreateInstance(algo, SPTAG::GetEnumValueType()); - BOOST_CHECK(nullptr != vecIndex); + ASSERT_NE(nullptr, vecIndex); if (algo == IndexAlgoType::KDT) vecIndex->SetParameter("KDTNumber", "2"); @@ -114,8 +114,8 @@ void PerfBuild(IndexAlgoType algo, std::string distCalcMethod, std::shared_ptrSetParameter("MaxCheck", "4096"); vecIndex->SetParameter("MaxCheckForRefineGraph", "8192"); - BOOST_CHECK(SPTAG::ErrorCode::Success == vecIndex->BuildIndex(vec, meta, true)); - BOOST_CHECK(SPTAG::ErrorCode::Success == vecIndex->SaveIndex(out)); + ASSERT_EQ(SPTAG::ErrorCode::Success, vecIndex->BuildIndex(vec, meta, true)); + ASSERT_EQ(SPTAG::ErrorCode::Success, vecIndex->SaveIndex(out)); Search(vecIndex, queryset, k, truth); } @@ -268,21 +268,22 @@ template void PTest(IndexAlgoType algo, std::string distCalcMethod) PerfAdd(algo, distCalcMethod, vecset, metaset, queryset, 10, truth, "testindices"); PerfBuild(algo, distCalcMethod, vecset, metaset, queryset, 10, truth, "testindices"); std::shared_ptr vecIndex; - BOOST_CHECK(ErrorCode::Success == VectorIndex::LoadIndex("testindices", vecIndex)); - BOOST_CHECK(nullptr != vecIndex); + ASSERT_EQ(ErrorCode::Success, VectorIndex::LoadIndex("testindices", vecIndex)); + ASSERT_NE(nullptr, vecIndex); Search(vecIndex, queryset, 10, truth); } -BOOST_AUTO_TEST_SUITE(PerfTest) +namespace PerfTest +{ -BOOST_AUTO_TEST_CASE(BKTTest) +TEST(PerfTest, BKTTest) { PTest(IndexAlgoType::BKT, "Cosine"); } -BOOST_AUTO_TEST_CASE(KDTTest) +TEST(PerfTest, KDTTest) { PTest(IndexAlgoType::KDT, "Cosine"); } -BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file +} // namespace PerfTest \ No newline at end of file diff --git a/Test/src/ReconstructIndexSimilarityTest.cpp b/Test/src/ReconstructIndexSimilarityTest.cpp index e7ca7806..f5d7988e 100644 --- a/Test/src/ReconstructIndexSimilarityTest.cpp +++ b/Test/src/ReconstructIndexSimilarityTest.cpp @@ -21,8 +21,7 @@ template void Search(std::shared_ptr &vecIndex, std::shared_ptr &vecset, std::shared_ptr &queryset, int k, std::shared_ptr &truth) { - std::vector> res(queryset->Count(), - COMMON::QueryResultSet(nullptr, k * 2)); + std::vector> res(queryset->Count(), COMMON::QueryResultSet(nullptr, k * 2)); auto t1 = std::chrono::high_resolution_clock::now(); for (SizeType i = 0; i < queryset->Count(); i++) { @@ -78,7 +77,7 @@ std::shared_ptr PerfBuild(IndexAlgoType algo, std::string distCalcM { std::shared_ptr vecIndex = VectorIndex::CreateInstance(algo, GetEnumValueType()); vecIndex->SetQuantizer(quantizer); - BOOST_CHECK(nullptr != vecIndex); + EXPECT_NE(nullptr, vecIndex); if (algo != IndexAlgoType::SPANN) { @@ -117,8 +116,8 @@ std::shared_ptr PerfBuild(IndexAlgoType algo, std::string distCalcM vecIndex->SetParameter("SearchInternalResultNum", "64", "BuildSSDIndex"); } - BOOST_CHECK(ErrorCode::Success == vecIndex->BuildIndex(vec, meta, true)); - BOOST_CHECK(ErrorCode::Success == vecIndex->SaveIndex(out)); + EXPECT_EQ(SPTAG::ErrorCode::Success, vecIndex->BuildIndex(vec, meta, true)); + EXPECT_EQ(SPTAG::ErrorCode::Success, vecIndex->SaveIndex(out)); // Search(vecIndex, queryset, k, truth); return vecIndex; } @@ -241,13 +240,13 @@ void GenerateReconstructData(std::shared_ptr &real_vecset, std::share if (fileexists(CODEBOOK_FILE.c_str()) && fileexists("quantest_quan_vector.bin") && fileexists("quantest_rec_vector.bin")) { - auto ptr = f_createIO(); + auto ptr = SPTAG::f_createIO(); if (ptr == nullptr || !ptr->Initialize(CODEBOOK_FILE.c_str(), std::ios::binary | std::ios::in)) { - BOOST_ASSERT("Canot Open CODEBOOK_FILE to read!" == "Error"); + GTEST_FAIL() << "Cannot open CODEBOOK_FILE to read!"; } - quantizer = COMMON::IQuantizer::LoadIQuantizer(ptr); - BOOST_ASSERT(quantizer); + quantizer = SPTAG::COMMON::IQuantizer::LoadIQuantizer(ptr); + ASSERT_TRUE(quantizer != nullptr); std::shared_ptr options( new Helper::ReaderOptions(GetEnumValueType(), m, VectorFileType::DEFAULT)); @@ -376,21 +375,21 @@ void GenerateReconstructData(std::shared_ptr &real_vecset, std::share } std::cout << "Building Finish!" << std::endl; - quantizer = std::make_shared>(M, Ks, QuanDim, false, std::move(codebooks)); - auto ptr = f_createIO(); + quantizer = std::make_shared>(M, Ks, QuanDim, false, std::move(codebooks)); + auto ptr = SPTAG::f_createIO(); if (ptr == nullptr || !ptr->Initialize(CODEBOOK_FILE.c_str(), std::ios::binary | std::ios::out)) { - BOOST_ASSERT("Canot Open CODEBOOK_FILE to write!" == "Error"); + GTEST_FAIL() << "Cannot open CODEBOOK_FILE to write!"; } quantizer->SaveQuantizer(ptr); ptr->ShutDown(); if (!ptr->Initialize(CODEBOOK_FILE.c_str(), std::ios::binary | std::ios::in)) { - BOOST_ASSERT("Canot Open CODEBOOK_FILE to read!" == "Error"); + GTEST_FAIL() << "Cannot open CODEBOOK_FILE to read!"; } quantizer->LoadIQuantizer(ptr); - BOOST_ASSERT(quantizer); + ASSERT_TRUE(quantizer != nullptr); rec_vecset.reset(new BasicVectorSet(ByteArray::Alloc(sizeof(R) * n * m), GetEnumValueType(), m, n)); quan_vecset.reset( @@ -444,24 +443,22 @@ template void ReconstructTest(IndexAlgoType algo, DistCalcMethod di std::filesystem::remove_all("quan_idx"); } -BOOST_AUTO_TEST_SUITE(ReconstructIndexSimilarityTest) - -BOOST_AUTO_TEST_CASE(BKTReconstructTest) +namespace ReconstructIndexSimilarityTest { +TEST(ReconstructIndexSimilarityTest, BKTReconstructTest) +{ ReconstructTest(IndexAlgoType::BKT, DistCalcMethod::L2); } -BOOST_AUTO_TEST_CASE(KDTReconstructTest) +TEST(ReconstructIndexSimilarityTest, KDTReconstructTest) { - ReconstructTest(IndexAlgoType::KDT, DistCalcMethod::L2); } -BOOST_AUTO_TEST_CASE(SPANNReconstructTest) +TEST(ReconstructIndexSimilarityTest, SPANNReconstructTest) { - ReconstructTest(IndexAlgoType::SPANN, DistCalcMethod::L2); } -BOOST_AUTO_TEST_SUITE_END() +} // namespace ReconstructIndexSimilarityTest diff --git a/Test/src/SIMDTest.cpp b/Test/src/SIMDTest.cpp index b4759492..5f483057 100644 --- a/Test/src/SIMDTest.cpp +++ b/Test/src/SIMDTest.cpp @@ -24,7 +24,7 @@ template void test(int high) { SPTAG::DimensionType dimension = random(256, 2); T *X = new T[dimension], *Y = new T[dimension]; - BOOST_ASSERT(X != nullptr && Y != nullptr); + ASSERT_TRUE(X != nullptr && Y != nullptr); for (SPTAG::DimensionType i = 0; i < dimension; i++) { X[i] = random(high, -high); @@ -39,7 +39,7 @@ template void test(int high) SPTAG::COMMON::SIMDUtils::ComputeSum(X_copy, Y, dimension); for (SPTAG::DimensionType i = 0; i < dimension; i++) { - BOOST_CHECK_CLOSE_FRACTION(double(X[i]), double(X_copy[i]), 1e-5); + EXPECT_NEAR(double(X[i]), double(X_copy[i]), 1e-5 * X[i]); } delete[] X; @@ -47,13 +47,14 @@ template void test(int high) delete[] X_copy; } -BOOST_AUTO_TEST_SUITE(SIMDTest) +namespace SIMDTest +{ -BOOST_AUTO_TEST_CASE(TestDistanceComputation) +TEST(SIMDTest, TestDistanceComputation) { test(1); test(127); test(32767); } -BOOST_AUTO_TEST_SUITE_END() +} // namespace SIMDTest diff --git a/Test/src/SPFreshTest.cpp b/Test/src/SPFreshTest.cpp index ddf42b14..dc7dbfaf 100644 --- a/Test/src/SPFreshTest.cpp +++ b/Test/src/SPFreshTest.cpp @@ -9,8 +9,8 @@ #include "inc/Core/VectorIndex.h" #include "inc/Helper/DiskIO.h" #include "inc/Helper/SimpleIniReader.h" -#include "inc/Helper/VectorSetReader.h" #include "inc/Helper/StringConvert.h" +#include "inc/Helper/VectorSetReader.h" #include "inc/Test.h" #include "inc/TestDataGenerator.h" @@ -42,7 +42,7 @@ std::shared_ptr BuildIndex(const std::string &outDirectory, std::sh [Base] DistCalcMethod=L2 IndexAlgoType=BKT - ValueType=)" + Helper::Convert::ConvertToString(GetEnumValueType()) + + ValueType=)" + Helper::Convert::ConvertToString(GetEnumValueType()) + R"( Dim=)" + std::to_string(M) + R"( @@ -141,7 +141,8 @@ std::vector SearchOnly(std::shared_ptr &vecIndex, std: template float EvaluateRecall(const std::vector &res, std::shared_ptr &vecIndex, std::shared_ptr &queryset, std::shared_ptr &truth, - std::shared_ptr &baseVec, std::shared_ptr &addVec, SizeType baseCount, int k, int batch) + std::shared_ptr &baseVec, std::shared_ptr &addVec, SizeType baseCount, int k, + int batch) { if (!truth) { @@ -192,8 +193,8 @@ float Search(std::shared_ptr &vecIndex, std::shared_ptr } template -void InsertVectors(SPANN::Index *p_index, int insertThreads, int step, - std::shared_ptr addset, std::shared_ptr &metaset, int start = 0) +void InsertVectors(SPANN::Index *p_index, int insertThreads, int step, std::shared_ptr addset, + std::shared_ptr &metaset, int start = 0) { SPANN::Options &p_opts = *(p_index->GetOptions()); p_index->ForceCompaction(); @@ -215,10 +216,10 @@ void InsertVectors(SPANN::Index *p_index, int insertThreads, int step } ByteArray p_meta = metaset->GetMetadata((SizeType)index); std::uint64_t *offsets = new std::uint64_t[2]{0, p_meta.Length()}; - std::shared_ptr meta(new MemMetadataSet( - p_meta, ByteArray((std::uint8_t *)offsets, 2 * sizeof(std::uint64_t), true), 1)); + std::shared_ptr meta( + new MemMetadataSet(p_meta, ByteArray((std::uint8_t *)offsets, 2 * sizeof(std::uint64_t), true), 1)); auto status = p_index->AddIndex(addset->GetVector((SizeType)index), 1, p_opts.m_dim, meta, true); - BOOST_REQUIRE(status == ErrorCode::Success); + ASSERT_EQ(status, ErrorCode::Success); } else { @@ -375,9 +376,10 @@ std::shared_ptr get_embeddings(uint32_t row_id, uint32_t end_id, uint return std::make_shared(vec, GetEnumValueType(), embedding_dim, count); } -BOOST_AUTO_TEST_SUITE(SPFreshTest) +namespace SPFreshTestSuite +{ -BOOST_AUTO_TEST_CASE(TestLoadAndSave) +TEST(SPFreshTest, TestLoadAndSave) { using namespace SPFreshTest; @@ -389,27 +391,27 @@ BOOST_AUTO_TEST_CASE(TestLoadAndSave) generator.Run(vecset, metaset, queryset, truth, addvecset, addmetaset, addtruth); auto originalIndex = BuildIndex("original_index", vecset, metaset); - BOOST_REQUIRE(originalIndex != nullptr); - BOOST_REQUIRE(originalIndex->SaveIndex("original_index") == ErrorCode::Success); + ASSERT_NE(originalIndex, nullptr); + ASSERT_EQ(originalIndex->SaveIndex("original_index"), ErrorCode::Success); originalIndex = nullptr; std::shared_ptr loadedIndex; - BOOST_REQUIRE(VectorIndex::LoadIndex("original_index", loadedIndex) == ErrorCode::Success); - BOOST_REQUIRE(loadedIndex != nullptr); - BOOST_REQUIRE(loadedIndex->SaveIndex("loaded_and_saved_index") == ErrorCode::Success); + ASSERT_EQ(VectorIndex::LoadIndex("original_index", loadedIndex), ErrorCode::Success); + ASSERT_NE(loadedIndex, nullptr); + ASSERT_EQ(loadedIndex->SaveIndex("loaded_and_saved_index"), ErrorCode::Success); loadedIndex = nullptr; std::unordered_set exceptions = {"indexloader.ini"}; // Compare files in both directories - BOOST_REQUIRE_MESSAGE(CompareDirectoriesWithLogging("original_index", "loaded_and_saved_index", exceptions), - "Saved index does not match loaded-then-saved index"); + ASSERT_TRUE(CompareDirectoriesWithLogging("original_index", "loaded_and_saved_index", exceptions)) + << "Saved index does not match loaded-then-saved index"; std::filesystem::remove_all("original_index"); std::filesystem::remove_all("loaded_and_saved_index"); } -BOOST_AUTO_TEST_CASE(TestReopenIndexRecall) +TEST(SPFreshTest, TestReopenIndexRecall) { using namespace SPFreshTest; @@ -420,30 +422,30 @@ BOOST_AUTO_TEST_CASE(TestReopenIndexRecall) generator.Run(vecset, metaset, queryset, truth, addvecset, addmetaset, addtruth); auto originalIndex = BuildIndex("original_index", vecset, metaset); - BOOST_REQUIRE(originalIndex != nullptr); - BOOST_REQUIRE(originalIndex->SaveIndex("original_index") == ErrorCode::Success); + ASSERT_NE(originalIndex, nullptr); + ASSERT_EQ(originalIndex->SaveIndex("original_index"), ErrorCode::Success); float recall1 = Search(originalIndex, queryset, vecset, addvecset, K, truth, N); originalIndex = nullptr; std::shared_ptr loadedOnce; - BOOST_REQUIRE(VectorIndex::LoadIndex("original_index", loadedOnce) == ErrorCode::Success); - BOOST_REQUIRE(loadedOnce != nullptr); - BOOST_REQUIRE(loadedOnce->SaveIndex("reopened_index") == ErrorCode::Success); + ASSERT_EQ(VectorIndex::LoadIndex("original_index", loadedOnce), ErrorCode::Success); + ASSERT_NE(loadedOnce, nullptr); + ASSERT_EQ(loadedOnce->SaveIndex("reopened_index"), ErrorCode::Success); loadedOnce = nullptr; std::shared_ptr loadedTwice; - BOOST_REQUIRE(VectorIndex::LoadIndex("reopened_index", loadedTwice) == ErrorCode::Success); - BOOST_REQUIRE(loadedTwice != nullptr); + ASSERT_EQ(VectorIndex::LoadIndex("reopened_index", loadedTwice), ErrorCode::Success); + ASSERT_NE(loadedTwice, nullptr); float recall2 = Search(loadedTwice, queryset, vecset, addvecset, K, truth, N); loadedTwice = nullptr; - BOOST_REQUIRE_MESSAGE(std::fabs(recall1 - recall2) < 1e-5, "Recall mismatch between original and reopened index"); + ASSERT_LT(std::fabs(recall1 - recall2), 1e-5) << "Recall mismatch between original and reopened index"; std::filesystem::remove_all("original_index"); std::filesystem::remove_all("reopened_index"); } -BOOST_AUTO_TEST_CASE(TestInsertAndSearch) +TEST(SPFreshTest, TestInsertAndSearch) { using namespace SPFreshTest; @@ -456,13 +458,13 @@ BOOST_AUTO_TEST_CASE(TestInsertAndSearch) // Build base index auto index = BuildIndex("insert_test_index", vecset, metaset); - BOOST_REQUIRE(index != nullptr); - BOOST_REQUIRE(index->SaveIndex("insert_test_index") == ErrorCode::Success); + ASSERT_NE(index, nullptr); + ASSERT_EQ(index->SaveIndex("insert_test_index"), ErrorCode::Success); index = nullptr; std::shared_ptr loadedOnce; - BOOST_REQUIRE(VectorIndex::LoadIndex("insert_test_index", loadedOnce) == ErrorCode::Success); - BOOST_REQUIRE(loadedOnce != nullptr); + ASSERT_EQ(VectorIndex::LoadIndex("insert_test_index", loadedOnce), ErrorCode::Success); + ASSERT_NE(loadedOnce, nullptr); InsertVectors(static_cast *>(loadedOnce.get()), 2, 1000, addvecset, addmetaset); SearchOnly(loadedOnce, queryset, K); @@ -471,7 +473,7 @@ BOOST_AUTO_TEST_CASE(TestInsertAndSearch) std::filesystem::remove_all("insert_test_index"); } -BOOST_AUTO_TEST_CASE(TestClone) +TEST(SPFreshTest, TestClone) { using namespace SPFreshTest; @@ -483,26 +485,26 @@ BOOST_AUTO_TEST_CASE(TestClone) generator.Run(vecset, metaset, queryset, truth, addvecset, addmetaset, addtruth); auto originalIndex = BuildIndex("original_index", vecset, metaset); - BOOST_REQUIRE(originalIndex != nullptr); - BOOST_REQUIRE(originalIndex->SaveIndex("original_index") == ErrorCode::Success); + ASSERT_NE(originalIndex, nullptr); + ASSERT_EQ(originalIndex->SaveIndex("original_index"), ErrorCode::Success); + originalIndex = nullptr; auto clonedIndex = originalIndex->Clone("cloned_index"); - BOOST_REQUIRE(clonedIndex != nullptr); - BOOST_REQUIRE(clonedIndex->SaveIndex("cloned_index") == ErrorCode::Success); - originalIndex.reset(); + ASSERT_NE(clonedIndex, nullptr); + ASSERT_EQ(clonedIndex->SaveIndex("cloned_index"), ErrorCode::Success); clonedIndex = nullptr; std::unordered_set exceptions = {"indexloader.ini"}; // Compare files in both directories - BOOST_REQUIRE_MESSAGE(CompareDirectoriesWithLogging("original_index", "cloned_index", exceptions), - "Saved index does not match loaded-then-saved index"); + ASSERT_TRUE(CompareDirectoriesWithLogging("original_index", "cloned_index", exceptions)) + << "Saved index does not match loaded-then-saved index"; std::filesystem::remove_all("original_index"); std::filesystem::remove_all("cloned_index"); } -BOOST_AUTO_TEST_CASE(TestCloneRecall) +TEST(SPFreshTest, TestCloneRecall) { using namespace SPFreshTest; @@ -514,30 +516,30 @@ BOOST_AUTO_TEST_CASE(TestCloneRecall) generator.Run(vecset, metaset, queryset, truth, addvecset, addmetaset, addtruth); auto originalIndex = BuildIndex("original_index", vecset, metaset); - BOOST_REQUIRE(originalIndex != nullptr); - BOOST_REQUIRE(originalIndex->SaveIndex("original_index") == ErrorCode::Success); + ASSERT_NE(originalIndex, nullptr); + ASSERT_EQ(originalIndex->SaveIndex("original_index"), ErrorCode::Success); float originalRecall = Search(originalIndex, queryset, vecset, addvecset, K, truth, N); auto clonedIndex = originalIndex->Clone("cloned_index"); - BOOST_REQUIRE(clonedIndex != nullptr); + ASSERT_NE(clonedIndex, nullptr); originalIndex.reset(); clonedIndex = nullptr; std::shared_ptr loadedClonedIndex; - BOOST_REQUIRE(VectorIndex::LoadIndex("cloned_index", loadedClonedIndex) == ErrorCode::Success); - BOOST_REQUIRE(loadedClonedIndex != nullptr); + ASSERT_EQ(VectorIndex::LoadIndex("cloned_index", loadedClonedIndex), ErrorCode::Success); + ASSERT_NE(loadedClonedIndex, nullptr); float clonedRecall = Search(loadedClonedIndex, queryset, vecset, addvecset, K, truth, N); loadedClonedIndex = nullptr; - BOOST_REQUIRE_MESSAGE(std::fabs(originalRecall - clonedRecall) < 1e-5, - "Recall mismatch between original and cloned index: " - << "original=" << originalRecall << ", cloned=" << clonedRecall); + ASSERT_LT(std::fabs(originalRecall - clonedRecall), 1e-5) + << "Recall mismatch between original and cloned index: " + << "original=" << originalRecall << ", cloned=" << clonedRecall; std::filesystem::remove_all("original_index"); std::filesystem::remove_all("cloned_index"); } -BOOST_AUTO_TEST_CASE(IndexPersistenceAndInsertSanity) +TEST(SPFreshTest, IndexPersistenceAndInsertSanity) { using namespace SPFreshTest; @@ -550,41 +552,41 @@ BOOST_AUTO_TEST_CASE(IndexPersistenceAndInsertSanity) // Build and save base index auto baseIndex = BuildIndex("insert_test_index", vecset, metaset); - BOOST_REQUIRE(baseIndex != nullptr); - BOOST_REQUIRE(baseIndex->SaveIndex("insert_test_index") == ErrorCode::Success); + ASSERT_NE(baseIndex, nullptr); + ASSERT_EQ(baseIndex->SaveIndex("insert_test_index"), ErrorCode::Success); baseIndex = nullptr; // Load the saved index std::shared_ptr loadedOnce; - BOOST_REQUIRE(VectorIndex::LoadIndex("insert_test_index", loadedOnce) == ErrorCode::Success); - BOOST_REQUIRE(loadedOnce != nullptr); + ASSERT_EQ(VectorIndex::LoadIndex("insert_test_index", loadedOnce), ErrorCode::Success); + ASSERT_NE(loadedOnce, nullptr); // Search sanity check SearchOnly(loadedOnce, queryset, K); // Clone the loaded index auto clonedIndex = loadedOnce->Clone("insert_cloned_index"); - BOOST_REQUIRE(clonedIndex != nullptr); + ASSERT_NE(clonedIndex, nullptr); // Save and reload the cloned index - BOOST_REQUIRE(clonedIndex->SaveIndex("insert_cloned_index") == ErrorCode::Success); + ASSERT_EQ(clonedIndex->SaveIndex("insert_cloned_index"), ErrorCode::Success); loadedOnce.reset(); clonedIndex = nullptr; std::shared_ptr loadedClone; - BOOST_REQUIRE(VectorIndex::LoadIndex("insert_cloned_index", loadedClone) == ErrorCode::Success); - BOOST_REQUIRE(loadedClone != nullptr); + ASSERT_EQ(VectorIndex::LoadIndex("insert_cloned_index", loadedClone), ErrorCode::Success); + ASSERT_NE(loadedClone, nullptr); // Insert new vectors InsertVectors(static_cast *>(loadedClone.get()), 1, static_cast(addvecset->Count()), addvecset, addmetaset); // Final save and reload after insert - BOOST_REQUIRE(loadedClone->SaveIndex("insert_final_index") == ErrorCode::Success); + ASSERT_EQ(loadedClone->SaveIndex("insert_final_index"), ErrorCode::Success); loadedClone = nullptr; std::shared_ptr reloadedFinal; - BOOST_REQUIRE(VectorIndex::LoadIndex("insert_final_index", reloadedFinal) == ErrorCode::Success); + ASSERT_EQ(VectorIndex::LoadIndex("insert_final_index", reloadedFinal), ErrorCode::Success); // Final search sanity SearchOnly(reloadedFinal, queryset, K); @@ -596,7 +598,7 @@ BOOST_AUTO_TEST_CASE(IndexPersistenceAndInsertSanity) std::filesystem::remove_all("insert_final_index"); } -BOOST_AUTO_TEST_CASE(IndexPersistenceAndInsertMultipleThreads) +TEST(SPFreshTest, IndexPersistenceAndInsertMultipleThreads) { using namespace SPFreshTest; @@ -609,42 +611,42 @@ BOOST_AUTO_TEST_CASE(IndexPersistenceAndInsertMultipleThreads) // Build and save base index auto baseIndex = BuildIndex("insert_test_index_multi", vecset, metaset); - BOOST_REQUIRE(baseIndex != nullptr); - BOOST_REQUIRE(baseIndex->SaveIndex("insert_test_index_multi") == ErrorCode::Success); + ASSERT_NE(baseIndex, nullptr); + ASSERT_EQ(baseIndex->SaveIndex("insert_test_index_multi"), ErrorCode::Success); baseIndex = nullptr; // Load the saved index std::shared_ptr loadedOnce; - BOOST_REQUIRE(VectorIndex::LoadIndex("insert_test_index_multi", loadedOnce) == ErrorCode::Success); - BOOST_REQUIRE(loadedOnce != nullptr); + ASSERT_EQ(VectorIndex::LoadIndex("insert_test_index_multi", loadedOnce), ErrorCode::Success); + ASSERT_NE(loadedOnce, nullptr); // Search sanity check SearchOnly(loadedOnce, queryset, K); // Clone the loaded index auto clonedIndex = loadedOnce->Clone("insert_cloned_index_multi"); - BOOST_REQUIRE(clonedIndex != nullptr); + ASSERT_NE(clonedIndex, nullptr); // Save and reload the cloned index - BOOST_REQUIRE(clonedIndex->SaveIndex("insert_cloned_index_multi") == ErrorCode::Success); + ASSERT_EQ(clonedIndex->SaveIndex("insert_cloned_index_multi"), ErrorCode::Success); loadedOnce.reset(); clonedIndex = nullptr; std::shared_ptr loadedClone; - BOOST_REQUIRE(VectorIndex::LoadIndex("insert_cloned_index_multi", loadedClone) == ErrorCode::Success); - BOOST_REQUIRE(loadedClone != nullptr); + ASSERT_EQ(VectorIndex::LoadIndex("insert_cloned_index_multi", loadedClone), ErrorCode::Success); + ASSERT_NE(loadedClone, nullptr); // Insert new vectors InsertVectors(static_cast *>(loadedClone.get()), 2, static_cast(addvecset->Count()), addvecset, addmetaset); // Final save and reload after insert - BOOST_REQUIRE(loadedClone->SaveIndex("insert_final_index_multi") == ErrorCode::Success); + ASSERT_EQ(loadedClone->SaveIndex("insert_final_index_multi"), ErrorCode::Success); loadedClone = nullptr; std::shared_ptr reloadedFinal; - BOOST_REQUIRE(VectorIndex::LoadIndex("insert_final_index_multi", reloadedFinal) == ErrorCode::Success); - BOOST_REQUIRE(reloadedFinal != nullptr); + ASSERT_EQ(VectorIndex::LoadIndex("insert_final_index_multi", reloadedFinal), ErrorCode::Success); + ASSERT_NE(reloadedFinal, nullptr); // Final search sanity SearchOnly(reloadedFinal, queryset, K); reloadedFinal = nullptr; @@ -655,7 +657,7 @@ BOOST_AUTO_TEST_CASE(IndexPersistenceAndInsertMultipleThreads) std::filesystem::remove_all("insert_final_index_multi"); } -BOOST_AUTO_TEST_CASE(IndexSaveDuringQuery) +TEST(SPFreshTest, IndexSaveDuringQuery) { using namespace SPFreshTest; @@ -666,7 +668,7 @@ BOOST_AUTO_TEST_CASE(IndexSaveDuringQuery) generator.Run(vecset, metaset, queryset, truth, addvecset, addmetaset, addtruth); auto index = BuildIndex("save_during_query_index", vecset, metaset); - BOOST_REQUIRE(index != nullptr); + ASSERT_NE(index, nullptr); std::atomic keepQuerying(true); std::thread queryThread([&]() { @@ -683,7 +685,7 @@ BOOST_AUTO_TEST_CASE(IndexSaveDuringQuery) // Wait a bit before saving std::this_thread::sleep_for(std::chrono::milliseconds(100)); ErrorCode saveStatus = index->SaveIndex("save_during_query_index"); - BOOST_REQUIRE(saveStatus == ErrorCode::Success); + ASSERT_EQ(saveStatus, ErrorCode::Success); keepQuerying = false; queryThread.join(); @@ -691,8 +693,8 @@ BOOST_AUTO_TEST_CASE(IndexSaveDuringQuery) index = nullptr; std::shared_ptr reloaded; - BOOST_REQUIRE(VectorIndex::LoadIndex("save_during_query_index", reloaded) == ErrorCode::Success); - BOOST_REQUIRE(reloaded != nullptr); + ASSERT_EQ(VectorIndex::LoadIndex("save_during_query_index", reloaded), ErrorCode::Success); + ASSERT_NE(reloaded, nullptr); SearchOnly(reloaded, queryset, K); reloaded = nullptr; @@ -700,7 +702,7 @@ BOOST_AUTO_TEST_CASE(IndexSaveDuringQuery) std::filesystem::remove_all("save_during_query_index"); } -BOOST_AUTO_TEST_CASE(IndexMultiThreadedQuerySanity) +TEST(SPFreshTest, IndexMultiThreadedQuerySanity) { using namespace SPFreshTest; @@ -713,18 +715,18 @@ BOOST_AUTO_TEST_CASE(IndexMultiThreadedQuerySanity) // Build and save index auto index = BuildIndex("multi_query_index", vecset, metaset); - BOOST_REQUIRE(index != nullptr); - BOOST_REQUIRE(index->SaveIndex("multi_query_index") == ErrorCode::Success); + ASSERT_NE(index, nullptr); + ASSERT_EQ(index->SaveIndex("multi_query_index"), ErrorCode::Success); index = nullptr; // Reload the index std::shared_ptr loaded; - BOOST_REQUIRE(VectorIndex::LoadIndex("multi_query_index", loaded) == ErrorCode::Success); - BOOST_REQUIRE(loaded != nullptr); + ASSERT_EQ(VectorIndex::LoadIndex("multi_query_index", loaded), ErrorCode::Success); + ASSERT_NE(loaded, nullptr); // Insert additional vectors - InsertVectors(static_cast *>(loaded.get()), 2, - static_cast(addvecset->Count()), addvecset, addmetaset); + InsertVectors(static_cast *>(loaded.get()), 2, static_cast(addvecset->Count()), + addvecset, addmetaset); // Perform multithreaded query const int threadCount = 4; @@ -762,7 +764,7 @@ BOOST_AUTO_TEST_CASE(IndexMultiThreadedQuerySanity) std::filesystem::remove_all("multi_query_index"); } -BOOST_AUTO_TEST_CASE(IndexShadowCloneLifecycleKeepLast) +TEST(SPFreshTest, IndexShadowCloneLifecycleKeepLast) { using namespace SPFreshTest; @@ -776,7 +778,7 @@ BOOST_AUTO_TEST_CASE(IndexShadowCloneLifecycleKeepLast) generator.Run(vecset, metaset, queryset, truth, addvecset, addmetaset, addtruth); const std::string baseIndexName = "base_index"; - BOOST_REQUIRE(BuildIndex(baseIndexName, vecset, metaset)->SaveIndex(baseIndexName) == ErrorCode::Success); + ASSERT_EQ(BuildIndex(baseIndexName, vecset, metaset)->SaveIndex(baseIndexName), ErrorCode::Success); std::string previousIndexName = baseIndexName; @@ -787,8 +789,8 @@ BOOST_AUTO_TEST_CASE(IndexShadowCloneLifecycleKeepLast) // Load previous index std::shared_ptr loaded; - BOOST_REQUIRE(VectorIndex::LoadIndex(previousIndexName, loaded) == ErrorCode::Success); - BOOST_REQUIRE(loaded != nullptr); + ASSERT_EQ(VectorIndex::LoadIndex(previousIndexName, loaded), ErrorCode::Success); + ASSERT_NE(loaded, nullptr); // Query check for (int i = 0; i < std::min(queryset->Count(), 5); ++i) @@ -804,12 +806,12 @@ BOOST_AUTO_TEST_CASE(IndexShadowCloneLifecycleKeepLast) } // Clone to shadow - BOOST_REQUIRE(loaded->Clone(shadowIndexName) != nullptr); + ASSERT_NE(loaded->Clone(shadowIndexName), nullptr); loaded.reset(); std::shared_ptr shadowLoaded; - BOOST_REQUIRE(VectorIndex::LoadIndex(shadowIndexName, shadowLoaded) == ErrorCode::Success); - BOOST_REQUIRE(shadowLoaded != nullptr); + ASSERT_EQ(VectorIndex::LoadIndex(shadowIndexName, shadowLoaded), ErrorCode::Success); + ASSERT_NE(shadowLoaded, nullptr); auto *shadowIndex = static_cast *>(shadowLoaded.get()); // Prepare insert batch @@ -845,7 +847,7 @@ BOOST_AUTO_TEST_CASE(IndexShadowCloneLifecycleKeepLast) std::this_thread::sleep_for(std::chrono::milliseconds(20)); } - BOOST_REQUIRE(shadowLoaded->SaveIndex(shadowIndexName) == ErrorCode::Success); + ASSERT_EQ(shadowLoaded->SaveIndex(shadowIndexName), ErrorCode::Success); SPTAGLIB_LOG(Helper::LogLevel::LL_Info, "[%d] Created new shadow index: %s\n", iter, shadowIndexName.c_str()); shadowLoaded = nullptr; @@ -864,7 +866,7 @@ BOOST_AUTO_TEST_CASE(IndexShadowCloneLifecycleKeepLast) } } -BOOST_AUTO_TEST_CASE(IterativeSearch) +TEST(SPFreshTest, IterativeSearch) { using namespace SPFreshTest; @@ -872,12 +874,11 @@ BOOST_AUTO_TEST_CASE(IterativeSearch) constexpr int insertBatchSize = 1000; constexpr int dimension = 1024; std::shared_ptr vecset = get_embeddings(0, insertBatchSize, dimension, -1); - std::shared_ptr metaset = - TestUtils::TestDataGenerator::GenerateMetadataSet(insertBatchSize, 0); + std::shared_ptr metaset = TestUtils::TestDataGenerator::GenerateMetadataSet(insertBatchSize, 0); auto originalIndex = BuildIndex("original_index", vecset, metaset); - BOOST_REQUIRE(originalIndex != nullptr); - BOOST_REQUIRE(originalIndex->SaveIndex("original_index") == ErrorCode::Success); + ASSERT_NE(originalIndex, nullptr); + ASSERT_EQ(originalIndex->SaveIndex("original_index"), ErrorCode::Success); originalIndex = nullptr; std::string prevPath = "original_index"; @@ -885,8 +886,8 @@ BOOST_AUTO_TEST_CASE(IterativeSearch) { std::string clone_path = "clone_index_" + std::to_string(iter); std::shared_ptr prevIndex; - BOOST_REQUIRE(VectorIndex::LoadIndex(prevPath, prevIndex) == ErrorCode::Success); - BOOST_REQUIRE(prevIndex != nullptr); + ASSERT_EQ(VectorIndex::LoadIndex(prevPath, prevIndex), ErrorCode::Success); + ASSERT_NE(prevIndex, nullptr); auto cloneIndex = prevIndex->Clone(clone_path); auto *cloneIndexPtr = static_cast *>(cloneIndex.get()); @@ -896,12 +897,12 @@ BOOST_AUTO_TEST_CASE(IterativeSearch) TestUtils::TestDataGenerator::GenerateMetadataSet(insertBatchSize, (iter + 1) * insertBatchSize); InsertVectors(cloneIndexPtr, 1, insertBatchSize, tmpvecs, tmpmetas); - BOOST_REQUIRE(cloneIndex->SaveIndex(clone_path) == ErrorCode::Success); + ASSERT_EQ(cloneIndex->SaveIndex(clone_path), ErrorCode::Success); cloneIndex = nullptr; std::shared_ptr loadedIndex; - BOOST_REQUIRE(VectorIndex::LoadIndex(clone_path, loadedIndex) == ErrorCode::Success); - BOOST_REQUIRE(loadedIndex != nullptr); + ASSERT_EQ(VectorIndex::LoadIndex(clone_path, loadedIndex), ErrorCode::Success); + ASSERT_NE(loadedIndex, nullptr); std::shared_ptr embedding = get_embeddings((1000 * iter) + 500, ((1000 * iter) + 501), dimension, -1); @@ -916,7 +917,7 @@ BOOST_AUTO_TEST_CASE(IterativeSearch) int resultCount = results->GetResultNum(); if (resultCount <= 0) break; - BOOST_CHECK(resultCount == batch); + EXPECT_EQ(resultCount, batch); previous = current; current = 0; for (int j = 0; j < resultCount; j++) @@ -942,7 +943,7 @@ BOOST_AUTO_TEST_CASE(IterativeSearch) std::filesystem::remove_all("original_index"); } -BOOST_AUTO_TEST_CASE(RefineIndex) +TEST(SPFreshTest, RefineIndex) { using namespace SPFreshTest; @@ -960,8 +961,8 @@ BOOST_AUTO_TEST_CASE(RefineIndex) // Build and save index auto originalIndex = BuildIndex("original_index", vecset, metaset); - BOOST_REQUIRE(originalIndex != nullptr); - BOOST_REQUIRE(originalIndex->SaveIndex("original_index") == ErrorCode::Success); + ASSERT_NE(originalIndex, nullptr); + ASSERT_EQ(originalIndex->SaveIndex("original_index"), ErrorCode::Success); float recall = Search(originalIndex, queryset, vecset, addvecset, K, truth, N); std::cout << "original: recall@5=" << recall << std::endl; @@ -979,19 +980,19 @@ BOOST_AUTO_TEST_CASE(RefineIndex) } std::cout << "Before Refine:" << " recall@5=" << recall << std::endl; static_cast *>(originalIndex.get())->GetDBStat(); - BOOST_REQUIRE(originalIndex->SaveIndex("original_index") == ErrorCode::Success); + ASSERT_EQ(originalIndex->SaveIndex("original_index"), ErrorCode::Success); originalIndex = nullptr; - BOOST_REQUIRE(VectorIndex::LoadIndex("original_index", originalIndex) == ErrorCode::Success); - BOOST_REQUIRE(originalIndex != nullptr); - BOOST_REQUIRE(originalIndex->Check() == ErrorCode::Success); + ASSERT_EQ(VectorIndex::LoadIndex("original_index", originalIndex), ErrorCode::Success); + ASSERT_NE(originalIndex, nullptr); + ASSERT_EQ(originalIndex->Check(), ErrorCode::Success); recall = Search(originalIndex, queryset, vecset, addvecset, K, truth, N, iterations); std::cout << "After Refine:" << " recall@5=" << recall << std::endl; static_cast *>(originalIndex.get())->GetDBStat(); } -BOOST_AUTO_TEST_CASE(IterativeSearchPerf) +TEST(SPFreshTest, IterativeSearchPerf) { using namespace SPFreshTest; @@ -1003,8 +1004,8 @@ BOOST_AUTO_TEST_CASE(IterativeSearchPerf) std::shared_ptr metaset = TestUtils::TestDataGenerator::GenerateMetadataSet(insertBatchSize, 0); auto originalIndex = BuildIndex("original_index", vecset, metaset); - BOOST_REQUIRE(originalIndex != nullptr); - BOOST_REQUIRE(originalIndex->SaveIndex("original_index") == ErrorCode::Success); + ASSERT_NE(originalIndex, nullptr); + ASSERT_EQ(originalIndex->SaveIndex("original_index"), ErrorCode::Success); originalIndex = nullptr; std::string prevPath = "original_index"; @@ -1012,12 +1013,14 @@ BOOST_AUTO_TEST_CASE(IterativeSearchPerf) { std::string clone_path = "clone_index_" + std::to_string(iter); std::shared_ptr prevIndex; - BOOST_REQUIRE(VectorIndex::LoadIndex(prevPath, prevIndex) == ErrorCode::Success); - BOOST_REQUIRE(prevIndex != nullptr); + ASSERT_EQ(VectorIndex::LoadIndex(prevPath, prevIndex), ErrorCode::Success); + ASSERT_NE(prevIndex, nullptr); auto t0 = std::chrono::high_resolution_clock::now(); - BOOST_REQUIRE(prevIndex->Check() == ErrorCode::Success); + ASSERT_EQ(prevIndex->Check(), ErrorCode::Success); std::cout << "Check time for iteration " << iter << ": " - << std::chrono::duration_cast(std::chrono::high_resolution_clock::now() - t0).count() + << std::chrono::duration_cast(std::chrono::high_resolution_clock::now() - + t0) + .count() << " ms" << std::endl; auto cloneIndex = prevIndex->Clone(clone_path); @@ -1034,7 +1037,7 @@ BOOST_AUTO_TEST_CASE(IterativeSearchPerf) .count() << " ms" << std::endl; - BOOST_REQUIRE(cloneIndex->SaveIndex(clone_path) == ErrorCode::Success); + ASSERT_EQ(cloneIndex->SaveIndex(clone_path), ErrorCode::Success); cloneIndex = nullptr; } @@ -1085,7 +1088,7 @@ std::shared_ptr get_embeddings_float32(int start_id, int end_id, int return std::make_shared(vec, GetEnumValueType(), embedding_dim, 2 * (end_id - start_id)); } -BOOST_AUTO_TEST_CASE(RefineTestIdx) +TEST(SPFreshTest, RefineTestIdx) { using namespace SPFreshTest; @@ -1094,17 +1097,19 @@ BOOST_AUTO_TEST_CASE(RefineTestIdx) std::shared_ptr vecset = get_embeddings_float32(0, 500, dimension); std::shared_ptr metaset = TestUtils::TestDataGenerator::GenerateMetadataSet(1000, 0); - for (auto i = 0; i < 2; ++i) { - void* p = vecset->GetVector(i); - for (auto i = 0; i < dimension; ++i) { - std::cout << ((float*)p)[i] << " "; + for (auto i = 0; i < 2; ++i) + { + void *p = vecset->GetVector(i); + for (auto i = 0; i < dimension; ++i) + { + std::cout << ((float *)p)[i] << " "; } std::cout << std::endl; } auto originalIndex = BuildIndex("original_index", vecset, metaset, "COSINE"); - BOOST_REQUIRE(originalIndex != nullptr); - BOOST_REQUIRE(originalIndex->SaveIndex("original_index") == ErrorCode::Success); + ASSERT_NE(originalIndex, nullptr); + ASSERT_EQ(originalIndex->SaveIndex("original_index"), ErrorCode::Success); originalIndex = nullptr; std::string prevPath = "original_index"; @@ -1112,10 +1117,10 @@ BOOST_AUTO_TEST_CASE(RefineTestIdx) { std::string clone_path = "clone_index_" + std::to_string(iter); std::shared_ptr prevIndex; - BOOST_REQUIRE(VectorIndex::LoadIndex(prevPath, prevIndex) == ErrorCode::Success); - BOOST_REQUIRE(prevIndex != nullptr); + ASSERT_EQ(VectorIndex::LoadIndex(prevPath, prevIndex), ErrorCode::Success); + ASSERT_NE(prevIndex, nullptr); auto t0 = std::chrono::high_resolution_clock::now(); - BOOST_REQUIRE(prevIndex->Check() == ErrorCode::Success); + ASSERT_EQ(prevIndex->Check(), ErrorCode::Success); std::cout << "Check time for iteration " << iter << ": " << std::chrono::duration_cast(std::chrono::high_resolution_clock::now() - t0) @@ -1139,7 +1144,7 @@ BOOST_AUTO_TEST_CASE(RefineTestIdx) cloneIndexPtr->DeleteIndex(i); } - BOOST_REQUIRE(cloneIndex->SaveIndex(clone_path) == ErrorCode::Success); + ASSERT_EQ(cloneIndex->SaveIndex(clone_path), ErrorCode::Success); cloneIndex = nullptr; } @@ -1148,5 +1153,5 @@ BOOST_AUTO_TEST_CASE(RefineTestIdx) std::filesystem::remove_all("clone_index_" + std::to_string(iter)); } // std::filesystem::remove_all("original_index"); -} -BOOST_AUTO_TEST_SUITE_END() +} +} // namespace SPFreshTestSuite \ No newline at end of file diff --git a/Test/src/SSDServingTest.cpp b/Test/src/SSDServingTest.cpp index edebfd40..758b674d 100644 --- a/Test/src/SSDServingTest.cpp +++ b/Test/src/SSDServingTest.cpp @@ -31,7 +31,7 @@ void GenerateVectors(std::string fileName, SPTAG::SizeType rows, SPTAG::Dimensio if (!of.is_open()) { fprintf(stderr, "%s can't be opened.\n", fileName.c_str()); - BOOST_CHECK(false); + GTEST_FAIL() << fileName << " can't be opened."; return; } @@ -138,7 +138,7 @@ void TestHead(std::string configName, std::string OutputIDFile, std::string Outp if (!config.is_open()) { fprintf(stderr, "%s can't be opened.\n", configName.c_str()); - BOOST_CHECK(false); + GTEST_FAIL() << configName << " can't be opened."; return; } @@ -188,7 +188,7 @@ void TestBuildHead(std::string configName, std::string p_headVectorFile, std::st if (!config.is_open()) { fprintf(stderr, "%s can't be opened.\n", configName.c_str()); - BOOST_CHECK(false); + GTEST_FAIL() << configName << " can't be opened."; return; } @@ -196,7 +196,7 @@ void TestBuildHead(std::string configName, std::string p_headVectorFile, std::st if (p_builderFile.empty()) { fprintf(stderr, "no builder file for head index build.\n"); - BOOST_CHECK(false); + GTEST_FAIL() << p_builderFile << " can't be opened."; return; } @@ -210,7 +210,7 @@ void TestBuildHead(std::string configName, std::string p_headVectorFile, std::st if (!bf.is_open()) { fprintf(stderr, "%s can't be opened.\n", p_builderFile.c_str()); - BOOST_CHECK(false); + GTEST_FAIL() << p_builderFile << " can't be opened."; return; } bf.close(); @@ -237,7 +237,7 @@ void TestBuildSSDIndex(std::string configName, std::string p_vectorIDTranslate, if (!config.is_open()) { fprintf(stderr, "%s can't be opened.\n", configName.c_str()); - BOOST_CHECK(false); + GTEST_FAIL() << configName << " can't be opened."; return; } @@ -253,7 +253,7 @@ void TestBuildSSDIndex(std::string configName, std::string p_vectorIDTranslate, if (!bf.is_open()) { fprintf(stderr, "%s can't be opened.\n", p_headConfig.c_str()); - BOOST_CHECK(false); + GTEST_FAIL() << p_headConfig << " can't be opened."; return; } bf << "[Index]" << std::endl; @@ -296,7 +296,7 @@ void TestSearchSSDIndex(std::string configName, std::string p_vectorIDTranslate, if (!config.is_open()) { fprintf(stderr, "%s can't be opened.\n", configName.c_str()); - BOOST_CHECK(false); + GTEST_FAIL() << configName << " can't be opened."; return; } @@ -312,7 +312,7 @@ void TestSearchSSDIndex(std::string configName, std::string p_vectorIDTranslate, if (!bf.is_open()) { fprintf(stderr, "%s can't be opened.\n", p_headConfig.c_str()); - BOOST_CHECK(false); + GTEST_FAIL() << p_headConfig << " can't be opened."; return; } bf << "[Index]" << std::endl; @@ -395,7 +395,8 @@ void RunFromMap() TestSearchSSDIndex("run_from_map_search_config.ini", "", "", "", "", "", "", config.str()); } -BOOST_AUTO_TEST_SUITE(SSDServingTest) +namespace SSDServingTestSuite +{ // #define RAW_VECTOR_NUM 1000 #define VECTOR_NUM 1000 @@ -404,7 +405,7 @@ BOOST_AUTO_TEST_SUITE(SSDServingTest) #define FLOAT #define INT8 -//#define UINT8 +// #define UINT8 #define INT16 #define TDEFAULT #define TXVEC @@ -433,7 +434,7 @@ BOOST_AUTO_TEST_SUITE(SSDServingTest) SSDTEST_DIRECTORY "test_search_ssd_" #VT "_" #DM "_" #ALGO "_" #FT "_" #TFT ".result" #define GVQ(VT, FT) \ - BOOST_AUTO_TEST_CASE(GenerateVectorsQueries##VT##FT) \ + TEST(SSDServingTest, GenerateVectorsQueries##VT##FT) \ { \ boost::filesystem::create_directory(SSDTEST_DIRECTORY_NAME); \ GenVec(VECTORS(VT, FT), SPTAG::VectorValueType::VT, SPTAG::VectorFileType::FT, VECTOR_NUM, VECTOR_DIM); \ @@ -452,7 +453,7 @@ GVQ(Int8, XVEC) #undef GVQ #define WTEV(VT, DM, FT) \ - BOOST_AUTO_TEST_CASE(TestHead##VT##DM##FT) \ + TEST(SSDServingTest, TestHead##VT##DM##FT) \ { \ std::string configName = SELECT_HEAD_CONFIG(VT, DM, FT); \ std::string OutputIDFile = HEAD_IDS(VT, DM, FT); \ @@ -516,7 +517,7 @@ WTEV(Int8, Cosine, XVEC) #undef WTEV #define BDHD(VT, DM, ALGO, FT) \ - BOOST_AUTO_TEST_CASE(TestBuildHead##VT##DM##ALGO##FT) \ + TEST(SSDServingTest, TestBuildHead##VT##DM##ALGO##FT) \ { \ std::string configName = BUILD_HEAD_CONFIG(VT, DM, ALGO); \ std::string builderFile = BUILD_HEAD_BUILDER_CONFIG(VT, DM, ALGO); \ @@ -596,7 +597,7 @@ BDHD(Int16, Cosine, KDT, XVEC) #undef BDHD #define BDSSD(VT, DM, ALGO, FT) \ - BOOST_AUTO_TEST_CASE(TestBuildSSDIndex##VT##DM##ALGO##FT) \ + TEST(SSDServingTest, TestBuildSSDIndex##VT##DM##ALGO##FT) \ { \ std::string configName = BUILD_SSD_CONFIG(VT, DM, ALGO); \ std::string base_config = CreateBaseConfig( \ @@ -675,7 +676,7 @@ BDSSD(Int16, Cosine, KDT, XVEC) #undef BDSSD #define SCSSD(VT, DM, ALGO, FT, TFT) \ - BOOST_AUTO_TEST_CASE(TestSearchSSDIndex##VT##DM##ALGO##FT##TFT) \ + TEST(SSDServingTest, TestSearchSSDIndex##VT##DM##ALGO##FT##TFT) \ { \ std::string configName = SEARCH_SSD_CONFIG(VT, DM, ALGO); \ std::string base_config = \ @@ -757,14 +758,14 @@ SCSSD(Int16, Cosine, KDT, XVEC, XVEC) #undef FLOAT #undef INT8 -//#undef UINT8 +// #undef UINT8 #undef INT16 #undef TDEFAULT #undef TXVEC -BOOST_AUTO_TEST_CASE(RUN_FROM_MAP) +TEST(SSDServingTest, RUN_FROM_MAP) { RunFromMap(); } -BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file +} // namespace SSDServingTestSuite \ No newline at end of file diff --git a/Test/src/StringConvertTest.cpp b/Test/src/StringConvertTest.cpp index 568eee00..21e127db 100644 --- a/Test/src/StringConvertTest.cpp +++ b/Test/src/StringConvertTest.cpp @@ -16,20 +16,21 @@ template void TestConvertSuccCase(ValueType p_val, const ch std::string str = ConvertToString(p_val); if (nullptr != p_valStr) { - BOOST_CHECK(str == p_valStr); + EXPECT_EQ(str, p_valStr); } ValueType val; - BOOST_CHECK(ConvertStringTo(str.c_str(), val)); - BOOST_CHECK(val == p_val); + ASSERT_TRUE(ConvertStringTo(str.c_str(), val)); + EXPECT_EQ(val, p_val); } } // namespace Local } // namespace -BOOST_AUTO_TEST_SUITE(StringConvertTest) +namespace StringConvertTest +{ -BOOST_AUTO_TEST_CASE(ConvertInt8) +TEST(StringConvertTest, ConvertInt8) { Local::TestConvertSuccCase(static_cast(-1), "-1"); Local::TestConvertSuccCase(static_cast(0), "0"); @@ -37,7 +38,7 @@ BOOST_AUTO_TEST_CASE(ConvertInt8) Local::TestConvertSuccCase(static_cast(100), "100"); } -BOOST_AUTO_TEST_CASE(ConvertInt16) +TEST(StringConvertTest, ConvertInt16) { Local::TestConvertSuccCase(static_cast(-1), "-1"); Local::TestConvertSuccCase(static_cast(0), "0"); @@ -45,7 +46,7 @@ BOOST_AUTO_TEST_CASE(ConvertInt16) Local::TestConvertSuccCase(static_cast(100), "100"); } -BOOST_AUTO_TEST_CASE(ConvertInt32) +TEST(StringConvertTest, ConvertInt32) { Local::TestConvertSuccCase(static_cast(-1), "-1"); Local::TestConvertSuccCase(static_cast(0), "0"); @@ -53,7 +54,7 @@ BOOST_AUTO_TEST_CASE(ConvertInt32) Local::TestConvertSuccCase(static_cast(100), "100"); } -BOOST_AUTO_TEST_CASE(ConvertInt64) +TEST(StringConvertTest, ConvertInt64) { Local::TestConvertSuccCase(static_cast(-1), "-1"); Local::TestConvertSuccCase(static_cast(0), "0"); @@ -61,35 +62,35 @@ BOOST_AUTO_TEST_CASE(ConvertInt64) Local::TestConvertSuccCase(static_cast(100), "100"); } -BOOST_AUTO_TEST_CASE(ConvertUInt8) +TEST(StringConvertTest, ConvertUInt8) { Local::TestConvertSuccCase(static_cast(0), "0"); Local::TestConvertSuccCase(static_cast(3), "3"); Local::TestConvertSuccCase(static_cast(100), "100"); } -BOOST_AUTO_TEST_CASE(ConvertUInt16) +TEST(StringConvertTest, ConvertUInt16) { Local::TestConvertSuccCase(static_cast(0), "0"); Local::TestConvertSuccCase(static_cast(3), "3"); Local::TestConvertSuccCase(static_cast(100), "100"); } -BOOST_AUTO_TEST_CASE(ConvertUInt32) +TEST(StringConvertTest, ConvertUInt32) { Local::TestConvertSuccCase(static_cast(0), "0"); Local::TestConvertSuccCase(static_cast(3), "3"); Local::TestConvertSuccCase(static_cast(100), "100"); } -BOOST_AUTO_TEST_CASE(ConvertUInt64) +TEST(StringConvertTest, ConvertUInt64) { Local::TestConvertSuccCase(static_cast(0), "0"); Local::TestConvertSuccCase(static_cast(3), "3"); Local::TestConvertSuccCase(static_cast(100), "100"); } -BOOST_AUTO_TEST_CASE(ConvertFloat) +TEST(StringConvertTest, ConvertFloat) { Local::TestConvertSuccCase(static_cast(-1), nullptr); Local::TestConvertSuccCase(static_cast(0), nullptr); @@ -97,7 +98,7 @@ BOOST_AUTO_TEST_CASE(ConvertFloat) Local::TestConvertSuccCase(static_cast(100), nullptr); } -BOOST_AUTO_TEST_CASE(ConvertDouble) +TEST(StringConvertTest, ConvertDouble) { Local::TestConvertSuccCase(static_cast(-1), nullptr); Local::TestConvertSuccCase(static_cast(0), nullptr); @@ -105,23 +106,23 @@ BOOST_AUTO_TEST_CASE(ConvertDouble) Local::TestConvertSuccCase(static_cast(100), nullptr); } -BOOST_AUTO_TEST_CASE(ConvertIndexAlgoType) +TEST(StringConvertTest, ConvertIndexAlgoType) { Local::TestConvertSuccCase(SPTAG::IndexAlgoType::BKT, "BKT"); Local::TestConvertSuccCase(SPTAG::IndexAlgoType::KDT, "KDT"); } -BOOST_AUTO_TEST_CASE(ConvertVectorValueType) +TEST(StringConvertTest, ConvertVectorValueType) { Local::TestConvertSuccCase(SPTAG::VectorValueType::Float, "Float"); Local::TestConvertSuccCase(SPTAG::VectorValueType::Int8, "Int8"); Local::TestConvertSuccCase(SPTAG::VectorValueType::Int16, "Int16"); } -BOOST_AUTO_TEST_CASE(ConvertDistCalcMethod) +TEST(StringConvertTest, ConvertDistCalcMethod) { Local::TestConvertSuccCase(SPTAG::DistCalcMethod::Cosine, "Cosine"); Local::TestConvertSuccCase(SPTAG::DistCalcMethod::L2, "L2"); } -BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file +} // namespace StringConvertTest \ No newline at end of file diff --git a/Test/src/main.cpp b/Test/src/main.cpp index f13500af..aaf4ebf2 100644 --- a/Test/src/main.cpp +++ b/Test/src/main.cpp @@ -1,39 +1,11 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -#define BOOST_TEST_MAIN -#define BOOST_TEST_MODULE Main +// GoogleTest main #include "inc/Test.h" -#include -#include +int main(int argc, char** argv) { + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} -using namespace boost::unit_test; - -class SPTAGVisitor : public test_tree_visitor -{ - public: - void visit(test_case const &test) - { - std::string prefix(2, '\t'); - std::cout << prefix << "Case: " << test.p_name << std::endl; - } - - bool test_suite_start(test_suite const &suite) - { - std::string prefix(1, '\t'); - std::cout << prefix << "Suite: " << suite.p_name << std::endl; - return true; - } -}; - -struct GlobalFixture -{ - GlobalFixture() - { - SPTAGVisitor visitor; - traverse_test_tree(framework::master_test_suite(), visitor, false); - } -}; - -BOOST_TEST_GLOBAL_FIXTURE(GlobalFixture);