From 8876883b5a6a60b83615833cee76f4f060481bd2 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Wed, 13 Aug 2025 12:30:25 +0900 Subject: [PATCH] TEST-38-FREEZER: use 'systemctl show' to get freezer state Also, use timeout command for waiting freezer state applied. (cherry picked from commit ee76ac1411549dc5517b2c58ff1dc84f01c24183) --- test/units/TEST-38-FREEZER.sh | 47 ++++++++--------------------------- 1 file changed, 11 insertions(+), 36 deletions(-) diff --git a/test/units/TEST-38-FREEZER.sh b/test/units/TEST-38-FREEZER.sh index 6c21a2d3e32..5ce073d045c 100755 --- a/test/units/TEST-38-FREEZER.sh +++ b/test/units/TEST-38-FREEZER.sh @@ -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 -- 2.47.3