CMakeLists.txt 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. # Tests for smartbotic-database
  2. # yyjson (v1.10+) — Phase A swaps nlohmann::json::parse for parse_to_nlohmann
  3. # at hot paths in wal.cpp, snapshot.cpp, history_store.cpp, etc. Any test
  4. # target that compiles those files now also needs json_parse.cpp linked and
  5. # yyjson linked. Resolve once at file scope so every test target below can
  6. # use ${yyjson_LIBRARIES} / ${yyjson_INCLUDE_DIRS}.
  7. if(NOT yyjson_FOUND)
  8. find_package(PkgConfig REQUIRED)
  9. pkg_check_modules(yyjson REQUIRED yyjson)
  10. endif()
  11. # Vector storage integration test
  12. # Compiles memory_store.cpp directly — no dependency on the full service executable.
  13. set(TEST_VECTOR_SOURCES
  14. test_vector_storage.cpp
  15. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/memory_store.cpp
  16. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/config/collection_config_manager.cpp
  17. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/persistence/history_store.cpp
  18. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/persistence/wal.cpp
  19. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/json_parse.cpp
  20. )
  21. add_executable(test_vector_storage ${TEST_VECTOR_SOURCES})
  22. target_include_directories(test_vector_storage PRIVATE
  23. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src
  24. )
  25. # nlohmann/json
  26. if(TARGET nlohmann_json::nlohmann_json)
  27. target_link_libraries(test_vector_storage PRIVATE nlohmann_json::nlohmann_json)
  28. else()
  29. target_include_directories(test_vector_storage PRIVATE ${NLOHMANN_JSON_INCLUDE_DIRS})
  30. endif()
  31. # spdlog
  32. if(TARGET spdlog::spdlog)
  33. target_link_libraries(test_vector_storage PRIVATE spdlog::spdlog)
  34. else()
  35. target_link_libraries(test_vector_storage PRIVATE ${SPDLOG_LIBRARIES})
  36. target_include_directories(test_vector_storage PRIVATE ${SPDLOG_INCLUDE_DIRS})
  37. endif()
  38. # Threads (required by MemoryStore background threads)
  39. find_package(Threads REQUIRED)
  40. target_link_libraries(test_vector_storage PRIVATE Threads::Threads)
  41. # yyjson (wal.cpp uses parse_to_nlohmann from v1.10+)
  42. target_link_libraries(test_vector_storage PRIVATE ${yyjson_LIBRARIES})
  43. target_include_directories(test_vector_storage PRIVATE ${yyjson_INCLUDE_DIRS})
  44. # View projection unit test
  45. set(TEST_VIEWS_SOURCES
  46. test_views.cpp
  47. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/views/projection.cpp
  48. )
  49. add_executable(test_views ${TEST_VIEWS_SOURCES})
  50. target_include_directories(test_views PRIVATE
  51. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src
  52. )
  53. # nlohmann/json
  54. if(TARGET nlohmann_json::nlohmann_json)
  55. target_link_libraries(test_views PRIVATE nlohmann_json::nlohmann_json)
  56. else()
  57. target_include_directories(test_views PRIVATE ${NLOHMANN_JSON_INCLUDE_DIRS})
  58. endif()
  59. # Per-collection timestamp precision test
  60. set(TEST_TIMESTAMP_PRECISION_SOURCES
  61. test_timestamp_precision.cpp
  62. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/memory_store.cpp
  63. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/config/collection_config_manager.cpp
  64. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/persistence/history_store.cpp
  65. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/persistence/wal.cpp
  66. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/json_parse.cpp
  67. )
  68. add_executable(test_timestamp_precision ${TEST_TIMESTAMP_PRECISION_SOURCES})
  69. target_include_directories(test_timestamp_precision PRIVATE
  70. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src
  71. )
  72. if(TARGET nlohmann_json::nlohmann_json)
  73. target_link_libraries(test_timestamp_precision PRIVATE nlohmann_json::nlohmann_json)
  74. else()
  75. target_include_directories(test_timestamp_precision PRIVATE ${NLOHMANN_JSON_INCLUDE_DIRS})
  76. endif()
  77. if(TARGET spdlog::spdlog)
  78. target_link_libraries(test_timestamp_precision PRIVATE spdlog::spdlog)
  79. else()
  80. target_link_libraries(test_timestamp_precision PRIVATE ${SPDLOG_LIBRARIES})
  81. target_include_directories(test_timestamp_precision PRIVATE ${SPDLOG_INCLUDE_DIRS})
  82. endif()
  83. find_package(Threads REQUIRED)
  84. target_link_libraries(test_timestamp_precision PRIVATE Threads::Threads)
  85. # yyjson (wal.cpp uses parse_to_nlohmann from v1.10+)
  86. target_link_libraries(test_timestamp_precision PRIVATE ${yyjson_LIBRARIES})
  87. target_include_directories(test_timestamp_precision PRIVATE ${yyjson_INCLUDE_DIRS})
  88. # Snapshot durability + fallback integration test
  89. # Exercises SnapshotManager directly; pulls in memory_store.cpp, snapshot.cpp,
  90. # and wal.cpp (for the crc32 helpers used by snapshot.cpp).
  91. set(TEST_SNAPSHOT_DURABILITY_SOURCES
  92. test_snapshot_durability.cpp
  93. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/memory_store.cpp
  94. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/config/collection_config_manager.cpp
  95. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/persistence/snapshot.cpp
  96. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/persistence/wal.cpp
  97. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/persistence/history_store.cpp
  98. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/json_parse.cpp
  99. )
  100. add_executable(test_snapshot_durability ${TEST_SNAPSHOT_DURABILITY_SOURCES})
  101. target_include_directories(test_snapshot_durability PRIVATE
  102. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src
  103. )
  104. if(TARGET nlohmann_json::nlohmann_json)
  105. target_link_libraries(test_snapshot_durability PRIVATE nlohmann_json::nlohmann_json)
  106. else()
  107. target_include_directories(test_snapshot_durability PRIVATE ${NLOHMANN_JSON_INCLUDE_DIRS})
  108. endif()
  109. if(TARGET spdlog::spdlog)
  110. target_link_libraries(test_snapshot_durability PRIVATE spdlog::spdlog)
  111. else()
  112. target_link_libraries(test_snapshot_durability PRIVATE ${SPDLOG_LIBRARIES})
  113. target_include_directories(test_snapshot_durability PRIVATE ${SPDLOG_INCLUDE_DIRS})
  114. endif()
  115. find_package(Threads REQUIRED)
  116. target_link_libraries(test_snapshot_durability PRIVATE Threads::Threads)
  117. # yyjson (wal.cpp/snapshot.cpp use parse_to_nlohmann from v1.10+)
  118. target_link_libraries(test_snapshot_durability PRIVATE ${yyjson_LIBRARIES})
  119. target_include_directories(test_snapshot_durability PRIVATE ${yyjson_INCLUDE_DIRS})
  120. # LZ4 — snapshot.cpp #includes <lz4.h> unless DISABLE_LZ4 is defined, so link it.
  121. find_package(PkgConfig QUIET)
  122. if(PKG_CONFIG_FOUND)
  123. pkg_check_modules(TEST_LZ4 QUIET liblz4)
  124. endif()
  125. if(TEST_LZ4_FOUND)
  126. target_link_libraries(test_snapshot_durability PRIVATE ${TEST_LZ4_LIBRARIES})
  127. target_include_directories(test_snapshot_durability PRIVATE ${TEST_LZ4_INCLUDE_DIRS})
  128. else()
  129. # Fallback: assume liblz4 is installed at a standard location
  130. target_link_libraries(test_snapshot_durability PRIVATE lz4)
  131. endif()
  132. # Config drop-in loader test (v1.7.0 T1 → T12)
  133. # Exercises loadLayeredConfig() in isolation.
  134. set(TEST_CONFIG_DROPINS_SOURCES
  135. test_config_dropins.cpp
  136. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/config/config_loader.cpp
  137. )
  138. add_executable(test_config_dropins ${TEST_CONFIG_DROPINS_SOURCES})
  139. target_include_directories(test_config_dropins PRIVATE
  140. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src
  141. )
  142. if(TARGET nlohmann_json::nlohmann_json)
  143. target_link_libraries(test_config_dropins PRIVATE nlohmann_json::nlohmann_json)
  144. else()
  145. target_include_directories(test_config_dropins PRIVATE ${NLOHMANN_JSON_INCLUDE_DIRS})
  146. endif()
  147. if(TARGET spdlog::spdlog)
  148. target_link_libraries(test_config_dropins PRIVATE spdlog::spdlog)
  149. else()
  150. target_link_libraries(test_config_dropins PRIVATE ${SPDLOG_LIBRARIES})
  151. target_include_directories(test_config_dropins PRIVATE ${SPDLOG_INCLUDE_DIRS})
  152. endif()
  153. # Eviction test (v1.7.0 T4+T5+T6 → T12)
  154. # Exercises chunked eviction, per-collection priorities, and the hot-write
  155. # floor directly through MemoryStore. Mirrors the link deps of test_timestamp_precision.
  156. set(TEST_EVICTION_SOURCES
  157. test_eviction.cpp
  158. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/memory_store.cpp
  159. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/config/collection_config_manager.cpp
  160. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/persistence/history_store.cpp
  161. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/persistence/wal.cpp
  162. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/json_parse.cpp
  163. )
  164. add_executable(test_eviction ${TEST_EVICTION_SOURCES})
  165. target_include_directories(test_eviction PRIVATE
  166. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src
  167. )
  168. if(TARGET nlohmann_json::nlohmann_json)
  169. target_link_libraries(test_eviction PRIVATE nlohmann_json::nlohmann_json)
  170. else()
  171. target_include_directories(test_eviction PRIVATE ${NLOHMANN_JSON_INCLUDE_DIRS})
  172. endif()
  173. if(TARGET spdlog::spdlog)
  174. target_link_libraries(test_eviction PRIVATE spdlog::spdlog)
  175. else()
  176. target_link_libraries(test_eviction PRIVATE ${SPDLOG_LIBRARIES})
  177. target_include_directories(test_eviction PRIVATE ${SPDLOG_INCLUDE_DIRS})
  178. endif()
  179. find_package(Threads REQUIRED)
  180. target_link_libraries(test_eviction PRIVATE Threads::Threads)
  181. # yyjson (wal.cpp uses parse_to_nlohmann from v1.10+)
  182. target_link_libraries(test_eviction PRIVATE ${yyjson_LIBRARIES})
  183. target_include_directories(test_eviction PRIVATE ${yyjson_INCLUDE_DIRS})
  184. # yyjson → nlohmann bridge helper test (v1.10 Phase A T2)
  185. # Exercises parse_to_nlohmann() in isolation against nlohmann::json::parse
  186. # for a corpus of production-shaped docs. yyjson is configured at the
  187. # service/ scope; re-resolve it here so the test target can find it
  188. # independently of the service build.
  189. if(NOT yyjson_FOUND)
  190. find_package(PkgConfig REQUIRED)
  191. pkg_check_modules(yyjson REQUIRED yyjson)
  192. endif()
  193. add_executable(test_json_parse
  194. test_json_parse.cpp
  195. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/json_parse.cpp
  196. )
  197. target_include_directories(test_json_parse PRIVATE
  198. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src
  199. ${yyjson_INCLUDE_DIRS}
  200. )
  201. if(TARGET nlohmann_json::nlohmann_json)
  202. target_link_libraries(test_json_parse PRIVATE nlohmann_json::nlohmann_json)
  203. else()
  204. target_include_directories(test_json_parse PRIVATE ${NLOHMANN_JSON_INCLUDE_DIRS})
  205. endif()
  206. target_link_libraries(test_json_parse PRIVATE ${yyjson_LIBRARIES})
  207. # Register with CTest
  208. enable_testing()
  209. add_test(NAME vector_storage COMMAND test_vector_storage)
  210. add_test(NAME views COMMAND test_views)
  211. add_test(NAME timestamp_precision COMMAND test_timestamp_precision)
  212. add_test(NAME snapshot_durability COMMAND test_snapshot_durability)
  213. add_test(NAME config_dropins COMMAND test_config_dropins)
  214. add_test(NAME eviction COMMAND test_eviction)
  215. add_test(NAME json_parse COMMAND test_json_parse)