ryantimwilson / rpms / systemd

Forked from rpms/systemd a month ago
Clone
ff2b41
From c53791854050661d34417f12755837abd74d213a Mon Sep 17 00:00:00 2001
ff2b41
From: Evgeny Vereshchagin <evvers@ya.ru>
ff2b41
Date: Tue, 17 Nov 2015 11:21:23 +0000
ff2b41
Subject: [PATCH] tests: add basic journal test
ff2b41
ff2b41
(cherry picked from commit 1c36b4a73b876258fbe01fbe9bc9b750b7dcc9ce)
ff2b41
(cherry picked from commit e974b9915ccc7bf56d23fd6fc67631990d893c89)
ff2b41
Resolves: #1803802
ff2b41
---
ff2b41
 test/TEST-04-JOURNAL/Makefile        |  1 +
ff2b41
 test/TEST-04-JOURNAL/test-journal.sh | 18 +++++++
ff2b41
 test/TEST-04-JOURNAL/test.sh         | 76 ++++++++++++++++++++++++++++
ff2b41
 test/test-functions                  |  2 +-
ff2b41
 4 files changed, 96 insertions(+), 1 deletion(-)
ff2b41
 create mode 120000 test/TEST-04-JOURNAL/Makefile
ff2b41
 create mode 100755 test/TEST-04-JOURNAL/test-journal.sh
ff2b41
 create mode 100755 test/TEST-04-JOURNAL/test.sh
