|
|
a3e2b5 |
From afb82e108fe45d8481f2be50c74c4c6f307f8d60 Mon Sep 17 00:00:00 2001
|
|
|
a3e2b5 |
From: Lennart Poettering <lennart@poettering.net>
|
|
|
a3e2b5 |
Date: Tue, 17 Jul 2018 12:35:12 +0200
|
|
|
a3e2b5 |
Subject: [PATCH] test: add test for Type=exec
|
|
|
a3e2b5 |
|
|
|
a3e2b5 |
(cherry picked from commit 0e1f17561f5f6061ec5503de044298372ed7ca37)
|
|
|
a3e2b5 |
|
|
|
a3e2b5 |
Resolves: #1683334
|
|
|
a3e2b5 |
---
|
|
|
a3e2b5 |
test/TEST-23-TYPE-EXEC/Makefile | 4 +++
|
|
|
a3e2b5 |
test/TEST-23-TYPE-EXEC/test.sh | 42 +++++++++++++++++++++++++++++
|
|
|
a3e2b5 |
test/TEST-23-TYPE-EXEC/testsuite.sh | 28 +++++++++++++++++++
|
|
|
a3e2b5 |
3 files changed, 74 insertions(+)
|
|
|
a3e2b5 |
create mode 100644 test/TEST-23-TYPE-EXEC/Makefile
|
|
|
a3e2b5 |
create mode 100755 test/TEST-23-TYPE-EXEC/test.sh
|
|
|
a3e2b5 |
create mode 100755 test/TEST-23-TYPE-EXEC/testsuite.sh
|
|
|
a3e2b5 |
|
|
|
a3e2b5 |
diff --git a/test/TEST-23-TYPE-EXEC/Makefile b/test/TEST-23-TYPE-EXEC/Makefile
|
|
|
a3e2b5 |
new file mode 100644
|
|
|
a3e2b5 |
index 0000000000..34d7cc6cdf
|
|
|
a3e2b5 |
--- /dev/null
|
|
|
a3e2b5 |
+++ b/test/TEST-23-TYPE-EXEC/Makefile
|
|
|
a3e2b5 |
@@ -0,0 +1,4 @@
|
|
|
a3e2b5 |
+BUILD_DIR=$(shell ../../tools/find-build-dir.sh)
|
|
|
a3e2b5 |
+
|
|
|
a3e2b5 |
+all setup clean run:
|
|
|
a3e2b5 |
+ @basedir=../.. TEST_BASE_DIR=../ BUILD_DIR=$(BUILD_DIR) ./test.sh --$@
|
|
|
a3e2b5 |
diff --git a/test/TEST-23-TYPE-EXEC/test.sh b/test/TEST-23-TYPE-EXEC/test.sh
|
|
|
a3e2b5 |
new file mode 100755
|
|
|
a3e2b5 |
index 0000000000..bdcea239a7
|
|
|
a3e2b5 |
--- /dev/null
|
|
|
a3e2b5 |
+++ b/test/TEST-23-TYPE-EXEC/test.sh
|
|
|
a3e2b5 |
@@ -0,0 +1,42 @@
|
|
|
a3e2b5 |
+#!/bin/bash
|
|
|
a3e2b5 |
+# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
|
|
|
a3e2b5 |
+# ex: ts=8 sw=4 sts=4 et filetype=sh
|
|
|
a3e2b5 |
+set -e
|
|
|
a3e2b5 |
+TEST_DESCRIPTION="test Type=exec"
|
|
|
a3e2b5 |
+
|
|
|
a3e2b5 |
+. $TEST_BASE_DIR/test-functions
|
|
|
a3e2b5 |
+
|
|
|
a3e2b5 |
+test_setup() {
|
|
|
a3e2b5 |
+ create_empty_image
|
|
|
a3e2b5 |
+ mkdir -p $TESTDIR/root
|
|
|
a3e2b5 |
+ mount ${LOOPDEV}p1 $TESTDIR/root
|
|
|
a3e2b5 |
+
|
|
|
a3e2b5 |
+ (
|
|
|
a3e2b5 |
+ LOG_LEVEL=5
|
|
|
a3e2b5 |
+ eval $(udevadm info --export --query=env --name=${LOOPDEV}p2)
|
|
|
a3e2b5 |
+
|
|
|
a3e2b5 |
+ setup_basic_environment
|
|
|
a3e2b5 |
+
|
|
|
a3e2b5 |
+ # setup the testsuite service
|
|
|
a3e2b5 |
+ cat >$initdir/etc/systemd/system/testsuite.service <
|
|
|
a3e2b5 |
+[Unit]
|
|
|
a3e2b5 |
+Description=Testsuite service
|
|
|
a3e2b5 |
+
|
|
|
a3e2b5 |
+[Service]
|
|
|
a3e2b5 |
+ExecStart=/testsuite.sh
|
|
|
a3e2b5 |
+Type=oneshot
|
|
|
a3e2b5 |
+StandardOutput=tty
|
|
|
a3e2b5 |
+StandardError=tty
|
|
|
a3e2b5 |
+NotifyAccess=all
|
|
|
a3e2b5 |
+EOF
|
|
|
a3e2b5 |
+ cp testsuite.sh $initdir/
|
|
|
a3e2b5 |
+
|
|
|
a3e2b5 |
+ setup_testsuite
|
|
|
a3e2b5 |
+ ) || return 1
|
|
|
a3e2b5 |
+ setup_nspawn_root
|
|
|
a3e2b5 |
+
|
|
|
a3e2b5 |
+ ddebug "umount $TESTDIR/root"
|
|
|
a3e2b5 |
+ umount $TESTDIR/root
|
|
|
a3e2b5 |
+}
|
|
|
a3e2b5 |
+
|
|
|
a3e2b5 |
+do_test "$@"
|
|
|
a3e2b5 |
diff --git a/test/TEST-23-TYPE-EXEC/testsuite.sh b/test/TEST-23-TYPE-EXEC/testsuite.sh
|
|
|
a3e2b5 |
new file mode 100755
|
|
|
a3e2b5 |
index 0000000000..80734bbbdc
|
|
|
a3e2b5 |
--- /dev/null
|
|
|
a3e2b5 |
+++ b/test/TEST-23-TYPE-EXEC/testsuite.sh
|
|
|
a3e2b5 |
@@ -0,0 +1,28 @@
|
|
|
a3e2b5 |
+#!/bin/bash
|
|
|
a3e2b5 |
+# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
|
|
|
a3e2b5 |
+# ex: ts=8 sw=4 sts=4 et filetype=sh
|
|
|
a3e2b5 |
+set -ex
|
|
|
a3e2b5 |
+set -o pipefail
|
|
|
a3e2b5 |
+
|
|
|
a3e2b5 |
+systemd-analyze set-log-level debug
|
|
|
a3e2b5 |
+systemd-analyze set-log-target console
|
|
|
a3e2b5 |
+
|
|
|
a3e2b5 |
+# Create a binary for which execve() will fail
|
|
|
a3e2b5 |
+touch /tmp/brokenbinary
|
|
|
a3e2b5 |
+chmod +x /tmp/brokenbinary
|
|
|
a3e2b5 |
+
|
|
|
a3e2b5 |
+# These three commands should succeed.
|
|
|
a3e2b5 |
+systemd-run --unit=one -p Type=simple /bin/sleep infinity
|
|
|
a3e2b5 |
+systemd-run --unit=two -p Type=simple -p User=idontexist /bin/sleep infinity
|
|
|
a3e2b5 |
+systemd-run --unit=three -p Type=simple /tmp/brokenbinary
|
|
|
a3e2b5 |
+
|
|
|
a3e2b5 |
+# And now, do the same with Type=exec, where the latter two should fail
|
|
|
a3e2b5 |
+systemd-run --unit=four -p Type=exec /bin/sleep infinity
|
|
|
a3e2b5 |
+! systemd-run --unit=five -p Type=exec -p User=idontexist /bin/sleep infinity
|
|
|
a3e2b5 |
+! systemd-run --unit=six -p Type=exec /tmp/brokenbinary
|
|
|
a3e2b5 |
+
|
|
|
a3e2b5 |
+systemd-analyze set-log-level info
|
|
|
a3e2b5 |
+
|
|
|
a3e2b5 |
+echo OK > /testok
|
|
|
a3e2b5 |
+
|
|
|
a3e2b5 |
+exit 0
|