summaryrefslogtreecommitdiffstats
path: root/test/test-bootctl-json.sh
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-10 20:49:52 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-10 20:49:52 +0000
commit55944e5e40b1be2afc4855d8d2baf4b73d1876b5 (patch)
tree33f869f55a1b149e9b7c2b7e201867ca5dd52992 /test/test-bootctl-json.sh
parentInitial commit. (diff)
downloadsystemd-55944e5e40b1be2afc4855d8d2baf4b73d1876b5.tar.xz
systemd-55944e5e40b1be2afc4855d8d2baf4b73d1876b5.zip
Adding upstream version 255.4.upstream/255.4
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'test/test-bootctl-json.sh')
-rwxr-xr-xtest/test-bootctl-json.sh50
1 files changed, 50 insertions, 0 deletions
diff --git a/test/test-bootctl-json.sh b/test/test-bootctl-json.sh
new file mode 100755
index 0000000..4d7c468
--- /dev/null
+++ b/test/test-bootctl-json.sh
@@ -0,0 +1,50 @@
+#!/usr/bin/env bash
+# SPDX-License-Identifier: LGPL-2.1-or-later
+set -e
+set -o pipefail
+
+bootctl="${1:?}"
+
+"$bootctl" --no-pager list >/dev/null || {
+ echo "$bootctl list failed, skipping tests" 1>&2
+ exit 77
+}
+
+set -x
+
+"$bootctl" list --json=pretty | python3 -m json.tool >/dev/null
+"$bootctl" list --json=short | python3 -m json.tool >/dev/null
+
+command -v jq >/dev/null || {
+ echo "jq is not available, skipping jq tests" 1>&2
+ exit 0
+}
+
+"$bootctl" list --json=pretty | jq . >/dev/null
+"$bootctl" list --json=short | jq . >/dev/null
+
+# bootctl --print-root-device should either succeed or fail with exit status 80
+# (because not backed by a single block device), but not fail otherwise.
+"$bootctl" -R || test "$?" -eq 80
+"$bootctl" -RR || test "$?" -eq 80
+
+# regression tests for
+# https://github.com/systemd/systemd/pull/27199#issuecomment-1511387731
+if ret=$("$bootctl" --print-esp-path); then
+ test "$ret" = "/efi" -o "$ret" = "/boot" -o "$ret" = "/boot/efi"
+fi
+if ret=$("bootctl" --print-boot-path); then
+ test "$ret" = "/efi" -o "$ret" = "/boot" -o "$ret" = "/boot/efi"
+fi
+
+if "$bootctl" -R > /dev/null ; then
+ P=$("$bootctl" -R)
+ PP=$("$bootctl" -RR)
+
+ echo "$P vs $PP"
+ test -b "$P"
+ test -b "$PP"
+
+ # $P must be a prefix of $PP
+ [[ $P = $PP* ]]
+fi