CMakeLists.txt 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. #
  2. # Licensed to the Apache Software Foundation (ASF) under one
  3. # or more contributor license agreements. See the NOTICE file
  4. # distributed with this work for additional information
  5. # regarding copyright ownership. The ASF licenses this file
  6. # to you under the Apache License, Version 2.0 (the
  7. # "License"); you may not use this file except in compliance
  8. # with the License. You may obtain a copy of the License at
  9. #
  10. # http://www.apache.org/licenses/LICENSE-2.0
  11. #
  12. # Unless required by applicable law or agreed to in writing, software
  13. # distributed under the License is distributed on an "AS IS" BASIS,
  14. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. # See the License for the specific language governing permissions and
  16. # limitations under the License.
  17. #
  18. find_package(Boost REQUIRED COMPONENTS date_time)
  19. # Delegate some functionality to libhdfs, until libhdfspp is complete.
  20. set (LIBHDFS_SRC_DIR ../../libhdfs)
  21. set (LIBHDFS_TESTS_DIR ../../libhdfs-tests)
  22. set (LIBHDFSPP_SRC_DIR ..)
  23. set (LIBHDFSPP_LIB_DIR ${LIBHDFSPP_SRC_DIR}/lib)
  24. set (LIBHDFSPP_BINDING_C ${LIBHDFSPP_LIB_DIR}/bindings/c)
  25. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-missing-field-initializers")
  26. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-missing-field-initializers")
  27. include_directories(
  28. ${GENERATED_JAVAH}
  29. ${CMAKE_CURRENT_LIST_DIR}
  30. ${CMAKE_BINARY_DIR}
  31. ${JNI_INCLUDE_DIRS}
  32. ${LIBHDFS_SRC_DIR}/include
  33. ${LIBHDFS_SRC_DIR}/..
  34. ${LIBHDFS_SRC_DIR}
  35. ${OS_DIR}
  36. )
  37. add_library(test_common_obj OBJECT mock_connection.cc)
  38. add_library(test_common $<TARGET_OBJECTS:test_common_obj>)
  39. set(PROTOBUF_IMPORT_DIRS ${PROTO_HADOOP_TEST_DIR})
  40. protobuf_generate_cpp(PROTO_TEST_SRCS PROTO_TEST_HDRS
  41. ${PROTO_HADOOP_TEST_DIR}/test.proto
  42. ${PROTO_HADOOP_TEST_DIR}/test_rpc_service.proto
  43. )
  44. # Shamelessly stolen from
  45. # http://stackoverflow.com/questions/9303711/how-do-i-make-ctest-run-a-program-with-valgrind-without-dart
  46. function(add_memcheck_test name binary)
  47. add_test(${name} ${binary} ${ARGN})
  48. if(NOT MEMORYCHECK_COMMAND MATCHES "MEMORYCHECK_COMMAND-NOTFOUND" AND NOT SKIP_VALGRIND)
  49. set(memcheck_command "${MEMORYCHECK_COMMAND} ${MEMORYCHECK_COMMAND_OPTIONS}")
  50. separate_arguments(memcheck_command)
  51. add_test(memcheck_${name} ${memcheck_command} ./${binary} ${ARGN})
  52. endif()
  53. endfunction(add_memcheck_test)
  54. #
  55. #
  56. # UNIT TESTS - TEST SELECTED PARTS OF THE LIBRARY
  57. #
  58. #
  59. add_subdirectory(x-platform)
  60. add_subdirectory(utils)
  61. add_subdirectory(tools)
  62. add_executable(uri_test uri_test.cc)
  63. target_link_libraries(uri_test common gmock_main ${CMAKE_THREAD_LIBS_INIT})
  64. add_memcheck_test(uri uri_test)
  65. add_executable(remote_block_reader_test remote_block_reader_test.cc)
  66. target_link_libraries(remote_block_reader_test test_common reader proto common connection ${PROTOBUF_LIBRARIES} ${OPENSSL_LIBRARIES} gmock_main ${CMAKE_THREAD_LIBS_INIT})
  67. add_memcheck_test(remote_block_reader remote_block_reader_test)
  68. add_executable(sasl_digest_md5_test sasl_digest_md5_test.cc)
  69. target_link_libraries(sasl_digest_md5_test common ${PROTOBUF_LIBRARIES} ${OPENSSL_LIBRARIES} gmock_main ${CMAKE_THREAD_LIBS_INIT})
  70. add_memcheck_test(sasl_digest_md5 sasl_digest_md5_test)
  71. add_executable(retry_policy_test retry_policy_test.cc)
  72. target_link_libraries(retry_policy_test common gmock_main ${CMAKE_THREAD_LIBS_INIT})
  73. add_memcheck_test(retry_policy retry_policy_test)
  74. include_directories(${CMAKE_CURRENT_BINARY_DIR})
  75. add_executable(rpc_engine_test rpc_engine_test.cc ${PROTO_TEST_SRCS} ${PROTO_TEST_HDRS})
  76. target_link_libraries(rpc_engine_test test_common rpc proto common ${PROTOBUF_LIBRARIES} ${OPENSSL_LIBRARIES} ${SASL_LIBRARIES} gmock_main ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES})
  77. add_memcheck_test(rpc_engine rpc_engine_test)
  78. add_executable(bad_datanode_test bad_datanode_test.cc)
  79. target_link_libraries(bad_datanode_test rpc reader proto fs bindings_c rpc proto common reader connection ${PROTOBUF_LIBRARIES} ${OPENSSL_LIBRARIES} ${SASL_LIBRARIES} gmock_main ${CMAKE_THREAD_LIBS_INIT})
  80. add_memcheck_test(bad_datanode bad_datanode_test)
  81. add_executable(node_exclusion_test node_exclusion_test.cc)
  82. target_link_libraries(node_exclusion_test fs gmock_main common ${PROTOBUF_LIBRARIES} ${OPENSSL_LIBRARIES} ${SASL_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
  83. add_memcheck_test(node_exclusion node_exclusion_test)
  84. add_executable(configuration_test $<TARGET_OBJECTS:test_utils> configuration_test.cc)
  85. target_include_directories(configuration_test PRIVATE ../lib)
  86. target_link_libraries(configuration_test common gmock_main ${CMAKE_THREAD_LIBS_INIT})
  87. add_memcheck_test(configuration configuration_test)
  88. add_executable(hdfs_configuration_test $<TARGET_OBJECTS:test_utils> hdfs_configuration_test.cc)
  89. target_include_directories(hdfs_configuration_test PRIVATE ../lib)
  90. target_link_libraries(hdfs_configuration_test common gmock_main ${CMAKE_THREAD_LIBS_INIT})
  91. add_memcheck_test(hdfs_configuration hdfs_configuration_test)
  92. add_executable(hdfspp_errors_test hdfspp_errors.cc)
  93. target_link_libraries(hdfspp_errors_test common gmock_main bindings_c fs rpc proto common reader connection ${PROTOBUF_LIBRARIES} ${OPENSSL_LIBRARIES} ${SASL_LIBRARIES} gmock_main ${CMAKE_THREAD_LIBS_INIT})
  94. add_memcheck_test(hdfspp_errors hdfspp_errors_test)
  95. add_executable(hdfs_builder_test $<TARGET_OBJECTS:test_utils> hdfs_builder_test.cc)
  96. target_include_directories(hdfs_builder_test PRIVATE ../lib)
  97. target_link_libraries(hdfs_builder_test test_common gmock_main bindings_c fs rpc proto common reader connection ${PROTOBUF_LIBRARIES} ${OPENSSL_LIBRARIES} ${SASL_LIBRARIES} gmock_main ${CMAKE_THREAD_LIBS_INIT})
  98. add_memcheck_test(hdfs_builder_test hdfs_builder_test)
  99. add_executable(logging_test logging_test.cc $<TARGET_OBJECTS:x_platform_obj>)
  100. target_include_directories(logging_test PRIVATE ../lib)
  101. target_link_libraries(logging_test common gmock_main bindings_c fs rpc proto common reader connection ${PROTOBUF_LIBRARIES} ${OPENSSL_LIBRARIES} ${SASL_LIBRARIES} gmock_main ${CMAKE_THREAD_LIBS_INIT})
  102. add_memcheck_test(logging_test logging_test)
  103. add_executable(hdfs_ioservice_test hdfs_ioservice_test.cc)
  104. target_link_libraries(hdfs_ioservice_test fs gmock_main common ${PROTOBUF_LIBRARIES} ${OPENSSL_LIBRARIES} ${SASL_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
  105. add_memcheck_test(hdfs_ioservice hdfs_ioservice_test)
  106. add_executable(user_lock_test user_lock_test.cc)
  107. target_link_libraries(user_lock_test fs gmock_main common ${PROTOBUF_LIBRARIES} ${OPENSSL_LIBRARIES} ${SASL_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
  108. add_memcheck_test(user_lock user_lock_test)
  109. add_executable(hdfs_config_connect_bugs_test $<TARGET_OBJECTS:test_utils> hdfs_config_connect_bugs.cc)
  110. target_include_directories(hdfs_config_connect_bugs_test PRIVATE ../lib)
  111. target_link_libraries(hdfs_config_connect_bugs_test common gmock_main bindings_c fs rpc proto common reader connection ${PROTOBUF_LIBRARIES} ${OPENSSL_LIBRARIES} ${SASL_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
  112. add_memcheck_test(hdfs_config_connect_bugs hdfs_config_connect_bugs_test)
  113. #
  114. #
  115. # INTEGRATION TESTS - TESTS THE FULL LIBRARY AGAINST ACTUAL SERVERS
  116. #
  117. #
  118. # This test requires a great deal of Hadoop Java infrastructure to run.
  119. #
  120. if(HADOOP_BUILD)
  121. include_directories (
  122. #TODO: Put this in a variable up top and pull it out here
  123. ${CMAKE_CURRENT_SOURCE_DIR}/../../libhdfs-tests/
  124. )
  125. add_library(hdfspp_test_shim_static STATIC $<TARGET_OBJECTS:x_platform_obj> hdfs_shim.c libhdfs_wrapper.c libhdfspp_wrapper.cc)
  126. add_dependencies(hdfspp_test_shim_static proto)
  127. add_library(hdfspp_test_static STATIC $<TARGET_OBJECTS:x_platform_obj> ${LIBHDFSPP_BINDING_C}/hdfs.cc)
  128. add_dependencies(hdfspp_test_static proto)
  129. # TODO: get all of the mini dfs library bits here in one place
  130. # add_library(hdfspp_mini_cluster native_mini_dfs ${JAVA_JVM_LIBRARY} )
  131. #TODO: Link against full library rather than just parts
  132. build_libhdfs_test(libhdfs_threaded hdfspp_test_shim_static expect.c test_libhdfs_threaded.c ${OS_DIR}/thread.c)
  133. link_libhdfs_test(libhdfs_threaded hdfspp_test_shim_static fs reader rpc proto common connection ${PROTOBUF_LIBRARIES} ${OPENSSL_LIBRARIES} native_mini_dfs ${JAVA_JVM_LIBRARY} ${SASL_LIBRARIES} )
  134. add_libhdfs_test (libhdfs_threaded hdfspp_test_shim_static)
  135. build_libhdfs_test(hdfspp_mini_dfs_smoke hdfspp_test_shim_static ${CMAKE_CURRENT_LIST_DIR}/hdfspp_mini_dfs_smoke.cc)
  136. link_libhdfs_test (hdfspp_mini_dfs_smoke hdfspp_test_shim_static fs reader rpc proto common connection gmock_main ${PROTOBUF_LIBRARIES} ${OPENSSL_LIBRARIES} native_mini_dfs ${JAVA_JVM_LIBRARY} ${SASL_LIBRARIES})
  137. add_libhdfs_test (hdfspp_mini_dfs_smoke hdfspp_test_shim_static)
  138. if (NOT MSVC)
  139. build_libhdfs_test(libhdfs_mini_stress_valgrind hdfspp_test_static expect.c test_libhdfs_mini_stress.c ${OS_DIR}/thread.c)
  140. link_libhdfs_test(libhdfs_mini_stress_valgrind hdfspp_test_static fs reader rpc proto common connection ${PROTOBUF_LIBRARIES} ${OPENSSL_LIBRARIES} native_mini_dfs ${JAVA_JVM_LIBRARY} ${SASL_LIBRARIES})
  141. add_memcheck_test(libhdfs_mini_stress_valgrind_hdfspp_test_static libhdfs_mini_stress_valgrind_hdfspp_test_static)
  142. set_target_properties(libhdfs_mini_stress_valgrind_hdfspp_test_static PROPERTIES COMPILE_DEFINITIONS "VALGRIND")
  143. endif (NOT MSVC)
  144. build_libhdfs_test(libhdfs_mini_stress hdfspp_test_shim_static expect.c test_libhdfs_mini_stress.c ${OS_DIR}/thread.c)
  145. link_libhdfs_test(libhdfs_mini_stress hdfspp_test_shim_static fs reader rpc proto common connection ${PROTOBUF_LIBRARIES} ${OPENSSL_LIBRARIES} native_mini_dfs ${JAVA_JVM_LIBRARY} ${SASL_LIBRARIES})
  146. add_libhdfs_test(libhdfs_mini_stress hdfspp_test_shim_static)
  147. build_libhdfs_test(hdfs_ext hdfspp_test_shim_static ${CMAKE_CURRENT_LIST_DIR}/hdfs_ext_test.cc)
  148. link_libhdfs_test (hdfs_ext hdfspp_test_shim_static hdfspp_static gmock_main native_mini_dfs ${JAVA_JVM_LIBRARY} ${SASL_LIBRARIES})
  149. add_libhdfs_test (hdfs_ext hdfspp_test_shim_static)
  150. #build_libhdfs_test(hdfs_config_connect_bugs hdfspp_test_shim_static ${CMAKE_CURRENT_LIST_DIR}/hdfs_config_connect_bugs.cc)
  151. #link_libhdfs_test (hdfs_config_connect_bugs hdfspp_test_shim_static hdfspp_static gmock_main native_mini_dfs ${JAVA_JVM_LIBRARY} ${SASL_LIBRARIES})
  152. #add_libhdfs_test (hdfs_config_connect_bugs hdfspp_test_shim_static)
  153. endif(HADOOP_BUILD)