MB-20054: Backport ep-engine_unit_tests from watson to 3.0.x
[ep-engine.git] / CMakeLists.txt
1 PROJECT(EventuallyPersistentEngine)
2 CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
3
4 INCLUDE(CheckFunctionExists)
5 INCLUDE(CheckIncludeFileCXX)
6 INCLUDE(CheckIncludeFiles)
7 INCLUDE(CheckLibraryExists)
8 INCLUDE(CheckSymbolExists)
9 INCLUDE(CheckTypeSize)
10
11 INCLUDE_DIRECTORIES(BEFORE ${CMAKE_INSTALL_PREFIX}/include
12                            ${CMAKE_CURRENT_SOURCE_DIR}/include
13                            ${CMAKE_CURRENT_SOURCE_DIR}
14                            ${CMAKE_CURRENT_SOURCE_DIR}/src
15                            ${CMAKE_CURRENT_BINARY_DIR}/src
16                            ${SNAPPY_INCLUDE_DIR}
17                            ${Platform_SOURCE_DIR}/include
18                            ${Memcached_SOURCE_DIR}
19                            ${Memcached_SOURCE_DIR}/include
20                            ${Couchstore_SOURCE_DIR}/include
21                            ${CMAKE_CURRENT_BINARY_DIR})
22
23 INCLUDE_DIRECTORIES(AFTER
24                     ${gtest_SOURCE_DIR}/include)
25
26 CHECK_INCLUDE_FILES("arpa/inet.h" HAVE_ARPA_INET_H)
27 CHECK_INCLUDE_FILES("unistd.h" HAVE_UNISTD_H)
28 CHECK_INCLUDE_FILES("netdb.h" HAVE_NETDB_H)
29 CHECK_INCLUDE_FILES("mach/mach_time.h" HAVE_MACH_MACH_TIME_H)
30 CHECK_INCLUDE_FILES("poll.h" HAVE_POLL_H)
31 CHECK_INCLUDE_FILES("atomic.h" HAVE_ATOMIC_H)
32 CHECK_INCLUDE_FILES("sysexits.h" HAVE_SYSEXITS_H)
33 CHECK_INCLUDE_FILES("unistd.h" HAVE_UNISTD_H)
34 CHECK_INCLUDE_FILES("sched.h" HAVE_SCHED_H)
35 CHECK_INCLUDE_FILES("sys/socket.h" HAVE_SYS_SOCKET_H)
36 CHECK_INCLUDE_FILES("sys/time.h" HAVE_SYS_TIME_H)
37 CHECK_INCLUDE_FILES("netinet/in.h" HAVE_NETINET_IN_H)
38 CHECK_INCLUDE_FILES("netinet/tcp.h" HAVE_NETINET_TCP_H)
39 CHECK_INCLUDE_FILE_CXX("tr1/memory" HAVE_TR1_MEMORY)
40 CHECK_INCLUDE_FILE_CXX("tr1/unordered_map" HAVE_TR1_UNORDERED_MAP)
41 CHECK_INCLUDE_FILE_CXX("unordered_map" HAVE_UNORDERED_MAP)
42 CHECK_INCLUDE_FILE_CXX("atomic" HAVE_ATOMIC)
43 CHECK_INCLUDE_FILE_CXX("thread" HAVE_THREAD)
44
45 CHECK_FUNCTION_EXISTS(clock_gettime HAVE_CLOCK_GETTIME)
46 CHECK_FUNCTION_EXISTS(mach_absolute_time HAVE_MACH_ABSOLUTE_TIME)
47 CHECK_FUNCTION_EXISTS(gettimeofday HAVE_GETTIMEOFDAY)
48 CHECK_FUNCTION_EXISTS(getopt_long HAVE_GETOPT_LONG)
49
50 # ---- uncomment the lines below ONLY for dev/debugging ---
51 #if ("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")
52 #    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0")
53 #elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
54 #    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0")
55 #endif()
56
57 IF (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git)
58    EXECUTE_PROCESS(COMMAND git describe
59                    WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
60                    OUTPUT_VARIABLE EP_ENGINE_VERSION
61                    ERROR_QUIET
62                    OUTPUT_STRIP_TRAILING_WHITESPACE)
63 ELSE (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git)
64    SET(EP_ENGINE_VERSION "unknown")
65 ENDIF (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git)
66
67 CONFIGURE_FILE (${CMAKE_CURRENT_SOURCE_DIR}/src/config.cmake.h
68                 ${CMAKE_CURRENT_BINARY_DIR}/src/config.h)
69
70 # Generate the python wrappers
71 CONFIGURE_FILE (${CMAKE_CURRENT_SOURCE_DIR}/wrapper/wrapper
72                 ${CMAKE_CURRENT_BINARY_DIR}/wrapper/cbadm-tap-registration)
73 CONFIGURE_FILE (${CMAKE_CURRENT_SOURCE_DIR}/wrapper/wrapper
74                 ${CMAKE_CURRENT_BINARY_DIR}/wrapper/cbepctl)
75 CONFIGURE_FILE (${CMAKE_CURRENT_SOURCE_DIR}/wrapper/wrapper
76                 ${CMAKE_CURRENT_BINARY_DIR}/wrapper/cbstats)
77 CONFIGURE_FILE (${CMAKE_CURRENT_SOURCE_DIR}/wrapper/wrapper
78                 ${CMAKE_CURRENT_BINARY_DIR}/wrapper/cbcompact)
79 CONFIGURE_FILE (${CMAKE_CURRENT_SOURCE_DIR}/wrapper/wrapper
80                 ${CMAKE_CURRENT_BINARY_DIR}/wrapper/cbvdiff)
81 CONFIGURE_FILE (${CMAKE_CURRENT_SOURCE_DIR}/wrapper/wrapper
82                 ${CMAKE_CURRENT_BINARY_DIR}/wrapper/cbvbucketctl)
83
84 IF (WIN32)
85    INCLUDE_DIRECTORIES(AFTER ${CMAKE_SOURCE_DIR}/platform/include/win32)
86 ENDIF (WIN32)
87
88 ADD_EXECUTABLE(gencode tools/gencode.cc)
89 TARGET_LINK_LIBRARIES(gencode cJSON platform)
90
91 ADD_EXECUTABLE(genconfig tools/genconfig.cc)
92 TARGET_LINK_LIBRARIES(genconfig cJSON platform)
93
94 ADD_CUSTOM_COMMAND(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/src/stats-info.c
95                           ${CMAKE_CURRENT_BINARY_DIR}/src/stats-info.h
96                   COMMAND
97                      gencode -j ${CMAKE_CURRENT_SOURCE_DIR}/docs/stats.json -h ${CMAKE_CURRENT_BINARY_DIR}/src/stats-info.h -c ${CMAKE_CURRENT_BINARY_DIR}/src/stats-info.c -f get_stats_info
98                   DEPENDS
99                         docs/stats.json
100                         gencode
101                   COMMENT "Generating code for stats info")
102
103 ADD_CUSTOM_COMMAND(OUTPUT
104                      ${CMAKE_CURRENT_BINARY_DIR}/src/generated_configuration.cc
105                      ${CMAKE_CURRENT_BINARY_DIR}/src/generated_configuration.h
106                   COMMAND
107                      genconfig ${CMAKE_CURRENT_SOURCE_DIR}/configuration.json
108                   DEPENDS
109                         configuration.json
110                         genconfig
111                   COMMENT "Generating code for configuration class")
112
113 SET(KVSTORE_SOURCE src/crc32.c src/kvstore.cc src/mutation_log.cc)
114 SET(COUCH_KVSTORE_SOURCE src/couch-kvstore/couch-kvstore.cc
115             src/couch-kvstore/couch-fs-stats.cc)
116 SET(OBJECTREGISTRY_SOURCE src/objectregistry.cc)
117 SET(CONFIG_SOURCE src/configuration.cc
118   ${CMAKE_CURRENT_BINARY_DIR}/src/generated_configuration.cc)
119
120 ADD_LIBRARY(ep SHARED
121             src/access_scanner.cc src/atomic.cc src/backfill.cc
122             src/bgfetcher.cc src/checkpoint.cc
123             src/checkpoint_remover.cc src/conflict_resolution.cc
124             src/ep.cc src/ep_engine.cc src/ep_time.c
125             src/executorpool.cc src/failover-table.cc
126             src/flusher.cc src/htresizer.cc
127             src/item.cc src/item_pager.cc src/kvshard.cc
128             src/memory_tracker.cc src/mutex.cc src/priority.cc
129             src/executorthread.cc
130             src/sizes.cc
131             ${CMAKE_CURRENT_BINARY_DIR}/src/stats-info.c
132             src/stored-value.cc src/tapconnection.cc src/connmap.cc
133             src/tapthrottle.cc src/tasks.cc
134             src/taskqueue.cc
135             src/dcp-response.cc src/dcp-consumer.cc
136             src/dcp-producer.cc src/dcp-stream.cc src/vbucket.cc
137             src/vbucketmap.cc src/warmup.cc
138             ${KVSTORE_SOURCE} ${COUCH_KVSTORE_SOURCE}
139             ${OBJECTREGISTRY_SOURCE} ${CONFIG_SOURCE})
140
141 SET_TARGET_PROPERTIES(ep PROPERTIES PREFIX "")
142 TARGET_LINK_LIBRARIES(ep cJSON JSON_checker couchstore dirutils platform ${LIBEVENT_LIBRARIES})
143
144 # Single executable containing all class-level unit tests involving
145 # EventuallyPersistentEngine driven by GoogleTest.
146 # (We end up compiling most of the src/ files of ep-engine for these unit tests,
147 # so simpler / quicker just to link them into a single executable).
148 ADD_EXECUTABLE(ep-engine_ep_unit_tests
149   tests/mock/mock_dcp.cc
150   tests/module_tests/ep_unit_tests_main.cc
151   tests/module_tests/dcp_test.cc
152   tests/module_tests/evp_engine_test.cc
153   tests/module_tests/evp_store_test.cc
154   tests/module_tests/evp_store_single_threaded_test.cc
155   src/access_scanner.cc
156   src/atomic.cc
157   src/backfill.cc
158   src/bgfetcher.cc
159   src/checkpoint.cc
160   src/checkpoint_remover.cc
161   src/conflict_resolution.cc
162   src/connmap.cc
163   src/dcp-consumer.cc
164   src/dcp-producer.cc
165   src/dcp-response.cc
166   src/dcp-stream.cc
167   src/ep.cc
168   src/ep_engine.cc
169   src/ep_time.c
170   src/executorpool.cc
171   src/executorthread.cc
172   src/failover-table.cc
173   src/flusher.cc
174   src/htresizer.cc
175   src/item.cc
176   src/item_pager.cc
177   src/kvshard.cc
178   src/memory_tracker.cc
179   src/mutation_log.cc
180   src/mutex.cc
181   src/objectregistry.cc
182   src/priority.cc
183   src/tapconnection.cc
184   src/stored-value.cc
185   src/tapthrottle.cc
186   src/tasks.cc
187   src/taskqueue.cc
188   src/vbucket.cc
189   src/vbucketmap.cc
190   src/warmup.cc
191   ${CMAKE_CURRENT_BINARY_DIR}/src/stats-info.c
192   ${CONFIG_SOURCE}
193   ${KVSTORE_SOURCE}
194   ${COUCH_KVSTORE_SOURCE}
195   ${Memcached_SOURCE_DIR}/programs/engine_testapp/mock_server.c)
196 TARGET_LINK_LIBRARIES(ep-engine_ep_unit_tests couchstore cJSON dirutils gtest JSON_checker mcd_util platform)
197
198 ADD_EXECUTABLE(ep-engine_atomic_ptr_test
199   tests/module_tests/atomic_ptr_test.cc
200   src/atomic.cc
201   src/testlogger.cc
202   src/mutex.cc)
203 TARGET_LINK_LIBRARIES(ep-engine_atomic_ptr_test platform)
204
205 ADD_EXECUTABLE(ep-engine_atomic_test
206   tests/module_tests/atomic_test.cc
207   src/testlogger.cc
208   src/mutex.cc)
209 TARGET_LINK_LIBRARIES(ep-engine_atomic_test platform)
210
211 ADD_EXECUTABLE(ep-engine_checkpoint_test
212   tests/module_tests/checkpoint_test.cc
213   src/checkpoint.cc src/failover-table.cc
214   src/testlogger.cc src/stored-value.cc
215   src/atomic.cc src/mutex.cc
216   tests/module_tests/test_memory_tracker.cc
217   src/item.cc src/vbucket.cc
218   ${OBJECTREGISTRY_SOURCE} ${CONFIG_SOURCE})
219 TARGET_LINK_LIBRARIES(ep-engine_checkpoint_test ${SNAPPY_LIBRARIES} cJSON platform)
220
221 ADD_EXECUTABLE(ep-engine_chunk_creation_test
222   tests/module_tests/chunk_creation_test.cc)
223
224 ADD_EXECUTABLE(ep-engine_hash_table_test
225   tests/module_tests/hash_table_test.cc src/item.cc
226   src/stored-value.cc
227   src/testlogger.cc src/atomic.cc src/mutex.cc
228   tests/module_tests/test_memory_tracker.cc
229   ${OBJECTREGISTRY_SOURCE} ${CONFIG_SOURCE})
230 TARGET_LINK_LIBRARIES(ep-engine_hash_table_test ${SNAPPY_LIBRARIES} platform)
231
232 ADD_EXECUTABLE(ep-engine_histo_test tests/module_tests/histo_test.cc)
233 ADD_EXECUTABLE(ep-engine_hrtime_test tests/module_tests/hrtime_test.cc)
234 TARGET_LINK_LIBRARIES(ep-engine_hrtime_test platform)
235
236 ADD_EXECUTABLE(ep-engine_misc_test tests/module_tests/misc_test.cc)
237 ADD_EXECUTABLE(ep-engine_mutex_test
238   tests/module_tests/mutex_test.cc src/testlogger.cc src/mutex.cc)
239 TARGET_LINK_LIBRARIES(ep-engine_mutex_test platform)
240
241 ADD_EXECUTABLE(ep-engine_priority_test  tests/module_tests/priority_test.cc
242                         src/priority.cc)
243 ADD_EXECUTABLE(ep-engine_ringbuffer_test tests/module_tests/ringbuffer_test.cc)
244
245 ADD_EXECUTABLE(ep-engine_failover_table_test tests/module_tests/failover_table_test.cc
246                         src/failover-table.cc src/mutex.cc src/testlogger.cc
247                         tests/module_tests/test_memory_tracker.cc
248                         ${OBJECTREGISTRY_SOURCE} ${CONFIG_SOURCE})
249 TARGET_LINK_LIBRARIES(ep-engine_failover_table_test cJSON platform)
250
251 ADD_TEST(ep-engine_atomic_ptr_test ep-engine_atomic_ptr_test)
252 ADD_TEST(ep-engine_atomic_test ep-engine_atomic_test)
253 ADD_TEST(ep-engine_checkpoint_test ep-engine_checkpoint_test)
254 ADD_TEST(ep-engine_chunk_creation_test ep-engine_chunk_creation_test)
255 ADD_TEST(ep-engine_ep_unit_tests ep-engine_ep_unit_tests)
256 ADD_TEST(ep-engine_failover_table_test ep-engine_failover_table_test)
257 ADD_TEST(ep-engine_hash_table_test ep-engine_hash_table_test)
258 ADD_TEST(ep-engine_histo_test ep-engine_histo_test)
259 ADD_TEST(ep-engine_hrtime_test ep-engine_hrtime_test)
260 ADD_TEST(ep-engine_misc_test ep-engine_misc_test)
261 ADD_TEST(ep-engine_mutex_test ep-engine_mutex_test)
262 ADD_TEST(ep-engine_priority_test ep-engine_priority_test)
263 ADD_TEST(ep-engine_ringbuffer_test ep-engine_ringbuffer_test)
264
265 ADD_LIBRARY(timing_tests SHARED tests/module_tests/timing_tests.cc)
266 SET_TARGET_PROPERTIES(timing_tests PROPERTIES PREFIX "")
267 TARGET_LINK_LIBRARIES(timing_tests platform)
268
269 ADD_EXECUTABLE(ep-engine_sizes src/sizes.cc src/mutex.h src/mutex.cc src/testlogger.cc
270               ${OBJECTREGISTRY_SOURCE} ${CONFIG_SOURCE})
271 TARGET_LINK_LIBRARIES(ep-engine_sizes platform)
272
273 ADD_LIBRARY(ep_testsuite SHARED
274    tests/ep_testsuite.cc
275    src/atomic.cc src/mutex.cc
276    src/item.cc src/testlogger.cc
277    src/ep_time.c
278    tests/mock/mock_dcp.cc
279    tests/ep_test_apis.cc ${OBJECTREGISTRY_SOURCE} ${CONFIG_SOURCE})
280 SET_TARGET_PROPERTIES(ep_testsuite PROPERTIES PREFIX "")
281 TARGET_LINK_LIBRARIES(ep_testsuite couchstore dirutils JSON_checker platform
282                       ${LIBEVENT_LIBRARIES} ${SNAPPY_LIBRARIES})
283
284
285 #ADD_CUSTOM_COMMAND(OUTPUT
286 #                     ${CMAKE_CURRENT_BINARY_DIR}/generated_suite_0.c
287 #                     ${CMAKE_CURRENT_BINARY_DIR}/generated_suite_1.c
288 #                     ${CMAKE_CURRENT_BINARY_DIR}/generated_suite_2.c
289 #                     ${CMAKE_CURRENT_BINARY_DIR}/generated_suite_3.c
290 #                     ${CMAKE_CURRENT_BINARY_DIR}/generated_suite_4.c
291 #                     ${CMAKE_CURRENT_BINARY_DIR}/generated_suite_5.c
292 #                     ${CMAKE_CURRENT_BINARY_DIR}/generated_suite_6.c
293 #                     ${CMAKE_CURRENT_BINARY_DIR}/generated_suite_7.c
294 #                     ${CMAKE_CURRENT_BINARY_DIR}/generated_suite_8.c
295 #                     ${CMAKE_CURRENT_BINARY_DIR}/generated_suite_9.c
296 #                  COMMAND
297 #                     ${PYTHON_EXECUTABLE} tests/module_tests/gen_engine_test.py
298 #                  DEPENDS
299 #                        tests/module_tests/gen_engine_test.py
300 #                        tests/module_tests/breakdancer.py
301 #                  COMMENT "Generating testsuite")
302 #
303 #ADD_LIBRARY(generated_testsuite SHARED
304 #            tests/suite_stubs.c
305 #            ${CMAKE_CURRENT_BINARY_DIR}/generated_suite_0.c
306 #            ${CMAKE_CURRENT_BINARY_DIR}/generated_suite_1.c
307 #            ${CMAKE_CURRENT_BINARY_DIR}/generated_suite_2.c
308 #            ${CMAKE_CURRENT_BINARY_DIR}/generated_suite_3.c
309 #            ${CMAKE_CURRENT_BINARY_DIR}/generated_suite_4.c
310 #            ${CMAKE_CURRENT_BINARY_DIR}/generated_suite_5.c
311 #            ${CMAKE_CURRENT_BINARY_DIR}/generated_suite_6.c
312 #            ${CMAKE_CURRENT_BINARY_DIR}/generated_suite_7.c
313 #            ${CMAKE_CURRENT_BINARY_DIR}/generated_suite_8.c
314 #            ${CMAKE_CURRENT_BINARY_DIR}/generated_suite_9.c)
315
316 #SET_TARGET_PROPERTIES(generated_testsuite PROPERTIES PREFIX "")
317
318 INSTALL(PROGRAMS
319         ${CMAKE_CURRENT_BINARY_DIR}/wrapper/cbadm-tap-registration
320         ${CMAKE_CURRENT_BINARY_DIR}/wrapper/cbepctl
321         ${CMAKE_CURRENT_BINARY_DIR}/wrapper/cbstats
322         ${CMAKE_CURRENT_BINARY_DIR}/wrapper/cbcompact
323         ${CMAKE_CURRENT_BINARY_DIR}/wrapper/cbvdiff
324         ${CMAKE_CURRENT_BINARY_DIR}/wrapper/cbvbucketctl
325         management/cbanalyze-core
326         DESTINATION bin)
327
328 INSTALL(PROGRAMS
329         management/cbadm-tap-registration
330         management/cbepctl
331         management/cbstats
332         management/cbcompact
333         management/cbvdiff
334         management/cbvbucketctl
335         DESTINATION lib/python)
336
337 INSTALL(FILES
338         management/clitool.py
339         management/mc_bin_client.py
340         management/mc_bin_server.py
341         management/memcacheConstants.py
342         management/tap.py
343         management/tap_example.py
344         DESTINATION lib/python)
345
346 INSTALL(TARGETS ep
347         RUNTIME DESTINATION lib/memcached
348         LIBRARY DESTINATION lib/memcached
349         ARCHIVE DESTINATION lib/memcached)
350
351 ADD_CUSTOM_TARGET(engine-tests
352                   COMMAND ${CMAKE_BINARY_DIR}/memcached/engine_testapp -E ep.so -T ep_testsuite.so -e "flushall_enabled=true;ht_size=13;ht_locks=7"
353                   VERBATIM)
354
355 ADD_TEST(ep-engine-engine-tests ${CMAKE_BINARY_DIR}/memcached/engine_testapp -E ep.so -T ep_testsuite.so -e "flushall_enabled=true;ht_size=13;ht_locks=7" )
356 # ADD_TEST(ep-engine-breakdancer-engine-tests ${CMAKE_BINARY_DIR}/memcached/engine_testapp -E ep.so -T generated_testsuite.so -e 'flushall_enabled=true;ht_size=13;ht_locks=7;backend=couchdb')
357
358 ADD_CUSTOM_TARGET(test-valgrind
359                   COMMAND valgrind --log-file=valgrind.log
360                                    --tool=Memcheck
361                                    --num-callers=50
362                                    --error-limit=yes
363                                    --track-origins=yes
364                                    --malloc-fill=55
365                                    --free-fill=aa
366                                    --dsymutil=yes -q
367                                    ${CMAKE_BINARY_DIR}/memcached/engine_testapp
368                                          -E ep.so
369                                          -T ep_testsuite.so
370                                          -e "flushall_enabled=true;ht_size=13;ht_locks=7"
371                   DEPENDS
372                         ${CMAKE_BINARY_DIR}/memcached/engine_testapp
373                         ep
374                         ep_testsuite
375                   VERBATIM)