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 |
tadeas-vintrlik | 36af696 | 2021-08-23 16:18:21 +0200 | [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 | 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) |
| 15 | list(APPEND tests test_pam) |
| 16 | endif() |
| 17 | |
David Sedlák | 19af266 | 2018-10-01 13:42:08 +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 |
Claus Klein | 2209191 | 2020-01-20 13:45:47 +0100 | [diff] [blame] | 39 | if(ENABLE_SSH OR ENABLE_TLS) |
Michal Vasko | a7b8ca5 | 2016-03-01 12:09:29 +0100 | [diff] [blame] | 40 | list(APPEND tests test_server_thread) |
Claus Klein | 2209191 | 2020-01-20 13:45:47 +0100 | [diff] [blame] | 41 | if(ENABLE_SSH) |
David Sedlák | ddde449 | 2018-09-30 21:34:38 +0200 | [diff] [blame] | 42 | list(APPEND client_tests test_client_ssh) |
| 43 | endif() |
| 44 | |
Claus Klein | 2209191 | 2020-01-20 13:45:47 +0100 | [diff] [blame] | 45 | if(ENABLE_TLS) |
David Sedlák | 6fdf1ec | 2018-09-30 21:42:31 +0200 | [diff] [blame] | 46 | list(APPEND client_tests test_client_tls) |
David Sedlák | ddde449 | 2018-09-30 21:34:38 +0200 | [diff] [blame] | 47 | endif() |
Michal Vasko | 061561f | 2016-02-08 15:36:22 +0100 | [diff] [blame] | 48 | endif() |
Michal Vasko | 294d4c6 | 2016-02-01 10:10:27 +0100 | [diff] [blame] | 49 | |
David Sedlák | ddde449 | 2018-09-30 21:34:38 +0200 | [diff] [blame] | 50 | foreach(src IN LISTS libsrc) |
| 51 | list(APPEND test_srcs "../${src}") |
| 52 | endforeach() |
| 53 | add_library(testobj OBJECT ${test_srcs}) |
| 54 | |
Michal Vasko | 294d4c6 | 2016-02-01 10:10:27 +0100 | [diff] [blame] | 55 | foreach(test_name IN LISTS tests) |
David Sedlák | ddde449 | 2018-09-30 21:34:38 +0200 | [diff] [blame] | 56 | add_executable(${test_name} $<TARGET_OBJECTS:testobj> ${test_name}.c) |
Michal Vasko | 294d4c6 | 2016-02-01 10:10:27 +0100 | [diff] [blame] | 57 | target_link_libraries(${test_name} ${CMOCKA_LIBRARIES} ${LIBYANG_LIBRARIES} netconf2) |
Claus Klein | 2209191 | 2020-01-20 13:45:47 +0100 | [diff] [blame] | 58 | target_include_directories(${test_name} PRIVATE ${CMOCKA_INCLUDE_DIR}) |
David Sedlák | ddde449 | 2018-09-30 21:34:38 +0200 | [diff] [blame] | 59 | set_target_properties(${test_name} PROPERTIES LINK_FLAGS "${${test_name}_wrap_link_flags}") |
| 60 | add_test(NAME ${test_name} COMMAND $<TARGET_FILE:${test_name}>) |
| 61 | endforeach() |
| 62 | |
| 63 | foreach(test_name IN LISTS client_tests) |
| 64 | add_executable(${test_name} $<TARGET_OBJECTS:testobj> ./client/${test_name}.c) |
| 65 | target_link_libraries(${test_name} ${CMOCKA_LIBRARIES} ${LIBYANG_LIBRARIES} netconf2) |
Claus Klein | 2209191 | 2020-01-20 13:45:47 +0100 | [diff] [blame] | 66 | target_include_directories(${test_name} PRIVATE ${CMOCKA_INCLUDE_DIR}) |
David Sedlák | ddde449 | 2018-09-30 21:34:38 +0200 | [diff] [blame] | 67 | set_target_properties(${test_name} PROPERTIES LINK_FLAGS "${${test_name}_wrap_link_flags}") |
| 68 | add_test(NAME ${test_name} COMMAND $<TARGET_FILE:${test_name}>) |
Michal Vasko | 061561f | 2016-02-08 15:36:22 +0100 | [diff] [blame] | 69 | endforeach() |
Radek Krejci | ce24ab8 | 2015-10-08 15:37:02 +0200 | [diff] [blame] | 70 | |
Claus Klein | 2209191 | 2020-01-20 13:45:47 +0100 | [diff] [blame] | 71 | if(ENABLE_VALGRIND_TESTS) |
Michal Vasko | 2cd7163 | 2021-06-04 12:03:12 +0200 | [diff] [blame] | 72 | foreach(test_name IN LISTS tests) |
| 73 | 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] | 74 | --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] | 75 | endforeach() |
David Sedlák | ddde449 | 2018-09-30 21:34:38 +0200 | [diff] [blame] | 76 | |
Michal Vasko | 2cd7163 | 2021-06-04 12:03:12 +0200 | [diff] [blame] | 77 | foreach(test_name IN LISTS client_tests) |
| 78 | 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] | 79 | --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] | 80 | endforeach() |
Fred Gan | 5eda9cb | 2020-12-11 16:32:08 +0800 | [diff] [blame] | 81 | endif() |
| 82 | |
Jan Kundrát | cf15d6c | 2017-10-26 18:07:56 +0200 | [diff] [blame] | 83 | include_directories(${CMAKE_SOURCE_DIR}/src ${PROJECT_BINARY_DIR}) |
| 84 | 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] | 85 | |
| 86 | if(LIBPAM_HAVE_CONFDIR) |
| 87 | |
| 88 | #compile PAM test module |
| 89 | add_library(pam_netconf SHARED ${CMAKE_SOURCE_DIR}/tests/pam/pam_netconf.c) |
| 90 | set_target_properties(pam_netconf PROPERTIES PREFIX "") |
| 91 | target_link_libraries(pam_netconf ${LIBPAM_LIBRARIES}) |
| 92 | |
| 93 | #generate PAM configuration file |
roman | e15ad54 | 2022-07-27 10:03:46 +0200 | [diff] [blame] | 94 | file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/netconf.conf |
roman | 41a11e4 | 2022-06-22 09:27:08 +0200 | [diff] [blame] | 95 | "#%PAM-1.4\n" |
Jan Kundrát | 1f50231 | 2022-07-26 11:41:14 +0200 | [diff] [blame] | 96 | "auth required ${CMAKE_CURRENT_BINARY_DIR}/pam_netconf.so\n" |
| 97 | "account required ${CMAKE_CURRENT_BINARY_DIR}/pam_netconf.so\n" |
| 98 | "password required ${CMAKE_CURRENT_BINARY_DIR}/pam_netconf.so\n" |
roman | 41a11e4 | 2022-06-22 09:27:08 +0200 | [diff] [blame] | 99 | ) |
| 100 | |
| 101 | endif() |