ff2b41
ff2b41
diff --git a/test/TEST-04-JOURNAL/Makefile b/test/TEST-04-JOURNAL/Makefile
ff2b41
new file mode 120000
ff2b41
index 0000000000..e9f93b1104
ff2b41
--- /dev/null
ff2b41
+++ b/test/TEST-04-JOURNAL/Makefile
ff2b41
@@ -0,0 +1 @@
ff2b41
+../TEST-01-BASIC/Makefile
ff2b41
\ No newline at end of file
ff2b41
diff --git a/test/TEST-04-JOURNAL/test-journal.sh b/test/TEST-04-JOURNAL/test-journal.sh
ff2b41
new file mode 100755
ff2b41
index 0000000000..c75f396ceb
ff2b41
--- /dev/null
ff2b41
+++ b/test/TEST-04-JOURNAL/test-journal.sh
ff2b41
@@ -0,0 +1,18 @@
ff2b41
+#!/bin/bash
ff2b41
+
ff2b41
+set -x
ff2b41
+set -e
ff2b41
+set -o pipefail
ff2b41
+
ff2b41
+# Test stdout stream
ff2b41
+
ff2b41
+# Skip empty lines
ff2b41
+ID=$(journalctl --new-id128 | sed -n 2p)
ff2b41
+>/expected
ff2b41
+printf $'\n\n\n' | systemd-cat -t "$ID" --level-prefix false
ff2b41
+journalctl --flush
ff2b41
+journalctl -b -o cat -t "$ID" >/output
ff2b41
+cmp /expected /output
ff2b41
+
ff2b41
+touch /testok
ff2b41
+exit 0
ff2b41
diff --git a/test/TEST-04-JOURNAL/test.sh b/test/TEST-04-JOURNAL/test.sh
ff2b41
new file mode 100755
ff2b41
index 0000000000..e37cb7d412
ff2b41
--- /dev/null
ff2b41
+++ b/test/TEST-04-JOURNAL/test.sh
ff2b41
@@ -0,0 +1,76 @@
ff2b41
+#!/bin/bash
ff2b41
+# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
ff2b41
+# ex: ts=8 sw=4 sts=4 et filetype=sh
ff2b41
+TEST_DESCRIPTION="Journal-related tests"
ff2b41
+
ff2b41
+. $TEST_BASE_DIR/test-functions
ff2b41
+
ff2b41
+check_result_qemu() {
ff2b41
+    ret=1
ff2b41
+    mkdir -p $TESTDIR/root
ff2b41
+    mount ${LOOPDEV}p1 $TESTDIR/root
ff2b41
+    [[ -e $TESTDIR/root/testok ]] && ret=0
ff2b41
+    [[ -f $TESTDIR/root/failed ]] && cp -a $TESTDIR/root/failed $TESTDIR
ff2b41
+    cp -a $TESTDIR/root/var/log/journal $TESTDIR
ff2b41
+    umount $TESTDIR/root
ff2b41
+    [[ -f $TESTDIR/failed ]] && cat $TESTDIR/failed
ff2b41
+    ls -l $TESTDIR/journal/*/*.journal
ff2b41
+    test -s $TESTDIR/failed && ret=$(($ret+1))
ff2b41
+    return $ret
ff2b41
+}
ff2b41
+
ff2b41
+test_run() {
ff2b41
+    if run_qemu; then
ff2b41
+        check_result_qemu || return 1
ff2b41
+    else
ff2b41
+        dwarn "can't run QEMU, skipping"
ff2b41
+    fi
ff2b41
+    if check_nspawn; then
ff2b41
+        run_nspawn
ff2b41
+        check_result_nspawn || return 1
ff2b41
+    else
ff2b41
+        dwarn "can't run systemd-nspawn, skipping"
ff2b41
+    fi
ff2b41
+    return 0
ff2b41
+}
ff2b41
+
ff2b41
+test_setup() {
ff2b41
+    create_empty_image
ff2b41
+    mkdir -p $TESTDIR/root
ff2b41
+    mount ${LOOPDEV}p1 $TESTDIR/root
ff2b41
+
ff2b41
+    # Create what will eventually be our root filesystem onto an overlay
ff2b41
+    (
ff2b41
+        LOG_LEVEL=5
ff2b41
+        eval $(udevadm info --export --query=env --name=${LOOPDEV}p2)
ff2b41
+
ff2b41
+        setup_basic_environment
ff2b41
+
ff2b41
+        # setup the testsuite service
ff2b41
+        cat >$initdir/etc/systemd/system/testsuite.service <
ff2b41
+[Unit]
ff2b41
+Description=Testsuite service
ff2b41
+After=multi-user.target
ff2b41
+
ff2b41
+[Service]
ff2b41
+ExecStart=/test-journal.sh
ff2b41
+Type=oneshot
ff2b41
+EOF
ff2b41
+
ff2b41
+        cp test-journal.sh $initdir/
ff2b41
+
ff2b41
+        setup_testsuite
ff2b41
+    )
ff2b41
+    setup_nspawn_root
ff2b41
+
ff2b41
+    ddebug "umount $TESTDIR/root"
ff2b41
+    umount $TESTDIR/root
ff2b41
+}
ff2b41
+
ff2b41
+test_cleanup() {
ff2b41
+    umount $TESTDIR/root 2>/dev/null
ff2b41
+    [[ $LOOPDEV ]] && losetup -d $LOOPDEV
ff2b41
+    return 0
ff2b41
+}
ff2b41
+
ff2b41
+do_test "$@"
ff2b41
diff --git a/test/test-functions b/test/test-functions
ff2b41
index e50ce556fd..d5e9650903 100644
ff2b41
--- a/test/test-functions
ff2b41
+++ b/test/test-functions
ff2b41
@@ -12,7 +12,7 @@ if ! ROOTLIBDIR=$(pkg-config --variable=systemdutildir systemd); then
ff2b41
     ROOTLIBDIR=/usr/lib/systemd
ff2b41
 fi
ff2b41
 
ff2b41
-BASICTOOLS="test sh bash setsid loadkeys setfont login sulogin gzip sleep echo mount umount cryptsetup date dmsetup modprobe chmod chown ln"
ff2b41
+BASICTOOLS="test sh bash setsid loadkeys setfont login sulogin gzip sleep echo mount umount cryptsetup date dmsetup modprobe chmod chown ln sed cmp tee"
ff2b41
 DEBUGTOOLS="df free ls stty cat ps ln ip route dmesg dhclient mkdir cp ping dhclient strace less grep id tty touch du sort hostname"
ff2b41
 
ff2b41
 function find_qemu_bin() {