From 9409c50e3f5c8f9eb0341f77f89e445f32555bb9 Mon Sep 17 00:00:00 2001 From: eugene-yujinwu <117058060+eugene-yujinwu@users.noreply.github.com> Date: Fri, 5 Jul 2024 05:33:37 +0800 Subject: [PATCH] Improve power-management/lid_close_suspend_open test case (Bugfix) (#1093) * Fix some issues related with the test case power-management/lid_close_suspend_open (bugfix) (#1080) - Make sure the test is executed at the appropriate time (i.e. not right after resuming the device) - Fix the typo in the test order number - Remove functionally similar test cases power-management/lid from the test plan - Adjust the place of test case to avoid running it just after the suspend case * Add test power-management/lid back per Clair's comments * Check the last suspend within the time of HoldoffTimeoutUSec as the review advised. * Change the script per the new comments from Hanhsuan * change the lid_close_suspend_open.sh per Stanley's advice Co-authored-by: stanley31huang * Fix the error in ShellcheckTests * Fix a wait time calculation issue and improve the PR per Pierre's comments Co-authored-by: Pierre Equoy --------- Co-authored-by: stanley31huang Co-authored-by: Pierre Equoy --- providers/base/bin/lid_close_suspend_open.sh | 17 ++++++++++++++++- providers/base/units/graphics/test-plan.pxu | 8 ++++---- providers/base/units/power-management/jobs.pxu | 1 + 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/providers/base/bin/lid_close_suspend_open.sh b/providers/base/bin/lid_close_suspend_open.sh index 84ad0abef..be63b916b 100755 --- a/providers/base/bin/lid_close_suspend_open.sh +++ b/providers/base/bin/lid_close_suspend_open.sh @@ -1,4 +1,19 @@ -#! /usr/bin/bash +#!/usr/bin/bash + +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=$((holdoff_timeout_usec / 1000000)) + +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. wait_time = holdoff_time - wakeup_time_from_last_suspend + sleep_time=$(("$holdoff_timeout_sec" - ($(date +"%s") - "$previous_sleep_time"))) + echo "DUT was resumed less than ${holdoff_timeout_sec} seconds ago. Waiting for ${sleep_time} seconds before running the test..." + 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" echo "Please close the lid and wait for 5 sec to make it suspend~" diff --git a/providers/base/units/graphics/test-plan.pxu b/providers/base/units/graphics/test-plan.pxu index 39ef346e0..8ace0f0b0 100644 --- a/providers/base/units/graphics/test-plan.pxu +++ b/providers/base/units/graphics/test-plan.pxu @@ -210,8 +210,6 @@ include: # depending on the amount of graphic cards available on the SUT: # suspend/suspend_advanced_auto (one GPU) # or suspend/{{ index }}_suspend_after_switch_to_card_{{ product_slug }}_auto (two GPUs) - power-management/lid_close_suspend_open certification-status=blocker - power-management/lid certification-status=blocker after-suspend-miscellanea/chvt suspend/1_display_after_suspend_.*_graphics certification-status=blocker after-suspend-graphics/1_maximum_resolution_.* certification-status=blocker @@ -220,6 +218,8 @@ include: after-suspend-graphics/1_video_.* certification-status=blocker after-suspend-graphics/1_cycle_resolution_.* certification-status=non-blocker suspend/1_xrandr_screens_after_suspend.tar.gz_auto + power-management/lid_close_suspend_open certification-status=blocker + power-management/lid certification-status=blocker id: after-suspend-graphics-discrete-gpu-cert-full unit: test plan @@ -296,8 +296,6 @@ _description: After suspend tests (integrated GPU, certification blockers only) include: after-suspend-graphics/1_auto_switch_card_.* certification-status=blocker suspend/1_suspend_after_switch_to_card_.*_auto certification-status=blocker - power-management/lid_close_suspend_open certification-status=blocker - power-management/lid certification-status=blocker suspend/1_gl_support_after_suspend_.*_auto certification-status=blocker suspend/1_driver_version_after_suspend_.*_auto certification-status=blocker suspend/1_resolution_after_suspend_.*_auto certification-status=blocker @@ -305,6 +303,8 @@ include: suspend/1_glxgears_after_suspend_.*_graphics certification-status=blocker suspend/1_rotation_after_suspend_.*_graphics certification-status=blocker suspend/1_video_after_suspend_.*_graphics certification-status=blocker + power-management/lid_close_suspend_open certification-status=blocker + power-management/lid certification-status=blocker id: after-suspend-graphics-discrete-gpu-cert-blockers unit: test plan diff --git a/providers/base/units/power-management/jobs.pxu b/providers/base/units/power-management/jobs.pxu index b2468f2b6..b37ad4232 100644 --- a/providers/base/units/power-management/jobs.pxu +++ b/providers/base/units/power-management/jobs.pxu @@ -189,6 +189,7 @@ _steps: 4. Open the lid _verification: Did the system suspend when the lid was closed, and resume back when the lid was opened? + Note: Systemd will not react to lid events if the DUT was just started or resumed. Please make sure the DUT has been running for long enough before running this test. command: lid_close_suspend_open.sh _summary: Test the functionality of the laptop's lid sensor for suspend/resume actions.