[Piglit] [PATCH 2/4] framework: Write each test result to the result file as the test completes
Chad Versace
chad at chad-versace.us
Tue Jul 19 12:36:41 PDT 2011
When a test run is interrupted, perhaps by a system crash, we often want
the test results. To accomplish this, Piglit must write each test result
to the result file as the test completes.
If the test run is interrupted, the result file will be corrupt. This is
corrected in a subsequent commit.
Signed-off-by: Chad Versace <chad at chad-versace.us>
---
framework/core.py | 21 ++++++++++++---------
piglit-run.py | 31 +++++++++++++------------------
2 files changed, 25 insertions(+), 27 deletions(-)
diff --git a/framework/core.py b/framework/core.py
index 921f19b..ca8fcfc 100644
--- a/framework/core.py
+++ b/framework/core.py
@@ -282,7 +282,7 @@ class TestrunResult:
# Serialize only the keys in serialized_keys.
keys = set(self.__dict__.keys()).intersection(self.serialized_keys)
raw_dict = dict([(k, self.__dict__[k]) for k in keys])
- json.dump(raw_dict, file, indent=4)
+ json.dump(raw_dict, file, indent=JSONWriter.INDENT)
def parseFile(self, file):
# If file contains the old, custom format, then raise
@@ -348,7 +348,7 @@ class Test:
def run(self):
raise NotImplementedError
- def doRun(self, env, path, testrun):
+ def doRun(self, env, path, json_writer):
'''
Schedule test to be run
@@ -361,13 +361,13 @@ class Test:
After this test has executed, the test's ``TestResult`` is
assigned to ``testrun.tests[path]``
'''
- args = (env, path, testrun)
+ args = (env, path, json_writer)
if self.runConcurrent:
ConcurrentTestPool().put(self.__doRunWork, args=args)
else:
self.__doRunWork(*args)
- def __doRunWork(self, env, path, testrun):
+ def __doRunWork(self, env, path, json_writer):
# Exclude tests that don't match the filter regexp
if len(env.filter) > 0:
if not True in map(lambda f: f.search(path) != None, env.filter):
@@ -404,7 +404,7 @@ class Test:
status(result['result'])
- testrun.tests[path] = result
+ json_writer.write_dict_item(path, result)
if Test.sleep:
time.sleep(Test.sleep)
else:
@@ -436,7 +436,7 @@ class Test:
class Group(dict):
- def doRun(self, env, path, testrun):
+ def doRun(self, env, path, json_writer):
'''
Schedule all tests in group for execution.
@@ -446,7 +446,7 @@ class Group(dict):
spath = sub
if len(path) > 0:
spath = path + '/' + spath
- self[sub].doRun(env, spath, testrun)
+ self[sub].doRun(env, spath, json_writer)
class TestProfile:
@@ -454,13 +454,16 @@ class TestProfile:
self.tests = Group()
self.sleep = 0
- def run(self, env, testrun):
+ def run(self, env, json_writer):
'''
Schedule all tests in profile for execution.
See ``Test.doRun``.
'''
- self.tests.doRun(env, '', testrun)
+ json_writer.write_dict_key('tests')
+ json_writer.open_dict()
+ self.tests.doRun(env, '', json_writer)
+ json_writer.close_dict()
ConcurrentTestPool().join()
def remove_test(self, test_path):
diff --git a/piglit-run.py b/piglit-run.py
index d5e85f8..0771ede 100755
--- a/piglit-run.py
+++ b/piglit-run.py
@@ -23,7 +23,6 @@
from getopt import getopt, GetoptError
-import json
import os.path as path
import re
import sys, os
@@ -132,31 +131,27 @@ def main():
else:
results.name = OptionName
- results.__dict__.update(env.collectData())
+ # Begin json.
+ result_filepath = os.path.join(resultsDir, 'main')
+ json_writer = core.JSONWriter(SyncFileWriter(result_filepath))
+ json_writer.open_dict()
+
+ json_writer.write_dict_item('name', results.name)
+ for (key, value) in env.collectData().items():
+ json_writer.write_dict_item(key, value)
profile = core.loadTestProfile(profileFilename)
time_start = time.time()
- try:
- profile.run(env, results)
- except Exception as e:
- if isinstance(e, KeyboardInterrupt):
- # When the user interrupts the test run, he may still
- # want the partial test results. So ignore
- # KeyboardInterruption and proceed to writing the
- # result files.
- pass
- else:
- traceback.print_exc()
- sys.exit(1)
+ profile.run(env, json_writer)
time_end = time.time()
results.time_elapsed = time_end - time_start
+ json_writer.write_dict_item('time_elapsed', results.time_elapsed)
- result_filepath = os.path.join(resultsDir, 'main')
- print("Writing results file...")
- with open(result_filepath, 'w') as f:
- results.write(f)
+ # End json.
+ json_writer.close_dict()
+ json_writer.file.close()
print
print 'Thank you for running Piglit!'
--
1.7.6
More information about the Piglit
mailing list