Merging upstream version 3.5.5 (Closes: #1098233).
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
c86ae7dcba
commit
6af28b7e8e
144 changed files with 43534 additions and 11497 deletions
|
@ -3,76 +3,100 @@ add_test(NAME headers
|
|||
COMMAND ${CMAKE_SOURCE_DIR}/compat/check_includes.sh ${CMAKE_SOURCE_DIR}/src/)
|
||||
|
||||
# format
|
||||
if (${SOURCE_FORMAT_ENABLED})
|
||||
add_test(NAME format WORKING_DIRECTORY ${CMAKE_BINARY_DIR} COMMAND make format-check)
|
||||
endif()
|
||||
|
||||
# list of all the tests in each directory
|
||||
set(tests test_io test_fd_comm test_init_destroy_client test_init_destroy_server test_client_thread test_thread_messages)
|
||||
set(client_tests test_client test_client_messages)
|
||||
|
||||
# add -Wl,--wrap flags
|
||||
set(test test_client_ssh)
|
||||
set(${test}_mock_funcs connect ssh_connect ssh_userauth_none ssh_userauth_kbdint ssh_is_connected
|
||||
ssh_channel_open_session ssh_channel_request_subsystem ssh_channel_is_close ssh_channel_write
|
||||
ssh_channel_poll_timeout ssh_userauth_password nc_handshake_io nc_ctx_check_and_fill
|
||||
ssh_userauth_try_publickey ssh_userauth_publickey nc_sock_listen_inet nc_sock_accept_binds nc_accept_callhome_ssh_sock)
|
||||
set(${test}_wrap_link_flags "-Wl")
|
||||
foreach(mock_func IN LISTS ${test}_mock_funcs)
|
||||
set(${test}_wrap_link_flags "${${test}_wrap_link_flags},--wrap=${mock_func}")
|
||||
endforeach()
|
||||
|
||||
set(test test_client_tls)
|
||||
set(${test}_mock_funcs connect SSL_connect nc_send_hello_io nc_handshake_io nc_ctx_check_and_fill)
|
||||
set(${test}_wrap_link_flags "-Wl")
|
||||
foreach(mock_func IN LISTS ${test}_mock_funcs)
|
||||
set(${test}_wrap_link_flags "${${test}_wrap_link_flags},--wrap=${mock_func}")
|
||||
endforeach()
|
||||
|
||||
#append tests depending on SSH/TLS
|
||||
if(ENABLE_SSH OR ENABLE_TLS)
|
||||
list(APPEND tests test_server_thread)
|
||||
if(ENABLE_SSH)
|
||||
list(APPEND client_tests test_client_ssh)
|
||||
endif()
|
||||
|
||||
if(ENABLE_TLS)
|
||||
list(APPEND client_tests test_client_tls)
|
||||
endif()
|
||||
if(${SOURCE_FORMAT_ENABLED})
|
||||
add_test(NAME format WORKING_DIRECTORY ${CMAKE_BINARY_DIR} COMMAND cmake --build ${CMAKE_BINARY_DIR} --target format-check)
|
||||
endif()
|
||||
|
||||
foreach(src IN LISTS libsrc)
|
||||
list(APPEND test_srcs "../${src}")
|
||||
endforeach()
|
||||
add_library(testobj OBJECT ${test_srcs})
|
||||
add_library(testobj OBJECT ${test_srcs} ${compatsrc})
|
||||
|
||||
foreach(test_name IN LISTS tests)
|
||||
add_executable(${test_name} $<TARGET_OBJECTS:testobj> ${test_name}.c)
|
||||
target_link_libraries(${test_name} ${CMOCKA_LIBRARIES} ${LIBYANG_LIBRARIES} netconf2)
|
||||
target_include_directories(${test_name} PRIVATE ${CMOCKA_INCLUDE_DIR})
|
||||
set_target_properties(${test_name} PROPERTIES LINK_FLAGS "${${test_name}_wrap_link_flags}")
|
||||
add_test(NAME ${test_name} COMMAND $<TARGET_FILE:${test_name}>)
|
||||
endforeach()
|
||||
set(TEST_SRC "ln2_test.c")
|
||||
set(NEXT_TEST_PORT 10050)
|
||||
|
||||
foreach(test_name IN LISTS client_tests)
|
||||
add_executable(${test_name} $<TARGET_OBJECTS:testobj> ./client/${test_name}.c)
|
||||
target_link_libraries(${test_name} ${CMOCKA_LIBRARIES} ${LIBYANG_LIBRARIES} netconf2)
|
||||
target_include_directories(${test_name} PRIVATE ${CMOCKA_INCLUDE_DIR})
|
||||
set_target_properties(${test_name} PROPERTIES LINK_FLAGS "${${test_name}_wrap_link_flags}")
|
||||
add_test(NAME ${test_name} COMMAND $<TARGET_FILE:${test_name}>)
|
||||
endforeach()
|
||||
macro(get_test_ports PORT_COUNT PORT_DEFINITIONS)
|
||||
if (NOT ${PORT_COUNT})
|
||||
set(${PORT_COUNT} 1)
|
||||
endif()
|
||||
|
||||
if(ENABLE_VALGRIND_TESTS)
|
||||
foreach(test_name IN LISTS tests)
|
||||
add_test(${test_name}_valgrind valgrind --leak-check=full --show-leak-kinds=all --error-exitcode=1
|
||||
--suppressions=${PROJECT_SOURCE_DIR}/tests/ld.supp ${CMAKE_BINARY_DIR}/tests/${test_name})
|
||||
endforeach()
|
||||
SET(PORT_INDEX 0)
|
||||
while(PORT_INDEX LESS ${${PORT_COUNT}})
|
||||
list(APPEND ${PORT_DEFINITIONS} "TEST_PORT_${PORT_INDEX}=${NEXT_TEST_PORT}")
|
||||
math(EXPR PORT_INDEX "${PORT_INDEX} + 1")
|
||||
math(EXPR NEXT_TEST_PORT "${NEXT_TEST_PORT} + 1")
|
||||
endwhile()
|
||||
set(NEXT_TEST_PORT ${NEXT_TEST_PORT} PARENT_SCOPE)
|
||||
endmacro()
|
||||
|
||||
foreach(test_name IN LISTS client_tests)
|
||||
add_test(${test_name}_valgrind valgrind --leak-check=full --show-leak-kinds=all --error-exitcode=1
|
||||
--suppressions=${PROJECT_SOURCE_DIR}/tests/ld.supp ${CMAKE_BINARY_DIR}/tests/${test_name})
|
||||
endforeach()
|
||||
function(libnetconf2_test)
|
||||
cmake_parse_arguments(TEST "" "NAME;PORT_COUNT" "WRAP_FUNCS" ${ARGN})
|
||||
|
||||
add_executable(${TEST_NAME} $<TARGET_OBJECTS:testobj> ${TEST_SRC} ${TEST_NAME}.c)
|
||||
target_link_libraries(${TEST_NAME} ${CMOCKA_LIBRARIES} ${LIBYANG_LIBRARIES} netconf2)
|
||||
target_include_directories(${TEST_NAME} PRIVATE ${CMOCKA_INCLUDE_DIR})
|
||||
|
||||
# wrap functions
|
||||
if(TEST_WRAP_FUNCS)
|
||||
set(wrap_link_flags "-Wl")
|
||||
foreach(mock_func IN LISTS TEST_WRAP_FUNCS)
|
||||
set(wrap_link_flags "${wrap_link_flags},--wrap=${mock_func}")
|
||||
endforeach()
|
||||
set_target_properties(${TEST_NAME} PROPERTIES LINK_FLAGS "${wrap_link_flags}")
|
||||
endif()
|
||||
|
||||
# create a test, generate port numbers and set them as env vars for the test
|
||||
add_test(NAME ${TEST_NAME} COMMAND $<TARGET_FILE:${TEST_NAME}>)
|
||||
get_test_ports(TEST_PORT_COUNT TEST_PORT_DEFINITIONS)
|
||||
set_tests_properties(${TEST_NAME} PROPERTIES ENVIRONMENT "${TEST_PORT_DEFINITIONS}")
|
||||
|
||||
# do the same for valgrind tests
|
||||
if(ENABLE_VALGRIND_TESTS)
|
||||
add_test(${TEST_NAME}_valgrind valgrind --leak-check=full --show-leak-kinds=all --error-exitcode=1
|
||||
--suppressions=${PROJECT_SOURCE_DIR}/tests/library_valgrind.supp ${CMAKE_BINARY_DIR}/tests/${TEST_NAME})
|
||||
get_test_ports(TEST_PORT_COUNT VALGRIND_TEST_PORT_DEFINITIONS)
|
||||
set_tests_properties(${TEST_NAME}_valgrind PROPERTIES ENVIRONMENT "${VALGRIND_TEST_PORT_DEFINITIONS}")
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
# all the tests that don't require SSH and TLS
|
||||
libnetconf2_test(NAME test_client_messages)
|
||||
libnetconf2_test(NAME test_client_thread)
|
||||
libnetconf2_test(NAME test_fd_comm)
|
||||
libnetconf2_test(NAME test_io)
|
||||
libnetconf2_test(NAME test_thread_messages)
|
||||
libnetconf2_test(NAME test_unix_socket)
|
||||
|
||||
# tests depending on SSH/TLS
|
||||
if(ENABLE_SSH_TLS)
|
||||
libnetconf2_test(NAME test_auth_ssh)
|
||||
libnetconf2_test(NAME test_authkeys)
|
||||
libnetconf2_test(NAME test_cert_exp_notif)
|
||||
libnetconf2_test(NAME test_ch PORT_COUNT 2)
|
||||
libnetconf2_test(NAME test_client_monitoring)
|
||||
libnetconf2_test(NAME test_endpt_share_clients PORT_COUNT 4)
|
||||
libnetconf2_test(NAME test_ks_ts)
|
||||
if (LIBPAM_HAVE_CONFDIR)
|
||||
libnetconf2_test(NAME test_pam WRAP_FUNCS pam_start)
|
||||
endif()
|
||||
libnetconf2_test(NAME test_replace)
|
||||
libnetconf2_test(NAME test_runtime_changes PORT_COUNT 2)
|
||||
libnetconf2_test(NAME test_tls)
|
||||
libnetconf2_test(NAME test_two_channels)
|
||||
endif()
|
||||
|
||||
include_directories(${CMAKE_SOURCE_DIR}/src ${PROJECT_BINARY_DIR})
|
||||
configure_file("${PROJECT_SOURCE_DIR}/tests/config.h.in" "${PROJECT_BINARY_DIR}/tests/config.h" ESCAPE_QUOTES @ONLY)
|
||||
|
||||
# compile PAM test module
|
||||
add_library(pam_netconf SHARED ${CMAKE_SOURCE_DIR}/tests/pam/pam_netconf.c)
|
||||
set_target_properties(pam_netconf PROPERTIES PREFIX "")
|
||||
target_link_libraries(pam_netconf ${LIBPAM_LIBRARIES})
|
||||
|
||||
# generate PAM configuration file
|
||||
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/netconf.conf
|
||||
"#%PAM-1.4\n"
|
||||
"auth required ${CMAKE_CURRENT_BINARY_DIR}/pam_netconf.so\n"
|
||||
"account required ${CMAKE_CURRENT_BINARY_DIR}/pam_netconf.so\n"
|
||||
"password required ${CMAKE_CURRENT_BINARY_DIR}/pam_netconf.so\n"
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue