/usr/lib/plainbox-provider-checkbox/bin/sleep_time_check is in plainbox-provider-checkbox 0.25-1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | #!/usr/bin/env python3
import sys
import argparse
from statistics import mean
def main():
parser = argparse.ArgumentParser()
parser.add_argument('filename',
action='store',
help='The output file from sleep tests to parse')
parser.add_argument('--s',
dest='sleep_threshold',
action='store',
type=float,
default=10.00,
help=('The max time a system should have taken to '
'enter a sleep state. (Default: %(default)s)'
))
parser.add_argument('--r',
action='store',
dest='resume_threshold',
type=float,
default=5.00,
help=('The max time a system should have taken to '
'resume from a sleep state. (Default: '
'%(default)s)'))
args = parser.parse_args()
try:
with open(args.filename) as file:
lines = file.readlines()
except IOError as e:
print(e)
return False
sleep_time = None
sleep_times = []
resume_time = None
resume_times = []
# find our times
for line in lines:
if "Average time to sleep" in line:
sleep_time = float(line.split(':')[1].strip())
sleep_times.append(sleep_time)
elif "Average time to resume" in line:
resume_time = float(line.split(':')[1].strip())
resume_times.append(resume_time)
if (sleep_time is None or resume_time is None) or \
(len(sleep_times) != len(resume_times)):
print("ERROR: One or more times was not reported correctly")
return False
print("Average time to enter sleep state: %.4f seconds" % mean(sleep_times))
print("Average time to resume from sleep state: %.4f seconds" % mean(resume_times))
failed = False
if sleep_time > args.sleep_threshold:
print("System failed to suspend in less than %s seconds" %
args.sleep_threshold)
failed = True
if resume_time > args.resume_threshold:
print("System failed to resume in less than %s seconds" %
args.resume_threshold)
failed = True
if sleep_time <= 0.00 or resume_time <= 0.00:
print("ERROR: One or more times was not reported correctly")
failed = True
return failed
if __name__ == "__main__":
sys.exit(main())
|