blob: 68aee07b970c588e81ec3132891c0e5fa3b8c60c [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
David Sedlákddde4492018-09-30 21:34:38 +020010# list of all the tests in each directory
roman45cec4e2023-02-17 10:21:39 +010011#set(tests test_io test_fd_comm test_init_destroy_client test_init_destroy_server test_client_thread test_thread_messages)
roman0bbc19c2023-05-26 09:59:09 +020012set(tests test_two_channels test_keystore test_unix_socket test_config_new test_truststore test_ec test_ed25519 test_replace test_endpt_share_clients)
roman41a11e42022-06-22 09:27:08 +020013
14# only enable PAM tests if the version of PAM is greater than 1.4
15if(LIBPAM_HAVE_CONFDIR)
roman45cec4e2023-02-17 10:21:39 +010016 list(APPEND tests test_auth)
roman41a11e42022-06-22 09:27:08 +020017endif()
18
David Sedlák19af2662018-10-01 13:42:08 +020019set(client_tests test_client test_client_messages)
Michal Vasko061561f2016-02-08 15:36:22 +010020
David Sedlákddde4492018-09-30 21:34:38 +020021# add -Wl,--wrap flags
22set(test test_client_ssh)
David Sedlák493f2b12018-10-08 21:50:33 +020023set(${test}_mock_funcs connect ssh_connect ssh_userauth_none ssh_userauth_kbdint ssh_is_connected
Claus Klein22091912020-01-20 13:45:47 +010024 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 Gan3a736e02021-01-04 17:59:38 +080026 ssh_userauth_try_publickey ssh_userauth_publickey nc_sock_listen_inet nc_sock_accept_binds nc_accept_callhome_ssh_sock)
David Sedlákddde4492018-09-30 21:34:38 +020027set(${test}_wrap_link_flags "-Wl")
28foreach(mock_func IN LISTS ${test}_mock_funcs)
29 set(${test}_wrap_link_flags "${${test}_wrap_link_flags},--wrap=${mock_func}")
30endforeach()
31
David Sedlák6fdf1ec2018-09-30 21:42:31 +020032set(test test_client_tls)
33set(${test}_mock_funcs connect SSL_connect nc_send_hello_io nc_handshake_io nc_ctx_check_and_fill)
34set(${test}_wrap_link_flags "-Wl")
35foreach(mock_func IN LISTS ${test}_mock_funcs)
36 set(${test}_wrap_link_flags "${${test}_wrap_link_flags},--wrap=${mock_func}")
37endforeach()
38
David Sedlákddde4492018-09-30 21:34:38 +020039#append tests depending on SSH/TLS
Claus Klein22091912020-01-20 13:45:47 +010040if(ENABLE_SSH OR ENABLE_TLS)
romanc1d2b092023-02-02 08:58:27 +010041 #list(APPEND tests test_server_thread)
Claus Klein22091912020-01-20 13:45:47 +010042 if(ENABLE_SSH)
David Sedlákddde4492018-09-30 21:34:38 +020043 list(APPEND client_tests test_client_ssh)
44 endif()
45
Claus Klein22091912020-01-20 13:45:47 +010046 if(ENABLE_TLS)
David Sedlák6fdf1ec2018-09-30 21:42:31 +020047 list(APPEND client_tests test_client_tls)
David Sedlákddde4492018-09-30 21:34:38 +020048 endif()
Michal Vasko061561f2016-02-08 15:36:22 +010049endif()
Michal Vasko294d4c62016-02-01 10:10:27 +010050
David Sedlákddde4492018-09-30 21:34:38 +020051foreach(src IN LISTS libsrc)
52 list(APPEND test_srcs "../${src}")
53endforeach()
Michal Vasko49c51922023-02-22 10:27:07 +010054add_library(testobj OBJECT ${test_srcs} ${compatsrc})
David Sedlákddde4492018-09-30 21:34:38 +020055
Michal Vasko294d4c62016-02-01 10:10:27 +010056foreach(test_name IN LISTS tests)
David Sedlákddde4492018-09-30 21:34:38 +020057 add_executable(${test_name} $<TARGET_OBJECTS:testobj> ${test_name}.c)
Michal Vasko294d4c62016-02-01 10:10:27 +010058 target_link_libraries(${test_name} ${CMOCKA_LIBRARIES} ${LIBYANG_LIBRARIES} netconf2)
Claus Klein22091912020-01-20 13:45:47 +010059 target_include_directories(${test_name} PRIVATE ${CMOCKA_INCLUDE_DIR})
David Sedlákddde4492018-09-30 21:34:38 +020060 set_target_properties(${test_name} PROPERTIES LINK_FLAGS "${${test_name}_wrap_link_flags}")
61 add_test(NAME ${test_name} COMMAND $<TARGET_FILE:${test_name}>)
62endforeach()
63
roman472420c2023-04-24 16:28:09 +020064# 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 Krejcice24ab82015-10-08 15:37:02 +020071
Claus Klein22091912020-01-20 13:45:47 +010072if(ENABLE_VALGRIND_TESTS)
Michal Vasko2cd71632021-06-04 12:03:12 +020073 foreach(test_name IN LISTS tests)
74 add_test(${test_name}_valgrind valgrind --leak-check=full --show-leak-kinds=all --error-exitcode=1
roman6a8947b2022-07-21 11:31:44 +020075 --suppressions=${PROJECT_SOURCE_DIR}/tests/library_valgrind.supp ${CMAKE_BINARY_DIR}/tests/${test_name})
Michal Vasko2cd71632021-06-04 12:03:12 +020076 endforeach()
David Sedlákddde4492018-09-30 21:34:38 +020077
roman472420c2023-04-24 16:28:09 +020078 # 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 Gan5eda9cb2020-12-11 16:32:08 +080082endif()
83
Jan Kundrátcf15d6c2017-10-26 18:07:56 +020084include_directories(${CMAKE_SOURCE_DIR}/src ${PROJECT_BINARY_DIR})
85configure_file("${PROJECT_SOURCE_DIR}/tests/config.h.in" "${PROJECT_BINARY_DIR}/tests/config.h" ESCAPE_QUOTES @ONLY)
roman41a11e42022-06-22 09:27:08 +020086
87if(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
romane15ad542022-07-27 10:03:46 +020095 file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/netconf.conf
roman41a11e42022-06-22 09:27:08 +020096 "#%PAM-1.4\n"
Jan Kundrát1f502312022-07-26 11:41:14 +020097 "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"
roman41a11e42022-06-22 09:27:08 +0200100 )
101
102endif()