ryantimwilson / rpms / systemd

Forked from rpms/systemd a month ago
Clone
b7dd4d
From 2bbaa4b647c8a60a6c6a591f71313b0667447246 Mon Sep 17 00:00:00 2001
b7dd4d
From: Lennart Poettering <lennart@poettering.net>
b7dd4d
Date: Mon, 26 Nov 2018 21:09:07 +0100
b7dd4d
Subject: [PATCH] =?UTF-8?q?test:=20add=20a=20test=20for=20StandardError=3D?=
b7dd4d
 =?UTF-8?q?file:=E2=80=A6?=
b7dd4d
MIME-Version: 1.0
b7dd4d
Content-Type: text/plain; charset=UTF-8
b7dd4d
Content-Transfer-Encoding: 8bit
b7dd4d
b7dd4d
This deserves a test of its, given how broken on so many levels this
b7dd4d
previously was.
b7dd4d
b7dd4d
(cherry picked from commit 196b0a11f306b8041e35316feb05ed1f00380957)
b7dd4d
b7dd4d
Related: #2093479
b7dd4d
---
b7dd4d
 test/TEST-27-STDOUTFILE/Makefile     |  1 +
b7dd4d
 test/TEST-27-STDOUTFILE/test.sh      | 52 ++++++++++++++++++++++++++++
b7dd4d
 test/TEST-27-STDOUTFILE/testsuite.sh | 40 +++++++++++++++++++++
b7dd4d
 3 files changed, 93 insertions(+)
b7dd4d
 create mode 120000 test/TEST-27-STDOUTFILE/Makefile
b7dd4d
 create mode 100755 test/TEST-27-STDOUTFILE/test.sh
b7dd4d
 create mode 100755 test/TEST-27-STDOUTFILE/testsuite.sh
