naccyde / rpms / systemd

Forked from rpms/systemd a year ago
Clone
b7dd4d
From 1c2a0bde1bc3510d9bdc07410ff90429ebed391f Mon Sep 17 00:00:00 2001
62b62a
From: Michal Sekletar <msekleta@redhat.com>
62b62a
Date: Wed, 23 Mar 2022 13:35:44 +0100
62b62a
Subject: [PATCH] tests: add test case for long unit names
62b62a
62b62a
(cherry picked from commit 2ef0101e0b2813e8c99fc8f137dbaa763ca16057)
62b62a
b7dd4d
Related: #1940973
62b62a
---
62b62a
 test/TEST-60-MOUNT-RATELIMIT/testsuite.sh | 19 +++++++++++++++++++
62b62a
 1 file changed, 19 insertions(+)
62b62a
62b62a
diff --git a/test/TEST-60-MOUNT-RATELIMIT/testsuite.sh b/test/TEST-60-MOUNT-RATELIMIT/testsuite.sh
62b62a
index 8158754667..6211050faf 100755
62b62a
--- a/test/TEST-60-MOUNT-RATELIMIT/testsuite.sh
62b62a
+++ b/test/TEST-60-MOUNT-RATELIMIT/testsuite.sh
62b62a
@@ -7,6 +7,25 @@ systemd-analyze log-target journal
62b62a
 
62b62a
 NUM_DIRS=20
62b62a
 
62b62a
+# make sure we can handle mounts at very long paths such that mount unit name must be hashed to fall within our unit name limit
62b62a
+LONGPATH="$(printf "/$(printf "x%0.s" {1..255})%0.s" {1..7})"
62b62a
+LONGMNT="$(systemd-escape --suffix=mount --path "$LONGPATH")"
62b62a
+TS="$(date '+%H:%M:%S')"
62b62a
+
62b62a
+mkdir -p "$LONGPATH"
62b62a
+mount -t tmpfs tmpfs "$LONGPATH"
62b62a
+systemctl daemon-reload
62b62a
+
62b62a
+# check that unit is active(mounted)
62b62a
+systemctl --no-pager show -p SubState --value "$LONGPATH" | grep -q mounted
62b62a
+
62b62a
+# check that relevant part of journal doesn't contain any errors related to unit
62b62a
+[ "$(journalctl -b --since="$TS" --priority=err | grep -c "$LONGMNT")" = "0" ]
62b62a
+
62b62a
+# check that we can successfully stop the mount unit
62b62a
+systemctl stop "$LONGPATH"
62b62a
+rm -rf "$LONGPATH"
62b62a
+
62b62a
 # mount/unmount enough times to trigger the /proc/self/mountinfo parsing rate limiting
62b62a
 
62b62a
 for ((i = 0; i < NUM_DIRS; i++)); do