Skip to content

Commit da7085e

Browse files
committed
Fix: Add validations to suspend_trigger (Bugfix)
* 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 da7085e

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

providers/base/bin/suspend_trigger.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,19 +67,42 @@ 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(
76+
list_jobs_cmd, capture_output=True, text=True, check=True
77+
)
78+
if "No jobs running" in ret_list.stdout:
79+
break
80+
print(f"Suspend jobs ongoing, waiting... ({timeout} left)")
81+
time.sleep(1)
82+
timeout -= 1
83+
else:
84+
print("Timed out waiting for suspend jobs to finish")
85+
return 1
7286
print(
7387
"Running: {} to suspend the system".format(" ".join(suspend_cmd))
7488
)
75-
subprocess.check_call(suspend_cmd)
89+
ret_suspend = subprocess.run(suspend_cmd)
90+
if ret_suspend.returncode != 0:
91+
print(
92+
"Issues running:{} returned:{}".format(
93+
" ".join(suspend_cmd), ret_suspend.returncode
94+
)
95+
)
96+
return ret_suspend.returncode
7697

7798
# Clean up the FWTS log file from its default path.
7899
log_path = "/tmp/fwts_results.log"
79100
if os.path.exists(log_path):
80101
print("Removing {}...".format(log_path))
81102
os.remove(log_path)
82103

104+
return 0
105+
83106

84107
if __name__ == "__main__":
85108
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)