EXTRA_DIST =
INSTALL_DIRS =
INSTALL_EXEC_HOOKS =
+TESTS =
UNINSTALL_EXEC_HOOKS =
noinst_DATA =
network_PROGRAMS =
dist_check_DATA = \
test/constants.sh \
- test/test-functions
+ test/test-functions \
+ test/networkd/test.sh
dist_check_SCRIPTS = \
- $(TESTS)
-
-TESTS = \
test/load-library \
test/functions/ip/ip_detect_protocol \
test/functions/ip/ip_get_prefix \
test/functions/ip/ip_protocol_is_supported \
test/functions/ip/ip_split_prefix
+TESTS += $(dist_check_SCRIPTS)
+
+TEST_EXTENSIONS = .t
+
+NETWORKD_TESTS = \
+ test/networkd/00_launch.t
+
+TESTS += $(NETWORKD_TESTS)
+
+EXTRA_DIST += \
+ test/networkd/test.sh \
+ $(NETWORKD_TESTS)
+
+# Run all networkd tests in their own namespaces
+T_LOG_COMPILER = unshare --net --ipc --uts --user --cgroup --time --pid --fork \
+ $(SHELL) test/networkd/test.sh
+
# - NITSI tests ----------------------------------------------------------------
# Files for the virtual environment
--- /dev/null
+#!/bin/bash
+###############################################################################
+# #
+# IPFire.org - A linux based firewall #
+# Copyright (C) 2023 IPFire Network Development Team #
+# #
+# This program is free software: you can redistribute it and/or modify #
+# it under the terms of the GNU General Public License as published by #
+# the Free Software Foundation, either version 3 of the License, or #
+# (at your option) any later version. #
+# #
+# This program is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
+# GNU General Public License for more details. #
+# #
+# You should have received a copy of the GNU General Public License #
+# along with this program. If not, see <http://www.gnu.org/licenses/>. #
+# #
+###############################################################################
+
+# Break if anything fails
+set -e
+
+# Turn on job control
+set -o monitor
+
+run_script() {
+ local script="${1}"
+ shift
+
+ if [ -f "${script}" ]; then
+ echo "Launching ${script}..."
+
+ # Launch the script in a separate shell and echo every command
+ if ! ${SHELL} -xe "${script}"; then
+ echo "${script} failed" >&2
+ return 1
+ fi
+ fi
+
+ return 0
+}
+
+# Launches networkd in the background
+launch_networkd() {
+ echo "Launching networkd..."
+
+ # Launch it!
+ coproc networkd { ./networkd "$@"; }
+
+ echo "networkd launched as PID ${networkd_PID}"
+}
+
+terminate_networkd() {
+ if [ -n "${networkd_PID}" ]; then
+ # Send SIGTERM
+ kill -TERM "${networkd_PID}"
+
+ # Wait until networkd has finished
+ echo "Waiting for networkd to terminate..."
+ wait "${networkd_PID}"
+
+ echo "networkd has terminated"
+ fi
+}
+
+# Make sure networkd has been terminated when this script exits
+trap "terminate_networkd" EXIT
+
+main() {
+ local test="${1}"
+ shift
+
+ echo "Running ${test}..."
+
+ # Check if the test exists
+ if [ ! -d "${test}" ]; then
+ echo "Test '${test}' does not exist" >&2
+ return 2
+ fi
+
+ # Run prepare script
+ if ! run_script "${test}/prepare.sh"; then
+ return 1
+ fi
+
+ # Launch networkd
+ launch_networkd --config="${test}/config"
+
+ # Run test script
+ if ! run_script "${test}/test.sh"; then
+ return 1
+ fi
+
+ # Terminate networkd
+ terminate_networkd
+
+ # Run cleanup script
+ if ! run_script "${test}/cleanup.sh"; then
+ return 1
+ fi
+
+ return 0
+}
+
+# Call main()
+main "$@" || exit $?