]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
TEST-38-FREEZER: use 'systemctl show' to get freezer state
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 13 Aug 2025 03:30:25 +0000 (12:30 +0900)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 3 Sep 2025 10:10:48 +0000 (12:10 +0200)
Also, use timeout command for waiting freezer state applied.

(cherry picked from commit ee76ac1411549dc5517b2c58ff1dc84f01c24183)

test/units/TEST-38-FREEZER.sh

index 6c21a2d3e328f97ccf17f8ae803d54af5d18df4b..5ce073d045cc75b9845060e11e3025f7f3a99a14 100755 (executable)
@@ -69,42 +69,18 @@ dbus_thaw_unit() {
            "$1"
 }
 
-dbus_can_freeze() {
-    local name object_path suffix
-
-    suffix="${1##*.}"
-    name="${1%".$suffix"}"
-    object_path="/org/freedesktop/systemd1/unit/${name//-/_2d}_2e${suffix}"
-
-    busctl get-property \
-           org.freedesktop.systemd1 \
-           "${object_path}" \
-           org.freedesktop.systemd1.Unit \
-           CanFreeze
-}
-
 check_freezer_state() {
-    local name object_path suffix
+    local name state expected
 
-    suffix="${1##*.}"
-    name="${1%".$suffix"}"
-    object_path="/org/freedesktop/systemd1/unit/${name//-/_2d}_2e${suffix}"
+    name="${1:?}"
+    expected="${2:?}"
+
+    # Ignore the intermediate freezing & thawing states in case we check the unit state too quickly.
+    timeout 10 bash -c "while [[ \"\$(systemctl show \"$name\" --property FreezerState --value)\" =~ (freezing|thawing) ]]; do sleep .5; done"
 
-    for _ in {0..10}; do
-        state=$(busctl get-property \
-                       org.freedesktop.systemd1 \
-                       "${object_path}" \
-                       org.freedesktop.systemd1.Unit \
-                       FreezerState | cut -d " " -f2 | tr -d '"')
-
-        # Ignore the intermediate freezing & thawing states in case we check
-        # the unit state too quickly
-        [[ "$state" =~ ^(freezing|thawing) ]] || break
-        sleep .5
-    done
-
-    [ "$state" = "$2" ] || {
-        echo "error: unexpected freezer state, expected: $2, actual: $state" >&2
+    state="$(systemctl show "$name" --property FreezerState --value)"
+    [[ "$state" = "$expected" ]] || {
+        echo "error: unexpected freezer state, expected: $expected, actual: $state" >&2
         exit 1
     }
 }
@@ -146,9 +122,8 @@ testcase_dbus_api() {
     check_cgroup_state "$unit" 0
     echo "[ OK ]"
 
-    echo -n "  - CanFreeze(): "
-    output=$(dbus_can_freeze "${unit}")
-    [ "$output" = "b true" ]
+    echo -n "  - CanFreeze: "
+    [[ "$(systemctl show "${unit}" --property=CanFreeze --value)" == 'yes' ]]
     echo "[ OK ]"
 
     echo