]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#3729] Checkpoint: doing dhcp4 tests
authorFrancis Dupont <fdupont@isc.org>
Fri, 7 Feb 2025 10:20:45 +0000 (11:20 +0100)
committerAndrei Pavel <andrei@isc.org>
Thu, 13 Feb 2025 08:05:42 +0000 (10:05 +0200)
src/bin/dhcp4/meson.build
src/bin/dhcp4/tests/dhcp4_process_tests.sh.in [changed mode: 0644->0755]
src/bin/dhcp4/tests/meson-dhcp4_process_tests.sh.in [new file with mode: 0755]
src/bin/dhcp4/tests/meson-test_libraries.h.in [new file with mode: 0644]
src/bin/dhcp4/tests/meson.build [new file with mode: 0644]
src/lib/dhcpsrv/tests/meson.build

index 5aad6a58fcfb9469ea7b28754d18ef4ae032f24e..84f0cf44d48cdb8a819b1dbe2d4c5038fb1f4676 100644 (file)
@@ -22,3 +22,4 @@ executable(
     install_dir: 'sbin',
     link_with: [dhcp4_lib] + LIBS_BUILT_SO_FAR,
 )
+# subdir('tests')
old mode 100644 (file)
new mode 100755 (executable)
diff --git a/src/bin/dhcp4/tests/meson-dhcp4_process_tests.sh.in b/src/bin/dhcp4/tests/meson-dhcp4_process_tests.sh.in
new file mode 100755 (executable)
index 0000000..f380286
--- /dev/null
@@ -0,0 +1,641 @@
+#!/bin/sh
+
+# Copyright (C) 2014-2024 Internet Systems Consortium, Inc. ("ISC")
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+# Exit with error if commands exit with non-zero and if undefined variables are
+# used.
+set -eu
+
+# Path to the temporary configuration file.
+CFG_FILE="@abs_top_builddir@/src/bin/dhcp4/tests/test_config.json"
+# Path to the Kea log file.
+LOG_FILE="@abs_top_builddir@/src/bin/dhcp4/tests/test.log"
+# Path to the Kea lease file.
+LEASE_FILE="@abs_top_builddir@/src/bin/dhcp4/tests/test_leases.csv"
+# Path to the Kea LFC application
+export KEA_LFC_EXECUTABLE="@abs_top_builddir@/src/bin/lfc/kea-lfc"
+# Path to test hooks library
+HOOK_FAIL_LOAD_PATH="@abs_top_builddir@/src/bin/dhcp4/tests/libco3.so"
+# Path to test hooks library
+HOOK_FAIL_POLL_PATH="@abs_top_builddir@/src/bin/dhcp4/tests/libco4.so"
+# Kea configuration to be stored in the configuration file.
+CONFIG="{
+    \"Dhcp4\":
+    {
+        \"interfaces-config\": {
+            \"interfaces\": [ ]
+        },
+        \"valid-lifetime\": 4000,
+        \"renew-timer\": 1000,
+        \"rebind-timer\": 2000,
+        \"lease-database\":
+        {
+            \"type\": \"memfile\",
+            \"name\": \"$LEASE_FILE\",
+            \"persist\": false,
+            \"lfc-interval\": 0
+        },
+        \"subnet4\": [
+        {
+            \"id\": 1,
+            \"subnet\": \"10.0.0.0/8\",
+            \"pools\": [ { \"pool\": \"10.0.0.10-10.0.0.100\" } ]
+        } ],
+        \"ddns-qualifying-suffix\": \"\",
+        \"dhcp-ddns\": {
+            \"enable-updates\": true
+        },
+        \"loggers\": [
+        {
+            \"name\": \"kea-dhcp4\",
+            \"output-options\": [
+                {
+                    \"output\": \"$LOG_FILE\"
+                }
+            ],
+            \"severity\": \"INFO\"
+        }
+        ]
+    }
+}"
+
+# Invalid configuration (syntax error) to check that Kea can check syntax.
+# This config has following errors:
+# - it should be interfaces-config/interfaces, not interfaces
+# - it should be subnet4/pools, no subnet4/pool
+CONFIG_BAD_SYNTAX="{
+    \"Dhcp4\":
+    {
+        \"interfaces\": [ ],
+        \"valid-lifetime\": 4000,
+        \"renew-timer\": 1000,
+        \"rebind-timer\": 2000,
+        \"lease-database\":
+        {
+            \"type\": \"memfile\",
+            \"persist\": false
+        },
+        \"subnet4\": [
+        {
+            \"id\": 1,
+            \"subnet\": \"10.0.0.0/8\",
+            \"pool\": [ { \"pool\": \"10.0.0.10-10.0.0.100\" } ]
+        } ],
+        \"loggers\": [
+        {
+            \"name\": \"kea-dhcp4\",
+            \"output-options\": [
+                {
+                    \"output\": \"$LOG_FILE\"
+                }
+            ],
+            \"severity\": \"INFO\"
+        }
+        ]
+    }
+}"
+
+# This config has bad pool values. The pool it out of scope for the subnet
+# it is defined in. Syntactically the config is correct, though.
+CONFIG_BAD_VALUES="{
+    \"Dhcp4\":
+    {
+        \"interfaces-config\": {
+            \"interfaces\": [ ]
+        },
+        \"valid-lifetime\": 4000,
+        \"renew-timer\": 1000,
+        \"rebind-timer\": 2000,
+        \"lease-database\":
+        {
+            \"type\": \"memfile\",
+            \"persist\": false
+        },
+        \"subnet4\": [
+        {
+            \"id\": 1,
+            \"subnet\": \"10.0.0.0/8\",
+            \"pools\": [ { \"pool\": \"192.168.0.10-192.168.0.100\" } ]
+        } ],
+        \"loggers\": [
+        {
+            \"name\": \"kea-dhcp4\",
+            \"output-options\": [
+                {
+                    \"output\": \"$LOG_FILE\"
+                }
+            ],
+            \"severity\": \"INFO\"
+        }
+        ]
+    }
+}"
+
+# Invalid configuration (negative valid-lifetime) to check that Kea
+# gracefully handles reconfiguration errors.
+CONFIG_INVALID="{
+    \"Dhcp4\":
+    {
+        \"interfaces-config\": {
+            \"interfaces\": [ ]
+        },
+        \"valid-lifetime\": -3,
+        \"renew-timer\": 1000,
+        \"rebind-timer\": 2000,
+        \"lease-database\":
+        {
+            \"type\": \"memfile\",
+            \"persist\": false
+        },
+        \"subnet4\": [
+        {
+            \"id\": 1,
+            \"subnet\": \"10.0.0.0/8\",
+            \"pool\": [ { \"pool\": \"10.0.0.10-10.0.0.100\" } ]
+        } ],
+        \"loggers\": [
+        {
+            \"name\": \"kea-dhcp4\",
+            \"output-options\": [
+                {
+                    \"output\": \"$LOG_FILE\"
+                }
+            ],
+            \"severity\": \"INFO\"
+        }
+        ]
+    }
+}"
+
+# Invalid configuration (hook explicitly fails to load) to check that performing
+# extra configuration checks detects the error.
+INVALID_CONFIG_HOOKS_LOAD="{
+    \"Dhcp4\":
+    {
+        \"interfaces-config\": {
+            \"interfaces\": [ ]
+        },
+        \"multi-threading\": {
+          \"enable-multi-threading\": false
+        },
+        \"valid-lifetime\": 4000,
+        \"renew-timer\": 1000,
+        \"rebind-timer\": 2000,
+        \"lease-database\":
+        {
+            \"type\": \"memfile\",
+            \"name\": \"$LEASE_FILE\",
+            \"persist\": false,
+            \"lfc-interval\": 0
+        },
+        \"subnet4\": [
+        {
+            \"id\": 1,
+            \"subnet\": \"10.0.0.0/8\",
+            \"pools\": [ { \"pool\": \"10.0.0.10-10.0.0.100\" } ]
+        } ],
+        \"ddns-qualifying-suffix\": \"\",
+        \"dhcp-ddns\": {
+            \"enable-updates\": true
+        },
+        \"hooks-libraries\": [
+        {
+            \"library\": \"$HOOK_FAIL_LOAD_PATH\",
+                \"parameters\": {
+                    \"mode\": \"fail-on-load\"
+            }
+        } ],
+        \"loggers\": [
+        {
+            \"name\": \"kea-dhcp4\",
+            \"output-options\": [
+                {
+                    \"output\": \"$LOG_FILE\"
+                }
+            ],
+            \"severity\": \"INFO\"
+        }
+        ]
+    }
+}"
+
+# Invalid configuration (hook point returns error) to check that performing
+# extra configuration checks detects the error.
+INVALID_CONFIG_HOOKS_CALLOUT_FAIL_ON_LOAD="{
+    \"Dhcp4\":
+    {
+        \"interfaces-config\": {
+            \"interfaces\": [ ]
+        },
+        \"multi-threading\": {
+            \"enable-multi-threading\": false
+        },
+        \"valid-lifetime\": 4000,
+        \"renew-timer\": 1000,
+        \"rebind-timer\": 2000,
+        \"lease-database\":
+        {
+            \"type\": \"memfile\",
+            \"name\": \"$LEASE_FILE\",
+            \"persist\": false,
+            \"lfc-interval\": 0
+        },
+        \"subnet4\": [
+        {
+            \"id\": 1,
+            \"subnet\": \"10.0.0.0/8\",
+            \"pools\": [ { \"pool\": \"10.0.0.10-10.0.0.100\" } ]
+        } ],
+        \"ddns-qualifying-suffix\": \"\",
+        \"dhcp-ddns\": {
+            \"enable-updates\": true
+        },
+        \"hooks-libraries\": [
+        {
+            \"library\": \"$HOOK_FAIL_LOAD_PATH\",
+                \"parameters\": {
+                    \"mode\": \"fail-without-error\"
+            }
+        } ],
+        \"loggers\": [
+        {
+            \"name\": \"kea-dhcp4\",
+            \"output-options\": [
+                {
+                    \"output\": \"$LOG_FILE\"
+                }
+            ],
+            \"severity\": \"INFO\"
+        }
+        ]
+    }
+}"
+
+# Invalid configuration (poll after load throws exception) to check that performing
+# extra configuration checks detects the error.
+INVALID_CONFIG_HOOKS_CALLOUT_FAIL_ON_POLL="{
+    \"Dhcp4\":
+    {
+        \"interfaces-config\": {
+            \"interfaces\": [ ]
+        },
+        \"multi-threading\": {
+            \"enable-multi-threading\": false
+        },
+        \"valid-lifetime\": 4000,
+        \"renew-timer\": 1000,
+        \"rebind-timer\": 2000,
+        \"lease-database\":
+        {
+            \"type\": \"memfile\",
+            \"name\": \"$LEASE_FILE\",
+            \"persist\": false,
+            \"lfc-interval\": 0
+        },
+        \"subnet4\": [
+        {
+            \"id\": 1,
+            \"subnet\": \"10.0.0.0/8\",
+            \"pools\": [ { \"pool\": \"10.0.0.10-10.0.0.100\" } ]
+        } ],
+        \"ddns-qualifying-suffix\": \"\",
+        \"dhcp-ddns\": {
+            \"enable-updates\": true
+        },
+        \"hooks-libraries\": [
+        {
+            \"library\": \"$HOOK_FAIL_POLL_PATH\",
+                \"parameters\": {
+                    \"mode\": \"fail-without-error\"
+            }
+        } ],
+        \"loggers\": [
+        {
+            \"name\": \"kea-dhcp4\",
+            \"output-options\": [
+                {
+                    \"output\": \"$LOG_FILE\"
+                }
+            ],
+            \"severity\": \"INFO\"
+        }
+        ]
+    }
+}"
+
+# Set the location of the executable.
+bin="kea-dhcp4"
+bin_path="@abs_top_builddir@/src/bin/dhcp4"
+
+# Import common test library.
+# shellcheck source=src/lib/testutils/dhcp_test_lib.sh.in
+. "@abs_top_builddir@/src/lib/testutils/dhcp_test_lib.sh"
+
+# This test verifies that syntax checking works properly. This function
+# requires 3 parameters:
+# test_name
+# config - string with a content of the config (will be written to a file)
+# expected_code - expected exit code returned by kea (0 - success, 1 - failure)
+syntax_check_test() {
+    local test_name="${1}"
+    local config="${2}"
+    local expected_code="${3}"
+    local check_type="${4}"
+
+    # Log the start of the test and print test name.
+    test_start "${test_name}"
+    # Create correct configuration file.
+    create_config "${config}"
+    # Check it
+    printf "Running command %s.\n" "\"${bin_path}/${bin} ${check_type} ${CFG_FILE}\""
+    run_command \
+        "${bin_path}/${bin}" "${check_type}" "${CFG_FILE}"
+    if [ "${EXIT_CODE}" -ne "${expected_code}" ]; then
+        printf 'ERROR: expected exit code %s, got %s\n' "${expected_code}" "${EXIT_CODE}"
+        clean_exit 1
+    fi
+    test_finish 0
+}
+
+# This test verifies that DHCPv4 can be reconfigured with a SIGHUP signal.
+dynamic_reconfiguration_test() {
+    # Log the start of the test and print test name.
+    test_start "dhcpv4_srv.dynamic_reconfiguration"
+    # Create new configuration file.
+    create_config "${CONFIG}"
+    # Instruct Kea to log to the specific file.
+    set_logger
+    # Start Kea.
+    start_kea "${bin_path}/${bin}"
+    # Wait up to 20s for Kea to start.
+    wait_for_kea 20
+    if [ "${_WAIT_FOR_KEA}" -eq 0 ]; then
+        printf "ERROR: timeout waiting for Kea to start.\n"
+        clean_exit 1
+    fi
+
+    # Check if it is still running. It could have terminated (e.g. as a result
+    # of configuration failure).
+    get_pid "${bin}"
+    if [ "${_GET_PIDS_NUM}" -ne 1 ]; then
+        printf "ERROR: expected one Kea process to be started. Found %d processes\
+ started.\n" "${_GET_PIDS_NUM}"
+        clean_exit 1
+    fi
+
+    # Check in the log file, how many times server has been configured. It should
+    # be just once on startup.
+    get_reconfigs
+    if [ "${_GET_RECONFIGS}" -ne 1 ]; then
+        printf "ERROR: server hasn't been configured.\n"
+        clean_exit 1
+    else
+        printf "Server successfully configured.\n"
+    fi
+
+    # Now use invalid configuration.
+    create_config "${CONFIG_INVALID}"
+
+    # Try to reconfigure by sending SIGHUP
+    send_signal 1 "${bin}"
+
+    # The configuration should fail and the error message should be there.
+    wait_for_message 10 "DHCP4_CONFIG_LOAD_FAIL" 1
+
+    # After receiving SIGHUP the server should try to reconfigure itself.
+    # The configuration provided is invalid so it should result in
+    # reconfiguration failure but the server should still be running.
+    get_reconfigs
+    if [ "${_GET_RECONFIGS}" -ne 1 ]; then
+        printf "ERROR: server has been reconfigured despite bogus configuration.\n"
+        clean_exit 1
+    elif [ "${_GET_RECONFIG_ERRORS}" -ne 1 ]; then
+        printf "ERROR: server did not report reconfiguration error despite attempt\
+ to configure it with invalid configuration.\n"
+        clean_exit 1
+    fi
+
+    # Make sure the server is still operational.
+    get_pid "${bin}"
+    if [ "${_GET_PIDS_NUM}" -ne 1 ]; then
+        printf "ERROR: Kea process was killed when attempting reconfiguration.\n"
+        clean_exit 1
+    fi
+
+    # Restore the good configuration.
+    create_config "${CONFIG}"
+
+    # Reconfigure the server with SIGHUP.
+    send_signal 1 "${bin}"
+
+    # There should be two occurrences of the DHCP4_CONFIG_COMPLETE messages.
+    # Wait for it up to 10s.
+    wait_for_message 10 "DHCP4_CONFIG_COMPLETE" 2
+
+    # After receiving SIGHUP the server should get reconfigured and the
+    # reconfiguration should be noted in the log file. We should now
+    # have two configurations logged in the log file.
+    if [ "${_WAIT_FOR_MESSAGE}" -eq 0 ]; then
+        printf "ERROR: server hasn't been reconfigured.\n"
+        clean_exit 1
+    else
+        printf "Server successfully reconfigured.\n"
+    fi
+
+    # Make sure the server is still operational.
+    get_pid "${bin}"
+    if [ "${_GET_PIDS_NUM}" -ne 1 ]; then
+        printf "ERROR: Kea process was killed when attempting reconfiguration.\n"
+        clean_exit 1
+    fi
+
+    # When the server receives a signal the call to select() function is
+    # interrupted. This should not be logged as an error.
+    get_log_messages "DHCP4_PACKET_RECEIVE_FAIL"
+    assert_eq 0 "${_GET_LOG_MESSAGES}" \
+        "Expected get_log_messages DHCP4_PACKET_RECEIVE_FAIL return %d, \
+returned %d."
+
+    # All ok. Shut down Kea and exit.
+    test_finish 0
+}
+
+# This test verifies that DHCPv4 server is shut down gracefully when it
+# receives a SIGINT or SIGTERM signal.
+shutdown_test() {
+    test_name=${1}  # Test name
+    signum=${2}      # Signal number
+    # Log the start of the test and print test name.
+    test_start "${test_name}"
+    # Create new configuration file.
+    create_config "${CONFIG}"
+    # Instruct Kea to log to the specific file.
+    set_logger
+    # Start Kea.
+    start_kea "${bin_path}/${bin}"
+    # Wait up to 20s for Kea to start.
+    wait_for_kea 20
+    if [ "${_WAIT_FOR_KEA}" -eq 0 ]; then
+        printf "ERROR: timeout waiting for Kea to start.\n"
+        clean_exit 1
+    fi
+
+    # Check if it is still running. It could have terminated (e.g. as a result
+    # of configuration failure).
+    get_pid "${bin}"
+    if [ "${_GET_PIDS_NUM}" -ne 1 ]; then
+        printf "ERROR: expected one Kea process to be started. Found %d processes\
+ started.\n" "${_GET_PIDS_NUM}"
+        clean_exit 1
+    fi
+
+    # Check in the log file, how many times server has been configured. It should
+    # be just once on startup.
+    get_reconfigs
+    if [ "${_GET_RECONFIGS}" -ne 1 ]; then
+        printf "ERROR: server hasn't been configured.\n"
+        clean_exit 1
+    else
+        printf "Server successfully configured.\n"
+    fi
+
+    # Send signal to Kea (SIGTERM, SIGINT etc.)
+    send_signal "${signum}" "${bin}"
+
+    # Wait up to 10s for the server's graceful shutdown. The graceful shut down
+    # should be recorded in the log file with the appropriate message.
+    wait_for_message 10 "DHCP4_SHUTDOWN" 1
+    if [ "${_WAIT_FOR_MESSAGE}" -eq 0 ]; then
+        printf "ERROR: Server did not record shutdown in the log.\n"
+        clean_exit 1
+    fi
+
+    # Make sure the server is down.
+    wait_for_server_down 5 "${bin}"
+    assert_eq 1 "${_WAIT_FOR_SERVER_DOWN}" \
+        "Expected wait_for_server_down return %d, returned %d"
+
+    # When the server receives a signal the call to select() function is
+    # interrupted. This should not be logged as an error.
+    get_log_messages "DHCP4_PACKET_RECEIVE_FAIL"
+    assert_eq 0 "${_GET_LOG_MESSAGES}" \
+        "Expected get_log_messages return %d, returned %d."
+
+    test_finish 0
+}
+
+# This test verifies that DHCPv4 can be configured to run lease file cleanup
+# periodically.
+lfc_timer_test() {
+    # Log the start of the test and print test name.
+    test_start "dhcpv4_srv.lfc_timer_test"
+    # Create a configuration with the LFC enabled, by replacing the section
+    # with the lfc-interval and persist parameters.
+    LFC_CONFIG=$(printf '%s' "${CONFIG}" | sed -e 's/\"lfc-interval\": 0/\"lfc-interval\": 3/g' \
+                        | sed -e 's/\"persist\": false/\"persist\": true/g')
+    # Create new configuration file.
+    create_config "${LFC_CONFIG}"
+    # Instruct Kea to log to the specific file.
+    set_logger
+    # Start Kea.
+    start_kea "${bin_path}/${bin}"
+    # Wait up to 20s for Kea to start.
+    wait_for_kea 20
+    if [ "${_WAIT_FOR_KEA}" -eq 0 ]; then
+        printf "ERROR: timeout waiting for Kea to start.\n"
+        clean_exit 1
+    fi
+
+    # Check if it is still running. It could have terminated (e.g. as a result
+    # of configuration failure).
+    get_pid "${bin}"
+    if [ "${_GET_PIDS_NUM}" -ne 1 ]; then
+        printf "ERROR: expected one Kea process to be started. Found %d processes\
+ started.\n" "${_GET_PIDS_NUM}"
+        clean_exit 1
+    fi
+
+    # Check if Kea emits the log message indicating that LFC is started.
+    wait_for_message 10 "DHCPSRV_MEMFILE_LFC_EXECUTE" 1
+    if [ "${_WAIT_FOR_MESSAGE}" -eq 0 ]; then
+        printf "ERROR: Server did not execute LFC.\n"
+        clean_exit 1
+    fi
+
+    # Give it a short time to run.
+    sleep 1
+
+    # Modify the interval.
+    LFC_CONFIG=$(printf '%s' "${LFC_CONFIG}" | sed -e 's/\"lfc-interval\": 3/\"lfc-interval\": 4/g')
+    # Create new configuration file.
+    create_config "${LFC_CONFIG}"
+
+    # Reconfigure the server with SIGHUP.
+    send_signal 1 "${bin}"
+
+    # There should be two occurrences of the DHCP4_CONFIG_COMPLETE messages.
+    # Wait for it up to 10s.
+    wait_for_message 10 "DHCP4_CONFIG_COMPLETE" 2
+
+    # After receiving SIGHUP the server should get reconfigured and the
+    # reconfiguration should be noted in the log file. We should now
+    # have two configurations logged in the log file.
+    if [ "${_WAIT_FOR_MESSAGE}" -eq 0 ]; then
+        printf "ERROR: server hasn't been reconfigured.\n"
+        clean_exit 1
+    else
+        printf "Server successfully reconfigured.\n"
+    fi
+
+    # Make sure the server is still operational.
+    get_pid "${bin}"
+    if [ "${_GET_PIDS_NUM}" -ne 1 ]; then
+        printf "ERROR: Kea process was killed when attempting reconfiguration.\n"
+        clean_exit 1
+    fi
+
+    # Wait for the LFC to run the second time.
+    wait_for_message 10 "DHCPSRV_MEMFILE_LFC_EXECUTE" 2
+    if [ "${_WAIT_FOR_MESSAGE}" -eq 0 ]; then
+        printf "ERROR: Server did not execute LFC.\n"
+        clean_exit 1
+    fi
+
+    # Send signal to Kea SIGTERM
+    send_signal 15 "${bin}"
+
+    # Wait up to 10s for the server's graceful shutdown. The graceful shut down
+    # should be recorded in the log file with the appropriate message.
+    wait_for_message 10 "DHCP4_SHUTDOWN" 1
+    if [ "${_WAIT_FOR_MESSAGE}" -eq 0 ]; then
+        printf "ERROR: Server did not record shutdown in the log.\n"
+        clean_exit 1
+    fi
+
+    # Make sure the server is down.
+    wait_for_server_down 5 "${bin}"
+    assert_eq 1 "${_WAIT_FOR_SERVER_DOWN}" \
+        "Expected wait_for_server_down return %d, returned %d"
+
+    # All ok. Shut down Kea and exit.
+    test_finish 0
+}
+
+server_pid_file_test "${CONFIG}" DHCP4_ALREADY_RUNNING
+dynamic_reconfiguration_test
+shutdown_test "dhcpv4.sigterm_test" 15
+shutdown_test "dhcpv4.sigint_test" 2
+version_test "dhcpv4.version"
+logger_vars_test "dhcpv4.variables"
+lfc_timer_test
+syntax_check_test "dhcpv4.syntax_check_success" "${CONFIG}" 0 -t
+syntax_check_test "dhcpv4.syntax_check_bad_syntax" "${CONFIG_BAD_SYNTAX}" 1 -t
+syntax_check_test "dhcpv4.syntax_check_bad_values" "${CONFIG_BAD_VALUES}" 1 -t
+syntax_check_test "dhcpv4.syntax_check_hooks_load_fail" "${INVALID_CONFIG_HOOKS_LOAD}" 1 -T
+syntax_check_test "dhcpv4.syntax_check_hooks_callout_fail_on_load" "${INVALID_CONFIG_HOOKS_CALLOUT_FAIL_ON_LOAD}" 1 -T
+syntax_check_test "dhcpv4.syntax_check_hooks_callout_fail_on_poll" "${INVALID_CONFIG_HOOKS_CALLOUT_FAIL_ON_POLL}" 1 -T
+password_redact_test "dhcpv4.password_redact_test" "$(kea_dhcp_config 4)" 0
diff --git a/src/bin/dhcp4/tests/meson-test_libraries.h.in b/src/bin/dhcp4/tests/meson-test_libraries.h.in
new file mode 100644 (file)
index 0000000..287178b
--- /dev/null
@@ -0,0 +1,33 @@
+// Copyright (C) 2013-2024 Internet Systems Consortium, Inc. ("ISC")
+//
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef TEST_LIBRARIES_H
+#define TEST_LIBRARIES_H
+
+#include <config.h>
+
+namespace {
+
+#define DLL_SUFFIX ".so"
+
+// Names of the libraries used in these tests.  These libraries are built using
+// libtool, so we need to look in the hidden ".libs" directory to locate the
+// shared library.
+
+// Library with load/unload functions creating marker files to check their
+// operation.
+const char* const CALLOUT_LIBRARY_1 = "@abs_builddir@/libco1.so";
+const char* const CALLOUT_LIBRARY_2 = "@abs_builddir@/libco2.so";
+const char* const CALLOUT_LIBRARY_3 = "@abs_builddir@/libco3.so";
+const char* const CALLOUT_LIBRARY_4 = "@abs_builddir@/libco4.so";
+
+// Name of a library which is not present.
+const char* const NOT_PRESENT_LIBRARY = "@abs_builddir@/libnothere.so";
+
+} // anonymous namespace
+
+
+#endif // TEST_LIBRARIES_H
diff --git a/src/bin/dhcp4/tests/meson.build b/src/bin/dhcp4/tests/meson.build
new file mode 100644 (file)
index 0000000..6f750fc
--- /dev/null
@@ -0,0 +1,114 @@
+if not gtest.found()
+    subdir_done()
+endif
+
+CURRENT_BUILD_DIR = meson.current_build_dir()
+CURRENT_SOURCE_DIR = meson.current_source_dir()
+libs_testutils = [
+    kea_dhcpsrv_testutils_lib,
+    kea_dhcp_testutils_lib,
+    kea_database_testutils_lib,
+    kea_testutils_lib,
+]
+dhcp4_tests_conf_data = configuration_data()
+dhcp4_tests_conf_data.set('abs_top_builddir', TOP_BUILD_DIR)
+dhcp4_tests_conf_data.set('abs_top_srcdir', TOP_SOURCE_DIR)
+dhcp4_tests_conf_data.set('abs_builddir', meson.current_build_dir())
+dhcp4_process_tests = configure_file(
+    input: 'meson-dhcp4_process_tests.sh.in',
+    output: 'dhcp4_process_tests.sh',
+    configuration: dhcp4_tests_conf_data,
+)
+test(
+    'dhcp4_process_tests.sh',
+    dhcp4_process_tests,
+    workdir: CURRENT_BUILD_DIR,
+    is_parallel: false,
+)
+configure_file(
+    input: 'marker_file.h.in',
+    output: 'marker_file.h',
+    configuration: dhcp4_tests_conf_data,
+)
+configure_file(
+    input: 'test_data_files_config.h.in',
+    output: 'test_data_files_config.h',
+    configuration: dhcp4_tests_conf_data,
+)
+configure_file(
+    input: 'meson-test_libraries.h.in',
+    output: 'test_libraries.h',
+    configuration: dhcp4_tests_conf_data,
+)
+# Not yet used configs-list.txt
+dhcp4_unittests = executable(
+    'dhcp4_unittests',
+    'classify_unittest.cc',
+    'client_handler_unittest.cc',
+    'config_parser_unittest.cc',
+    'config_backend_unittest.cc',
+    'ctrl_dhcp4_srv_unittest.cc',
+    'http_control_socket_unittest.cc',
+    'd2_unittest.cc',
+    'decline_unittest.cc',
+    'dhcp4_client.cc',
+    'dhcp4_srv_unittest.cc',
+    'dhcp4_test_utils.cc',
+    'dhcp4_unittests.cc',
+    'dhcp4to6_ipc_unittest.cc',
+    'direct_client_unittest.cc',
+    'dora_unittest.cc',
+    'fqdn_unittest.cc',
+    'get_config_unittest.cc',
+    'hooks_unittest.cc',
+    'host_options_unittest.cc',
+    cpp_args: [
+        f'-DTEST_DATA_BUILDDIR="@CURRENT_BUILD_DIR@"',
+        f'-DCFG_EXAMPLES="@TOP_SOURCE_DIR@/doc/examples/kea4"',
+        f'-DDHCP_DATA_DIR="@CURRENT_BUILD_DIR@"',
+        f'-DSYNTAX_FILE="@CURRENT_SOURCE_DIR@/../dhcp4_parser.yy"',
+        f'-DKEA_LFC_EXECUTABLE="@KEA_LFC@"',
+        f'-DTEST_CA_DIR="@TEST_CA_DIR@"',
+    ],
+    dependencies: [boost, crypto, gtest],
+    include_directories: [include_directories('.')] + INCLUDES,
+    link_with: [kea_util_unittests_lib] + libs_testutils + LIBS_BUILT_SO_FAR,
+)
+test('dhcp4_unittests', dhcp4_unittests, protocol: 'gtest', is_parallel: false)
+
+shared_library(
+    'co1',
+    'callout_library_1.cc',
+    dependencies: [boost],
+    include_directories: [include_directories('.')] + INCLUDES,
+    link_with: LIBS_BUILT_SO_FAR,
+    build_rpath: '/nowhere',
+    name_suffix: 'so',
+)
+shared_library(
+    'co2',
+    'callout_library_2.cc',
+    dependencies: [boost],
+    include_directories: [include_directories('.')] + INCLUDES,
+    link_with: LIBS_BUILT_SO_FAR,
+    build_rpath: '/nowhere',
+    name_suffix: 'so',
+)
+shared_library(
+    'co3',
+    'callout_library_3.cc',
+    dependencies: [boost],
+    include_directories: [include_directories('.')] + INCLUDES,
+    link_with: LIBS_BUILT_SO_FAR,
+    build_rpath: '/nowhere',
+    name_suffix: 'so',
+)
+shared_library(
+    'co4',
+    'callout_library_4.cc',
+    dependencies: [boost],
+    include_directories: [include_directories('.')] + INCLUDES,
+    link_with: LIBS_BUILT_SO_FAR,
+    build_rpath: '/nowhere',
+    name_suffix: 'so',
+)
index 6e4b4326cb4dd5e76c225c87d0ed4cc1eb71d5a5..f122e5602d5e77a18554b479b3b9c6438a7bb00e 100644 (file)
@@ -15,7 +15,7 @@ configure_file(
     copy: true,
 )
 kea_dhcpsrv_conf_data = configuration_data()
-kea_dhcpsrv_conf_data.set('abs_builddir', meson.current_build_dir())
+kea_dhcpsrv_conf_data.set('abs_builddir', CURRENT_BUILD_DIR)
 configure_file(
     input: 'meson-test_libraries.h.in',
     output: 'test_libraries.h',