CMakeLists.txt 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. # Tests for smartbotic-database
  2. # Vector storage integration test
  3. # Compiles memory_store.cpp directly — no dependency on the full service executable.
  4. set(TEST_VECTOR_SOURCES
  5. test_vector_storage.cpp
  6. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/memory_store.cpp
  7. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/config/collection_config_manager.cpp
  8. )
  9. add_executable(test_vector_storage ${TEST_VECTOR_SOURCES})
  10. target_include_directories(test_vector_storage PRIVATE
  11. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src
  12. )
  13. # nlohmann/json
  14. if(TARGET nlohmann_json::nlohmann_json)
  15. target_link_libraries(test_vector_storage PRIVATE nlohmann_json::nlohmann_json)
  16. else()
  17. target_include_directories(test_vector_storage PRIVATE ${NLOHMANN_JSON_INCLUDE_DIRS})
  18. endif()
  19. # spdlog
  20. if(TARGET spdlog::spdlog)
  21. target_link_libraries(test_vector_storage PRIVATE spdlog::spdlog)
  22. else()
  23. target_link_libraries(test_vector_storage PRIVATE ${SPDLOG_LIBRARIES})
  24. target_include_directories(test_vector_storage PRIVATE ${SPDLOG_INCLUDE_DIRS})
  25. endif()
  26. # Threads (required by MemoryStore background threads)
  27. find_package(Threads REQUIRED)
  28. target_link_libraries(test_vector_storage PRIVATE Threads::Threads)
  29. # View projection unit test
  30. set(TEST_VIEWS_SOURCES
  31. test_views.cpp
  32. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/views/projection.cpp
  33. )
  34. add_executable(test_views ${TEST_VIEWS_SOURCES})
  35. target_include_directories(test_views PRIVATE
  36. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src
  37. )
  38. # nlohmann/json
  39. if(TARGET nlohmann_json::nlohmann_json)
  40. target_link_libraries(test_views PRIVATE nlohmann_json::nlohmann_json)
  41. else()
  42. target_include_directories(test_views PRIVATE ${NLOHMANN_JSON_INCLUDE_DIRS})
  43. endif()
  44. # Per-collection timestamp precision test
  45. set(TEST_TIMESTAMP_PRECISION_SOURCES
  46. test_timestamp_precision.cpp
  47. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/memory_store.cpp
  48. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/config/collection_config_manager.cpp
  49. )
  50. add_executable(test_timestamp_precision ${TEST_TIMESTAMP_PRECISION_SOURCES})
  51. target_include_directories(test_timestamp_precision PRIVATE
  52. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src
  53. )
  54. if(TARGET nlohmann_json::nlohmann_json)
  55. target_link_libraries(test_timestamp_precision PRIVATE nlohmann_json::nlohmann_json)
  56. else()
  57. target_include_directories(test_timestamp_precision PRIVATE ${NLOHMANN_JSON_INCLUDE_DIRS})
  58. endif()
  59. if(TARGET spdlog::spdlog)
  60. target_link_libraries(test_timestamp_precision PRIVATE spdlog::spdlog)
  61. else()
  62. target_link_libraries(test_timestamp_precision PRIVATE ${SPDLOG_LIBRARIES})
  63. target_include_directories(test_timestamp_precision PRIVATE ${SPDLOG_INCLUDE_DIRS})
  64. endif()
  65. find_package(Threads REQUIRED)
  66. target_link_libraries(test_timestamp_precision PRIVATE Threads::Threads)
  67. # Snapshot durability + fallback integration test
  68. # Exercises SnapshotManager directly; pulls in memory_store.cpp, snapshot.cpp,
  69. # and wal.cpp (for the crc32 helpers used by snapshot.cpp).
  70. set(TEST_SNAPSHOT_DURABILITY_SOURCES
  71. test_snapshot_durability.cpp
  72. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/memory_store.cpp
  73. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/config/collection_config_manager.cpp
  74. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/persistence/snapshot.cpp
  75. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/persistence/wal.cpp
  76. )
  77. add_executable(test_snapshot_durability ${TEST_SNAPSHOT_DURABILITY_SOURCES})
  78. target_include_directories(test_snapshot_durability PRIVATE
  79. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src
  80. )
  81. if(TARGET nlohmann_json::nlohmann_json)
  82. target_link_libraries(test_snapshot_durability PRIVATE nlohmann_json::nlohmann_json)
  83. else()
  84. target_include_directories(test_snapshot_durability PRIVATE ${NLOHMANN_JSON_INCLUDE_DIRS})
  85. endif()
  86. if(TARGET spdlog::spdlog)
  87. target_link_libraries(test_snapshot_durability PRIVATE spdlog::spdlog)
  88. else()
  89. target_link_libraries(test_snapshot_durability PRIVATE ${SPDLOG_LIBRARIES})
  90. target_include_directories(test_snapshot_durability PRIVATE ${SPDLOG_INCLUDE_DIRS})
  91. endif()
  92. find_package(Threads REQUIRED)
  93. target_link_libraries(test_snapshot_durability PRIVATE Threads::Threads)
  94. # LZ4 — snapshot.cpp #includes <lz4.h> unless DISABLE_LZ4 is defined, so link it.
  95. find_package(PkgConfig QUIET)
  96. if(PKG_CONFIG_FOUND)
  97. pkg_check_modules(TEST_LZ4 QUIET liblz4)
  98. endif()
  99. if(TEST_LZ4_FOUND)
  100. target_link_libraries(test_snapshot_durability PRIVATE ${TEST_LZ4_LIBRARIES})
  101. target_include_directories(test_snapshot_durability PRIVATE ${TEST_LZ4_INCLUDE_DIRS})
  102. else()
  103. # Fallback: assume liblz4 is installed at a standard location
  104. target_link_libraries(test_snapshot_durability PRIVATE lz4)
  105. endif()
  106. # Register with CTest
  107. enable_testing()
  108. add_test(NAME vector_storage COMMAND test_vector_storage)
  109. add_test(NAME views COMMAND test_views)
  110. add_test(NAME timestamp_precision COMMAND test_timestamp_precision)
  111. add_test(NAME snapshot_durability COMMAND test_snapshot_durability)