blob: 769a42bba92d5834fa5136d51b27a8c767c93ad2 [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
roman41a11e42022-06-22 09:27:08 +02006if(${SOURCE_FORMAT_ENABLED})
Jan Kundrát70299452021-12-17 07:11:48 +01007 add_test(NAME format WORKING_DIRECTORY ${CMAKE_BINARY_DIR} COMMAND cmake --build ${CMAKE_BINARY_DIR} --target format-check)
Michal Vaskob0e3ec42021-05-26 09:48:31 +02008endif()
9
roman98066c72023-10-26 16:18:22 +020010foreach(src IN LISTS libsrc)
11 list(APPEND test_srcs "../${src}")
12endforeach()
13add_library(testobj OBJECT ${test_srcs} ${compatsrc})
14
Jan Kundrátf8d9e8d2024-04-08 12:13:02 +020015set(NEXT_TEST_PORT 10005)
16
Jan Kundrát60e31622024-04-08 11:26:33 +020017function(libnetconf2_test)
Jan Kundrátf8d9e8d2024-04-08 12:13:02 +020018 cmake_parse_arguments(TEST "" "NAME;PORT_COUNT" "WRAP_FUNCS" ${ARGN})
David Sedlákddde4492018-09-30 21:34:38 +020019
Jan Kundrát60e31622024-04-08 11:26:33 +020020 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átf8d9e8d2024-04-08 12:13:02 +020030 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át60e31622024-04-08 11:26:33 +020042 add_test(NAME ${TEST_NAME} COMMAND $<TARGET_FILE:${TEST_NAME}>)
David Sedlák6fdf1ec2018-09-30 21:42:31 +020043
Jan Kundrát60e31622024-04-08 11:26:33 +020044 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()
48endfunction()
David Sedlákddde4492018-09-30 21:34:38 +020049
Jan Kundrát60e31622024-04-08 11:26:33 +020050# all the tests that don't require SSH and TLS
51libnetconf2_test(NAME test_unix_socket)
52libnetconf2_test(NAME test_client_thread)
53libnetconf2_test(NAME test_fd_comm)
54libnetconf2_test(NAME test_init_destroy_client)
55libnetconf2_test(NAME test_init_destroy_server)
56libnetconf2_test(NAME test_io)
57libnetconf2_test(NAME test_thread_messages)
58libnetconf2_test(NAME test_client_messages)
59
60# tests depending on SSH/TLS
61if(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átf8d9e8d2024-04-08 12:13:02 +020068 libnetconf2_test(NAME test_endpt_share_clients PORT_COUNT 4)
Jan Kundrát60e31622024-04-08 11:26:33 +020069 libnetconf2_test(NAME test_tls)
70 libnetconf2_test(NAME test_crl)
Jan Kundrátf8d9e8d2024-04-08 12:13:02 +020071 libnetconf2_test(NAME test_ch PORT_COUNT 2)
72 libnetconf2_test(NAME test_runtime_changes PORT_COUNT 2)
Jan Kundrát60e31622024-04-08 11:26:33 +020073 libnetconf2_test(NAME test_authkeys)
74 if (LIBPAM_HAVE_CONFDIR)
75 libnetconf2_test(NAME test_pam WRAP_FUNCS pam_start)
76 endif()
Fred Gan5eda9cb2020-12-11 16:32:08 +080077endif()
78
Jan Kundrát60e31622024-04-08 11:26:33 +020079
Jan Kundrátcf15d6c2017-10-26 18:07:56 +020080include_directories(${CMAKE_SOURCE_DIR}/src ${PROJECT_BINARY_DIR})
81configure_file("${PROJECT_SOURCE_DIR}/tests/config.h.in" "${PROJECT_BINARY_DIR}/tests/config.h" ESCAPE_QUOTES @ONLY)
roman7d136682023-12-14 10:43:36 +010082
83# compile PAM test module
84add_library(pam_netconf SHARED ${CMAKE_SOURCE_DIR}/tests/pam/pam_netconf.c)
85set_target_properties(pam_netconf PROPERTIES PREFIX "")
86target_link_libraries(pam_netconf ${LIBPAM_LIBRARIES})
87
88# generate PAM configuration file
89file(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)