Michal Vasko | b0e3ec4 | 2021-05-26 09:48:31 +0200 | [diff] [blame] | 1 | # headers test for including compat.h |
| 2 | add_test(NAME headers |
| 3 | COMMAND ${CMAKE_SOURCE_DIR}/compat/check_includes.sh ${CMAKE_SOURCE_DIR}/src/) |
| 4 | |
| 5 | # format |
roman | 41a11e4 | 2022-06-22 09:27:08 +0200 | [diff] [blame] | 6 | if(${SOURCE_FORMAT_ENABLED}) |
Jan Kundrát | 7029945 | 2021-12-17 07:11:48 +0100 | [diff] [blame] | 7 | add_test(NAME format WORKING_DIRECTORY ${CMAKE_BINARY_DIR} COMMAND cmake --build ${CMAKE_BINARY_DIR} --target format-check) |
Michal Vasko | b0e3ec4 | 2021-05-26 09:48:31 +0200 | [diff] [blame] | 8 | endif() |
| 9 | |
roman | 98066c7 | 2023-10-26 16:18:22 +0200 | [diff] [blame] | 10 | foreach(src IN LISTS libsrc) |
| 11 | list(APPEND test_srcs "../${src}") |
| 12 | endforeach() |
| 13 | add_library(testobj OBJECT ${test_srcs} ${compatsrc}) |
| 14 | |
roman | abe6990 | 2024-08-13 14:43:49 +0200 | [diff] [blame] | 15 | set(TEST_SRC "ln2_test.c") |
| 16 | set(NEXT_TEST_PORT 10050) |
| 17 | |
| 18 | macro(get_test_ports PORT_COUNT PORT_DEFINITIONS) |
| 19 | if (NOT ${PORT_COUNT}) |
| 20 | set(${PORT_COUNT} 1) |
| 21 | endif() |
| 22 | |
| 23 | SET(PORT_INDEX 0) |
| 24 | while(PORT_INDEX LESS ${${PORT_COUNT}}) |
| 25 | list(APPEND ${PORT_DEFINITIONS} "TEST_PORT_${PORT_INDEX}=${NEXT_TEST_PORT}") |
| 26 | math(EXPR PORT_INDEX "${PORT_INDEX} + 1") |
| 27 | math(EXPR NEXT_TEST_PORT "${NEXT_TEST_PORT} + 1") |
| 28 | endwhile() |
| 29 | set(NEXT_TEST_PORT ${NEXT_TEST_PORT} PARENT_SCOPE) |
| 30 | endmacro() |
Jan Kundrát | f8d9e8d | 2024-04-08 12:13:02 +0200 | [diff] [blame] | 31 | |
Jan Kundrát | 60e3162 | 2024-04-08 11:26:33 +0200 | [diff] [blame] | 32 | function(libnetconf2_test) |
Jan Kundrát | f8d9e8d | 2024-04-08 12:13:02 +0200 | [diff] [blame] | 33 | cmake_parse_arguments(TEST "" "NAME;PORT_COUNT" "WRAP_FUNCS" ${ARGN}) |
David Sedlák | ddde449 | 2018-09-30 21:34:38 +0200 | [diff] [blame] | 34 | |
roman | abe6990 | 2024-08-13 14:43:49 +0200 | [diff] [blame] | 35 | add_executable(${TEST_NAME} $<TARGET_OBJECTS:testobj> ${TEST_SRC} ${TEST_NAME}.c) |
Jan Kundrát | 60e3162 | 2024-04-08 11:26:33 +0200 | [diff] [blame] | 36 | target_link_libraries(${TEST_NAME} ${CMOCKA_LIBRARIES} ${LIBYANG_LIBRARIES} netconf2) |
| 37 | target_include_directories(${TEST_NAME} PRIVATE ${CMOCKA_INCLUDE_DIR}) |
roman | abe6990 | 2024-08-13 14:43:49 +0200 | [diff] [blame] | 38 | |
| 39 | # wrap functions |
Jan Kundrát | 60e3162 | 2024-04-08 11:26:33 +0200 | [diff] [blame] | 40 | if(TEST_WRAP_FUNCS) |
| 41 | set(wrap_link_flags "-Wl") |
| 42 | foreach(mock_func IN LISTS TEST_WRAP_FUNCS) |
| 43 | set(wrap_link_flags "${wrap_link_flags},--wrap=${mock_func}") |
| 44 | endforeach() |
| 45 | set_target_properties(${TEST_NAME} PROPERTIES LINK_FLAGS "${wrap_link_flags}") |
| 46 | endif() |
David Sedlák | 6fdf1ec | 2018-09-30 21:42:31 +0200 | [diff] [blame] | 47 | |
roman | abe6990 | 2024-08-13 14:43:49 +0200 | [diff] [blame] | 48 | # create a test, generate port numbers and set them as env vars for the test |
| 49 | add_test(NAME ${TEST_NAME} COMMAND $<TARGET_FILE:${TEST_NAME}>) |
| 50 | get_test_ports(TEST_PORT_COUNT TEST_PORT_DEFINITIONS) |
| 51 | set_tests_properties(${TEST_NAME} PROPERTIES ENVIRONMENT "${TEST_PORT_DEFINITIONS}") |
| 52 | |
| 53 | # do the same for valgrind tests |
Jan Kundrát | 60e3162 | 2024-04-08 11:26:33 +0200 | [diff] [blame] | 54 | if(ENABLE_VALGRIND_TESTS) |
| 55 | add_test(${TEST_NAME}_valgrind valgrind --leak-check=full --show-leak-kinds=all --error-exitcode=1 |
| 56 | --suppressions=${PROJECT_SOURCE_DIR}/tests/library_valgrind.supp ${CMAKE_BINARY_DIR}/tests/${TEST_NAME}) |
roman | abe6990 | 2024-08-13 14:43:49 +0200 | [diff] [blame] | 57 | get_test_ports(TEST_PORT_COUNT VALGRIND_TEST_PORT_DEFINITIONS) |
| 58 | set_tests_properties(${TEST_NAME}_valgrind PROPERTIES ENVIRONMENT "${VALGRIND_TEST_PORT_DEFINITIONS}") |
Jan Kundrát | 60e3162 | 2024-04-08 11:26:33 +0200 | [diff] [blame] | 59 | endif() |
| 60 | endfunction() |
David Sedlák | ddde449 | 2018-09-30 21:34:38 +0200 | [diff] [blame] | 61 | |
Jan Kundrát | 60e3162 | 2024-04-08 11:26:33 +0200 | [diff] [blame] | 62 | # all the tests that don't require SSH and TLS |
roman | 2ca058f | 2024-08-14 10:35:36 +0200 | [diff] [blame] | 63 | libnetconf2_test(NAME test_client_messages) |
Jan Kundrát | 60e3162 | 2024-04-08 11:26:33 +0200 | [diff] [blame] | 64 | libnetconf2_test(NAME test_client_thread) |
| 65 | libnetconf2_test(NAME test_fd_comm) |
Jan Kundrát | 60e3162 | 2024-04-08 11:26:33 +0200 | [diff] [blame] | 66 | libnetconf2_test(NAME test_io) |
| 67 | libnetconf2_test(NAME test_thread_messages) |
roman | 2ca058f | 2024-08-14 10:35:36 +0200 | [diff] [blame] | 68 | libnetconf2_test(NAME test_unix_socket) |
Jan Kundrát | 60e3162 | 2024-04-08 11:26:33 +0200 | [diff] [blame] | 69 | |
| 70 | # tests depending on SSH/TLS |
| 71 | if(ENABLE_SSH_TLS) |
roman | 1920cd5 | 2024-08-14 13:05:23 +0200 | [diff] [blame] | 72 | libnetconf2_test(NAME test_auth_ssh) |
roman | 2ca058f | 2024-08-14 10:35:36 +0200 | [diff] [blame] | 73 | libnetconf2_test(NAME test_authkeys) |
roman | 2969750 | 2024-07-09 15:09:34 +0200 | [diff] [blame] | 74 | libnetconf2_test(NAME test_cert_exp_notif) |
roman | 2ca058f | 2024-08-14 10:35:36 +0200 | [diff] [blame] | 75 | libnetconf2_test(NAME test_ch PORT_COUNT 2) |
Jan Kundrát | f8d9e8d | 2024-04-08 12:13:02 +0200 | [diff] [blame] | 76 | libnetconf2_test(NAME test_endpt_share_clients PORT_COUNT 4) |
roman | 2ca058f | 2024-08-14 10:35:36 +0200 | [diff] [blame] | 77 | libnetconf2_test(NAME test_ks_ts) |
Jan Kundrát | 60e3162 | 2024-04-08 11:26:33 +0200 | [diff] [blame] | 78 | if (LIBPAM_HAVE_CONFDIR) |
| 79 | libnetconf2_test(NAME test_pam WRAP_FUNCS pam_start) |
| 80 | endif() |
roman | 2ca058f | 2024-08-14 10:35:36 +0200 | [diff] [blame] | 81 | libnetconf2_test(NAME test_replace) |
| 82 | libnetconf2_test(NAME test_runtime_changes PORT_COUNT 2) |
| 83 | libnetconf2_test(NAME test_tls) |
| 84 | libnetconf2_test(NAME test_two_channels) |
Fred Gan | 5eda9cb | 2020-12-11 16:32:08 +0800 | [diff] [blame] | 85 | endif() |
| 86 | |
Jan Kundrát | cf15d6c | 2017-10-26 18:07:56 +0200 | [diff] [blame] | 87 | include_directories(${CMAKE_SOURCE_DIR}/src ${PROJECT_BINARY_DIR}) |
| 88 | configure_file("${PROJECT_SOURCE_DIR}/tests/config.h.in" "${PROJECT_BINARY_DIR}/tests/config.h" ESCAPE_QUOTES @ONLY) |
roman | 7d13668 | 2023-12-14 10:43:36 +0100 | [diff] [blame] | 89 | |
| 90 | # compile PAM test module |
| 91 | add_library(pam_netconf SHARED ${CMAKE_SOURCE_DIR}/tests/pam/pam_netconf.c) |
| 92 | set_target_properties(pam_netconf PROPERTIES PREFIX "") |
| 93 | target_link_libraries(pam_netconf ${LIBPAM_LIBRARIES}) |
| 94 | |
| 95 | # generate PAM configuration file |
| 96 | file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/netconf.conf |
| 97 | "#%PAM-1.4\n" |
| 98 | "auth required ${CMAKE_CURRENT_BINARY_DIR}/pam_netconf.so\n" |
| 99 | "account required ${CMAKE_CURRENT_BINARY_DIR}/pam_netconf.so\n" |
| 100 | "password required ${CMAKE_CURRENT_BINARY_DIR}/pam_netconf.so\n" |
| 101 | ) |