CMakeLists.txt 8.0 KB
Newer Older
1 2 3 4 5 6 7
set(CC_TESTS_DIR
    ${PADDLE_BINARY_DIR}/test/cpp
    CACHE INTERNAL "c++ tests directory")
set(PYTHON_TESTS_DIR
    ${PADDLE_BINARY_DIR}/test
    CACHE INTERNAL "python tests directory")

8 9 10 11 12 13 14 15 16 17
function(py_test_modules TARGET_NAME)
  if(WITH_TESTING)
    set(options SERIAL)
    set(oneValueArgs "")
    set(multiValueArgs MODULES DEPS ENVS)
    cmake_parse_arguments(py_test_modules "${options}" "${oneValueArgs}"
                          "${multiValueArgs}" ${ARGN})

    if(WITH_COVERAGE AND NOT (WITH_INCREMENTAL_COVERAGE
                              AND "$ENV{PADDLE_GIT_DIFF_PY_FILE}" STREQUAL ""))
18 19 20 21 22 23 24 25 26
      add_test(
        NAME ${TARGET_NAME}
        COMMAND
          ${CMAKE_COMMAND} -E env PYTHONPATH=${PADDLE_BINARY_DIR}/python
          ${py_test_modules_ENVS}
          COVERAGE_FILE=${PADDLE_BINARY_DIR}/python-coverage.data
          ${PYTHON_EXECUTABLE} -m coverage run --branch -p
          ${PADDLE_SOURCE_DIR}/tools/test_runner.py ${py_test_modules_MODULES}
        WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
27
    else()
28 29 30 31 32 33 34
      add_test(
        NAME ${TARGET_NAME}
        COMMAND
          ${CMAKE_COMMAND} -E env PYTHONPATH=${PADDLE_BINARY_DIR}/python
          ${py_test_modules_ENVS} ${PYTHON_EXECUTABLE}
          ${PADDLE_SOURCE_DIR}/tools/test_runner.py ${py_test_modules_MODULES}
        WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
35 36 37 38 39 40 41 42 43 44 45
    endif()

    if(py_test_modules_SERIAL)
      set_property(TEST ${TARGET_NAME} PROPERTY RUN_SERIAL 1)
    endif()
    if(WIN32)
      set_tests_properties(${TARGET_NAME} PROPERTIES TIMEOUT 150)
    endif()
  endif()
endfunction()

46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
function(bash_test_modules TARGET_NAME)
  if(NOT WITH_TESTING)
    return()
  endif()

  set(options SERIAL)
  set(oneValueArgs TIMEOUT START_BASH)
  set(multiValueArgs DEPS ENVS LABELS)
  cmake_parse_arguments(bash_test_modules "${options}" "${oneValueArgs}"
                        "${multiValueArgs}" ${ARGN})

  set(timeout 350)
  if(${bash_test_modules_TIMEOUT})
    set(timeout ${bash_test_modules_TIMEOUT})
  endif()

  if(WITH_COVERAGE)
    add_test(
      NAME ${TARGET_NAME}
      COMMAND
        ${CMAKE_COMMAND} -E env PYTHONPATH=${PADDLE_BINARY_DIR}/python
        TEST_TARGET_NAME=${TARGET_NAME} TEST_TIMEOUT=${timeout}
        ${bash_test_modules_ENVS} WITH_COVERAGE=ON
        COVERAGE_FILE=${PADDLE_BINARY_DIR}/python-coverage.data bash
        ${CMAKE_CURRENT_BINARY_DIR}/${bash_test_modules_START_BASH}
      WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
  else()
    add_test(
      NAME ${TARGET_NAME}
      COMMAND
        ${CMAKE_COMMAND} -E env PYTHONPATH=${PADDLE_BINARY_DIR}/python
        TEST_TARGET_NAME=${TARGET_NAME} TEST_TIMEOUT=${timeout}
        ${bash_test_modules_ENVS} bash
        ${CMAKE_CURRENT_BINARY_DIR}/${bash_test_modules_START_BASH}
      WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
  endif()

  if(bash_test_modules_SERIAL)
    set_property(TEST ${TARGET_NAME} PROPERTY RUN_SERIAL 1)
  endif()

  if(bash_test_modules_LABELS)
    set_tests_properties(${TARGET_NAME} PROPERTIES LABELS
                                                   ${bash_test_modules_LABELS})
  endif()
endfunction()

93
if(WITH_TESTING)
94
  if(WITH_CINN)
95
    add_subdirectory(cpp/cinn)
96 97
  endif()
  if(CINN_ONLY)
98 99 100
    add_subdirectory(cinn)
    return()
  endif()
101
  add_subdirectory(amp)
G
gouzil 已提交
102
  add_subdirectory(asp)
G
gouzil 已提交
103
  add_subdirectory(autograd)
104
  add_subdirectory(book)
105
  # add_subdirectory(composite_ops)
106
  add_subdirectory(contrib)
Z
Zheng-Bicheng 已提交
107
  add_subdirectory(cpp)
Z
Zheng-Bicheng 已提交
108
  add_subdirectory(custom_kernel)
109
  add_subdirectory(custom_op)
110
  add_subdirectory(custom_runtime)
K
Kim 已提交
111
  add_subdirectory(dataset)
112
  add_subdirectory(cpp_extension)
T
tianshuo78520a 已提交
113 114 115 116 117 118 119
  if(WITH_DISTRIBUTE)
    add_subdirectory(collective)
    add_subdirectory(auto_parallel)
    add_subdirectory(distributed_passes)
    add_subdirectory(ps)
  endif()
  add_subdirectory(distribution)
120
  add_subdirectory(dygraph_to_static)
K
Kai Xing 已提交
121 122 123
  if(NOT WIN32 OR NOT WITH_GPU)
    add_subdirectory(fft)
  endif()
Z
Zheng-Bicheng 已提交
124
  # add_subdirectory(fleet)
G
gouzil 已提交
125 126 127
  if(WITH_IPU)
    add_subdirectory(ipu)
  endif()
T
tianshuo78520a 已提交
128
  add_subdirectory(ir)
Z
Zheng-Bicheng 已提交
129
  add_subdirectory(legacy_test)
130 131 132
  if(WITH_MKLDNN)
    add_subdirectory(mkldnn)
  endif()
Z
Zheng-Bicheng 已提交
133
  add_subdirectory(prim)
Z
Zheng-Bicheng 已提交
134
  add_subdirectory(quantization)
L
liulinduo 已提交
135
  add_subdirectory(rnn)
Z
Zheng-Bicheng 已提交
136
  add_subdirectory(rpc)
T
tianshuo78520a 已提交
137
  add_subdirectory(sequence)
138
  add_subdirectory(standalone_executor)
139
  add_subdirectory(tokenizer)
140
  # add_subdirectory(white_list)
R
RedContritio 已提交
141 142 143
  if(WITH_XPU)
    add_subdirectory(xpu)
  endif()
144
endif()
145

146 147 148 149 150 151 152 153 154
if(WITH_CPP_DIST)
  add_test(NAME test_paddle_lib
           COMMAND ${PADDLE_BINARY_DIR}/test/paddle_lib/test_paddle_lib)
  if(WITH_GPU)
    add_test(NAME test_paddle_lib_gpu
             COMMAND ${PADDLE_BINARY_DIR}/test/paddle_lib/test_paddle_lib_gpu)
  endif()
endif()

155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
get_property(test_srcs GLOBAL PROPERTY TEST_SRCS)
get_property(test_names GLOBAL PROPERTY TEST_NAMES)

get_property(paddle_lib GLOBAL PROPERTY PADDLE_LIB_NAME)

set(POSTFIX ".so")
if(WIN32)
  set(POSTFIX ".dll")
endif()

list(LENGTH test_names len)
if(${len} GREATER_EQUAL 1)
  message("Total cpp tests using dynamic link: ${len}")
  math(EXPR stop "${len} - 1")
  foreach(idx RANGE ${stop})
    if(WITH_TESTING)
      list(GET test_srcs ${idx} test_src)
      list(GET test_names ${idx} test_name)
      get_property(test_arg GLOBAL PROPERTY "${test_name}_ARGS")
      # message("add test ${test_name}")
      add_executable(${test_name} ${test_src})
      target_link_libraries(${test_name} paddle_gtest_main_new)
      target_link_libraries(${test_name} $<TARGET_LINKER_FILE:${paddle_lib}>)
178 179 180
      if(WITH_SHARED_PHI)
        target_link_libraries(${test_name} $<TARGET_LINKER_FILE:phi>)
      endif()
181 182 183
      if(WITH_SHARED_IR)
        target_link_libraries(${test_name} $<TARGET_LINKER_FILE:ir>)
      endif()
184 185 186 187 188 189 190 191 192
      add_dependencies(${test_name} ${paddle_lib} paddle_gtest_main_new)
      if(WITH_GPU)
        target_link_libraries(${test_name} ${CUDA_CUDART_LIBRARY}
                              "-Wl,--as-needed")
      endif()
      if(WITH_ROCM)
        target_link_libraries(${test_name} ${ROCM_HIPRTC_LIB})
      endif()
      if(APPLE)
193 194
        target_link_libraries(
          ${test_name}
195
          "-Wl,-rpath,$<TARGET_FILE_DIR:${paddle_lib}> -Wl,-rpath,$<TARGET_FILE_DIR:phi> -Wl,-rpath,$<TARGET_FILE_DIR:ir>"
196
        )
197 198 199 200 201 202 203
      endif()
      if(NOT ((NOT WITH_PYTHON) AND ON_INFER))
        target_link_libraries(${test_name} ${PYTHON_LIBRARIES})
      endif()
      if(WITH_XPU)
        target_link_libraries(${test_name} xpulib)
      endif()
K
Kim Yann 已提交
204 205 206 207 208 209 210 211
      cc_test_run(
        ${test_name}
        COMMAND
        ${test_name}
        ARGS
        ${test_arg}
        DIR
        ${CC_TESTS_DIR})
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228
    elseif(WITH_TESTING AND NOT TEST ${test_name})
      add_test(NAME ${test_name} COMMAND ${CMAKE_COMMAND} -E echo CI skip
                                         ${test_name}.)
    endif()
    set_target_properties(${test_name} PROPERTIES RUNTIME_OUTPUT_DIRECTORY
                                                  "${CC_TESTS_DIR}")
  endforeach()
endif()

# set properties for some tests, it should be set after the tests defined.
if(TARGET standalone_executor_test)
  set_tests_properties(standalone_executor_test PROPERTIES TIMEOUT 100)
  if(NOT WIN32)
    add_dependencies(standalone_executor_test download_program)
  endif()
endif()

229 230 231 232 233 234 235 236
if(TARGET standalone_executor_new_ir_test)
  if(NOT WIN32)
    set_tests_properties(
      standalone_executor_new_ir_test
      PROPERTIES ENVIRONMENT "FLAGS_enable_new_ir_in_executor=true")
  endif()
endif()

237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257
if(TARGET layer_test)
  add_dependencies(layer_test jit_download_program)
  add_dependencies(layer_test_new jit_download_program)
  set_tests_properties(layer_test_new PROPERTIES ENVIRONMENT
                                                 "FLAGS_jit_engine_type=New")
endif()

if(TEST buddy_allocator_test)
  if(NOT WIN32)
    add_dependencies(buddy_allocator_test download_data)
  endif()
  set_tests_properties(buddy_allocator_test PROPERTIES LABELS
                                                       "RUN_TYPE=EXCLUSIVE")
endif()

add_custom_target(build_tests)

# add target to build all cpp tests
if(${len} GREATER_EQUAL 1)
  add_dependencies(build_tests ${test_names})
endif()