blob: 01c7db53fa6181eac993a847081d55c610ed9500 [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
roman2eab4742023-06-06 10:00:26 +020010# list of all the tests that don't require SSH and TLS
roman899a91f2023-10-26 14:51:44 +020011set(tests test_unix_socket test_client_thread test_fd_comm test_init_destroy_client test_init_destroy_server
roman98066c72023-10-26 16:18:22 +020012 test_io test_thread_messages test_client_messages)
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
roman98066c72023-10-26 16:18:22 +020019#append tests depending on SSH/TLS
20if(ENABLE_SSH_TLS)
21 list(APPEND tests test_two_channels test_ks_ts test_ec
22 test_ed25519 test_replace test_endpt_share_clients test_tls test_crl test_ch
23 test_runtime_changes test_client_ssh test_client_tls)
24endif()
25
26foreach(src IN LISTS libsrc)
27 list(APPEND test_srcs "../${src}")
28endforeach()
29add_library(testobj OBJECT ${test_srcs} ${compatsrc})
30
David Sedlákddde4492018-09-30 21:34:38 +020031# add -Wl,--wrap flags
32set(test test_client_ssh)
David Sedlák493f2b12018-10-08 21:50:33 +020033set(${test}_mock_funcs connect ssh_connect ssh_userauth_none ssh_userauth_kbdint ssh_is_connected
Claus Klein22091912020-01-20 13:45:47 +010034 ssh_channel_open_session ssh_channel_request_subsystem ssh_channel_is_close ssh_channel_write
35 ssh_channel_poll_timeout ssh_userauth_password nc_handshake_io nc_ctx_check_and_fill
Fred Gan3a736e02021-01-04 17:59:38 +080036 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 +020037set(${test}_wrap_link_flags "-Wl")
38foreach(mock_func IN LISTS ${test}_mock_funcs)
39 set(${test}_wrap_link_flags "${${test}_wrap_link_flags},--wrap=${mock_func}")
40endforeach()
41
David Sedlák6fdf1ec2018-09-30 21:42:31 +020042set(test test_client_tls)
43set(${test}_mock_funcs connect SSL_connect nc_send_hello_io nc_handshake_io nc_ctx_check_and_fill)
44set(${test}_wrap_link_flags "-Wl")
45foreach(mock_func IN LISTS ${test}_mock_funcs)
46 set(${test}_wrap_link_flags "${${test}_wrap_link_flags},--wrap=${mock_func}")
47endforeach()
48
Michal Vasko294d4c62016-02-01 10:10:27 +010049foreach(test_name IN LISTS tests)
David Sedlákddde4492018-09-30 21:34:38 +020050 add_executable(${test_name} $<TARGET_OBJECTS:testobj> ${test_name}.c)
Michal Vasko294d4c62016-02-01 10:10:27 +010051 target_link_libraries(${test_name} ${CMOCKA_LIBRARIES} ${LIBYANG_LIBRARIES} netconf2)
Claus Klein22091912020-01-20 13:45:47 +010052 target_include_directories(${test_name} PRIVATE ${CMOCKA_INCLUDE_DIR})
David Sedlákddde4492018-09-30 21:34:38 +020053 set_target_properties(${test_name} PROPERTIES LINK_FLAGS "${${test_name}_wrap_link_flags}")
54 add_test(NAME ${test_name} COMMAND $<TARGET_FILE:${test_name}>)
55endforeach()
56
Claus Klein22091912020-01-20 13:45:47 +010057if(ENABLE_VALGRIND_TESTS)
Michal Vasko2cd71632021-06-04 12:03:12 +020058 foreach(test_name IN LISTS tests)
59 add_test(${test_name}_valgrind valgrind --leak-check=full --show-leak-kinds=all --error-exitcode=1
roman6a8947b2022-07-21 11:31:44 +020060 --suppressions=${PROJECT_SOURCE_DIR}/tests/library_valgrind.supp ${CMAKE_BINARY_DIR}/tests/${test_name})
Michal Vasko2cd71632021-06-04 12:03:12 +020061 endforeach()
Fred Gan5eda9cb2020-12-11 16:32:08 +080062endif()
63
Jan Kundrátcf15d6c2017-10-26 18:07:56 +020064include_directories(${CMAKE_SOURCE_DIR}/src ${PROJECT_BINARY_DIR})
65configure_file("${PROJECT_SOURCE_DIR}/tests/config.h.in" "${PROJECT_BINARY_DIR}/tests/config.h" ESCAPE_QUOTES @ONLY)
roman41a11e42022-06-22 09:27:08 +020066
67if(LIBPAM_HAVE_CONFDIR)
roman41a11e42022-06-22 09:27:08 +020068 #compile PAM test module
69 add_library(pam_netconf SHARED ${CMAKE_SOURCE_DIR}/tests/pam/pam_netconf.c)
70 set_target_properties(pam_netconf PROPERTIES PREFIX "")
71 target_link_libraries(pam_netconf ${LIBPAM_LIBRARIES})
72
73 #generate PAM configuration file
romane15ad542022-07-27 10:03:46 +020074 file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/netconf.conf
roman41a11e42022-06-22 09:27:08 +020075 "#%PAM-1.4\n"
Jan Kundrát1f502312022-07-26 11:41:14 +020076 "auth required ${CMAKE_CURRENT_BINARY_DIR}/pam_netconf.so\n"
77 "account required ${CMAKE_CURRENT_BINARY_DIR}/pam_netconf.so\n"
78 "password required ${CMAKE_CURRENT_BINARY_DIR}/pam_netconf.so\n"
roman41a11e42022-06-22 09:27:08 +020079 )
80
81endif()