teknoraver / rpms / systemd

Forked from rpms/systemd 2 months ago
Clone

Blame SOURCES/0763-tests-add-basic-journal-test.patch

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