2020-03-04 09:35:06 +00:00
#!/usr/bin/env bash
2021-10-17 18:13:06 +02:00
# SPDX-License-Identifier: LGPL-2.1-or-later
2021-04-09 19:39:41 +02:00
set -eux
set -o pipefail
2018-09-19 14:30:29 +09:00
2023-06-12 21:05:30 +02:00
if ! systemd-detect-virt -qc && [ [ " ${ TEST_CMDLINE_NEWLINE :- } " != bar ] ] ; then
cat /proc/cmdline
echo >& 2 "Expected TEST_CMDLINE_NEWLINE=bar from the kernel command line"
exit 1
fi
2023-06-07 13:51:02 +02:00
# If we're running with TEST_PREFER_NSPAWN=1 limit the set of tests we run
# in QEMU to only those that can't run in a container to avoid running
# the same tests again in a, most likely, very slow environment
if ! systemd-detect-virt -qc && [ [ " ${ TEST_PREFER_NSPAWN :- 0 } " -ne 0 ] ] ; then
TESTS_GLOB = "test-loop-block"
else
TESTS_GLOB = ${ TESTS_GLOB :- test -* }
fi
2019-03-05 13:50:28 +01:00
NPROC = $( nproc)
MAX_QUEUE_SIZE = ${ NPROC :- 2 }
2023-06-12 14:13:25 +02:00
# Reset state
2023-07-12 15:27:26 +02:00
rm -fv /failed /skipped /testok
2024-04-20 21:13:18 +02:00
touch /lock
2019-12-13 12:34:41 +01:00
2023-06-12 14:13:25 +02:00
if ! systemd-detect-virt -qc; then
# Make sure ping works for unprivileged users (for test-bpf-firewall)
sysctl net.ipv4.ping_group_range= "0 2147483647"
fi
2019-03-05 13:50:28 +01:00
# Check & report test results
# Arguments:
# $1: test path
# $2: test exit code
2024-04-20 21:13:18 +02:00
run_test( ) {
if [ [ $# -ne 1 ] ] ; then
echo >& 2 "run_test: missing arguments"
2019-03-05 13:50:28 +01:00
exit 1
fi
2024-04-20 21:13:18 +02:00
local test = " $1 "
local name = " ${ test ##*/ } "
echo " Executing test $name as unit $name .service "
systemd-run --quiet --property Delegate = 1 --unit= " $name " --wait " $test " && ret = 0 || ret = $?
exec { LOCK_FD} > /lock
flock --exclusive ${ LOCK_FD }
2019-03-05 13:50:28 +01:00
2023-05-06 11:49:31 +02:00
if [ [ $ret -ne 0 && $ret != 77 && $ret != 127 ] ] ; then
2019-03-05 13:50:28 +01:00
echo " $name failed with $ret "
2019-12-10 15:31:09 +01:00
echo " $name " >>/failed-tests
2019-03-05 13:50:28 +01:00
{
echo " --- $name begin --- "
2024-04-20 21:13:18 +02:00
journalctl --unit= " $name " --no-hostname -o short-monotonic
2019-03-05 13:50:28 +01:00
echo " --- $name end --- "
2019-12-10 15:31:09 +01:00
} >>/failed
2023-05-06 11:49:31 +02:00
elif [ [ $ret = = 77 || $ret = = 127 ] ] ; then
2019-03-05 13:50:28 +01:00
echo " $name skipped "
2019-12-10 15:31:09 +01:00
echo " $name " >>/skipped-tests
2019-03-05 13:50:28 +01:00
{
echo " --- $name begin --- "
2024-04-20 21:13:18 +02:00
journalctl --unit= " $name " --no-hostname -o short-monotonic
2019-03-05 13:50:28 +01:00
echo " --- $name end --- "
2019-12-10 15:31:09 +01:00
} >>/skipped
2018-09-19 14:30:29 +09:00
else
2019-03-05 13:50:28 +01:00
echo " $name OK "
2019-12-10 15:31:09 +01:00
echo " $name " >>/testok
2019-03-05 13:50:28 +01:00
fi
2024-04-20 21:13:18 +02:00
exec { LOCK_FD} <& -
}
2018-09-19 14:30:29 +09:00
2024-04-20 21:13:18 +02:00
export -f run_test
2018-09-19 14:30:29 +09:00
2024-04-20 21:13:18 +02:00
find /usr/lib/systemd/tests/unit-tests/ -maxdepth 1 -type f -name " ${ TESTS_GLOB } " -print0 |
xargs -0 -I { } --max-procs= " $MAX_QUEUE_SIZE " bash -ec "run_test {}"
2022-06-17 14:44:49 +02:00
2021-06-21 12:34:07 +01:00
# Test logs are sometimes lost, as the system shuts down immediately after
journalctl --sync
2023-07-12 15:27:26 +02:00
test ! -s /failed
2023-07-12 15:49:55 +02:00
touch /testok