blob: 965fb6c90509dfdb647433e6e308fde6d120b347 [file] [log] [blame]
Michal Vaskob0e3ec42021-05-26 09:48:31 +02001# headers test for including compat.h
2add_test(NAME headers
3 COMMAND ${CMAKE_SOURCE_DIR}/compat/check_includes.sh ${CMAKE_SOURCE_DIR}/src/)
4
5# format
roman41a11e42022-06-22 09:27:08 +02006if(${SOURCE_FORMAT_ENABLED})
Jan Kundrát70299452021-12-17 07:11:48 +01007 add_test(NAME format WORKING_DIRECTORY ${CMAKE_BINARY_DIR} COMMAND cmake --build ${CMAKE_BINARY_DIR} --target format-check)
Michal Vaskob0e3ec42021-05-26 09:48:31 +02008endif()
9
roman2eab4742023-06-06 10:00:26 +020010# list of all the tests that don't require SSH and TLS
roman899a91f2023-10-26 14:51:44 +020011set(tests test_unix_socket test_client_thread test_fd_comm test_init_destroy_client test_init_destroy_server
roman98066c72023-10-26 16:18:22 +020012 test_io test_thread_messages test_client_messages)
roman41a11e42022-06-22 09:27:08 +020013
roman98066c72023-10-26 16:18:22 +020014#append tests depending on SSH/TLS
15if(ENABLE_SSH_TLS)
roman808f3f62023-11-23 16:01:04 +010016 list(APPEND tests test_auth test_two_channels test_ks_ts test_ec
roman98066c72023-10-26 16:18:22 +020017 test_ed25519 test_replace test_endpt_share_clients test_tls test_crl test_ch
18 test_runtime_changes test_client_ssh test_client_tls)
roman7d136682023-12-14 10:43:36 +010019
20 if (LIBPAM_HAVE_CONFDIR)
21 list(APPEND tests test_pam)
22 endif()
roman98066c72023-10-26 16:18:22 +020023endif()
24
25foreach(src IN LISTS libsrc)
26 list(APPEND test_srcs "../${src}")
27endforeach()
28add_library(testobj OBJECT ${test_srcs} ${compatsrc})
29
roman7d136682023-12-14 10:43:36 +010030# set the mocked functions for the tests
31set(mock_tests test_client_ssh test_client_tls test_pam)
32set(test_client_ssh_mock_funcs connect ssh_connect ssh_userauth_none ssh_userauth_kbdint ssh_is_connected
Claus Klein22091912020-01-20 13:45:47 +010033 ssh_channel_open_session ssh_channel_request_subsystem ssh_channel_is_close ssh_channel_write
34 ssh_channel_poll_timeout ssh_userauth_password nc_handshake_io nc_ctx_check_and_fill
Fred Gan3a736e02021-01-04 17:59:38 +080035 ssh_userauth_try_publickey ssh_userauth_publickey nc_sock_listen_inet nc_sock_accept_binds nc_accept_callhome_ssh_sock)
roman7d136682023-12-14 10:43:36 +010036set(test_client_tls_mock_funcs connect SSL_connect nc_send_hello_io nc_handshake_io nc_ctx_check_and_fill)
37set(test_pam_mock_funcs pam_start)
David Sedlákddde4492018-09-30 21:34:38 +020038
roman7d136682023-12-14 10:43:36 +010039# add -Wl,--wrap flags to tests that require it
40set(moc_funcs test_client_ssh_mock_funcs test_client_tls_mock_funcs test_pam_mock_funcs)
41foreach(mock_test IN LISTS mock_tests)
42 set(${mock_test}_wrap_link_flags "-Wl")
43 foreach(mock_func IN LISTS ${mock_test}_mock_funcs)
44 set(${mock_test}_wrap_link_flags "${${mock_test}_wrap_link_flags},--wrap=${mock_func}")
45 endforeach()
David Sedlák6fdf1ec2018-09-30 21:42:31 +020046endforeach()
47
Michal Vasko294d4c62016-02-01 10:10:27 +010048foreach(test_name IN LISTS tests)
David Sedlákddde4492018-09-30 21:34:38 +020049 add_executable(${test_name} $<TARGET_OBJECTS:testobj> ${test_name}.c)
Michal Vasko294d4c62016-02-01 10:10:27 +010050 target_link_libraries(${test_name} ${CMOCKA_LIBRARIES} ${LIBYANG_LIBRARIES} netconf2)
Claus Klein22091912020-01-20 13:45:47 +010051 target_include_directories(${test_name} PRIVATE ${CMOCKA_INCLUDE_DIR})
David Sedlákddde4492018-09-30 21:34:38 +020052 set_target_properties(${test_name} PROPERTIES LINK_FLAGS "${${test_name}_wrap_link_flags}")
53 add_test(NAME ${test_name} COMMAND $<TARGET_FILE:${test_name}>)
54endforeach()
55
Claus Klein22091912020-01-20 13:45:47 +010056if(ENABLE_VALGRIND_TESTS)
Michal Vasko2cd71632021-06-04 12:03:12 +020057 foreach(test_name IN LISTS tests)
58 add_test(${test_name}_valgrind valgrind --leak-check=full --show-leak-kinds=all --error-exitcode=1
roman6a8947b2022-07-21 11:31:44 +020059 --suppressions=${PROJECT_SOURCE_DIR}/tests/library_valgrind.supp ${CMAKE_BINARY_DIR}/tests/${test_name})
Michal Vasko2cd71632021-06-04 12:03:12 +020060 endforeach()
Fred Gan5eda9cb2020-12-11 16:32:08 +080061endif()
62
Jan Kundrátcf15d6c2017-10-26 18:07:56 +020063include_directories(${CMAKE_SOURCE_DIR}/src ${PROJECT_BINARY_DIR})
64configure_file("${PROJECT_SOURCE_DIR}/tests/config.h.in" "${PROJECT_BINARY_DIR}/tests/config.h" ESCAPE_QUOTES @ONLY)
roman7d136682023-12-14 10:43:36 +010065
66# compile PAM test module
67add_library(pam_netconf SHARED ${CMAKE_SOURCE_DIR}/tests/pam/pam_netconf.c)
68set_target_properties(pam_netconf PROPERTIES PREFIX "")
69target_link_libraries(pam_netconf ${LIBPAM_LIBRARIES})
70
71# generate PAM configuration file
72file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/netconf.conf
73 "#%PAM-1.4\n"
74 "auth required ${CMAKE_CURRENT_BINARY_DIR}/pam_netconf.so\n"
75 "account required ${CMAKE_CURRENT_BINARY_DIR}/pam_netconf.so\n"
76 "password required ${CMAKE_CURRENT_BINARY_DIR}/pam_netconf.so\n"
77)