Skip to content

Commit 8053763

Browse files
committed
Fix: Add validations to suspend_trigger
* Run "systemctl list-jobs suspend" to check if there are suspend jobs running before running one more. * If "systemctl list-jobs suspend" detects suspend jobs running wait for a while before proceeding. * Check the return code of "systemctl suspend" and fail with error when needed. * Set "set -o pipefail" on the Checkbox job definition for the job to be marked as "failed" when exiting on error.
1 parent aed87f5 commit 8053763

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

providers/base/bin/suspend_trigger.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,19 +67,38 @@ def main(args=sys.argv[1:]):
6767
str(args.sleep_delay),
6868
]
6969
suspend_cmd = ["systemctl", "suspend"]
70+
list_jobs_cmd = ["systemctl", "list-jobs", "*suspend*"]
7071
print("Running: {}".format(" ".join(rtcwake_cmd)))
7172
subprocess.check_call(rtcwake_cmd)
73+
timeout = 100
74+
while timeout > 0:
75+
ret_list = subprocess.run(list_jobs_cmd, capture_output=True, text=True, check=True)
76+
if "No jobs running" in ret_list.stdout:
77+
break
78+
print(f"Suspend jobs ongoing, waiting... ({timeout} left)")
79+
time.sleep(1)
80+
timeout -= 1
81+
else:
82+
print("Timed out waiting for suspend jobs to finish")
83+
return 1
7284
print(
7385
"Running: {} to suspend the system".format(" ".join(suspend_cmd))
7486
)
75-
subprocess.check_call(suspend_cmd)
87+
ret_suspend = subprocess.run(suspend_cmd)
88+
if ret_suspend.returncode != 0:
89+
print(
90+
"Issues running:{} returned:{}".format(" ".join(suspend_cmd), ret_suspend.returncode)
91+
)
92+
return ret_suspend.returncode
7693

7794
# Clean up the FWTS log file from its default path.
7895
log_path = "/tmp/fwts_results.log"
7996
if os.path.exists(log_path):
8097
print("Removing {}...".format(log_path))
8198
os.remove(log_path)
8299

100+
return 0
101+
83102

84103
if __name__ == "__main__":
85104
sys.exit(main())

providers/base/units/stress/suspend_cycles_reboot.pxu

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ estimated_duration: 75.0
7979
environ: PLAINBOX_SESSION_SHARE STRESS_S3_INIT_DELAY STRESS_S3_SLEEP_DELAY STRESS_S3_WAIT_DELAY LD_LIBRARY_PATH RTC_DEVICE_FILE
8080
user: root
8181
command:
82+
set -o pipefail
8283
echo "Current boot ID is: $(tr -d - < /proc/sys/kernel/random/boot_id)"
8384
suspend_trigger.py --wait "${STRESS_S3_INIT_DELAY:-120}" --check-delay "${STRESS_S3_WAIT_DELAY:-45}" --sleep-delay "${STRESS_S3_SLEEP_DELAY:-30}" --rtc-device "${RTC_DEVICE_FILE:-/dev/rtc0}" 2>&1 | tee -a "$PLAINBOX_SESSION_SHARE"/suspend_cycles_with_reboot_total.log
8485
summary:
@@ -105,6 +106,7 @@ environ: PLAINBOX_SESSION_SHARE STRESS_S3_INIT_DELAY STRESS_S3_SLEEP_DELAY STRES
105106
after: stress-tests/suspend_cycles_reboot{{suspend_reboot_previous}}
106107
user: root
107108
command:
109+
set -o pipefail
108110
echo "Current boot ID is: $(tr -d - < /proc/sys/kernel/random/boot_id)"
109111
suspend_trigger.py --wait "${STRESS_S3_INIT_DELAY:-120}" --check-delay "${STRESS_S3_WAIT_DELAY:-45}" --sleep-delay "${STRESS_S3_SLEEP_DELAY:-30}" --rtc-device "${RTC_DEVICE_FILE:-/dev/rtc0}" 2>&1 | tee -a "$PLAINBOX_SESSION_SHARE"/suspend_cycles_with_reboot_total.log
110112
summary:
@@ -129,6 +131,7 @@ environ: PLAINBOX_SESSION_SHARE STRESS_S3_INIT_DELAY STRESS_S3_SLEEP_DELAY STRES
129131
after: stress-tests/suspend_cycles_{{suspend_id_previous}}_reboot{{suspend_reboot_id}}
130132
user: root
131133
command:
134+
set -o pipefail
132135
echo "Current boot ID is: $(tr -d - < /proc/sys/kernel/random/boot_id)"
133136
suspend_trigger.py --check-delay "${STRESS_S3_WAIT_DELAY:-45}" --sleep-delay "${STRESS_S3_SLEEP_DELAY:-30}" --rtc-device "${RTC_DEVICE_FILE:-/dev/rtc0}" 2>&1 | tee -a "$PLAINBOX_SESSION_SHARE"/suspend_cycles_with_reboot_total.log
134137
summary:

0 commit comments

Comments
 (0)