blob: 050b50005e52b18d7ccdc8f3e92f1eba48b0af8d [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
6if (${SOURCE_FORMAT_ENABLED})
7 add_test(NAME format WORKING_DIRECTORY ${CMAKE_BINARY_DIR} COMMAND make format-check)
8endif()
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)
David Sedlák19af2662018-10-01 13:42:08 +020012set(client_tests test_client test_client_messages)
Michal Vasko061561f2016-02-08 15:36:22 +010013
David Sedlákddde4492018-09-30 21:34:38 +020014# add -Wl,--wrap flags
15set(test test_client_ssh)
David Sedlák493f2b12018-10-08 21:50:33 +020016set(${test}_mock_funcs connect ssh_connect ssh_userauth_none ssh_userauth_kbdint ssh_is_connected
Claus Klein22091912020-01-20 13:45:47 +010017 ssh_channel_open_session ssh_channel_request_subsystem ssh_channel_is_close ssh_channel_write
18 ssh_channel_poll_timeout ssh_userauth_password nc_handshake_io nc_ctx_check_and_fill
Fred Gan3a736e02021-01-04 17:59:38 +080019 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 +020020set(${test}_wrap_link_flags "-Wl")
21foreach(mock_func IN LISTS ${test}_mock_funcs)
22 set(${test}_wrap_link_flags "${${test}_wrap_link_flags},--wrap=${mock_func}")
23endforeach()
24
David Sedlák6fdf1ec2018-09-30 21:42:31 +020025set(test test_client_tls)
26set(${test}_mock_funcs connect SSL_connect nc_send_hello_io nc_handshake_io nc_ctx_check_and_fill)
27set(${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ákddde4492018-09-30 21:34:38 +020032#append tests depending on SSH/TLS
Claus Klein22091912020-01-20 13:45:47 +010033if(ENABLE_SSH OR ENABLE_TLS)
Michal Vaskoa7b8ca52016-03-01 12:09:29 +010034 list(APPEND tests test_server_thread)
Claus Klein22091912020-01-20 13:45:47 +010035 if(ENABLE_SSH)
David Sedlákddde4492018-09-30 21:34:38 +020036 list(APPEND client_tests test_client_ssh)
37 endif()
38
Claus Klein22091912020-01-20 13:45:47 +010039 if(ENABLE_TLS)
David Sedlák6fdf1ec2018-09-30 21:42:31 +020040 list(APPEND client_tests test_client_tls)
David Sedlákddde4492018-09-30 21:34:38 +020041 endif()
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()
47add_library(testobj OBJECT ${test_srcs})
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
57foreach(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)
Claus Klein22091912020-01-20 13:45:47 +010060 target_include_directories(${test_name} PRIVATE ${CMOCKA_INCLUDE_DIR})
David Sedlákddde4492018-09-30 21:34:38 +020061 set_target_properties(${test_name} PROPERTIES LINK_FLAGS "${${test_name}_wrap_link_flags}")
62 add_test(NAME ${test_name} COMMAND $<TARGET_FILE:${test_name}>)
Michal Vasko061561f2016-02-08 15:36:22 +010063endforeach()
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
68 --suppressions=${PROJECT_SOURCE_DIR}/tests/ld.supp ${CMAKE_BINARY_DIR}/tests/${test_name})
69 endforeach()
David Sedlákddde4492018-09-30 21:34:38 +020070
Michal Vasko2cd71632021-06-04 12:03:12 +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/ld.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)