CMakeLists.txt 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/persistence/history_store.cpp
  9. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/persistence/wal.cpp
  10. )
  11. add_executable(test_vector_storage ${TEST_VECTOR_SOURCES})
  12. target_include_directories(test_vector_storage PRIVATE
  13. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src
  14. )
  15. # nlohmann/json
  16. if(TARGET nlohmann_json::nlohmann_json)
  17. target_link_libraries(test_vector_storage PRIVATE nlohmann_json::nlohmann_json)
  18. else()
  19. target_include_directories(test_vector_storage PRIVATE ${NLOHMANN_JSON_INCLUDE_DIRS})
  20. endif()
  21. # spdlog
  22. if(TARGET spdlog::spdlog)
  23. target_link_libraries(test_vector_storage PRIVATE spdlog::spdlog)
  24. else()
  25. target_link_libraries(test_vector_storage PRIVATE ${SPDLOG_LIBRARIES})
  26. target_include_directories(test_vector_storage PRIVATE ${SPDLOG_INCLUDE_DIRS})
  27. endif()
  28. # Threads (required by MemoryStore background threads)
  29. find_package(Threads REQUIRED)
  30. target_link_libraries(test_vector_storage PRIVATE Threads::Threads)
  31. # View projection unit test
  32. set(TEST_VIEWS_SOURCES
  33. test_views.cpp
  34. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/views/projection.cpp
  35. )
  36. add_executable(test_views ${TEST_VIEWS_SOURCES})
  37. target_include_directories(test_views PRIVATE
  38. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src
  39. )
  40. # nlohmann/json
  41. if(TARGET nlohmann_json::nlohmann_json)
  42. target_link_libraries(test_views PRIVATE nlohmann_json::nlohmann_json)
  43. else()
  44. target_include_directories(test_views PRIVATE ${NLOHMANN_JSON_INCLUDE_DIRS})
  45. endif()
  46. # Per-collection timestamp precision test
  47. set(TEST_TIMESTAMP_PRECISION_SOURCES
  48. test_timestamp_precision.cpp
  49. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/memory_store.cpp
  50. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/config/collection_config_manager.cpp
  51. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/persistence/history_store.cpp
  52. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/persistence/wal.cpp
  53. )
  54. add_executable(test_timestamp_precision ${TEST_TIMESTAMP_PRECISION_SOURCES})
  55. target_include_directories(test_timestamp_precision PRIVATE
  56. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src
  57. )
  58. if(TARGET nlohmann_json::nlohmann_json)
  59. target_link_libraries(test_timestamp_precision PRIVATE nlohmann_json::nlohmann_json)
  60. else()
  61. target_include_directories(test_timestamp_precision PRIVATE ${NLOHMANN_JSON_INCLUDE_DIRS})
  62. endif()
  63. if(TARGET spdlog::spdlog)
  64. target_link_libraries(test_timestamp_precision PRIVATE spdlog::spdlog)
  65. else()
  66. target_link_libraries(test_timestamp_precision PRIVATE ${SPDLOG_LIBRARIES})
  67. target_include_directories(test_timestamp_precision PRIVATE ${SPDLOG_INCLUDE_DIRS})
  68. endif()
  69. find_package(Threads REQUIRED)
  70. target_link_libraries(test_timestamp_precision PRIVATE Threads::Threads)
  71. # Snapshot durability + fallback integration test
  72. # Exercises SnapshotManager directly; pulls in memory_store.cpp, snapshot.cpp,
  73. # and wal.cpp (for the crc32 helpers used by snapshot.cpp).
  74. set(TEST_SNAPSHOT_DURABILITY_SOURCES
  75. test_snapshot_durability.cpp
  76. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/memory_store.cpp
  77. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/config/collection_config_manager.cpp
  78. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/persistence/snapshot.cpp
  79. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/persistence/wal.cpp
  80. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/persistence/history_store.cpp
  81. )
  82. add_executable(test_snapshot_durability ${TEST_SNAPSHOT_DURABILITY_SOURCES})
  83. target_include_directories(test_snapshot_durability PRIVATE
  84. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src
  85. )
  86. if(TARGET nlohmann_json::nlohmann_json)
  87. target_link_libraries(test_snapshot_durability PRIVATE nlohmann_json::nlohmann_json)
  88. else()
  89. target_include_directories(test_snapshot_durability PRIVATE ${NLOHMANN_JSON_INCLUDE_DIRS})
  90. endif()
  91. if(TARGET spdlog::spdlog)
  92. target_link_libraries(test_snapshot_durability PRIVATE spdlog::spdlog)
  93. else()
  94. target_link_libraries(test_snapshot_durability PRIVATE ${SPDLOG_LIBRARIES})
  95. target_include_directories(test_snapshot_durability PRIVATE ${SPDLOG_INCLUDE_DIRS})
  96. endif()
  97. find_package(Threads REQUIRED)
  98. target_link_libraries(test_snapshot_durability PRIVATE Threads::Threads)
  99. # LZ4 — snapshot.cpp #includes <lz4.h> unless DISABLE_LZ4 is defined, so link it.
  100. find_package(PkgConfig QUIET)
  101. if(PKG_CONFIG_FOUND)
  102. pkg_check_modules(TEST_LZ4 QUIET liblz4)
  103. endif()
  104. if(TEST_LZ4_FOUND)
  105. target_link_libraries(test_snapshot_durability PRIVATE ${TEST_LZ4_LIBRARIES})
  106. target_include_directories(test_snapshot_durability PRIVATE ${TEST_LZ4_INCLUDE_DIRS})
  107. else()
  108. # Fallback: assume liblz4 is installed at a standard location
  109. target_link_libraries(test_snapshot_durability PRIVATE lz4)
  110. endif()
  111. # Config drop-in loader test (v1.7.0 T1 → T12)
  112. # Exercises loadLayeredConfig() in isolation.
  113. set(TEST_CONFIG_DROPINS_SOURCES
  114. test_config_dropins.cpp
  115. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/config/config_loader.cpp
  116. )
  117. add_executable(test_config_dropins ${TEST_CONFIG_DROPINS_SOURCES})
  118. target_include_directories(test_config_dropins PRIVATE
  119. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src
  120. )
  121. if(TARGET nlohmann_json::nlohmann_json)
  122. target_link_libraries(test_config_dropins PRIVATE nlohmann_json::nlohmann_json)
  123. else()
  124. target_include_directories(test_config_dropins PRIVATE ${NLOHMANN_JSON_INCLUDE_DIRS})
  125. endif()
  126. if(TARGET spdlog::spdlog)
  127. target_link_libraries(test_config_dropins PRIVATE spdlog::spdlog)
  128. else()
  129. target_link_libraries(test_config_dropins PRIVATE ${SPDLOG_LIBRARIES})
  130. target_include_directories(test_config_dropins PRIVATE ${SPDLOG_INCLUDE_DIRS})
  131. endif()
  132. # Eviction test (v1.7.0 T4+T5+T6 → T12)
  133. # Exercises chunked eviction, per-collection priorities, and the hot-write
  134. # floor directly through MemoryStore. Mirrors the link deps of test_timestamp_precision.
  135. set(TEST_EVICTION_SOURCES
  136. test_eviction.cpp
  137. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/memory_store.cpp
  138. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/config/collection_config_manager.cpp
  139. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/persistence/history_store.cpp
  140. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/persistence/wal.cpp
  141. )
  142. add_executable(test_eviction ${TEST_EVICTION_SOURCES})
  143. target_include_directories(test_eviction PRIVATE
  144. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src
  145. )
  146. if(TARGET nlohmann_json::nlohmann_json)
  147. target_link_libraries(test_eviction PRIVATE nlohmann_json::nlohmann_json)
  148. else()
  149. target_include_directories(test_eviction PRIVATE ${NLOHMANN_JSON_INCLUDE_DIRS})
  150. endif()
  151. if(TARGET spdlog::spdlog)
  152. target_link_libraries(test_eviction PRIVATE spdlog::spdlog)
  153. else()
  154. target_link_libraries(test_eviction PRIVATE ${SPDLOG_LIBRARIES})
  155. target_include_directories(test_eviction PRIVATE ${SPDLOG_INCLUDE_DIRS})
  156. endif()
  157. find_package(Threads REQUIRED)
  158. target_link_libraries(test_eviction PRIVATE Threads::Threads)
  159. # Register with CTest
  160. enable_testing()
  161. add_test(NAME vector_storage COMMAND test_vector_storage)
  162. add_test(NAME views COMMAND test_views)
  163. add_test(NAME timestamp_precision COMMAND test_timestamp_precision)
  164. add_test(NAME snapshot_durability COMMAND test_snapshot_durability)
  165. add_test(NAME config_dropins COMMAND test_config_dropins)
  166. add_test(NAME eviction COMMAND test_eviction)