TEST-38-FREEZER: use 'systemctl show' to get freezer state

Also, use timeout command for waiting freezer state applied.
This commit is contained in:
Yu Watanabe
2025-08-13 12:30:25 +09:00
parent 0e25939a9d
commit ee76ac1411

View File

@@ -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:?}"
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.
timeout 10 bash -c "while [[ \"\$(systemctl show \"$name\" --property FreezerState --value)\" =~ (freezing|thawing) ]]; do sleep .5; done"
# 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