From ed500bafc98ccb767757434b5d9a526591002538 Mon Sep 17 00:00:00 2001 From: eugene2021 Date: Fri, 24 May 2024 18:17:46 +0800 Subject: [PATCH] change the lid_close_suspend_open.sh per Stanley's advice Co-authored-by: stanley31huang --- providers/base/bin/lid_close_suspend_open.sh | 22 +++++++++----------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/providers/base/bin/lid_close_suspend_open.sh b/providers/base/bin/lid_close_suspend_open.sh index c497a91b9..653fd1a47 100755 --- a/providers/base/bin/lid_close_suspend_open.sh +++ b/providers/base/bin/lid_close_suspend_open.sh @@ -3,18 +3,16 @@ holdoff_timeout_usec=$(gdbus introspect --system --dest org.freedesktop.login1 --object-path /org/freedesktop/login1 -p | grep HoldoffTimeoutUSec | awk '{print $5}' | awk -F\; '{print $1}') holdoff_timeout_sec=$(echo "scale=0; $holdoff_timeout_usec / 1000000" | bc) -if [ "$holdoff_timeout_sec" -ne 0 ]; then - if (journalctl --since "$holdoff_timeout_sec seconds ago" -b 0 -r | grep "suspend exit" >/dev/null 2>&1); then - echo "The system just resume from suspend, the lid event will be hold off on in $holdoff_timeout_sec seconds" - echo "Please wait for the new prompt before starting the test." - fi - while (journalctl --since "$holdoff_timeout_sec seconds ago" -b 0 -r | grep "suspend exit" >/dev/null 2>&1) - do - echo "waiting... " - sleep 3 - done - echo "" +previous_sleep_log=$(journalctl --output=short-unix --since "$holdoff_timeout_sec seconds ago" -b 0 -r | grep "suspend exit") +if [[ "$holdoff_timeout_sec" != 0 && "$previous_sleep_log" != "" ]]; then + # set the previous_sleep_time + previous_sleep_time=$(echo $previous_sleep_log | awk -F'.' '{ print $1 }') + # sleep a period of time + sleep_time=$(( $(date +"%s") - "$previous_sleep_time" )) + echo "sleep for $sleep_time seconds ..." + sleep "$sleep_time" fi +echo "System is ready for suspend test" prev_suspend_number=$(cat /sys/power/suspend_stats/success) echo "Number of successful suspends until now: $prev_suspend_number" @@ -71,4 +69,4 @@ do done echo "=============================================================" echo "Lid is not closed within $runTime!!!" -exit 1 \ No newline at end of file +exit 1