Radek Krejci | ce24ab8 | 2015-10-08 15:37:02 +0200 | [diff] [blame] | 1 | cmake_minimum_required(VERSION 2.6) |
Radek Krejci | ce24ab8 | 2015-10-08 15:37:02 +0200 | [diff] [blame] | 2 | |
David Sedlák | ddde449 | 2018-09-30 21:34:38 +0200 | [diff] [blame] | 3 | # list of all the tests in each directory |
Radek Krejci | 2e32e39 | 2017-05-26 13:25:46 +0200 | [diff] [blame] | 4 | set(tests test_io test_fd_comm test_init_destroy_client test_init_destroy_server test_time test_client_thread) |
David Sedlák | ddde449 | 2018-09-30 21:34:38 +0200 | [diff] [blame] | 5 | set(client_tests ) |
Michal Vasko | 061561f | 2016-02-08 15:36:22 +0100 | [diff] [blame] | 6 | |
David Sedlák | ddde449 | 2018-09-30 21:34:38 +0200 | [diff] [blame] | 7 | # add -Wl,--wrap flags |
| 8 | set(test test_client_ssh) |
| 9 | set(${test}_mock_funcs connect ssh_connect ssh_userauth_none ssh_userauth_kbdint ssh_is_connected ssh_channel_open_session ssh_channel_request_subsystem ssh_channel_is_closed ssh_channel_write ssh_channel_poll_timeout ssh_userauth_password nc_handshake_io nc_ctx_check_and_fill) |
| 10 | set(${test}_wrap_link_flags "-Wl") |
| 11 | foreach(mock_func IN LISTS ${test}_mock_funcs) |
| 12 | set(${test}_wrap_link_flags "${${test}_wrap_link_flags},--wrap=${mock_func}") |
| 13 | endforeach() |
| 14 | |
David Sedlák | 6fdf1ec | 2018-09-30 21:42:31 +0200 | [diff] [blame^] | 15 | set(test test_client_tls) |
| 16 | set(${test}_mock_funcs connect SSL_connect nc_send_hello_io nc_handshake_io nc_ctx_check_and_fill) |
| 17 | set(${test}_wrap_link_flags "-Wl") |
| 18 | foreach(mock_func IN LISTS ${test}_mock_funcs) |
| 19 | set(${test}_wrap_link_flags "${${test}_wrap_link_flags},--wrap=${mock_func}") |
| 20 | endforeach() |
| 21 | |
David Sedlák | ddde449 | 2018-09-30 21:34:38 +0200 | [diff] [blame] | 22 | #append tests depending on SSH/TLS |
Michal Vasko | 8f0c028 | 2016-02-29 10:17:14 +0100 | [diff] [blame] | 23 | if (ENABLE_SSH OR ENABLE_TLS) |
Michal Vasko | a7b8ca5 | 2016-03-01 12:09:29 +0100 | [diff] [blame] | 24 | list(APPEND tests test_server_thread) |
David Sedlák | ddde449 | 2018-09-30 21:34:38 +0200 | [diff] [blame] | 25 | if (ENABLE_SSH) |
| 26 | list(APPEND client_tests test_client_ssh) |
| 27 | endif() |
| 28 | |
| 29 | if (ENABLE_TLS) |
David Sedlák | 6fdf1ec | 2018-09-30 21:42:31 +0200 | [diff] [blame^] | 30 | list(APPEND client_tests test_client_tls) |
David Sedlák | ddde449 | 2018-09-30 21:34:38 +0200 | [diff] [blame] | 31 | endif() |
Michal Vasko | 061561f | 2016-02-08 15:36:22 +0100 | [diff] [blame] | 32 | endif() |
Michal Vasko | 294d4c6 | 2016-02-01 10:10:27 +0100 | [diff] [blame] | 33 | |
David Sedlák | ddde449 | 2018-09-30 21:34:38 +0200 | [diff] [blame] | 34 | foreach(src IN LISTS libsrc) |
| 35 | list(APPEND test_srcs "../${src}") |
| 36 | endforeach() |
| 37 | add_library(testobj OBJECT ${test_srcs}) |
| 38 | |
Michal Vasko | 294d4c6 | 2016-02-01 10:10:27 +0100 | [diff] [blame] | 39 | foreach(test_name IN LISTS tests) |
David Sedlák | ddde449 | 2018-09-30 21:34:38 +0200 | [diff] [blame] | 40 | add_executable(${test_name} $<TARGET_OBJECTS:testobj> ${test_name}.c) |
Michal Vasko | 294d4c6 | 2016-02-01 10:10:27 +0100 | [diff] [blame] | 41 | target_link_libraries(${test_name} ${CMOCKA_LIBRARIES} ${LIBYANG_LIBRARIES} netconf2) |
David Sedlák | ddde449 | 2018-09-30 21:34:38 +0200 | [diff] [blame] | 42 | set_target_properties(${test_name} PROPERTIES LINK_FLAGS "${${test_name}_wrap_link_flags}") |
| 43 | add_test(NAME ${test_name} COMMAND $<TARGET_FILE:${test_name}>) |
| 44 | endforeach() |
| 45 | |
| 46 | foreach(test_name IN LISTS client_tests) |
| 47 | add_executable(${test_name} $<TARGET_OBJECTS:testobj> ./client/${test_name}.c) |
| 48 | target_link_libraries(${test_name} ${CMOCKA_LIBRARIES} ${LIBYANG_LIBRARIES} netconf2) |
| 49 | set_target_properties(${test_name} PROPERTIES LINK_FLAGS "${${test_name}_wrap_link_flags}") |
| 50 | add_test(NAME ${test_name} COMMAND $<TARGET_FILE:${test_name}>) |
Michal Vasko | 061561f | 2016-02-08 15:36:22 +0100 | [diff] [blame] | 51 | endforeach() |
Radek Krejci | ce24ab8 | 2015-10-08 15:37:02 +0200 | [diff] [blame] | 52 | |
Michal Vasko | 061561f | 2016-02-08 15:36:22 +0100 | [diff] [blame] | 53 | if (ENABLE_VALGRIND_TESTS) |
Michal Vasko | 294d4c6 | 2016-02-01 10:10:27 +0100 | [diff] [blame] | 54 | find_program(valgrind_FOUND valgrind) |
Michal Vasko | 061561f | 2016-02-08 15:36:22 +0100 | [diff] [blame] | 55 | if (valgrind_FOUND) |
| 56 | foreach (test_name IN LISTS tests) |
Radek Krejci | 16c94f6 | 2017-05-26 10:53:30 +0200 | [diff] [blame] | 57 | add_test(${test_name}_valgrind valgrind --leak-check=full --show-leak-kinds=all --error-exitcode=1 --suppressions=${PROJECT_SOURCE_DIR}/tests/ld.supp ${CMAKE_BINARY_DIR}/tests/${test_name}) |
Michal Vasko | 061561f | 2016-02-08 15:36:22 +0100 | [diff] [blame] | 58 | endforeach() |
David Sedlák | ddde449 | 2018-09-30 21:34:38 +0200 | [diff] [blame] | 59 | |
| 60 | foreach (test_name IN LISTS client_tests) |
| 61 | add_test(${test_name}_valgrind valgrind --leak-check=full --show-leak-kinds=all --error-exitcode=1 --suppressions=${PROJECT_SOURCE_DIR}/tests/ld.supp ${CMAKE_BINARY_DIR}/tests/${test_name}) |
| 62 | endforeach() |
Michal Vasko | 061561f | 2016-02-08 15:36:22 +0100 | [diff] [blame] | 63 | else (valgrind_FOUND) |
Michal Vasko | 294d4c6 | 2016-02-01 10:10:27 +0100 | [diff] [blame] | 64 | Message("-- valgrind executable not found! Disabling memory leaks tests") |
Michal Vasko | 061561f | 2016-02-08 15:36:22 +0100 | [diff] [blame] | 65 | endif() |
Radek Krejci | ce24ab8 | 2015-10-08 15:37:02 +0200 | [diff] [blame] | 66 | endif() |
| 67 | |
Jan Kundrát | cf15d6c | 2017-10-26 18:07:56 +0200 | [diff] [blame] | 68 | include_directories(${CMAKE_SOURCE_DIR}/src ${PROJECT_BINARY_DIR}) |
| 69 | configure_file("${PROJECT_SOURCE_DIR}/tests/config.h.in" "${PROJECT_BINARY_DIR}/tests/config.h" ESCAPE_QUOTES @ONLY) |