From: Andrei Pavel Date: Tue, 11 Nov 2025 08:50:22 +0000 (+0200) Subject: [#4159] Add unit tests X-Git-Tag: Kea-3.1.4~43 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=0421bcde886fa8ccdd79be3bf7dd2c29030ef6ff;p=thirdparty%2Fkea.git [#4159] Add unit tests --- diff --git a/src/bin/admin/tests/admin_tests.sh.in b/src/bin/admin/tests/admin_tests.sh.in index 4b59c95059..c928606a69 100755 --- a/src/bin/admin/tests/admin_tests.sh.in +++ b/src/bin/admin/tests/admin_tests.sh.in @@ -140,6 +140,20 @@ kea_admin_error_reporting_tests() { assert_eq 1 "${EXIT_CODE}" assert_str_eq 'ERROR/kea-admin: -x or --extra requires a parameter' "$(printf '%s\n' "${OUTPUT}" | head -n 1)" test_finish ${?} + + test_start 'kea_admin_version.version' + run_command \ + "${kea_admin}" -v + assert_eq 0 "${EXIT_CODE}" + assert_str_eq '@version@' "$(printf '%s\n' "${OUTPUT}" | head -n 1)" + test_finish ${?} + + test_start 'kea_admin_version.extended_version' + run_command \ + "${kea_admin}" -V + assert_eq 0 "${EXIT_CODE}" + assert_str_eq '@extended_version@' "$(printf '%s\n' "${OUTPUT}" | head -n 1)" + test_finish ${?} } # Run tests. diff --git a/src/bin/admin/tests/meson.build b/src/bin/admin/tests/meson.build index adfc32831f..2a4af41c00 100644 --- a/src/bin/admin/tests/meson.build +++ b/src/bin/admin/tests/meson.build @@ -5,6 +5,8 @@ endif kea_admin_tests_conf_data = configuration_data() kea_admin_tests_conf_data.set('abs_top_builddir', TOP_BUILD_DIR) kea_admin_tests_conf_data.set('abs_top_srcdir', TOP_SOURCE_DIR) +kea_admin_tests_conf_data.set('version', PROJECT_VERSION) +kea_admin_tests_conf_data.set('extended_version', EXTENDED_VERSION) admin_tests = configure_file( input: 'admin_tests.sh.in', output: 'admin_tests.sh', diff --git a/src/bin/lfc/tests/lfc_process_tests.sh.in b/src/bin/lfc/tests/lfc_process_tests.sh.in new file mode 100755 index 0000000000..d3b8ea211a --- /dev/null +++ b/src/bin/lfc/tests/lfc_process_tests.sh.in @@ -0,0 +1,21 @@ +#!/bin/sh + +# Copyright (C) 2025 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 + +# Set the location of the executable. +bin='kea-lfc' +bin_path='@abs_top_builddir@/src/bin/lfc' + +# Import common test library. +# shellcheck source=src/lib/testutils/dhcp_test_lib.sh.in +. '@abs_top_builddir@/src/lib/testutils/dhcp_test_lib.sh' + +version_test "lfc.version" diff --git a/src/bin/lfc/tests/meson.build b/src/bin/lfc/tests/meson.build index 59692ce1a4..d096cdee7c 100644 --- a/src/bin/lfc/tests/meson.build +++ b/src/bin/lfc/tests/meson.build @@ -22,3 +22,19 @@ test( depends: [kea_lfc], protocol: 'gtest', ) + +lfc_tests_conf_data = configuration_data() +lfc_tests_conf_data.set('abs_top_builddir', TOP_BUILD_DIR) +lfc_process_tests = configure_file( + input: 'lfc_process_tests.sh.in', + output: 'lfc_process_tests.sh', + configuration: lfc_tests_conf_data, +) +test( + 'lfc_process_tests.sh', + lfc_process_tests, + workdir: current_build_dir, + is_parallel: false, + priority: -1, + suite: 'shell-tests', +) diff --git a/src/bin/perfdhcp/tests/meson.build b/src/bin/perfdhcp/tests/meson.build index ba08ef865c..b0d50496df 100644 --- a/src/bin/perfdhcp/tests/meson.build +++ b/src/bin/perfdhcp/tests/meson.build @@ -30,3 +30,19 @@ test( is_parallel: false, priority: -1, ) + +perfdhcp_tests_conf_data = configuration_data() +perfdhcp_tests_conf_data.set('abs_top_builddir', TOP_BUILD_DIR) +perfdhcp_process_tests = configure_file( + input: 'perfdhcp_process_tests.sh.in', + output: 'perfdhcp_process_tests.sh', + configuration: perfdhcp_tests_conf_data, +) +test( + 'perfdhcp_process_tests.sh', + perfdhcp_process_tests, + workdir: current_build_dir, + is_parallel: false, + priority: -1, + suite: 'shell-tests', +) diff --git a/src/bin/perfdhcp/tests/perfdhcp_process_tests.sh.in b/src/bin/perfdhcp/tests/perfdhcp_process_tests.sh.in new file mode 100755 index 0000000000..110668bd49 --- /dev/null +++ b/src/bin/perfdhcp/tests/perfdhcp_process_tests.sh.in @@ -0,0 +1,21 @@ +#!/bin/sh + +# Copyright (C) 2025 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 + +# Set the location of the executable. +bin='perfdhcp' +bin_path='@abs_top_builddir@/src/bin/perfdhcp' + +# Import common test library. +# shellcheck source=src/lib/testutils/dhcp_test_lib.sh.in +. '@abs_top_builddir@/src/lib/testutils/dhcp_test_lib.sh' + +version_test "perfdhcp.version" diff --git a/src/bin/shell/tests/meson.build b/src/bin/shell/tests/meson.build index 18a7bc3339..3ead8123fa 100644 --- a/src/bin/shell/tests/meson.build +++ b/src/bin/shell/tests/meson.build @@ -165,6 +165,19 @@ test( priority: -1, suite: 'shell-tests', ) +shell_process_tests = configure_file( + input: 'shell_process_tests.sh.in', + output: 'shell_process_tests.sh', + configuration: shell_tests_conf_data, +) +test( + 'shell_process_tests.sh', + shell_process_tests, + workdir: current_build_dir, + is_parallel: false, + priority: -1, + suite: 'shell-tests', +) auth_bad_password_file = configure_file( input: 'auth_bad_password_file.in', output: 'auth_bad_password_file', diff --git a/src/bin/shell/tests/shell_process_tests.sh.in b/src/bin/shell/tests/shell_process_tests.sh.in new file mode 100755 index 0000000000..6deb8aa204 --- /dev/null +++ b/src/bin/shell/tests/shell_process_tests.sh.in @@ -0,0 +1,21 @@ +#!/bin/sh + +# Copyright (C) 2025 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 + +# Set the location of the executable. +bin='kea-shell' +bin_path='@abs_top_builddir@/src/bin/shell' + +# Import common test library. +# shellcheck source=src/lib/testutils/dhcp_test_lib.sh.in +. '@abs_top_builddir@/src/lib/testutils/dhcp_test_lib.sh' + +version_test "shell.version" diff --git a/src/lib/process/cfgrpt/tests/config_report_unittests.cc b/src/lib/process/cfgrpt/tests/config_report_unittests.cc index c83360d986..2564d64397 100644 --- a/src/lib/process/cfgrpt/tests/config_report_unittests.cc +++ b/src/lib/process/cfgrpt/tests/config_report_unittests.cc @@ -26,6 +26,7 @@ TEST(ConfigReportTest, getConfigReport) { ASSERT_FALSE(cfgReport.empty()); EXPECT_NE(std::string::npos, cfgReport.find(VERSION)); EXPECT_NE(std::string::npos, cfgReport.find(EXTENDED_VERSION)); + EXPECT_NE(std::string::npos, cfgReport.find(SOURCE_OF_INSTALLATION)); EXPECT_NE(std::string::npos, cfgReport.find(std::string("Hooks directory: ") + HooksLibrariesParser::getHooksPath())); } diff --git a/src/lib/testutils/dhcp_test_lib.sh.in b/src/lib/testutils/dhcp_test_lib.sh.in index 13565bd03f..15c5e86917 100755 --- a/src/lib/testutils/dhcp_test_lib.sh.in +++ b/src/lib/testutils/dhcp_test_lib.sh.in @@ -26,7 +26,8 @@ set -eu prefix="@prefix@" # Expected version -EXPECTED_VERSION="@PACKAGE_VERSION@" +VERSION='@VERSION@' +EXTENDED_VERSION='@EXTENDED_VERSION@' # Kea environment variables for shell tests. # KEA_LOGGER_DESTINATION is set per test with set_logger. @@ -935,13 +936,33 @@ version_test() { run_command \ "${bin_path}/${bin}" "${v}" - if test "${OUTPUT}" != "${EXPECTED_VERSION}"; then + if test 0 -ne "${EXIT_CODE}"; then + printf 'ERROR: Expected exit code 0, got "%s" when calling "%s"\n' \ + "${EXIT_CODE}" "${bin} -V" + clean_exit 1 + fi + + if test "${OUTPUT}" != "${VERSION}"; then printf 'ERROR: Expected version "%s", got "%s" when calling "%s"\n' \ - "${EXPECTED_VERSION}" "${OUTPUT}" "${bin} ${v}" + "${VERSION}" "${OUTPUT}" "${bin} ${v}" test_finish 1 fi done + # Check -V. + run_command \ + "${bin_path}/${bin}" -V + if test 0 -ne "${EXIT_CODE}"; then + printf 'ERROR: Expected exit code 0, got "%s" when calling "%s"\n' \ + "${EXIT_CODE}" "${bin} -V" + clean_exit 1 + fi + if test "${EXTENDED_VERSION}" != "$(echo "${OUTPUT}" | head -n 1)"; then + printf 'ERROR: Expected version "%s", got "%s" when calling "%s"\n' \ + "${EXTENDED_VERSION}" "${OUTPUT}" "${bin} -V" + clean_exit 1 + fi + test_finish 0 } @@ -1080,10 +1101,10 @@ server_pid_file_test() { } # This test verifies that passwords are redacted in logs. -# This function takes 2 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) +# This function takes 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) password_redact_test() { local test_name="${1}" local config="${2}" diff --git a/src/lib/testutils/meson.build b/src/lib/testutils/meson.build index 11de1d46a0..f3cf9f431b 100644 --- a/src/lib/testutils/meson.build +++ b/src/lib/testutils/meson.build @@ -18,7 +18,8 @@ kea_testutils_lib = static_library( dhcp_test_lib_conf_data = configuration_data() dhcp_test_lib_conf_data.set('abs_top_builddir', TOP_BUILD_DIR) dhcp_test_lib_conf_data.set('prefix', PREFIX) -dhcp_test_lib_conf_data.set('PACKAGE_VERSION', PROJECT_VERSION) +dhcp_test_lib_conf_data.set('VERSION', PROJECT_VERSION) +dhcp_test_lib_conf_data.set('EXTENDED_VERSION', EXTENDED_VERSION) configure_file( input: 'dhcp_test_lib.sh.in', output: 'dhcp_test_lib.sh',