naccyde / rpms / systemd

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