summaryrefslogtreecommitdiff
path: root/bin
diff options
authorDaniel Manrique <roadmr@ubuntu.com>2014-09-26 14:26:51 -0400
committerDaniel Manrique <roadmr@ubuntu.com>2014-09-26 14:26:51 -0400
commitda82278330abfa0bca07bef2c188d1610dc5adf0 (patch)
tree8fe5e1841b2d42bab37a916e763db60e89db4c85 /bin
parent849e07e9c3983f95e8a06098eb6f5ef062e902d1 (diff)
providers:checkbox: Added visual progress indicator to fwts sleep/hibernate tests
The script will automatically use zenity or dialog, if available and suitable for the current environment. It will fall back to the old text-only behavior if no suitable progress indicators are found.
Diffstat (limited to 'bin')
-rwxr-xr-xbin/fwts_test53
1 files changed, 48 insertions, 5 deletions
diff --git a/bin/fwts_test b/bin/fwts_test
index 646c2df..d6c39fe 100755
--- a/bin/fwts_test
+++ b/bin/fwts_test
@@ -6,7 +6,8 @@ from time import time
from argparse import ArgumentParser, RawTextHelpFormatter, REMAINDER
from subprocess import Popen, PIPE
from syslog import *
-
+from distutils.spawn import find_executable
+import os
# These tests require user interaction and need either special handling
# or skipping altogether (right now, we skip them but they're kept here
@@ -137,6 +138,20 @@ def fix_sleep_args(args):
return new_args
+def detect_progress_indicator():
+ # Return a command suitable for piping progress information to its
+ # stdin (invoked via Popen), in list format.
+ # Return zenity if installed and DISPLAY (--auto-close)
+ # return dialog if installed and no DISPLAY (width height)
+ display = os.environ.get('DISPLAY')
+ if display and find_executable('zenity'):
+ return ["zenity", "--progress", "--text", "Progress", "--auto-close"]
+ if not display and find_executable('dialog'):
+ return ["dialog", "--gauge", "Progress", "20", "70"]
+ # Return None if no progress indicator is to be used
+ return None
+
+
def main():
description_text = 'Tests the system BIOS using the Firmware Test Suite'
epilog_text = ('To perform sleep testing, you will need at least some of '
@@ -308,6 +323,10 @@ def main():
if args.sleep:
iteration_results = {}
print('=' * 20 + ' Test Results ' + '=' * 20)
+ progress_indicator = None
+ if detect_progress_indicator():
+ progress_indicator = Popen(detect_progress_indicator(),
+ stdin=PIPE)
for iteration in range(0, iterations):
timestamp = int(time())
start_marker = 'CHECKBOX SLEEP TEST START %s' % timestamp
@@ -324,12 +343,36 @@ def main():
args.sleep_time,
args.resume_time)
iteration_results[iteration] = sleep_times
- print(' - Cycle %s: Status: %s Sleep Elapsed: %0.5f '
- 'Resume Elapsed: '
- ' %0.5f' % (iteration,
+ progress_tuple = (iteration,
iteration_results[iteration][0],
iteration_results[iteration][1],
- iteration_results[iteration][2]))
+ iteration_results[iteration][2])
+ progress_string = (' - Cycle %s: Status: %s '
+ 'Sleep Elapsed: %0.5f '
+ 'Resume Elapsed: '
+ ' %0.5f' % progress_tuple)
+ progress_pct = "{}".format(int(100 * iteration / iterations))
+ if "zenity" in detect_progress_indicator():
+ progress_indicator.stdin.write("# {}\n".format(
+ progress_string).encode('utf-8'))
+ progress_indicator.stdin.write("{}\n".format(
+ progress_pct).encode('utf-8'))
+ progress_indicator.stdin.flush()
+ elif "dialog" in detect_progress_indicator():
+ progress_indicator.stdin.write("XXX\n".encode('utf-8'))
+ progress_indicator.stdin.write(
+ progress_pct.encode('utf-8'))
+ progress_indicator.stdin.write(
+ "\nTest progress\n".encode('utf-8'))
+ progress_indicator.stdin.write(
+ progress_string.encode('utf-8'))
+ progress_indicator.stdin.write(
+ "\nXXX\n".encode('utf-8'))
+ progress_indicator.stdin.flush()
+ else:
+ print(progress_string)
+ progress_indicator.terminate()
+
if 's4' not in args.sleep:
average_times(iteration_results)
for run in iteration_results.keys():