blob: 70006545d4131d4768fc1e96647e8e07b9550245 [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
roman3f9b65c2023-06-05 14:26:58 +020011set(tests test_unix_socket)
roman41a11e42022-06-22 09:27:08 +020012
13# only enable PAM tests if the version of PAM is greater than 1.4
14if(LIBPAM_HAVE_CONFDIR)
roman45cec4e2023-02-17 10:21:39 +010015 list(APPEND tests test_auth)
roman41a11e42022-06-22 09:27:08 +020016endif()
17
roman2eab4742023-06-06 10:00:26 +020018# set(client_tests test_client test_client_messages)
Michal Vasko061561f2016-02-08 15:36:22 +010019
David Sedlákddde4492018-09-30 21:34:38 +020020# add -Wl,--wrap flags
21set(test test_client_ssh)
David Sedlák493f2b12018-10-08 21:50:33 +020022set(${test}_mock_funcs connect ssh_connect ssh_userauth_none ssh_userauth_kbdint ssh_is_connected
Claus Klein22091912020-01-20 13:45:47 +010023 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 Gan3a736e02021-01-04 17:59:38 +080025 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 +020026set(${test}_wrap_link_flags "-Wl")
27foreach(mock_func IN LISTS ${test}_mock_funcs)
28 set(${test}_wrap_link_flags "${${test}_wrap_link_flags},--wrap=${mock_func}")
29endforeach()
30
David Sedlák6fdf1ec2018-09-30 21:42:31 +020031set(test test_client_tls)
32set(${test}_mock_funcs connect SSL_connect nc_send_hello_io nc_handshake_io nc_ctx_check_and_fill)
33set(${test}_wrap_link_flags "-Wl")
34foreach(mock_func IN LISTS ${test}_mock_funcs)
35 set(${test}_wrap_link_flags "${${test}_wrap_link_flags},--wrap=${mock_func}")
36endforeach()
37
David Sedlákddde4492018-09-30 21:34:38 +020038#append tests depending on SSH/TLS
roman2eab4742023-06-06 10:00:26 +020039if(ENABLE_SSH_TLS)
roman142718b2023-06-29 09:15:29 +020040 list(APPEND tests test_two_channels test_ks_ts test_config_new test_ec
roman5cbb6532023-06-22 12:53:17 +020041 test_ed25519 test_replace test_endpt_share_clients test_tls test_crl test_ch)
Michal Vasko061561f2016-02-08 15:36:22 +010042endif()
Michal Vasko294d4c62016-02-01 10:10:27 +010043
David Sedlákddde4492018-09-30 21:34:38 +020044foreach(src IN LISTS libsrc)
45 list(APPEND test_srcs "../${src}")
46endforeach()
Michal Vasko49c51922023-02-22 10:27:07 +010047add_library(testobj OBJECT ${test_srcs} ${compatsrc})
David Sedlákddde4492018-09-30 21:34:38 +020048
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
roman472420c2023-04-24 16:28:09 +020057# 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 Krejcice24ab82015-10-08 15:37:02 +020064
Claus Klein22091912020-01-20 13:45:47 +010065if(ENABLE_VALGRIND_TESTS)
Michal Vasko2cd71632021-06-04 12:03:12 +020066 foreach(test_name IN LISTS tests)
67 add_test(${test_name}_valgrind valgrind --leak-check=full --show-leak-kinds=all --error-exitcode=1
roman6a8947b2022-07-21 11:31:44 +020068 --suppressions=${PROJECT_SOURCE_DIR}/tests/library_valgrind.supp ${CMAKE_BINARY_DIR}/tests/${test_name})
Michal Vasko2cd71632021-06-04 12:03:12 +020069 endforeach()
David Sedlákddde4492018-09-30 21:34:38 +020070
roman472420c2023-04-24 16:28:09 +020071 # 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 Gan5eda9cb2020-12-11 16:32:08 +080075endif()
76
Jan Kundrátcf15d6c2017-10-26 18:07:56 +020077include_directories(${CMAKE_SOURCE_DIR}/src ${PROJECT_BINARY_DIR})
78configure_file("${PROJECT_SOURCE_DIR}/tests/config.h.in" "${PROJECT_BINARY_DIR}/tests/config.h" ESCAPE_QUOTES @ONLY)
roman41a11e42022-06-22 09:27:08 +020079
80if(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
romane15ad542022-07-27 10:03:46 +020088 file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/netconf.conf
roman41a11e42022-06-22 09:27:08 +020089 "#%PAM-1.4\n"
Jan Kundrát1f502312022-07-26 11:41:14 +020090 "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"
roman41a11e42022-06-22 09:27:08 +020093 )
94
95endif()