b7dd4d
b7dd4d
diff --git a/test/TEST-27-STDOUTFILE/Makefile b/test/TEST-27-STDOUTFILE/Makefile
b7dd4d
new file mode 120000
b7dd4d
index 0000000000..e9f93b1104
b7dd4d
--- /dev/null
b7dd4d
+++ b/test/TEST-27-STDOUTFILE/Makefile
b7dd4d
@@ -0,0 +1 @@
b7dd4d
+../TEST-01-BASIC/Makefile
b7dd4d
\ No newline at end of file
b7dd4d
diff --git a/test/TEST-27-STDOUTFILE/test.sh b/test/TEST-27-STDOUTFILE/test.sh
b7dd4d
new file mode 100755
b7dd4d
index 0000000000..724dbef231
b7dd4d
--- /dev/null
b7dd4d
+++ b/test/TEST-27-STDOUTFILE/test.sh
b7dd4d
@@ -0,0 +1,52 @@
b7dd4d
+#!/bin/bash
b7dd4d
+# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
b7dd4d
+# ex: ts=8 sw=4 sts=4 et filetype=sh
b7dd4d
+set -e
b7dd4d
+TEST_DESCRIPTION="test StandardOutput=file:"
b7dd4d
+
b7dd4d
+. $TEST_BASE_DIR/test-functions
b7dd4d
+
b7dd4d
+test_setup() {
b7dd4d
+    create_empty_image
b7dd4d
+    mkdir -p $TESTDIR/root
b7dd4d
+    mount ${LOOPDEV}p1 $TESTDIR/root
b7dd4d
+
b7dd4d
+    (
b7dd4d
+        LOG_LEVEL=5
b7dd4d
+        eval $(udevadm info --export --query=env --name=${LOOPDEV}p2)
b7dd4d
+
b7dd4d
+        inst_binary cmp
b7dd4d
+
b7dd4d
+        setup_basic_environment
b7dd4d
+
b7dd4d
+        # mask some services that we do not want to run in these tests
b7dd4d
+        ln -fs /dev/null $initdir/etc/systemd/system/systemd-hwdb-update.service
b7dd4d
+        ln -fs /dev/null $initdir/etc/systemd/system/systemd-journal-catalog-update.service
b7dd4d
+        ln -fs /dev/null $initdir/etc/systemd/system/systemd-networkd.service
b7dd4d
+        ln -fs /dev/null $initdir/etc/systemd/system/systemd-networkd.socket
b7dd4d
+        ln -fs /dev/null $initdir/etc/systemd/system/systemd-resolved.service
b7dd4d
+        ln -fs /dev/null $initdir/etc/systemd/system/systemd-machined.service
b7dd4d
+
b7dd4d
+        # setup the testsuite service
b7dd4d
+        cat >$initdir/etc/systemd/system/testsuite.service <
b7dd4d
+[Unit]
b7dd4d
+Description=Testsuite service
b7dd4d
+
b7dd4d
+[Service]
b7dd4d
+ExecStart=/testsuite.sh
b7dd4d
+Type=oneshot
b7dd4d
+StandardOutput=tty
b7dd4d
+StandardError=tty
b7dd4d
+NotifyAccess=all
b7dd4d
+EOF
b7dd4d
+        cp testsuite.sh $initdir/
b7dd4d
+
b7dd4d
+        setup_testsuite
b7dd4d
+    ) || return 1
b7dd4d
+    setup_nspawn_root
b7dd4d
+
b7dd4d
+    ddebug "umount $TESTDIR/root"
b7dd4d
+    umount $TESTDIR/root
b7dd4d
+}
b7dd4d
+
b7dd4d
+do_test "$@"
b7dd4d
diff --git a/test/TEST-27-STDOUTFILE/testsuite.sh b/test/TEST-27-STDOUTFILE/testsuite.sh
b7dd4d
new file mode 100755
b7dd4d
index 0000000000..75559e03e5
b7dd4d
--- /dev/null
b7dd4d
+++ b/test/TEST-27-STDOUTFILE/testsuite.sh
b7dd4d
@@ -0,0 +1,40 @@
b7dd4d
+#!/bin/bash
b7dd4d
+# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
b7dd4d
+# ex: ts=8 sw=4 sts=4 et filetype=sh
b7dd4d
+set -ex
b7dd4d
+set -o pipefail
b7dd4d
+
b7dd4d
+systemd-analyze set-log-level debug
b7dd4d
+systemd-analyze set-log-target console
b7dd4d
+
b7dd4d
+systemd-run --unit=one -p StandardOutput=file:/tmp/stdout -p StandardError=file:/tmp/stderr -p Type=exec sh -c 'echo x ; echo y >&2'
b7dd4d
+cmp /tmp/stdout <
b7dd4d
+x
b7dd4d
+EOF
b7dd4d
+cmp /tmp/stderr <
b7dd4d
+y
b7dd4d
+EOF
b7dd4d
+
b7dd4d
+systemd-run --unit=two -p StandardOutput=file:/tmp/stdout -p StandardError=file:/tmp/stderr -p Type=exec sh -c 'echo z ; echo a >&2'
b7dd4d
+cmp /tmp/stdout <
b7dd4d
+z
b7dd4d
+EOF
b7dd4d
+cmp /tmp/stderr <
b7dd4d
+a
b7dd4d
+EOF
b7dd4d
+
b7dd4d
+systemd-run --unit=three -p StandardOutput=append:/tmp/stdout -p StandardError=append:/tmp/stderr -p Type=exec sh -c 'echo b ; echo c >&2'
b7dd4d
+cmp /tmp/stdout <
b7dd4d
+z
b7dd4d
+b
b7dd4d
+EOF
b7dd4d
+cmp /tmp/stderr <
b7dd4d
+a
b7dd4d
+c
b7dd4d
+EOF
b7dd4d
+
b7dd4d
+systemd-analyze set-log-level info
b7dd4d
+
b7dd4d
+echo OK > /testok
b7dd4d
+
b7dd4d
+exit 0