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