CMakeLists.txt 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  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. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/doc_binary.cpp
  21. )
  22. add_executable(test_vector_storage ${TEST_VECTOR_SOURCES})
  23. target_include_directories(test_vector_storage PRIVATE
  24. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src
  25. )
  26. # nlohmann/json
  27. if(TARGET nlohmann_json::nlohmann_json)
  28. target_link_libraries(test_vector_storage PRIVATE nlohmann_json::nlohmann_json)
  29. else()
  30. target_include_directories(test_vector_storage PRIVATE ${NLOHMANN_JSON_INCLUDE_DIRS})
  31. endif()
  32. # spdlog
  33. if(TARGET spdlog::spdlog)
  34. target_link_libraries(test_vector_storage PRIVATE spdlog::spdlog)
  35. else()
  36. target_link_libraries(test_vector_storage PRIVATE ${SPDLOG_LIBRARIES})
  37. target_include_directories(test_vector_storage PRIVATE ${SPDLOG_INCLUDE_DIRS})
  38. endif()
  39. # Threads (required by MemoryStore background threads)
  40. find_package(Threads REQUIRED)
  41. target_link_libraries(test_vector_storage PRIVATE Threads::Threads)
  42. # yyjson (wal.cpp uses parse_to_nlohmann from v1.10+)
  43. target_link_libraries(test_vector_storage PRIVATE ${yyjson_LIBRARIES})
  44. target_include_directories(test_vector_storage PRIVATE ${yyjson_INCLUDE_DIRS})
  45. # View projection unit test
  46. set(TEST_VIEWS_SOURCES
  47. test_views.cpp
  48. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/views/projection.cpp
  49. )
  50. add_executable(test_views ${TEST_VIEWS_SOURCES})
  51. target_include_directories(test_views PRIVATE
  52. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src
  53. )
  54. # nlohmann/json
  55. if(TARGET nlohmann_json::nlohmann_json)
  56. target_link_libraries(test_views PRIVATE nlohmann_json::nlohmann_json)
  57. else()
  58. target_include_directories(test_views PRIVATE ${NLOHMANN_JSON_INCLUDE_DIRS})
  59. endif()
  60. # Per-collection timestamp precision test
  61. set(TEST_TIMESTAMP_PRECISION_SOURCES
  62. test_timestamp_precision.cpp
  63. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/memory_store.cpp
  64. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/config/collection_config_manager.cpp
  65. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/persistence/history_store.cpp
  66. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/persistence/wal.cpp
  67. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/json_parse.cpp
  68. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/doc_binary.cpp
  69. )
  70. add_executable(test_timestamp_precision ${TEST_TIMESTAMP_PRECISION_SOURCES})
  71. target_include_directories(test_timestamp_precision PRIVATE
  72. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src
  73. )
  74. if(TARGET nlohmann_json::nlohmann_json)
  75. target_link_libraries(test_timestamp_precision PRIVATE nlohmann_json::nlohmann_json)
  76. else()
  77. target_include_directories(test_timestamp_precision PRIVATE ${NLOHMANN_JSON_INCLUDE_DIRS})
  78. endif()
  79. if(TARGET spdlog::spdlog)
  80. target_link_libraries(test_timestamp_precision PRIVATE spdlog::spdlog)
  81. else()
  82. target_link_libraries(test_timestamp_precision PRIVATE ${SPDLOG_LIBRARIES})
  83. target_include_directories(test_timestamp_precision PRIVATE ${SPDLOG_INCLUDE_DIRS})
  84. endif()
  85. find_package(Threads REQUIRED)
  86. target_link_libraries(test_timestamp_precision PRIVATE Threads::Threads)
  87. # yyjson (wal.cpp uses parse_to_nlohmann from v1.10+)
  88. target_link_libraries(test_timestamp_precision PRIVATE ${yyjson_LIBRARIES})
  89. target_include_directories(test_timestamp_precision PRIVATE ${yyjson_INCLUDE_DIRS})
  90. # Snapshot durability + fallback integration test
  91. # Exercises SnapshotManager directly; pulls in memory_store.cpp, snapshot.cpp,
  92. # and wal.cpp (for the crc32 helpers used by snapshot.cpp).
  93. set(TEST_SNAPSHOT_DURABILITY_SOURCES
  94. test_snapshot_durability.cpp
  95. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/memory_store.cpp
  96. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/config/collection_config_manager.cpp
  97. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/persistence/snapshot.cpp
  98. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/persistence/wal.cpp
  99. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/persistence/history_store.cpp
  100. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/json_parse.cpp
  101. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/doc_binary.cpp
  102. )
  103. add_executable(test_snapshot_durability ${TEST_SNAPSHOT_DURABILITY_SOURCES})
  104. target_include_directories(test_snapshot_durability PRIVATE
  105. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src
  106. )
  107. if(TARGET nlohmann_json::nlohmann_json)
  108. target_link_libraries(test_snapshot_durability PRIVATE nlohmann_json::nlohmann_json)
  109. else()
  110. target_include_directories(test_snapshot_durability PRIVATE ${NLOHMANN_JSON_INCLUDE_DIRS})
  111. endif()
  112. if(TARGET spdlog::spdlog)
  113. target_link_libraries(test_snapshot_durability PRIVATE spdlog::spdlog)
  114. else()
  115. target_link_libraries(test_snapshot_durability PRIVATE ${SPDLOG_LIBRARIES})
  116. target_include_directories(test_snapshot_durability PRIVATE ${SPDLOG_INCLUDE_DIRS})
  117. endif()
  118. find_package(Threads REQUIRED)
  119. target_link_libraries(test_snapshot_durability PRIVATE Threads::Threads)
  120. # yyjson (wal.cpp/snapshot.cpp use parse_to_nlohmann from v1.10+)
  121. target_link_libraries(test_snapshot_durability PRIVATE ${yyjson_LIBRARIES})
  122. target_include_directories(test_snapshot_durability PRIVATE ${yyjson_INCLUDE_DIRS})
  123. # LZ4 — snapshot.cpp #includes <lz4.h> unless DISABLE_LZ4 is defined, so link it.
  124. find_package(PkgConfig QUIET)
  125. if(PKG_CONFIG_FOUND)
  126. pkg_check_modules(TEST_LZ4 QUIET liblz4)
  127. endif()
  128. if(TEST_LZ4_FOUND)
  129. target_link_libraries(test_snapshot_durability PRIVATE ${TEST_LZ4_LIBRARIES})
  130. target_include_directories(test_snapshot_durability PRIVATE ${TEST_LZ4_INCLUDE_DIRS})
  131. else()
  132. # Fallback: assume liblz4 is installed at a standard location
  133. target_link_libraries(test_snapshot_durability PRIVATE lz4)
  134. endif()
  135. # Config drop-in loader test (v1.7.0 T1 → T12)
  136. # Exercises loadLayeredConfig() in isolation.
  137. set(TEST_CONFIG_DROPINS_SOURCES
  138. test_config_dropins.cpp
  139. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/config/config_loader.cpp
  140. )
  141. add_executable(test_config_dropins ${TEST_CONFIG_DROPINS_SOURCES})
  142. target_include_directories(test_config_dropins PRIVATE
  143. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src
  144. )
  145. if(TARGET nlohmann_json::nlohmann_json)
  146. target_link_libraries(test_config_dropins PRIVATE nlohmann_json::nlohmann_json)
  147. else()
  148. target_include_directories(test_config_dropins PRIVATE ${NLOHMANN_JSON_INCLUDE_DIRS})
  149. endif()
  150. if(TARGET spdlog::spdlog)
  151. target_link_libraries(test_config_dropins PRIVATE spdlog::spdlog)
  152. else()
  153. target_link_libraries(test_config_dropins PRIVATE ${SPDLOG_LIBRARIES})
  154. target_include_directories(test_config_dropins PRIVATE ${SPDLOG_INCLUDE_DIRS})
  155. endif()
  156. # Eviction test (v1.7.0 T4+T5+T6 → T12)
  157. # Exercises chunked eviction, per-collection priorities, and the hot-write
  158. # floor directly through MemoryStore. Mirrors the link deps of test_timestamp_precision.
  159. set(TEST_EVICTION_SOURCES
  160. test_eviction.cpp
  161. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/memory_store.cpp
  162. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/config/collection_config_manager.cpp
  163. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/persistence/history_store.cpp
  164. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/persistence/wal.cpp
  165. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/json_parse.cpp
  166. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/doc_binary.cpp
  167. )
  168. add_executable(test_eviction ${TEST_EVICTION_SOURCES})
  169. target_include_directories(test_eviction PRIVATE
  170. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src
  171. )
  172. if(TARGET nlohmann_json::nlohmann_json)
  173. target_link_libraries(test_eviction PRIVATE nlohmann_json::nlohmann_json)
  174. else()
  175. target_include_directories(test_eviction PRIVATE ${NLOHMANN_JSON_INCLUDE_DIRS})
  176. endif()
  177. if(TARGET spdlog::spdlog)
  178. target_link_libraries(test_eviction PRIVATE spdlog::spdlog)
  179. else()
  180. target_link_libraries(test_eviction PRIVATE ${SPDLOG_LIBRARIES})
  181. target_include_directories(test_eviction PRIVATE ${SPDLOG_INCLUDE_DIRS})
  182. endif()
  183. find_package(Threads REQUIRED)
  184. target_link_libraries(test_eviction PRIVATE Threads::Threads)
  185. # yyjson (wal.cpp uses parse_to_nlohmann from v1.10+)
  186. target_link_libraries(test_eviction PRIVATE ${yyjson_LIBRARIES})
  187. target_include_directories(test_eviction PRIVATE ${yyjson_INCLUDE_DIRS})
  188. # yyjson → nlohmann bridge helper test (v1.10 Phase A T2)
  189. # Exercises parse_to_nlohmann() in isolation against nlohmann::json::parse
  190. # for a corpus of production-shaped docs. yyjson is configured at the
  191. # service/ scope; re-resolve it here so the test target can find it
  192. # independently of the service build.
  193. if(NOT yyjson_FOUND)
  194. find_package(PkgConfig REQUIRED)
  195. pkg_check_modules(yyjson REQUIRED yyjson)
  196. endif()
  197. add_executable(test_json_parse
  198. test_json_parse.cpp
  199. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/json_parse.cpp
  200. )
  201. target_include_directories(test_json_parse PRIVATE
  202. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src
  203. ${yyjson_INCLUDE_DIRS}
  204. )
  205. if(TARGET nlohmann_json::nlohmann_json)
  206. target_link_libraries(test_json_parse PRIVATE nlohmann_json::nlohmann_json)
  207. else()
  208. target_include_directories(test_json_parse PRIVATE ${NLOHMANN_JSON_INCLUDE_DIRS})
  209. endif()
  210. target_link_libraries(test_json_parse PRIVATE ${yyjson_LIBRARIES})
  211. # Binary doc encoder/decoder test (v1.11 Phase B T2)
  212. # Exercises doc_binary::Doc, encode, decode, get_field, to_json_text against
  213. # nlohmann::json round-trips. yyjson resolution is shared at file scope above.
  214. add_executable(test_doc_binary
  215. test_doc_binary.cpp
  216. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/doc_binary.cpp
  217. )
  218. target_include_directories(test_doc_binary PRIVATE
  219. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src
  220. ${yyjson_INCLUDE_DIRS}
  221. )
  222. if(TARGET nlohmann_json::nlohmann_json)
  223. target_link_libraries(test_doc_binary PRIVATE nlohmann_json::nlohmann_json)
  224. else()
  225. target_include_directories(test_doc_binary PRIVATE ${NLOHMANN_JSON_INCLUDE_DIRS})
  226. endif()
  227. target_link_libraries(test_doc_binary PRIVATE ${yyjson_LIBRARIES})
  228. # Parse-time micro-benchmark (v1.10 Phase A T8) — manual bench, NOT
  229. # registered with CTest. Run as ./build/tests/bench_json_parse <corpus>.
  230. add_executable(bench_json_parse
  231. bench_json_parse.cpp
  232. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/json_parse.cpp
  233. )
  234. target_include_directories(bench_json_parse PRIVATE
  235. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src
  236. ${yyjson_INCLUDE_DIRS}
  237. )
  238. if(TARGET nlohmann_json::nlohmann_json)
  239. target_link_libraries(bench_json_parse PRIVATE nlohmann_json::nlohmann_json)
  240. else()
  241. target_include_directories(bench_json_parse PRIVATE ${NLOHMANN_JSON_INCLUDE_DIRS})
  242. endif()
  243. target_link_libraries(bench_json_parse PRIVATE ${yyjson_LIBRARIES})
  244. # RSS bench (v1.11 Phase B T8) — manual bench, NOT registered with CTest.
  245. # Run as ./build/tests/bench_doc_memory [N].
  246. add_executable(bench_doc_memory
  247. bench_doc_memory.cpp
  248. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/doc_binary.cpp
  249. )
  250. target_include_directories(bench_doc_memory PRIVATE
  251. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src
  252. ${yyjson_INCLUDE_DIRS}
  253. )
  254. if(TARGET nlohmann_json::nlohmann_json)
  255. target_link_libraries(bench_doc_memory PRIVATE nlohmann_json::nlohmann_json)
  256. else()
  257. target_include_directories(bench_doc_memory PRIVATE ${NLOHMANN_JSON_INCLUDE_DIRS})
  258. endif()
  259. target_link_libraries(bench_doc_memory PRIVATE ${yyjson_LIBRARIES})
  260. # Register with CTest
  261. enable_testing()
  262. add_test(NAME vector_storage COMMAND test_vector_storage)
  263. add_test(NAME views COMMAND test_views)
  264. add_test(NAME timestamp_precision COMMAND test_timestamp_precision)
  265. add_test(NAME snapshot_durability COMMAND test_snapshot_durability)
  266. add_test(NAME config_dropins COMMAND test_config_dropins)
  267. add_test(NAME eviction COMMAND test_eviction)
  268. add_test(NAME json_parse COMMAND test_json_parse)
  269. add_test(NAME doc_binary COMMAND test_doc_binary)