b11b5f
From 1925845dc10330e4b48fec68333fac6ef2b7bf5c Mon Sep 17 00:00:00 2001
b11b5f
From: Yu Watanabe <watanabe.yu+github@gmail.com>
b11b5f
Date: Wed, 1 Jun 2022 08:56:08 +0900
b11b5f
Subject: [PATCH] test: import logind test from debian/ubuntu test suite
b11b5f
b11b5f
[dtardon: Picked just the scaffolding, not the tests themselves.]
b11b5f
b11b5f
(cherry picked from commit 9c94ab0f6ff22da4278a6e9a93ddc480607c55ac)
b11b5f
b11b5f
Related: #1866955
b11b5f
---
b11b5f
 test/TEST-35-LOGIN/Makefile     |  1 +
b11b5f
 test/TEST-35-LOGIN/test.sh      | 55 +++++++++++++++++++++++++++++++++
b11b5f
 test/TEST-35-LOGIN/testsuite.sh |  9 ++++++
b11b5f
 3 files changed, 65 insertions(+)
b11b5f
 create mode 120000 test/TEST-35-LOGIN/Makefile
b11b5f
 create mode 100755 test/TEST-35-LOGIN/test.sh
b11b5f
 create mode 100755 test/TEST-35-LOGIN/testsuite.sh
b11b5f
b11b5f
diff --git a/test/TEST-35-LOGIN/Makefile b/test/TEST-35-LOGIN/Makefile
b11b5f
new file mode 120000
b11b5f
index 0000000000..e9f93b1104
b11b5f
--- /dev/null
b11b5f
+++ b/test/TEST-35-LOGIN/Makefile
b11b5f
@@ -0,0 +1 @@
b11b5f
+../TEST-01-BASIC/Makefile
b11b5f
\ No newline at end of file
b11b5f
diff --git a/test/TEST-35-LOGIN/test.sh b/test/TEST-35-LOGIN/test.sh
b11b5f
new file mode 100755
b11b5f
index 0000000000..32410c8149
b11b5f
--- /dev/null
b11b5f
+++ b/test/TEST-35-LOGIN/test.sh
b11b5f
@@ -0,0 +1,55 @@
b11b5f
+#!/usr/bin/env bash
b11b5f
+# SPDX-License-Identifier: LGPL-2.1-or-later
b11b5f
+set -e
b11b5f
+
b11b5f
+TEST_DESCRIPTION="LOGIN"
b11b5f
+
b11b5f
+# shellcheck source=test/test-functions
b11b5f
+. "${TEST_BASE_DIR:?}/test-functions"
b11b5f
+
b11b5f
+test_setup() {
b11b5f
+    create_empty_image
b11b5f
+    mkdir -p "$TESTDIR"/root
b11b5f
+    mount "${LOOPDEV}p1" "$TESTDIR"/root
b11b5f
+
b11b5f
+    (
b11b5f
+        LOG_LEVEL=5
b11b5f
+        eval $(udevadm info --export --query=env --name="${LOOPDEV}p2")
b11b5f
+
b11b5f
+        setup_basic_environment
b11b5f
+
b11b5f
+        inst_binary pkill
b11b5f
+        inst_binary useradd
b11b5f
+        inst_binary userdel
b11b5f
+
b11b5f
+        # mask some services that we do not want to run in these tests
b11b5f
+        ln -fs /dev/null "$initdir"/etc/systemd/system/systemd-hwdb-update.service
b11b5f
+        ln -fs /dev/null "$initdir"/etc/systemd/system/systemd-journal-catalog-update.service
b11b5f
+        ln -fs /dev/null "$initdir"/etc/systemd/system/systemd-networkd.service
b11b5f
+        ln -fs /dev/null "$initdir"/etc/systemd/system/systemd-networkd.socket
b11b5f
+        ln -fs /dev/null "$initdir"/etc/systemd/system/systemd-resolved.service
b11b5f
+        ln -fs /dev/null "$initdir"/etc/systemd/system/systemd-machined.service
b11b5f
+
b11b5f
+        # setup the testsuite service
b11b5f
+        cat >"$initdir"/etc/systemd/system/testsuite.service <
b11b5f
+[Unit]
b11b5f
+Description=Testsuite service
b11b5f
+
b11b5f
+[Service]
b11b5f
+ExecStart=/bin/bash -x /testsuite.sh
b11b5f
+Type=oneshot
b11b5f
+StandardOutput=tty
b11b5f
+StandardError=tty
b11b5f
+NotifyAccess=all
b11b5f
+EOF
b11b5f
+        cp testsuite.sh "$initdir"/
b11b5f
+
b11b5f
+        setup_testsuite
b11b5f
+    ) || return 1
b11b5f
+    setup_nspawn_root
b11b5f
+
b11b5f
+    ddebug "umount $TESTDIR/root"
b11b5f
+    umount "$TESTDIR"/root
b11b5f
+}
b11b5f
+
b11b5f
+do_test "$@"
b11b5f
diff --git a/test/TEST-35-LOGIN/testsuite.sh b/test/TEST-35-LOGIN/testsuite.sh
b11b5f
new file mode 100755
b11b5f
index 0000000000..9855b4bc80
b11b5f
--- /dev/null
b11b5f
+++ b/test/TEST-35-LOGIN/testsuite.sh
b11b5f
@@ -0,0 +1,9 @@
b11b5f
+#!/usr/bin/env bash
b11b5f
+# SPDX-License-Identifier: LGPL-2.1-or-later
b11b5f
+set -eux
b11b5f
+set -o pipefail
b11b5f
+
b11b5f
+: >/failed
b11b5f
+
b11b5f
+touch /testok
b11b5f
+rm /failed