dryang / rpms / systemd

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