[Piglit] [PATCH] RFC: Example of my proposal
Dylan Baker
baker.dylan.c at gmail.com
Sat Feb 15 04:33:30 PST 2014
There are some things that need to be worked out still
---
framework/core.py | 15 ++++++++-------
framework/log.py | 41 ++++++++++++++++++++++-------------------
2 files changed, 30 insertions(+), 26 deletions(-)
diff --git a/framework/core.py b/framework/core.py
index ee39616..e4a18ea 100644
--- a/framework/core.py
+++ b/framework/core.py
@@ -435,12 +435,14 @@ class Test(object):
``spec/glsl-1.30/preprocessor/compiler/keywords/void.frag``.
'''
- log_current = log.get_current()
+ log_current = log.pre_log()
counts = {}
# Run the test
if env.execute:
try:
- log.log(env.verbose, log_current, path, "running")
+ if env.verbose:
+ log.log(log_current, path, "running")
+
time_start = time.time()
dmesg.update_dmesg()
self._test_hook_execute_run()
@@ -464,8 +466,7 @@ class Test(object):
result['traceback'] = \
"".join(traceback.format_tb(sys.exc_info()[2]))
- if env.verbose:
- log.log(env.verbose, log_current, path, result["result"])
+ log.log(log_current, path, result["result"])
if 'subtest' in result and len(result['subtest']) > 1:
for test in result['subtest']:
@@ -476,8 +477,8 @@ class Test(object):
counts[result['result']] = 1
json_writer.write_dict_item(path, result)
else:
- log.log(env.verbose, log_current, path, "noexec")
- log.mark_complete(log_current, counts)
+ log.log(log_current, path, "dry-run")
+ log.post_log(log_current, counts)
class Group(dict):
@@ -562,7 +563,7 @@ class TestProfile(object):
'''
self.prepare_test_list(env)
- log = Log(len(self.test_list))
+ log = Log(len(self.test_list), env.verbose)
def test(pair):
""" Function to call test.execute from .map
diff --git a/framework/log.py b/framework/log.py
index 880cff3..5b5a7af 100644
--- a/framework/log.py
+++ b/framework/log.py
@@ -31,7 +31,7 @@ class Log(object):
total -- The total number of tests to run.
"""
- def __init__(self, total):
+ def __init__(self, total, verbose):
self.__total = total
self.__complete = 1
self.__running = []
@@ -39,22 +39,29 @@ class Log(object):
self.__pad = len(str(self.__total))
self.__summary = {}
+ if verbose:
+ self.__output = "[{percent} {summary}] :: {result:>7} :: {name}\n"
+ else:
+ self.__output = "[{percent}] {running} {summary}\r"
+
def _summary(self):
+ """ Print a summary of test statuses """
return ", ".join("{0}: {1}".format(k, self.__summary[k])
for k in sorted(self.__summary))
def _running(self):
+ """ Print running tests """
return "Running Test(s): {}".format(
" ".join([str(x).zfill(self.__pad) for x in self.__running]))
def _percent(self):
- return "[{0}/{1}] {2}".format(
- str(self.__complete).zfill(self.__pad),
- str(self.__total).zfill(self.__pad),
- self._summary())
+ """ Print the percentage of tests completed in form <finsihed>/<total>
+ """
+ return "{0}/{1}".format(str(self.__complete).zfill(self.__pad),
+ str(self.__total).zfill(self.__pad))
@synchronized_self
- def mark_complete(self, value, counts):
+ def post_log(self, value, counts):
""" Used to mark a test as complete in the log
Arguments:
@@ -73,27 +80,23 @@ class Log(object):
self.__summary[k] = self.__summary.get(k, 0) + v
@synchronized_self
- def log(self, verbose, id, name, result):
+ def log(self, test_id, name, result):
""" Print to the screen
Works by moving the cursor back to the front of the line and printing
over it.
"""
- if verbose:
- sys.stdout.write("[{0}/{1}] :: {2:>7} :: {3}\n".format(
- str(id).zfill(self.__pad),
- str(self.__total).zfill(self.__pad),
- result,
- name))
- else:
- sys.stdout.write("{0} {1} \r".format(self._percent(), self._running()))
- # Need to flush explicitly, otherwise it all gets buffered without a
- # newline.
- sys.stdout.flush()
+ sys.stdout.write(self.__output.format(**{'percent': self._percent(),
+ 'running': self._running(),
+ 'summary': self._summary(),
+ 'name': name,
+ 'result': result}))
+
+ sys.stdout.flush()
@synchronized_self
- def get_current(self):
+ def pre_log(self):
""" Returns a new number to know what processes are running """
x = self.__generator.next()
self.__running.append(x)
--
1.8.5.4
More information about the Piglit
mailing list