blob: e7ca099f67fb0f1ad9b54fbc2ff7623c98bdb9a8 [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
tadeas-vintrlik36af6962021-08-23 16:18:21 +020011set(tests test_io test_fd_comm test_init_destroy_client test_init_destroy_server test_client_thread test_thread_messages)
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)
15 list(APPEND tests test_pam)
16endif()
17
David Sedlák19af2662018-10-01 13:42:08 +020018set(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
Claus Klein22091912020-01-20 13:45:47 +010039if(ENABLE_SSH OR ENABLE_TLS)
Michal Vaskoa7b8ca52016-03-01 12:09:29 +010040 list(APPEND tests test_server_thread)
Claus Klein22091912020-01-20 13:45:47 +010041 if(ENABLE_SSH)
David Sedlákddde4492018-09-30 21:34:38 +020042 list(APPEND client_tests test_client_ssh)
43 endif()
44
Claus Klein22091912020-01-20 13:45:47 +010045 if(ENABLE_TLS)
David Sedlák6fdf1ec2018-09-30 21:42:31 +020046 list(APPEND client_tests test_client_tls)
David Sedlákddde4492018-09-30 21:34:38 +020047 endif()
Michal Vasko061561f2016-02-08 15:36:22 +010048endif()
Michal Vasko294d4c62016-02-01 10:10:27 +010049
David Sedlákddde4492018-09-30 21:34:38 +020050foreach(src IN LISTS libsrc)
51 list(APPEND test_srcs "../${src}")
52endforeach()
53add_library(testobj OBJECT ${test_srcs})
54
Michal Vasko294d4c62016-02-01 10:10:27 +010055foreach(test_name IN LISTS tests)
David Sedlákddde4492018-09-30 21:34:38 +020056 add_executable(${test_name} $<TARGET_OBJECTS:testobj> ${test_name}.c)
Michal Vasko294d4c62016-02-01 10:10:27 +010057 target_link_libraries(${test_name} ${CMOCKA_LIBRARIES} ${LIBYANG_LIBRARIES} netconf2)
Claus Klein22091912020-01-20 13:45:47 +010058 target_include_directories(${test_name} PRIVATE ${CMOCKA_INCLUDE_DIR})
David Sedlákddde4492018-09-30 21:34:38 +020059 set_target_properties(${test_name} PROPERTIES LINK_FLAGS "${${test_name}_wrap_link_flags}")
60 add_test(NAME ${test_name} COMMAND $<TARGET_FILE:${test_name}>)
61endforeach()
62
63foreach(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 Klein22091912020-01-20 13:45:47 +010066 target_include_directories(${test_name} PRIVATE ${CMOCKA_INCLUDE_DIR})
David Sedlákddde4492018-09-30 21:34:38 +020067 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 Vasko061561f2016-02-08 15:36:22 +010069endforeach()
Radek Krejcice24ab82015-10-08 15:37:02 +020070
Claus Klein22091912020-01-20 13:45:47 +010071if(ENABLE_VALGRIND_TESTS)
Michal Vasko2cd71632021-06-04 12:03:12 +020072 foreach(test_name IN LISTS tests)
73 add_test(${test_name}_valgrind valgrind --leak-check=full --show-leak-kinds=all --error-exitcode=1
roman6a8947b2022-07-21 11:31:44 +020074 --suppressions=${PROJECT_SOURCE_DIR}/tests/library_valgrind.supp ${CMAKE_BINARY_DIR}/tests/${test_name})
Michal Vasko2cd71632021-06-04 12:03:12 +020075 endforeach()
David Sedlákddde4492018-09-30 21:34:38 +020076
Michal Vasko2cd71632021-06-04 12:03:12 +020077 foreach(test_name IN LISTS client_tests)
78 add_test(${test_name}_valgrind valgrind --leak-check=full --show-leak-kinds=all --error-exitcode=1
roman6a8947b2022-07-21 11:31:44 +020079 --suppressions=${PROJECT_SOURCE_DIR}/tests/library_valgrind.supp ${CMAKE_BINARY_DIR}/tests/${test_name})
Michal Vasko2cd71632021-06-04 12:03:12 +020080 endforeach()
Fred Gan5eda9cb2020-12-11 16:32:08 +080081endif()
82
Jan Kundrátcf15d6c2017-10-26 18:07:56 +020083include_directories(${CMAKE_SOURCE_DIR}/src ${PROJECT_BINARY_DIR})
84configure_file("${PROJECT_SOURCE_DIR}/tests/config.h.in" "${PROJECT_BINARY_DIR}/tests/config.h" ESCAPE_QUOTES @ONLY)
roman41a11e42022-06-22 09:27:08 +020085
86if(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
romane15ad542022-07-27 10:03:46 +020094 file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/netconf.conf
roman41a11e42022-06-22 09:27:08 +020095 "#%PAM-1.4\n"
Jan Kundrát1f502312022-07-26 11:41:14 +020096 "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"
roman41a11e42022-06-22 09:27:08 +020099 )
100
101endif()