CMakeLists.txt 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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. # Delegate some functionality to libhdfs, until libhdfspp is complete.
  19. set (LIBHDFS_SRC_DIR ../../libhdfs)
  20. set (LIBHDFS_TESTS_DIR ../../libhdfs-tests)
  21. set (LIBHDFSPP_SRC_DIR ..)
  22. set (LIBHDFSPP_LIB_DIR ${LIBHDFSPP_SRC_DIR}/lib)
  23. set (LIBHDFSPP_BINDING_C ${LIBHDFSPP_LIB_DIR}/bindings/c)
  24. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-missing-field-initializers")
  25. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-missing-field-initializers")
  26. include_directories(
  27. ${GENERATED_JAVAH}
  28. ${CMAKE_CURRENT_LIST_DIR}
  29. ${CMAKE_BINARY_DIR}
  30. ${JNI_INCLUDE_DIRS}
  31. ${LIBHDFS_SRC_DIR}/include
  32. ${LIBHDFS_SRC_DIR}/..
  33. ${LIBHDFS_SRC_DIR}
  34. ${OS_DIR}
  35. )
  36. add_library(test_common_obj OBJECT mock_connection.cc)
  37. add_library(test_common $<TARGET_OBJECTS:test_common_obj>)
  38. set(PROTOBUF_IMPORT_DIRS ${PROTO_HADOOP_TEST_DIR})
  39. protobuf_generate_cpp(PROTO_TEST_SRCS PROTO_TEST_HDRS
  40. ${PROTO_HADOOP_TEST_DIR}/test.proto
  41. ${PROTO_HADOOP_TEST_DIR}/test_rpc_service.proto
  42. )
  43. # Shamelessly stolen from
  44. # http://stackoverflow.com/questions/9303711/how-do-i-make-ctest-run-a-program-with-valgrind-without-dart
  45. function(add_memcheck_test name binary)
  46. add_test(${name} ${binary} ${ARGN})
  47. if(NOT MEMORYCHECK_COMMAND MATCHES "MEMORYCHECK_COMMAND-NOTFOUND" AND NOT SKIP_VALGRIND)
  48. set(memcheck_command "${MEMORYCHECK_COMMAND} ${MEMORYCHECK_COMMAND_OPTIONS}")
  49. separate_arguments(memcheck_command)
  50. add_test(memcheck_${name} ${memcheck_command} ./${binary} ${ARGN})
  51. endif()
  52. endfunction(add_memcheck_test)
  53. #
  54. #
  55. # UNIT TESTS - TEST SELECTED PARTS OF THE LIBRARY
  56. #
  57. #
  58. add_executable(uri_test uri_test.cc)
  59. target_link_libraries(uri_test common gmock_main ${CMAKE_THREAD_LIBS_INIT})
  60. add_memcheck_test(uri uri_test)
  61. add_executable(remote_block_reader_test remote_block_reader_test.cc)
  62. target_link_libraries(remote_block_reader_test test_common reader proto common connection ${PROTOBUF_LIBRARIES} ${OPENSSL_LIBRARIES} gmock_main ${CMAKE_THREAD_LIBS_INIT})
  63. add_memcheck_test(remote_block_reader remote_block_reader_test)
  64. add_executable(sasl_digest_md5_test sasl_digest_md5_test.cc)
  65. target_link_libraries(sasl_digest_md5_test common ${PROTOBUF_LIBRARIES} ${OPENSSL_LIBRARIES} gmock_main ${CMAKE_THREAD_LIBS_INIT})
  66. add_memcheck_test(sasl_digest_md5 sasl_digest_md5_test)
  67. add_executable(retry_policy_test retry_policy_test.cc)
  68. target_link_libraries(retry_policy_test common gmock_main ${CMAKE_THREAD_LIBS_INIT})
  69. add_memcheck_test(retry_policy retry_policy_test)
  70. include_directories(${CMAKE_CURRENT_BINARY_DIR})
  71. add_executable(rpc_engine_test rpc_engine_test.cc ${PROTO_TEST_SRCS} ${PROTO_TEST_HDRS})
  72. target_link_libraries(rpc_engine_test test_common rpc proto common ${PROTOBUF_LIBRARIES} ${OPENSSL_LIBRARIES} ${SASL_LIBRARIES} gmock_main ${CMAKE_THREAD_LIBS_INIT})
  73. add_memcheck_test(rpc_engine rpc_engine_test)
  74. add_executable(bad_datanode_test bad_datanode_test.cc)
  75. 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})
  76. add_memcheck_test(bad_datanode bad_datanode_test)
  77. add_executable(node_exclusion_test node_exclusion_test.cc)
  78. target_link_libraries(node_exclusion_test fs gmock_main common ${PROTOBUF_LIBRARIES} ${OPENSSL_LIBRARIES} ${SASL_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
  79. add_memcheck_test(node_exclusion node_exclusion_test)
  80. add_executable(configuration_test configuration_test.cc)
  81. target_link_libraries(configuration_test common gmock_main ${CMAKE_THREAD_LIBS_INIT})
  82. add_memcheck_test(configuration configuration_test)
  83. add_executable(hdfs_configuration_test hdfs_configuration_test.cc)
  84. target_link_libraries(hdfs_configuration_test common gmock_main ${CMAKE_THREAD_LIBS_INIT})
  85. add_memcheck_test(hdfs_configuration hdfs_configuration_test)
  86. add_executable(hdfspp_errors_test hdfspp_errors.cc)
  87. 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})
  88. add_memcheck_test(hdfspp_errors hdfspp_errors_test)
  89. add_executable(hdfs_builder_test hdfs_builder_test.cc)
  90. 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})
  91. add_memcheck_test(hdfs_builder_test hdfs_builder_test)
  92. add_executable(logging_test logging_test.cc)
  93. 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})
  94. add_memcheck_test(logging_test logging_test)
  95. add_executable(hdfs_ioservice_test hdfs_ioservice_test.cc)
  96. target_link_libraries(hdfs_ioservice_test fs gmock_main common ${PROTOBUF_LIBRARIES} ${OPENSSL_LIBRARIES} ${SASL_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
  97. add_memcheck_test(hdfs_ioservice hdfs_ioservice_test)
  98. add_executable(user_lock_test user_lock_test.cc)
  99. target_link_libraries(user_lock_test fs gmock_main common ${PROTOBUF_LIBRARIES} ${OPENSSL_LIBRARIES} ${SASL_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
  100. add_memcheck_test(user_lock user_lock_test)
  101. add_executable(hdfs_config_connect_bugs_test hdfs_config_connect_bugs.cc)
  102. 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})
  103. add_memcheck_test(hdfs_config_connect_bugs hdfs_config_connect_bugs_test)
  104. #
  105. #
  106. # INTEGRATION TESTS - TESTS THE FULL LIBRARY AGAINST ACTUAL SERVERS
  107. #
  108. #
  109. # This test requires a great deal of Hadoop Java infrastructure to run.
  110. #
  111. if(HADOOP_BUILD)
  112. include_directories (
  113. #TODO: Put this in a variable up top and pull it out here
  114. ${CMAKE_CURRENT_SOURCE_DIR}/../../libhdfs-tests/
  115. )
  116. add_library(hdfspp_test_shim_static STATIC hdfs_shim.c libhdfs_wrapper.c libhdfspp_wrapper.cc ${LIBHDFSPP_BINDING_C}/hdfs.cc)
  117. add_library(hdfspp_test_static STATIC ${LIBHDFSPP_BINDING_C}/hdfs.cc)
  118. # Add dependencies
  119. add_dependencies(hdfspp_test_shim_static proto)
  120. add_dependencies(hdfspp_test_static proto)
  121. # TODO: get all of the mini dfs library bits here in one place
  122. # add_library(hdfspp_mini_cluster native_mini_dfs ${JAVA_JVM_LIBRARY} )
  123. #TODO: Link against full library rather than just parts
  124. build_libhdfs_test(libhdfs_threaded hdfspp_test_shim_static expect.c test_libhdfs_threaded.c ${OS_DIR}/thread.c)
  125. 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} )
  126. add_libhdfs_test (libhdfs_threaded hdfspp_test_shim_static)
  127. build_libhdfs_test(hdfspp_mini_dfs_smoke hdfspp_test_shim_static ${CMAKE_CURRENT_LIST_DIR}/hdfspp_mini_dfs_smoke.cc)
  128. 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})
  129. add_libhdfs_test (hdfspp_mini_dfs_smoke hdfspp_test_shim_static)
  130. build_libhdfs_test(libhdfs_mini_stress_valgrind hdfspp_test_static expect.c test_libhdfs_mini_stress.c ${OS_DIR}/thread.c)
  131. 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})
  132. add_memcheck_test(libhdfs_mini_stress_valgrind_hdfspp_test_static libhdfs_mini_stress_valgrind_hdfspp_test_static)
  133. set_target_properties(libhdfs_mini_stress_valgrind_hdfspp_test_static PROPERTIES COMPILE_DEFINITIONS "VALGRIND")
  134. build_libhdfs_test(libhdfs_mini_stress hdfspp_test_shim_static expect.c test_libhdfs_mini_stress.c ${OS_DIR}/thread.c)
  135. 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})
  136. add_libhdfs_test(libhdfs_mini_stress hdfspp_test_shim_static)
  137. build_libhdfs_test(hdfs_ext hdfspp_test_shim_static ${CMAKE_CURRENT_LIST_DIR}/hdfs_ext_test.cc)
  138. link_libhdfs_test (hdfs_ext hdfspp_test_shim_static hdfspp_static gmock_main native_mini_dfs ${JAVA_JVM_LIBRARY} ${SASL_LIBRARIES})
  139. add_libhdfs_test (hdfs_ext hdfspp_test_shim_static)
  140. #build_libhdfs_test(hdfs_config_connect_bugs hdfspp_test_shim_static ${CMAKE_CURRENT_LIST_DIR}/hdfs_config_connect_bugs.cc)
  141. #link_libhdfs_test (hdfs_config_connect_bugs hdfspp_test_shim_static hdfspp_static gmock_main native_mini_dfs ${JAVA_JVM_LIBRARY} ${SASL_LIBRARIES})
  142. #add_libhdfs_test (hdfs_config_connect_bugs hdfspp_test_shim_static)
  143. endif(HADOOP_BUILD)