summaryrefslogtreecommitdiffstats
path: root/test/TEST-24-UNIT-TESTS
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-06 02:25:50 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-06 02:25:50 +0000
commit19f4f86bfed21c5326ed2acebe1163f3a83e832b (patch)
treed59b9989ce55ed23693e80974d94c856f1c2c8b1 /test/TEST-24-UNIT-TESTS
parentInitial commit. (diff)
downloadsystemd-19f4f86bfed21c5326ed2acebe1163f3a83e832b.tar.xz
systemd-19f4f86bfed21c5326ed2acebe1163f3a83e832b.zip
Adding upstream version 241.upstream/241upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'test/TEST-24-UNIT-TESTS')
l---------test/TEST-24-UNIT-TESTS/Makefile1
-rwxr-xr-xtest/TEST-24-UNIT-TESTS/test.sh106
-rwxr-xr-xtest/TEST-24-UNIT-TESTS/testsuite.sh34
3 files changed, 141 insertions, 0 deletions
diff --git a/test/TEST-24-UNIT-TESTS/Makefile b/test/TEST-24-UNIT-TESTS/Makefile
new file mode 120000
index 0000000..e9f93b1
--- /dev/null
+++ b/test/TEST-24-UNIT-TESTS/Makefile
@@ -0,0 +1 @@
+../TEST-01-BASIC/Makefile \ No newline at end of file
diff --git a/test/TEST-24-UNIT-TESTS/test.sh b/test/TEST-24-UNIT-TESTS/test.sh
new file mode 100755
index 0000000..014ee52
--- /dev/null
+++ b/test/TEST-24-UNIT-TESTS/test.sh
@@ -0,0 +1,106 @@
+#!/bin/bash
+# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
+# ex: ts=8 sw=4 sts=4 et filetype=sh
+set -e
+TEST_DESCRIPTION="Run unit tests under containers"
+RUN_IN_UNPRIVILEGED_CONTAINER=yes
+
+. $TEST_BASE_DIR/test-functions
+
+check_result_nspawn() {
+ local _ret=1
+ [[ -e $TESTDIR/$1/testok ]] && _ret=0
+ if [[ -s $TESTDIR/$1/failed ]]; then
+ _ret=$(($_ret+1))
+ echo "=== Failed test log ==="
+ cat $TESTDIR/$1/failed
+ else
+ if [[ -s $TESTDIR/$1/skipped ]]; then
+ echo "=== Skipped test log =="
+ cat $TESTDIR/$1/skipped
+ fi
+ if [[ -s $TESTDIR/$1/testok ]]; then
+ echo "=== Passed tests ==="
+ cat $TESTDIR/$1/testok
+ fi
+ fi
+ cp -a $TESTDIR/$1/var/log/journal $TESTDIR
+ [[ -n "$TIMED_OUT" ]] && _ret=$(($_ret+1))
+ return $_ret
+}
+
+check_result_qemu() {
+ local _ret=1
+ mkdir -p $TESTDIR/root
+ mount ${LOOPDEV}p1 $TESTDIR/root
+ [[ -e $TESTDIR/root/testok ]] && _ret=0
+ if [[ -s $TESTDIR/root/failed ]]; then
+ _ret=$(($_ret+1))
+ echo "=== Failed test log ==="
+ cat $TESTDIR/root/failed
+ else
+ if [[ -s $TESTDIR/root/skipped ]]; then
+ echo "=== Skipped test log =="
+ cat $TESTDIR/root/skipped
+ fi
+ if [[ -s $TESTDIR/root/testok ]]; then
+ echo "=== Passed tests ==="
+ cat $TESTDIR/root/testok
+ fi
+ fi
+ cp -a $TESTDIR/root/var/log/journal $TESTDIR
+ umount $TESTDIR/root
+ [[ -n "$TIMED_OUT" ]] && _ret=$(($_ret+1))
+ return $_ret
+}
+
+test_setup() {
+ if type -P meson && [[ "$(meson configure $BUILD_DIR | grep install-tests | awk '{ print $2 }')" != "true" ]]; then
+ dfatal "Needs to be built with -Dinstall-tests=true"
+ exit 1
+ fi
+
+ create_empty_image
+ mkdir -p $TESTDIR/root
+ mount ${LOOPDEV}p1 $TESTDIR/root
+
+ # Create what will eventually be our root filesystem onto an overlay
+ (
+ LOG_LEVEL=5
+ eval $(udevadm info --export --query=env --name=${LOOPDEV}p2)
+
+ for i in getfacl dirname basename capsh cut rev stat mktemp rmdir ionice unshare uname tr awk getent diff xzcat lz4cat; do
+ inst_binary $i
+ done
+
+ inst /etc/hosts
+
+ setup_basic_environment
+ install_keymaps yes
+ install_zoneinfo
+
+ # setup the testsuite service
+ cat >$initdir/etc/systemd/system/testsuite.service <<EOF
+[Unit]
+Description=Testsuite service
+
+[Service]
+ExecStart=/testsuite.sh
+Type=oneshot
+EOF
+ cp testsuite.sh $initdir/
+
+ setup_testsuite
+ ) || return 1
+ setup_nspawn_root
+
+ # mask some services that we do not want to run in these tests
+ ln -s /dev/null $initdir/etc/systemd/system/systemd-networkd.service
+ ln -s /dev/null $initdir/etc/systemd/system/systemd-networkd.socket
+ ln -s /dev/null $initdir/etc/systemd/system/systemd-resolved.service
+
+ ddebug "umount $TESTDIR/root"
+ umount $TESTDIR/root
+}
+
+do_test "$@"
diff --git a/test/TEST-24-UNIT-TESTS/testsuite.sh b/test/TEST-24-UNIT-TESTS/testsuite.sh
new file mode 100755
index 0000000..7c0e495
--- /dev/null
+++ b/test/TEST-24-UNIT-TESTS/testsuite.sh
@@ -0,0 +1,34 @@
+#!/bin/bash
+# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
+# ex: ts=8 sw=4 sts=4 et filetype=sh
+#set -ex
+#set -o pipefail
+
+for i in /usr/lib/systemd/tests/test-*; do
+ if [[ ! -x $i ]]; then continue; fi
+ NAME=${i##*/}
+ echo "Running $NAME"
+ $i > /$NAME.log 2>&1
+ ret=$?
+ if (( $ret && $ret != 77 )); then
+ echo "$NAME failed with $ret"
+ echo $NAME >> /failed-tests
+ echo "--- $NAME begin ---" >> /failed
+ cat /$NAME.log >> /failed
+ echo "--- $NAME end ---" >> /failed
+ elif (( $ret == 77 )); then
+ echo "$NAME skipped"
+ echo $NAME >> /skipped-tests
+ echo "--- $NAME begin ---" >> /skipped
+ cat /$NAME.log >> /skipped
+ echo "--- $NAME end ---" >> /skipped
+ else
+ echo "$NAME OK"
+ echo $NAME >> /testok
+ fi
+
+ systemd-cat echo "--- $NAME ---"
+ systemd-cat cat /$NAME.log
+done
+
+exit 0