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 | |
David Sedlák | ddde449 | 2018-09-30 21:34:38 +0200 | [diff] [blame] | 10 | # list of all the tests in each directory |
roman | 45cec4e | 2023-02-17 10:21:39 +0100 | [diff] [blame] | 11 | #set(tests test_io test_fd_comm test_init_destroy_client test_init_destroy_server test_client_thread test_thread_messages) |
roman | 0bbc19c | 2023-05-26 09:59:09 +0200 | [diff] [blame] | 12 | set(tests test_two_channels test_keystore test_unix_socket test_config_new test_truststore test_ec test_ed25519 test_replace test_endpt_share_clients) |
roman | 41a11e4 | 2022-06-22 09:27:08 +0200 | [diff] [blame] | 13 | |
| 14 | # only enable PAM tests if the version of PAM is greater than 1.4 |
| 15 | if(LIBPAM_HAVE_CONFDIR) |
roman | 45cec4e | 2023-02-17 10:21:39 +0100 | [diff] [blame] | 16 | list(APPEND tests test_auth) |
roman | 41a11e4 | 2022-06-22 09:27:08 +0200 | [diff] [blame] | 17 | endif() |
| 18 | |
David Sedlák | 19af266 | 2018-10-01 13:42:08 +0200 | [diff] [blame] | 19 | set(client_tests test_client test_client_messages) |
Michal Vasko | 061561f | 2016-02-08 15:36:22 +0100 | [diff] [blame] | 20 | |
David Sedlák | ddde449 | 2018-09-30 21:34:38 +0200 | [diff] [blame] | 21 | # add -Wl,--wrap flags |
| 22 | set(test test_client_ssh) |
David Sedlák | 493f2b1 | 2018-10-08 21:50:33 +0200 | [diff] [blame] | 23 | set(${test}_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] | 24 | ssh_channel_open_session ssh_channel_request_subsystem ssh_channel_is_close ssh_channel_write |
| 25 | 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] | 26 | ssh_userauth_try_publickey ssh_userauth_publickey nc_sock_listen_inet nc_sock_accept_binds nc_accept_callhome_ssh_sock) |
David Sedlák | ddde449 | 2018-09-30 21:34:38 +0200 | [diff] [blame] | 27 | set(${test}_wrap_link_flags "-Wl") |
| 28 | foreach(mock_func IN LISTS ${test}_mock_funcs) |
| 29 | set(${test}_wrap_link_flags "${${test}_wrap_link_flags},--wrap=${mock_func}") |
| 30 | endforeach() |
| 31 | |
David Sedlák | 6fdf1ec | 2018-09-30 21:42:31 +0200 | [diff] [blame] | 32 | set(test test_client_tls) |
| 33 | set(${test}_mock_funcs connect SSL_connect nc_send_hello_io nc_handshake_io nc_ctx_check_and_fill) |
| 34 | set(${test}_wrap_link_flags "-Wl") |
| 35 | foreach(mock_func IN LISTS ${test}_mock_funcs) |
| 36 | set(${test}_wrap_link_flags "${${test}_wrap_link_flags},--wrap=${mock_func}") |
| 37 | endforeach() |
| 38 | |
David Sedlák | ddde449 | 2018-09-30 21:34:38 +0200 | [diff] [blame] | 39 | #append tests depending on SSH/TLS |
Claus Klein | 2209191 | 2020-01-20 13:45:47 +0100 | [diff] [blame] | 40 | if(ENABLE_SSH OR ENABLE_TLS) |
roman | c1d2b09 | 2023-02-02 08:58:27 +0100 | [diff] [blame] | 41 | #list(APPEND tests test_server_thread) |
Claus Klein | 2209191 | 2020-01-20 13:45:47 +0100 | [diff] [blame] | 42 | if(ENABLE_SSH) |
David Sedlák | ddde449 | 2018-09-30 21:34:38 +0200 | [diff] [blame] | 43 | list(APPEND client_tests test_client_ssh) |
| 44 | endif() |
| 45 | |
Claus Klein | 2209191 | 2020-01-20 13:45:47 +0100 | [diff] [blame] | 46 | if(ENABLE_TLS) |
David Sedlák | 6fdf1ec | 2018-09-30 21:42:31 +0200 | [diff] [blame] | 47 | list(APPEND client_tests test_client_tls) |
David Sedlák | ddde449 | 2018-09-30 21:34:38 +0200 | [diff] [blame] | 48 | endif() |
Michal Vasko | 061561f | 2016-02-08 15:36:22 +0100 | [diff] [blame] | 49 | endif() |
Michal Vasko | 294d4c6 | 2016-02-01 10:10:27 +0100 | [diff] [blame] | 50 | |
David Sedlák | ddde449 | 2018-09-30 21:34:38 +0200 | [diff] [blame] | 51 | foreach(src IN LISTS libsrc) |
| 52 | list(APPEND test_srcs "../${src}") |
| 53 | endforeach() |
Michal Vasko | 49c5192 | 2023-02-22 10:27:07 +0100 | [diff] [blame] | 54 | add_library(testobj OBJECT ${test_srcs} ${compatsrc}) |
David Sedlák | ddde449 | 2018-09-30 21:34:38 +0200 | [diff] [blame] | 55 | |
Michal Vasko | 294d4c6 | 2016-02-01 10:10:27 +0100 | [diff] [blame] | 56 | foreach(test_name IN LISTS tests) |
David Sedlák | ddde449 | 2018-09-30 21:34:38 +0200 | [diff] [blame] | 57 | add_executable(${test_name} $<TARGET_OBJECTS:testobj> ${test_name}.c) |
Michal Vasko | 294d4c6 | 2016-02-01 10:10:27 +0100 | [diff] [blame] | 58 | target_link_libraries(${test_name} ${CMOCKA_LIBRARIES} ${LIBYANG_LIBRARIES} netconf2) |
Claus Klein | 2209191 | 2020-01-20 13:45:47 +0100 | [diff] [blame] | 59 | target_include_directories(${test_name} PRIVATE ${CMOCKA_INCLUDE_DIR}) |
David Sedlák | ddde449 | 2018-09-30 21:34:38 +0200 | [diff] [blame] | 60 | set_target_properties(${test_name} PROPERTIES LINK_FLAGS "${${test_name}_wrap_link_flags}") |
| 61 | add_test(NAME ${test_name} COMMAND $<TARGET_FILE:${test_name}>) |
| 62 | endforeach() |
| 63 | |
roman | 472420c | 2023-04-24 16:28:09 +0200 | [diff] [blame] | 64 | # foreach(test_name IN LISTS client_tests) |
| 65 | # add_executable(${test_name} $<TARGET_OBJECTS:testobj> ./client/${test_name}.c) |
| 66 | # target_link_libraries(${test_name} ${CMOCKA_LIBRARIES} ${LIBYANG_LIBRARIES} netconf2) |
| 67 | # target_include_directories(${test_name} PRIVATE ${CMOCKA_INCLUDE_DIR}) |
| 68 | # set_target_properties(${test_name} PROPERTIES LINK_FLAGS "${${test_name}_wrap_link_flags}") |
| 69 | # add_test(NAME ${test_name} COMMAND $<TARGET_FILE:${test_name}>) |
| 70 | # endforeach() |
Radek Krejci | ce24ab8 | 2015-10-08 15:37:02 +0200 | [diff] [blame] | 71 | |
Claus Klein | 2209191 | 2020-01-20 13:45:47 +0100 | [diff] [blame] | 72 | if(ENABLE_VALGRIND_TESTS) |
Michal Vasko | 2cd7163 | 2021-06-04 12:03:12 +0200 | [diff] [blame] | 73 | foreach(test_name IN LISTS tests) |
| 74 | 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] | 75 | --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] | 76 | endforeach() |
David Sedlák | ddde449 | 2018-09-30 21:34:38 +0200 | [diff] [blame] | 77 | |
roman | 472420c | 2023-04-24 16:28:09 +0200 | [diff] [blame] | 78 | # foreach(test_name IN LISTS client_tests) |
| 79 | # add_test(${test_name}_valgrind valgrind --leak-check=full --show-leak-kinds=all --error-exitcode=1 |
| 80 | # --suppressions=${PROJECT_SOURCE_DIR}/tests/library_valgrind.supp ${CMAKE_BINARY_DIR}/tests/${test_name}) |
| 81 | # endforeach() |
Fred Gan | 5eda9cb | 2020-12-11 16:32:08 +0800 | [diff] [blame] | 82 | endif() |
| 83 | |
Jan Kundrát | cf15d6c | 2017-10-26 18:07:56 +0200 | [diff] [blame] | 84 | include_directories(${CMAKE_SOURCE_DIR}/src ${PROJECT_BINARY_DIR}) |
| 85 | configure_file("${PROJECT_SOURCE_DIR}/tests/config.h.in" "${PROJECT_BINARY_DIR}/tests/config.h" ESCAPE_QUOTES @ONLY) |
roman | 41a11e4 | 2022-06-22 09:27:08 +0200 | [diff] [blame] | 86 | |
| 87 | if(LIBPAM_HAVE_CONFDIR) |
| 88 | |
| 89 | #compile PAM test module |
| 90 | add_library(pam_netconf SHARED ${CMAKE_SOURCE_DIR}/tests/pam/pam_netconf.c) |
| 91 | set_target_properties(pam_netconf PROPERTIES PREFIX "") |
| 92 | target_link_libraries(pam_netconf ${LIBPAM_LIBRARIES}) |
| 93 | |
| 94 | #generate PAM configuration file |
roman | e15ad54 | 2022-07-27 10:03:46 +0200 | [diff] [blame] | 95 | file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/netconf.conf |
roman | 41a11e4 | 2022-06-22 09:27:08 +0200 | [diff] [blame] | 96 | "#%PAM-1.4\n" |
Jan Kundrát | 1f50231 | 2022-07-26 11:41:14 +0200 | [diff] [blame] | 97 | "auth required ${CMAKE_CURRENT_BINARY_DIR}/pam_netconf.so\n" |
| 98 | "account required ${CMAKE_CURRENT_BINARY_DIR}/pam_netconf.so\n" |
| 99 | "password required ${CMAKE_CURRENT_BINARY_DIR}/pam_netconf.so\n" |
roman | 41a11e4 | 2022-06-22 09:27:08 +0200 | [diff] [blame] | 100 | ) |
| 101 | |
| 102 | endif() |