blob: 8807247cdc99d27ea80df36d874eea1dc282bc4b [file] [log] [blame]
David Sedlákddde4492018-09-30 21:34:38 +02001# list of all the tests in each directory
Radek Krejci2e32e392017-05-26 13:25:46 +02002set(tests test_io test_fd_comm test_init_destroy_client test_init_destroy_server test_time test_client_thread)
David Sedlák19af2662018-10-01 13:42:08 +02003set(client_tests test_client test_client_messages)
Michal Vasko061561f2016-02-08 15:36:22 +01004
David Sedlákddde4492018-09-30 21:34:38 +02005# add -Wl,--wrap flags
6set(test test_client_ssh)
David Sedlák493f2b12018-10-08 21:50:33 +02007set(${test}_mock_funcs connect ssh_connect ssh_userauth_none ssh_userauth_kbdint ssh_is_connected
Claus Klein22091912020-01-20 13:45:47 +01008 ssh_channel_open_session ssh_channel_request_subsystem ssh_channel_is_close ssh_channel_write
9 ssh_channel_poll_timeout ssh_userauth_password nc_handshake_io nc_ctx_check_and_fill
10 ssh_userauth_try_publickey ssh_userauth_publickey)
David Sedlákddde4492018-09-30 21:34:38 +020011set(${test}_wrap_link_flags "-Wl")
12foreach(mock_func IN LISTS ${test}_mock_funcs)
13 set(${test}_wrap_link_flags "${${test}_wrap_link_flags},--wrap=${mock_func}")
14endforeach()
15
David Sedlák6fdf1ec2018-09-30 21:42:31 +020016set(test test_client_tls)
17set(${test}_mock_funcs connect SSL_connect nc_send_hello_io nc_handshake_io nc_ctx_check_and_fill)
18set(${test}_wrap_link_flags "-Wl")
19foreach(mock_func IN LISTS ${test}_mock_funcs)
20 set(${test}_wrap_link_flags "${${test}_wrap_link_flags},--wrap=${mock_func}")
21endforeach()
22
David Sedlákddde4492018-09-30 21:34:38 +020023#append tests depending on SSH/TLS
Claus Klein22091912020-01-20 13:45:47 +010024if(ENABLE_SSH OR ENABLE_TLS)
Michal Vaskoa7b8ca52016-03-01 12:09:29 +010025 list(APPEND tests test_server_thread)
Claus Klein22091912020-01-20 13:45:47 +010026 if(ENABLE_SSH)
David Sedlákddde4492018-09-30 21:34:38 +020027 list(APPEND client_tests test_client_ssh)
28 endif()
29
Claus Klein22091912020-01-20 13:45:47 +010030 if(ENABLE_TLS)
David Sedlák6fdf1ec2018-09-30 21:42:31 +020031 list(APPEND client_tests test_client_tls)
David Sedlákddde4492018-09-30 21:34:38 +020032 endif()
Michal Vasko061561f2016-02-08 15:36:22 +010033endif()
Michal Vasko294d4c62016-02-01 10:10:27 +010034
David Sedlákddde4492018-09-30 21:34:38 +020035foreach(src IN LISTS libsrc)
36 list(APPEND test_srcs "../${src}")
37endforeach()
38add_library(testobj OBJECT ${test_srcs})
39
Michal Vasko294d4c62016-02-01 10:10:27 +010040foreach(test_name IN LISTS tests)
David Sedlákddde4492018-09-30 21:34:38 +020041 add_executable(${test_name} $<TARGET_OBJECTS:testobj> ${test_name}.c)
Michal Vasko294d4c62016-02-01 10:10:27 +010042 target_link_libraries(${test_name} ${CMOCKA_LIBRARIES} ${LIBYANG_LIBRARIES} netconf2)
Claus Klein22091912020-01-20 13:45:47 +010043 target_include_directories(${test_name} PRIVATE ${CMOCKA_INCLUDE_DIR})
David Sedlákddde4492018-09-30 21:34:38 +020044 set_target_properties(${test_name} PROPERTIES LINK_FLAGS "${${test_name}_wrap_link_flags}")
45 add_test(NAME ${test_name} COMMAND $<TARGET_FILE:${test_name}>)
46endforeach()
47
48foreach(test_name IN LISTS client_tests)
49 add_executable(${test_name} $<TARGET_OBJECTS:testobj> ./client/${test_name}.c)
50 target_link_libraries(${test_name} ${CMOCKA_LIBRARIES} ${LIBYANG_LIBRARIES} netconf2)
Claus Klein22091912020-01-20 13:45:47 +010051 target_include_directories(${test_name} PRIVATE ${CMOCKA_INCLUDE_DIR})
David Sedlákddde4492018-09-30 21:34:38 +020052 set_target_properties(${test_name} PROPERTIES LINK_FLAGS "${${test_name}_wrap_link_flags}")
53 add_test(NAME ${test_name} COMMAND $<TARGET_FILE:${test_name}>)
Michal Vasko061561f2016-02-08 15:36:22 +010054endforeach()
Radek Krejcice24ab82015-10-08 15:37:02 +020055
Claus Klein22091912020-01-20 13:45:47 +010056if(ENABLE_VALGRIND_TESTS)
Michal Vasko294d4c62016-02-01 10:10:27 +010057 find_program(valgrind_FOUND valgrind)
Claus Klein22091912020-01-20 13:45:47 +010058 if(valgrind_FOUND)
59 foreach(test_name IN LISTS tests)
David Sedlák493f2b12018-10-08 21:50:33 +020060 add_test(${test_name}_valgrind valgrind --leak-check=full --show-leak-kinds=all --error-exitcode=1
Claus Klein22091912020-01-20 13:45:47 +010061 --suppressions=${PROJECT_SOURCE_DIR}/tests/ld.supp ${CMAKE_BINARY_DIR}/tests/${test_name})
Michal Vasko061561f2016-02-08 15:36:22 +010062 endforeach()
David Sedlákddde4492018-09-30 21:34:38 +020063
Claus Klein22091912020-01-20 13:45:47 +010064 foreach(test_name IN LISTS client_tests)
David Sedlák493f2b12018-10-08 21:50:33 +020065 add_test(${test_name}_valgrind valgrind --leak-check=full --show-leak-kinds=all --error-exitcode=1
Claus Klein22091912020-01-20 13:45:47 +010066 --suppressions=${PROJECT_SOURCE_DIR}/tests/ld.supp ${CMAKE_BINARY_DIR}/tests/${test_name})
David Sedlákddde4492018-09-30 21:34:38 +020067 endforeach()
Claus Klein22091912020-01-20 13:45:47 +010068 else()
69 message("-- valgrind executable not found! Disabling memory leaks tests")
Michal Vasko061561f2016-02-08 15:36:22 +010070 endif()
Radek Krejcice24ab82015-10-08 15:37:02 +020071endif()
72
Jan Kundrátcf15d6c2017-10-26 18:07:56 +020073include_directories(${CMAKE_SOURCE_DIR}/src ${PROJECT_BINARY_DIR})
74configure_file("${PROJECT_SOURCE_DIR}/tests/config.h.in" "${PROJECT_BINARY_DIR}/tests/config.h" ESCAPE_QUOTES @ONLY)