Michal Vasko | b0e3ec4 | 2021-05-26 09:48:31 +0200 | [diff] [blame] | 1 | # headers test for including compat.h |
| 2 | add_test(NAME headers |
| 3 | COMMAND ${CMAKE_SOURCE_DIR}/compat/check_includes.sh ${CMAKE_SOURCE_DIR}/src/) |
| 4 | |
| 5 | # format |
roman | 41a11e4 | 2022-06-22 09:27:08 +0200 | [diff] [blame] | 6 | if(${SOURCE_FORMAT_ENABLED}) |
Jan Kundrát | 7029945 | 2021-12-17 07:11:48 +0100 | [diff] [blame] | 7 | add_test(NAME format WORKING_DIRECTORY ${CMAKE_BINARY_DIR} COMMAND cmake --build ${CMAKE_BINARY_DIR} --target format-check) |
Michal Vasko | b0e3ec4 | 2021-05-26 09:48:31 +0200 | [diff] [blame] | 8 | endif() |
| 9 | |
roman | 2eab474 | 2023-06-06 10:00:26 +0200 | [diff] [blame] | 10 | # list of all the tests that don't require SSH and TLS |
roman | 899a91f | 2023-10-26 14:51:44 +0200 | [diff] [blame] | 11 | set(tests test_unix_socket test_client_thread test_fd_comm test_init_destroy_client test_init_destroy_server |
roman | 98066c7 | 2023-10-26 16:18:22 +0200 | [diff] [blame] | 12 | test_io test_thread_messages test_client_messages) |
roman | 41a11e4 | 2022-06-22 09:27:08 +0200 | [diff] [blame] | 13 | |
roman | 98066c7 | 2023-10-26 16:18:22 +0200 | [diff] [blame] | 14 | #append tests depending on SSH/TLS |
| 15 | if(ENABLE_SSH_TLS) |
roman | 808f3f6 | 2023-11-23 16:01:04 +0100 | [diff] [blame] | 16 | list(APPEND tests test_auth test_two_channels test_ks_ts test_ec |
roman | 98066c7 | 2023-10-26 16:18:22 +0200 | [diff] [blame] | 17 | test_ed25519 test_replace test_endpt_share_clients test_tls test_crl test_ch |
| 18 | test_runtime_changes test_client_ssh test_client_tls) |
roman | 7d13668 | 2023-12-14 10:43:36 +0100 | [diff] [blame] | 19 | |
| 20 | if (LIBPAM_HAVE_CONFDIR) |
| 21 | list(APPEND tests test_pam) |
| 22 | endif() |
roman | 98066c7 | 2023-10-26 16:18:22 +0200 | [diff] [blame] | 23 | endif() |
| 24 | |
| 25 | foreach(src IN LISTS libsrc) |
| 26 | list(APPEND test_srcs "../${src}") |
| 27 | endforeach() |
| 28 | add_library(testobj OBJECT ${test_srcs} ${compatsrc}) |
| 29 | |
roman | 7d13668 | 2023-12-14 10:43:36 +0100 | [diff] [blame] | 30 | # set the mocked functions for the tests |
| 31 | set(mock_tests test_client_ssh test_client_tls test_pam) |
| 32 | set(test_client_ssh_mock_funcs connect ssh_connect ssh_userauth_none ssh_userauth_kbdint ssh_is_connected |
Claus Klein | 2209191 | 2020-01-20 13:45:47 +0100 | [diff] [blame] | 33 | 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 Gan | 3a736e0 | 2021-01-04 17:59:38 +0800 | [diff] [blame] | 35 | ssh_userauth_try_publickey ssh_userauth_publickey nc_sock_listen_inet nc_sock_accept_binds nc_accept_callhome_ssh_sock) |
roman | 7d13668 | 2023-12-14 10:43:36 +0100 | [diff] [blame] | 36 | set(test_client_tls_mock_funcs connect SSL_connect nc_send_hello_io nc_handshake_io nc_ctx_check_and_fill) |
| 37 | set(test_pam_mock_funcs pam_start) |
David Sedlák | ddde449 | 2018-09-30 21:34:38 +0200 | [diff] [blame] | 38 | |
roman | 7d13668 | 2023-12-14 10:43:36 +0100 | [diff] [blame] | 39 | # add -Wl,--wrap flags to tests that require it |
| 40 | set(moc_funcs test_client_ssh_mock_funcs test_client_tls_mock_funcs test_pam_mock_funcs) |
| 41 | foreach(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ák | 6fdf1ec | 2018-09-30 21:42:31 +0200 | [diff] [blame] | 46 | endforeach() |
| 47 | |
Michal Vasko | 294d4c6 | 2016-02-01 10:10:27 +0100 | [diff] [blame] | 48 | foreach(test_name IN LISTS tests) |
David Sedlák | ddde449 | 2018-09-30 21:34:38 +0200 | [diff] [blame] | 49 | add_executable(${test_name} $<TARGET_OBJECTS:testobj> ${test_name}.c) |
Michal Vasko | 294d4c6 | 2016-02-01 10:10:27 +0100 | [diff] [blame] | 50 | target_link_libraries(${test_name} ${CMOCKA_LIBRARIES} ${LIBYANG_LIBRARIES} netconf2) |
Claus Klein | 2209191 | 2020-01-20 13:45:47 +0100 | [diff] [blame] | 51 | target_include_directories(${test_name} PRIVATE ${CMOCKA_INCLUDE_DIR}) |
David Sedlák | ddde449 | 2018-09-30 21:34:38 +0200 | [diff] [blame] | 52 | set_target_properties(${test_name} PROPERTIES LINK_FLAGS "${${test_name}_wrap_link_flags}") |
| 53 | add_test(NAME ${test_name} COMMAND $<TARGET_FILE:${test_name}>) |
| 54 | endforeach() |
| 55 | |
Claus Klein | 2209191 | 2020-01-20 13:45:47 +0100 | [diff] [blame] | 56 | if(ENABLE_VALGRIND_TESTS) |
Michal Vasko | 2cd7163 | 2021-06-04 12:03:12 +0200 | [diff] [blame] | 57 | foreach(test_name IN LISTS tests) |
| 58 | add_test(${test_name}_valgrind valgrind --leak-check=full --show-leak-kinds=all --error-exitcode=1 |
roman | 6a8947b | 2022-07-21 11:31:44 +0200 | [diff] [blame] | 59 | --suppressions=${PROJECT_SOURCE_DIR}/tests/library_valgrind.supp ${CMAKE_BINARY_DIR}/tests/${test_name}) |
Michal Vasko | 2cd7163 | 2021-06-04 12:03:12 +0200 | [diff] [blame] | 60 | endforeach() |
Fred Gan | 5eda9cb | 2020-12-11 16:32:08 +0800 | [diff] [blame] | 61 | endif() |
| 62 | |
Jan Kundrát | cf15d6c | 2017-10-26 18:07:56 +0200 | [diff] [blame] | 63 | include_directories(${CMAKE_SOURCE_DIR}/src ${PROJECT_BINARY_DIR}) |
| 64 | configure_file("${PROJECT_SOURCE_DIR}/tests/config.h.in" "${PROJECT_BINARY_DIR}/tests/config.h" ESCAPE_QUOTES @ONLY) |
roman | 7d13668 | 2023-12-14 10:43:36 +0100 | [diff] [blame] | 65 | |
| 66 | # compile PAM test module |
| 67 | add_library(pam_netconf SHARED ${CMAKE_SOURCE_DIR}/tests/pam/pam_netconf.c) |
| 68 | set_target_properties(pam_netconf PROPERTIES PREFIX "") |
| 69 | target_link_libraries(pam_netconf ${LIBPAM_LIBRARIES}) |
| 70 | |
| 71 | # generate PAM configuration file |
| 72 | file(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 | ) |