summaryrefslogtreecommitdiff
path: root/bin
diff options
authorDaniel Manrique <roadmr@ubuntu.com>2015-04-17 13:56:29 -0400
committerDaniel Manrique <roadmr@ubuntu.com>2015-04-17 13:56:29 -0400
commit9c9ee36ff92ef1c746a500ca88618a3a5192466a (patch)
tree94d19d8f83f576f5d78c7095edaf56d8bf72cd2a /bin
parentd7bd4fafe1fb5c4fd99b04b25d1793f5f4330dcc (diff)
providers:checkbox: Minor fixes on sleep_time_test
Fixes: LP #1445593
Diffstat (limited to 'bin')
-rwxr-xr-xbin/sleep_time_check25
1 files changed, 16 insertions, 9 deletions
diff --git a/bin/sleep_time_check b/bin/sleep_time_check
index a0f53bf..d392769 100755
--- a/bin/sleep_time_check
+++ b/bin/sleep_time_check
@@ -26,13 +26,16 @@ def main():
'resume from a sleep state. (Default: '
'%(default)s)'))
args = parser.parse_args()
-
+
try:
- file = open(args.filename)
- lines = file.readlines()
- finally:
- file.close()
+ with open(args.filename) as file:
+ lines = file.readlines()
+ except IOError as e:
+ print(e)
+ return False
+ sleep_time = None
+ resume_time = None
# find our times
for line in lines:
if "Average time to sleep" in line:
@@ -40,17 +43,21 @@ def main():
elif "Average time to resume" in line:
resume_time = float(line.split(':')[1].strip())
+ if sleep_time is None or resume_time is None:
+ print("ERROR: One or more times was not reported correctly")
+ return False
+
print("Average time to enter sleep state: %s seconds" % sleep_time)
print("Average time to resume from sleep state: %s seconds" % resume_time)
-
+
failed = False
if sleep_time > args.sleep_threshold:
- print("System failed to suspend in less than %s seconds" %
- 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)
+ 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")