2020-03-04 12:35:06 +03:00
#!/usr/bin/env bash
2021-10-17 19:13:06 +03:00
# SPDX-License-Identifier: LGPL-2.1-or-later
2021-04-09 20:39:41 +03:00
set -eux
set -o pipefail
2018-09-19 08:30:29 +03:00
2023-06-12 22:05:30 +03: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 14:51:02 +03: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 15:50:28 +03:00
NPROC = $( nproc)
MAX_QUEUE_SIZE = ${ NPROC :- 2 }
2023-06-12 15:13:25 +03:00
# Reset state
2023-07-12 16:27:26 +03:00
rm -fv /failed /skipped /testok
2024-04-20 22:13:18 +03:00
touch /lock
2019-12-13 14:34:41 +03:00
2023-06-12 15:13:25 +03: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 15:50:28 +03:00
# Check & report test results
# Arguments:
# $1: test path
# $2: test exit code
2024-04-20 22:13:18 +03:00
run_test( ) {
if [ [ $# -ne 1 ] ] ; then
echo >& 2 "run_test: missing arguments"
2019-03-05 15:50:28 +03:00
exit 1
fi
2024-04-20 22:13:18 +03:00
local test = " $1 "
local name = " ${ test ##*/ } "
2024-05-28 08:05:15 +03:00
local environment =
2024-04-20 22:13:18 +03:00
echo " Executing test $name as unit $name .service "
2024-05-28 08:05:15 +03:00
case " $name " in
test-journal-flush)
environment = "SYSTEMD_LOG_LEVEL=info"
; ;
test-journal-verify)
environment = "SYSTEMD_LOG_LEVEL=crit"
; ;
esac
2024-05-27 20:40:35 +03:00
systemd-run \
--quiet \
--property Delegate = 1 \
--property EnvironmentFile = -/usr/lib/systemd/systemd-asan-env \
--property " Environment= $environment " \
--unit= " $name " \
--wait " $test " && ret = 0 || ret = $?
2024-04-20 22:13:18 +03:00
exec { LOCK_FD} > /lock
flock --exclusive ${ LOCK_FD }
2019-03-05 15:50:28 +03:00
2024-05-26 19:22:54 +03:00
if [ [ $ret -eq 77 ] ] || [ [ $ret -eq 127 ] ] ; then
echo " $name skipped "
echo " $name " >>/skipped-tests
2019-03-05 15:50:28 +03:00
{
echo " --- $name begin --- "
2024-04-20 22:13:18 +03:00
journalctl --unit= " $name " --no-hostname -o short-monotonic
2019-03-05 15:50:28 +03:00
echo " --- $name end --- "
2024-05-26 19:22:54 +03:00
} >>/skipped
elif [ [ $ret -ne 0 ] ] ; then
echo " $name failed with $ret "
echo " $name " >>/failed-tests
2019-03-05 15:50:28 +03:00
{
echo " --- $name begin --- "
2024-04-20 22:13:18 +03:00
journalctl --unit= " $name " --no-hostname -o short-monotonic
2019-03-05 15:50:28 +03:00
echo " --- $name end --- "
2024-05-26 19:22:54 +03:00
} >>/failed
2018-09-19 08:30:29 +03:00
else
2019-03-05 15:50:28 +03:00
echo " $name OK "
2019-12-10 17:31:09 +03:00
echo " $name " >>/testok
2019-03-05 15:50:28 +03:00
fi
2024-04-20 22:13:18 +03:00
exec { LOCK_FD} <& -
}
2018-09-19 08:30:29 +03:00
2024-04-20 22:13:18 +03:00
export -f run_test
2018-09-19 08:30:29 +03:00
2024-04-20 22:13:18 +03: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 15:44:49 +03:00
2024-06-12 13:09:25 +03:00
# Write all pending messages, so they don't get mixed with the summaries below
journalctl --sync
# No need for full test logs in this case
if [ [ -s /skipped-tests ] ] ; then
: "=== SKIPPED TESTS ==="
cat /skipped-tests
fi
if [ [ -s /failed ] ] ; then
: "=== FAILED TESTS ==="
cat /failed
fi
2021-06-21 14:34:07 +03:00
# Test logs are sometimes lost, as the system shuts down immediately after
journalctl --sync
2023-07-12 16:27:26 +03:00
test ! -s /failed
2023-07-12 16:49:55 +03:00
touch /testok