|
|
ff6046 |
From e4ff044489f43d2c7e1ecbdfb88692d87d63bd2a Mon Sep 17 00:00:00 2001
|
|
|
ff6046 |
From: Yu Watanabe <watanabe.yu+github@gmail.com>
|
|
|
ff6046 |
Date: Wed, 19 Sep 2018 14:30:29 +0900
|
|
|
ff6046 |
Subject: [PATCH] test: add TEST-24-UNIT-TESTS running all basic tests under
|
|
|
ff6046 |
containers
|
|
|
ff6046 |
|
|
|
ff6046 |
(cherry picked from commit 3f6f58e03a7d22154aabe036439e7f2fb4849570)
|
|
|
ff6046 |
---
|
|
|
ff6046 |
test/TEST-24-UNIT-TESTS/Makefile | 1 +
|
|
|
ff6046 |
test/TEST-24-UNIT-TESTS/test.sh | 106 +++++++++++++++++++++++++++
|
|
|
ff6046 |
test/TEST-24-UNIT-TESTS/testsuite.sh | 34 +++++++++
|
|
|
ff6046 |
3 files changed, 141 insertions(+)
|
|
|
ff6046 |
create mode 120000 test/TEST-24-UNIT-TESTS/Makefile
|
|
|
ff6046 |
create mode 100755 test/TEST-24-UNIT-TESTS/test.sh
|
|
|
ff6046 |
create mode 100755 test/TEST-24-UNIT-TESTS/testsuite.sh
|
|
|
ff6046 |
|
|
|
ff6046 |
diff --git a/test/TEST-24-UNIT-TESTS/Makefile b/test/TEST-24-UNIT-TESTS/Makefile
|
|
|
ff6046 |
new file mode 120000
|
|
|
ff6046 |
index 0000000000..e9f93b1104
|
|
|
ff6046 |
--- /dev/null
|
|
|
ff6046 |
+++ b/test/TEST-24-UNIT-TESTS/Makefile
|
|
|
ff6046 |
@@ -0,0 +1 @@
|
|
|
ff6046 |
+../TEST-01-BASIC/Makefile
|
|
|
ff6046 |
\ No newline at end of file
|
|
|
ff6046 |
diff --git a/test/TEST-24-UNIT-TESTS/test.sh b/test/TEST-24-UNIT-TESTS/test.sh
|
|
|
ff6046 |
new file mode 100755
|
|
|
ff6046 |
index 0000000000..014ee52277
|
|
|
ff6046 |
--- /dev/null
|
|
|
ff6046 |
+++ b/test/TEST-24-UNIT-TESTS/test.sh
|
|
|
ff6046 |
@@ -0,0 +1,106 @@
|
|
|
ff6046 |
+#!/bin/bash
|
|
|
ff6046 |
+# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
|
|
|
ff6046 |
+# ex: ts=8 sw=4 sts=4 et filetype=sh
|
|
|
ff6046 |
+set -e
|
|
|
ff6046 |
+TEST_DESCRIPTION="Run unit tests under containers"
|
|
|
ff6046 |
+RUN_IN_UNPRIVILEGED_CONTAINER=yes
|
|
|
ff6046 |
+
|
|
|
ff6046 |
+. $TEST_BASE_DIR/test-functions
|
|
|
ff6046 |
+
|
|
|
ff6046 |
+check_result_nspawn() {
|
|
|
ff6046 |
+ local _ret=1
|
|
|
ff6046 |
+ [[ -e $TESTDIR/$1/testok ]] && _ret=0
|
|
|
ff6046 |
+ if [[ -s $TESTDIR/$1/failed ]]; then
|
|
|
ff6046 |
+ _ret=$(($_ret+1))
|
|
|
ff6046 |
+ echo "=== Failed test log ==="
|
|
|
ff6046 |
+ cat $TESTDIR/$1/failed
|
|
|
ff6046 |
+ else
|
|
|
ff6046 |
+ if [[ -s $TESTDIR/$1/skipped ]]; then
|
|
|
ff6046 |
+ echo "=== Skipped test log =="
|
|
|
ff6046 |
+ cat $TESTDIR/$1/skipped
|
|
|
ff6046 |
+ fi
|
|
|
ff6046 |
+ if [[ -s $TESTDIR/$1/testok ]]; then
|
|
|
ff6046 |
+ echo "=== Passed tests ==="
|
|
|
ff6046 |
+ cat $TESTDIR/$1/testok
|
|
|
ff6046 |
+ fi
|
|
|
ff6046 |
+ fi
|
|
|
ff6046 |
+ cp -a $TESTDIR/$1/var/log/journal $TESTDIR
|
|
|
ff6046 |
+ [[ -n "$TIMED_OUT" ]] && _ret=$(($_ret+1))
|
|
|
ff6046 |
+ return $_ret
|
|
|
ff6046 |
+}
|
|
|
ff6046 |
+
|
|
|
ff6046 |
+check_result_qemu() {
|
|
|
ff6046 |
+ local _ret=1
|
|
|
ff6046 |
+ mkdir -p $TESTDIR/root
|
|
|
ff6046 |
+ mount ${LOOPDEV}p1 $TESTDIR/root
|
|
|
ff6046 |
+ [[ -e $TESTDIR/root/testok ]] && _ret=0
|
|
|
ff6046 |
+ if [[ -s $TESTDIR/root/failed ]]; then
|
|
|
ff6046 |
+ _ret=$(($_ret+1))
|
|
|
ff6046 |
+ echo "=== Failed test log ==="
|
|
|
ff6046 |
+ cat $TESTDIR/root/failed
|
|
|
ff6046 |
+ else
|
|
|
ff6046 |
+ if [[ -s $TESTDIR/root/skipped ]]; then
|
|
|
ff6046 |
+ echo "=== Skipped test log =="
|
|
|
ff6046 |
+ cat $TESTDIR/root/skipped
|
|
|
ff6046 |
+ fi
|
|
|
ff6046 |
+ if [[ -s $TESTDIR/root/testok ]]; then
|
|
|
ff6046 |
+ echo "=== Passed tests ==="
|
|
|
ff6046 |
+ cat $TESTDIR/root/testok
|
|
|
ff6046 |
+ fi
|
|
|
ff6046 |
+ fi
|
|
|
ff6046 |
+ cp -a $TESTDIR/root/var/log/journal $TESTDIR
|
|
|
ff6046 |
+ umount $TESTDIR/root
|
|
|
ff6046 |
+ [[ -n "$TIMED_OUT" ]] && _ret=$(($_ret+1))
|
|
|
ff6046 |
+ return $_ret
|
|
|
ff6046 |
+}
|
|
|
ff6046 |
+
|
|
|
ff6046 |
+test_setup() {
|
|
|
ff6046 |
+ if type -P meson && [[ "$(meson configure $BUILD_DIR | grep install-tests | awk '{ print $2 }')" != "true" ]]; then
|
|
|
ff6046 |
+ dfatal "Needs to be built with -Dinstall-tests=true"
|
|
|
ff6046 |
+ exit 1
|
|
|
ff6046 |
+ fi
|
|
|
ff6046 |
+
|
|
|
ff6046 |
+ create_empty_image
|
|
|
ff6046 |
+ mkdir -p $TESTDIR/root
|
|
|
ff6046 |
+ mount ${LOOPDEV}p1 $TESTDIR/root
|
|
|
ff6046 |
+
|
|
|
ff6046 |
+ # Create what will eventually be our root filesystem onto an overlay
|
|
|
ff6046 |
+ (
|
|
|
ff6046 |
+ LOG_LEVEL=5
|
|
|
ff6046 |
+ eval $(udevadm info --export --query=env --name=${LOOPDEV}p2)
|
|
|
ff6046 |
+
|
|
|
ff6046 |
+ for i in getfacl dirname basename capsh cut rev stat mktemp rmdir ionice unshare uname tr awk getent diff xzcat lz4cat; do
|
|
|
ff6046 |
+ inst_binary $i
|
|
|
ff6046 |
+ done
|
|
|
ff6046 |
+
|
|
|
ff6046 |
+ inst /etc/hosts
|
|
|
ff6046 |
+
|
|
|
ff6046 |
+ setup_basic_environment
|
|
|
ff6046 |
+ install_keymaps yes
|
|
|
ff6046 |
+ install_zoneinfo
|
|
|
ff6046 |
+
|
|
|
ff6046 |
+ # setup the testsuite service
|
|
|
ff6046 |
+ cat >$initdir/etc/systemd/system/testsuite.service <
|
|
|
ff6046 |
+[Unit]
|
|
|
ff6046 |
+Description=Testsuite service
|
|
|
ff6046 |
+
|
|
|
ff6046 |
+[Service]
|
|
|
ff6046 |
+ExecStart=/testsuite.sh
|
|
|
ff6046 |
+Type=oneshot
|
|
|
ff6046 |
+EOF
|
|
|
ff6046 |
+ cp testsuite.sh $initdir/
|
|
|
ff6046 |
+
|
|
|
ff6046 |
+ setup_testsuite
|
|
|
ff6046 |
+ ) || return 1
|
|
|
ff6046 |
+ setup_nspawn_root
|
|
|
ff6046 |
+
|
|
|
ff6046 |
+ # mask some services that we do not want to run in these tests
|
|
|
ff6046 |
+ ln -s /dev/null $initdir/etc/systemd/system/systemd-networkd.service
|
|
|
ff6046 |
+ ln -s /dev/null $initdir/etc/systemd/system/systemd-networkd.socket
|
|
|
ff6046 |
+ ln -s /dev/null $initdir/etc/systemd/system/systemd-resolved.service
|
|
|
ff6046 |
+
|
|
|
ff6046 |
+ ddebug "umount $TESTDIR/root"
|
|
|
ff6046 |
+ umount $TESTDIR/root
|
|
|
ff6046 |
+}
|
|
|
ff6046 |
+
|
|
|
ff6046 |
+do_test "$@"
|
|
|
ff6046 |
diff --git a/test/TEST-24-UNIT-TESTS/testsuite.sh b/test/TEST-24-UNIT-TESTS/testsuite.sh
|
|
|
ff6046 |
new file mode 100755
|
|
|
ff6046 |
index 0000000000..7c0e495dbd
|
|
|
ff6046 |
--- /dev/null
|
|
|
ff6046 |
+++ b/test/TEST-24-UNIT-TESTS/testsuite.sh
|
|
|
ff6046 |
@@ -0,0 +1,34 @@
|
|
|
ff6046 |
+#!/bin/bash
|
|
|
ff6046 |
+# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
|
|
|
ff6046 |
+# ex: ts=8 sw=4 sts=4 et filetype=sh
|
|
|
ff6046 |
+#set -ex
|
|
|
ff6046 |
+#set -o pipefail
|
|
|
ff6046 |
+
|
|
|
ff6046 |
+for i in /usr/lib/systemd/tests/test-*; do
|
|
|
ff6046 |
+ if [[ ! -x $i ]]; then continue; fi
|
|
|
ff6046 |
+ NAME=${i##*/}
|
|
|
ff6046 |
+ echo "Running $NAME"
|
|
|
ff6046 |
+ $i > /$NAME.log 2>&1
|
|
|
ff6046 |
+ ret=$?
|
|
|
ff6046 |
+ if (( $ret && $ret != 77 )); then
|
|
|
ff6046 |
+ echo "$NAME failed with $ret"
|
|
|
ff6046 |
+ echo $NAME >> /failed-tests
|
|
|
ff6046 |
+ echo "--- $NAME begin ---" >> /failed
|
|
|
ff6046 |
+ cat /$NAME.log >> /failed
|
|
|
ff6046 |
+ echo "--- $NAME end ---" >> /failed
|
|
|
ff6046 |
+ elif (( $ret == 77 )); then
|
|
|
ff6046 |
+ echo "$NAME skipped"
|
|
|
ff6046 |
+ echo $NAME >> /skipped-tests
|
|
|
ff6046 |
+ echo "--- $NAME begin ---" >> /skipped
|
|
|
ff6046 |
+ cat /$NAME.log >> /skipped
|
|
|
ff6046 |
+ echo "--- $NAME end ---" >> /skipped
|
|
|
ff6046 |
+ else
|
|
|
ff6046 |
+ echo "$NAME OK"
|
|
|
ff6046 |
+ echo $NAME >> /testok
|
|
|
ff6046 |
+ fi
|
|
|
ff6046 |
+
|
|
|
ff6046 |
+ systemd-cat echo "--- $NAME ---"
|
|
|
ff6046 |
+ systemd-cat cat /$NAME.log
|
|
|
ff6046 |
+done
|
|
|
ff6046 |
+
|
|
|
ff6046 |
+exit 0
|