| 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, |
| 13 |
# software distributed under the License is distributed on an |
| 14 |
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 |
# KIND, either express or implied. See the License for the |
| 16 |
# specific language governing permissions and limitations |
| 17 |
# under the License. |
| 18 |
# |
| 19 |
|
| 20 |
configure_file(test_config.h.in test_config.h) |
| 21 |
include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_SOURCE_DIR}/tests/include) |
| 22 |
if (WIN32) |
| 23 |
set(test_env "PATH=$<TARGET_FILE_DIR:qpid-proton-core>") |
| 24 |
else() |
| 25 |
set(test_env "") |
| 26 |
set(platform_test_src ssl_test.cpp) |
| 27 |
endif() |
| 28 |
|
| 29 |
# NOTE: C library tests are written in C++ using the Catch2 framework. |
| 30 |
# The tests are more concise than with a native C framework and we can |
| 31 |
# use the same framework for C++ tests. |
| 32 |
# See https://github.com/catchorg/Catch2/blob/v2.x/docs/tutorial.md for more. |
| 33 |
# |
| 34 |
# ${CMAKE_SOURCE_DIR}/include/tests/catch_extra.cpp has some general extensions to catch. |
| 35 |
# ./pn_test.hpp contains proton-C specific code to help with testing. |
| 36 |
# |
| 37 |
# Tests for each library are combined in a single executable. |
| 38 |
|
| 39 |
if (CMAKE_CXX_COMPILER) |
| 40 |
|
| 41 |
add_library(test_main OBJECT test_main.cpp) |
| 42 |
set_target_properties(test_main PROPERTIES |
| 43 |
COMPILE_FLAGS "${CXX_STANDARD} ${CMAKE_CXX_FLAGS} ${CXX_WARNING_FLAGS} ${LTO}") |
| 44 |
|
| 45 |
macro(add_c_test exe) |
| 46 |
add_executable(${exe} $<TARGET_OBJECTS:test_main> pn_test.cpp ${ARGN}) |
| 47 |
set_target_properties(${exe} PROPERTIES |
| 48 |
COMPILE_FLAGS "${CXX_STANDARD} ${CMAKE_CXX_FLAGS} ${CXX_WARNING_FLAGS} ${LTO}" |
| 49 |
LINK_FLAGS "${CATCH_UNDEFINED} ${LINK_LTO}") |
| 50 |
pn_add_test( |
| 51 |
EXECUTABLE |
| 52 |
NAME ${exe} |
| 53 |
PREPEND_ENVIRONMENT ${test_env} |
| 54 |
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} |
| 55 |
COMMAND $<TARGET_FILE:${exe}>) |
| 56 |
endmacro() |
| 57 |
|
| 58 |
## Tests that depend only on qpid-proton-core |
| 59 |
add_c_test(c-core-test |
| 60 |
pn_test_test.cpp |
| 61 |
object_test.cpp |
| 62 |
event_test.cpp |
| 63 |
message_test.cpp |
| 64 |
condition_test.cpp |
| 65 |
connection_driver_test.cpp |
| 66 |
data_test.cpp |
| 67 |
engine_test.cpp |
| 68 |
refcount_test.cpp |
| 69 |
${platform_test_src}) |
| 70 |
|
| 71 |
target_link_libraries(c-core-test qpid-proton-core ${PLATFORM_LIBS}) |
| 72 |
|
| 73 |
## Tests for the deprecated "extra" part of the qpid-proton library. |
| 74 |
add_c_test(c-extra-test url_test.cpp) |
| 75 |
target_link_libraries(c-extra-test qpid-proton ${PLATFORM_LIBS}) |
| 76 |
|
| 77 |
if(HAS_PROACTOR) |
| 78 |
# Tests for qpid-proton-proactor |
| 79 |
add_c_test(c-proactor-test pn_test_proactor.cpp proactor_test.cpp) |
| 80 |
target_link_libraries(c-proactor-test qpid-proton-core qpid-proton-proactor ${PLATFORM_LIBS}) |
| 81 |
|
| 82 |
add_c_test(c-raw-connection-test raw_connection_test.cpp $<TARGET_OBJECTS:qpid-proton-proactor-objects>) |
| 83 |
target_link_libraries(c-raw-connection-test qpid-proton-core ${PLATFORM_LIBS} ${PROACTOR_LIBS}) |
| 84 |
|
| 85 |
add_c_test(c-ssl-proactor-test pn_test_proactor.cpp ssl_proactor_test.cpp) |
| 86 |
target_link_libraries(c-ssl-proactor-test qpid-proton-core qpid-proton-proactor ${PLATFORM_LIBS}) |
| 87 |
|
| 88 |
# Thread race test. |
| 89 |
# Temporarily disable threaderciser tests by default. Re-enabled in CI configs as appropriate. |
| 90 |
set(DEFAULT_THREADERCISER OFF) |
| 91 |
option(THREADERCISER "Run the threaderciser concurrency tests" ${DEFAULT_THREADERCISER}) |
| 92 |
if (THREADERCISER) |
| 93 |
add_executable(c-threaderciser threaderciser.c) |
| 94 |
set_target_properties(c-threaderciser |
| 95 |
PROPERTIES COMPILE_FLAGS "${C_STANDARD_FLAGS} ${COMPILE_WARNING_FLAGS}") |
| 96 |
target_link_libraries (c-threaderciser qpid-proton-proactor Threads::Threads) |
| 97 |
pn_add_test( |
| 98 |
EXECUTABLE |
| 99 |
NAME c-threaderciser |
| 100 |
PREPEND_ENVIRONMENT ${test_env} |
| 101 |
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} |
| 102 |
COMMAND $<TARGET_FILE:c-threaderciser>) |
| 103 |
endif() |
| 104 |
|
| 105 |
if(WIN32) |
| 106 |
set(path "$<TARGET_FILE_DIR:c-broker>\\;$<TARGET_FILE_DIR:qpid-proton>") |
| 107 |
else(WIN32) |
| 108 |
set(path "$<TARGET_FILE_DIR:c-broker>:$ENV{PATH}") |
| 109 |
endif(WIN32) |
| 110 |
|
| 111 |
set(pypath "${CMAKE_SOURCE_DIR}/tests/py") |
| 112 |
|
| 113 |
# unset TEST_EXE_PREFIX as valgrind does not run successfully when fds are limited |
| 114 |
pn_add_test( |
| 115 |
UNWRAPPED |
| 116 |
NAME c-fdlimit-tests |
| 117 |
PREPEND_ENVIRONMENT "PATH=${path}" "PYTHONPATH=${pypath}" "${test_env}" |
| 118 |
APPEND_ENVIRONMENT "TEST_EXE_PREFIX=" |
| 119 |
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} |
| 120 |
COMMAND ${Python_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/fdlimit.py) |
| 121 |
endif(HAS_PROACTOR) |
| 122 |
|
| 123 |
if(HAS_TLS) |
| 124 |
# Tests for qpid-proton-tls raw TLS library |
| 125 |
add_c_test(c-tls-test tls_test.cpp $<TARGET_OBJECTS:qpid-proton-tls-objects>) |
| 126 |
target_link_libraries(c-tls-test qpid-proton-core qpid-proton-proactor ${SSL_LIB} ${PLATFORM_LIBS}) |
| 127 |
endif(HAS_TLS) |
| 128 |
|
| 129 |
else (CMAKE_CXX_COMPILER) |
| 130 |
message(WARNING "No C++ compiler, some C library tests were not built") |
| 131 |
endif (CMAKE_CXX_COMPILER) |
| 132 |
|
| 133 |
# fuzz tests: tests/fuzz |
| 134 |
if (ENABLE_FUZZ_TESTING) |
| 135 |
add_subdirectory(fuzz) |
| 136 |
endif (ENABLE_FUZZ_TESTING) |