This adds the boilerplate code required to make multiple backends actually work, a backend option and a helper to facilitate getting the requested backend.
Signed-off-by: Dylan Baker <[email protected]> --- framework/programs/run.py | 23 ++++++++++++++--------- framework/results.py | 20 ++++++++++++++++++-- framework/tests/results_tests.py | 20 ++++++++++++++++++-- 3 files changed, 50 insertions(+), 13 deletions(-) diff --git a/framework/programs/run.py b/framework/programs/run.py index 8493611..8b7045d 100644 --- a/framework/programs/run.py +++ b/framework/programs/run.py @@ -108,6 +108,10 @@ def _run_parser(input_): metavar="<regex>", help="Exclude matching tests " "(can be used more than once)") + parser.add_argument('-b', '--backend', + default='json', + choices=framework.results.BACKENDS, + help='select a results backend to use') conc_parser = parser.add_mutually_exclusive_group() conc_parser.add_argument('-c', '--all-concurrent', action="store_const", @@ -219,9 +223,8 @@ def run(input_): options['env'] = core.collect_system_info() # Begin json. - result_filepath = path.join(args.results_path, 'results.json') - backend = framework.results.JSONWriter( - result_filepath, + backend = framework.results.get_backend(args.backend)( + args.results_path, options, file_fsync=opts.sync) @@ -239,7 +242,7 @@ def run(input_): backend.finalize({'time_elapsed': results.time_elapsed}) print('Thank you for running Piglit!\n' - 'Results have been written to ' + result_filepath) + 'Results have been written to ' + args.results_path) def resume(input_): @@ -270,10 +273,12 @@ def resume(input_): opts.env['PIGLIT_PLATFORM'] = results.options['platform'] results.options['env'] = core.collect_system_info() - results_path = path.join(args.results_path, 'results.json') - backend = framework.results.JSONWriter(results_path, - results.options, - file_fsync=opts.sync) + + # Resume only works with the JSON backend + backend = framework.results.get_backend('json')( + args.results_path, + results.options, + file_fsync=opts.sync) for key, value in results.tests.iteritems(): backend.write_test(key, value) @@ -290,4 +295,4 @@ def resume(input_): backend.finalize() print("Thank you for running Piglit!\n" - "Results have ben wrriten to {0}".format(results_path)) + "Results have ben wrriten to {0}".format(args.results_path)) diff --git a/framework/results.py b/framework/results.py index c3aac9f..fcdd154 100644 --- a/framework/results.py +++ b/framework/results.py @@ -37,10 +37,14 @@ import framework.status as status __all__ = [ 'TestrunResult', 'TestResult', - 'JSONWriter', 'load_results', + 'get_backend', + 'BACKENDS', ] +# A list of available backends +BACKENDS = ['json'] + # The current version of the JSON results CURRENT_JSON_VERSION = 1 @@ -178,7 +182,7 @@ class JSONWriter(Backend): _LOCK = threading.RLock() def __init__(self, f, metadata, file_fsync=False): - self.file = open(f, 'w') + self.file = open(os.path.join(f, 'results.json'), 'w') self.fsync = file_fsync self.__indent_level = 0 self.__inhibit_next_indent = False @@ -579,6 +583,18 @@ def update_results(results, filepath): return results +def get_backend(backend): + """ Returns a BackendInstance based on the string passed """ + backends = { + 'json': JSONWriter, + } + + # Be sure that we're exporting the same list of backends that we actually + # have available + assert backends.keys() == BACKENDS + return backends[backend] + + def _update_zero_to_one(results): """ Update version zero results to version 1 results diff --git a/framework/tests/results_tests.py b/framework/tests/results_tests.py index 12b6e80..9f364fa 100644 --- a/framework/tests/results_tests.py +++ b/framework/tests/results_tests.py @@ -68,8 +68,8 @@ def test_initialize_jsonwriter(): arguments """ - with utils.with_tempfile('') as tfile: - func = results.JSONWriter(tfile, BACKEND_INITIAL_META) + with utils.tempdir() as tdir: + func = results.JSONWriter(tdir, BACKEND_INITIAL_META) assert isinstance(func, results.JSONWriter) @@ -165,3 +165,19 @@ def test_update_results_old(): res = results.update_results(base, f.name) nt.assert_equal(res.results_version, results.CURRENT_JSON_VERSION) + + [email protected]_generator +def test_get_backend(): + """ Generate tests to get various backends """ + # We use a hand generated list here to ensure that we are getting what we + # expect + backends = { + 'json': results.JSONWriter, + } + + check = lambda n, i: nt.assert_is(results.get_backend(n), i) + + for name, inst in backends.iteritems(): + check.description = 'get_backend({0}) returns {0} backend'.format(name) + yield check, name, inst -- 2.1.0 _______________________________________________ Piglit mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/piglit
