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