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 | |
Jan Kundrát | f8d9e8d | 2024-04-08 12:13:02 +0200 | [diff] [blame] | 15 | set(NEXT_TEST_PORT 10005) |
| 16 | |
Jan Kundrát | 60e3162 | 2024-04-08 11:26:33 +0200 | [diff] [blame] | 17 | function(libnetconf2_test) |
Jan Kundrát | f8d9e8d | 2024-04-08 12:13:02 +0200 | [diff] [blame] | 18 | cmake_parse_arguments(TEST "" "NAME;PORT_COUNT" "WRAP_FUNCS" ${ARGN}) |
David Sedlák | ddde449 | 2018-09-30 21:34:38 +0200 | [diff] [blame] | 19 | |
Jan Kundrát | 60e3162 | 2024-04-08 11:26:33 +0200 | [diff] [blame] | 20 | add_executable(${TEST_NAME} $<TARGET_OBJECTS:testobj> ${TEST_NAME}.c) |
| 21 | target_link_libraries(${TEST_NAME} ${CMOCKA_LIBRARIES} ${LIBYANG_LIBRARIES} netconf2) |
| 22 | target_include_directories(${TEST_NAME} PRIVATE ${CMOCKA_INCLUDE_DIR}) |
| 23 | if(TEST_WRAP_FUNCS) |
| 24 | set(wrap_link_flags "-Wl") |
| 25 | foreach(mock_func IN LISTS TEST_WRAP_FUNCS) |
| 26 | set(wrap_link_flags "${wrap_link_flags},--wrap=${mock_func}") |
| 27 | endforeach() |
| 28 | set_target_properties(${TEST_NAME} PROPERTIES LINK_FLAGS "${wrap_link_flags}") |
| 29 | endif() |
Jan Kundrát | f8d9e8d | 2024-04-08 12:13:02 +0200 | [diff] [blame] | 30 | target_compile_definitions(${TEST_NAME} PRIVATE "TEST_PORT=${NEXT_TEST_PORT}" "TEST_PORT_STR=\"${NEXT_TEST_PORT}\"") |
| 31 | if(NOT TEST_PORT_COUNT) |
| 32 | set(TEST_PORT_COUNT 1) |
| 33 | endif() |
| 34 | SET(PORT_INDEX 2) |
| 35 | while(PORT_INDEX LESS_EQUAL TEST_PORT_COUNT) |
| 36 | math(EXPR ANOTHER_PORT "${NEXT_TEST_PORT} + ${PORT_INDEX} - 1") |
| 37 | target_compile_definitions(${TEST_NAME} PRIVATE "TEST_PORT_${PORT_INDEX}=${ANOTHER_PORT}" "TEST_PORT_${PORT_INDEX}_STR=\"${ANOTHER_PORT}\"") |
| 38 | math(EXPR PORT_INDEX "${PORT_INDEX} + 1") |
| 39 | endwhile() |
| 40 | math(EXPR NEXT_TEST_PORT "${NEXT_TEST_PORT} + ${TEST_PORT_COUNT}") |
| 41 | set(NEXT_TEST_PORT ${NEXT_TEST_PORT} PARENT_SCOPE) |
Jan Kundrát | 60e3162 | 2024-04-08 11:26:33 +0200 | [diff] [blame] | 42 | add_test(NAME ${TEST_NAME} COMMAND $<TARGET_FILE:${TEST_NAME}>) |
David Sedlák | 6fdf1ec | 2018-09-30 21:42:31 +0200 | [diff] [blame] | 43 | |
Jan Kundrát | 60e3162 | 2024-04-08 11:26:33 +0200 | [diff] [blame] | 44 | if(ENABLE_VALGRIND_TESTS) |
| 45 | add_test(${TEST_NAME}_valgrind valgrind --leak-check=full --show-leak-kinds=all --error-exitcode=1 |
| 46 | --suppressions=${PROJECT_SOURCE_DIR}/tests/library_valgrind.supp ${CMAKE_BINARY_DIR}/tests/${TEST_NAME}) |
| 47 | endif() |
| 48 | endfunction() |
David Sedlák | ddde449 | 2018-09-30 21:34:38 +0200 | [diff] [blame] | 49 | |
Jan Kundrát | 60e3162 | 2024-04-08 11:26:33 +0200 | [diff] [blame] | 50 | # all the tests that don't require SSH and TLS |
| 51 | libnetconf2_test(NAME test_unix_socket) |
| 52 | libnetconf2_test(NAME test_client_thread) |
| 53 | libnetconf2_test(NAME test_fd_comm) |
| 54 | libnetconf2_test(NAME test_init_destroy_client) |
| 55 | libnetconf2_test(NAME test_init_destroy_server) |
| 56 | libnetconf2_test(NAME test_io) |
| 57 | libnetconf2_test(NAME test_thread_messages) |
| 58 | libnetconf2_test(NAME test_client_messages) |
| 59 | |
| 60 | # tests depending on SSH/TLS |
| 61 | if(ENABLE_SSH_TLS) |
| 62 | libnetconf2_test(NAME test_auth) |
| 63 | libnetconf2_test(NAME test_two_channels) |
| 64 | libnetconf2_test(NAME test_ks_ts) |
| 65 | libnetconf2_test(NAME test_ec) |
| 66 | libnetconf2_test(NAME test_ed25519) |
| 67 | libnetconf2_test(NAME test_replace) |
Jan Kundrát | f8d9e8d | 2024-04-08 12:13:02 +0200 | [diff] [blame] | 68 | libnetconf2_test(NAME test_endpt_share_clients PORT_COUNT 4) |
Jan Kundrát | 60e3162 | 2024-04-08 11:26:33 +0200 | [diff] [blame] | 69 | libnetconf2_test(NAME test_tls) |
| 70 | libnetconf2_test(NAME test_crl) |
Jan Kundrát | f8d9e8d | 2024-04-08 12:13:02 +0200 | [diff] [blame] | 71 | libnetconf2_test(NAME test_ch PORT_COUNT 2) |
| 72 | libnetconf2_test(NAME test_runtime_changes PORT_COUNT 2) |
Jan Kundrát | 60e3162 | 2024-04-08 11:26:33 +0200 | [diff] [blame] | 73 | libnetconf2_test(NAME test_authkeys) |
| 74 | if (LIBPAM_HAVE_CONFDIR) |
| 75 | libnetconf2_test(NAME test_pam WRAP_FUNCS pam_start) |
| 76 | endif() |
Fred Gan | 5eda9cb | 2020-12-11 16:32:08 +0800 | [diff] [blame] | 77 | endif() |
| 78 | |
Jan Kundrát | 60e3162 | 2024-04-08 11:26:33 +0200 | [diff] [blame] | 79 | |
Jan Kundrát | cf15d6c | 2017-10-26 18:07:56 +0200 | [diff] [blame] | 80 | include_directories(${CMAKE_SOURCE_DIR}/src ${PROJECT_BINARY_DIR}) |
| 81 | 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] | 82 | |
| 83 | # compile PAM test module |
| 84 | add_library(pam_netconf SHARED ${CMAKE_SOURCE_DIR}/tests/pam/pam_netconf.c) |
| 85 | set_target_properties(pam_netconf PROPERTIES PREFIX "") |
| 86 | target_link_libraries(pam_netconf ${LIBPAM_LIBRARIES}) |
| 87 | |
| 88 | # generate PAM configuration file |
| 89 | file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/netconf.conf |
| 90 | "#%PAM-1.4\n" |
| 91 | "auth required ${CMAKE_CURRENT_BINARY_DIR}/pam_netconf.so\n" |
| 92 | "account required ${CMAKE_CURRENT_BINARY_DIR}/pam_netconf.so\n" |
| 93 | "password required ${CMAKE_CURRENT_BINARY_DIR}/pam_netconf.so\n" |
| 94 | ) |