Since Test is exclusively used as a parent for ExecTest, the two classes should be in the same module.
Signed-off-by: Dylan Baker <[email protected]> --- framework/core.py | 70 -------------------------------------- framework/exectest.py | 72 +++++++++++++++++++++++++++++++++++++++- framework/tests/core_tests.py | 2 +- framework/tests/exectest_test.py | 15 +++++++-- 4 files changed, 84 insertions(+), 75 deletions(-) diff --git a/framework/core.py b/framework/core.py index 5f5cf86..86ed993 100644 --- a/framework/core.py +++ b/framework/core.py @@ -29,8 +29,6 @@ import platform import re import subprocess import sys -import time -import traceback from cStringIO import StringIO import multiprocessing import multiprocessing.dummy @@ -55,7 +53,6 @@ __all__ = ['PIGLIT_CONFIG', 'TestResult', 'TestProfile', 'Group', - 'Test', 'testBinDir'] @@ -410,73 +407,6 @@ class Environment: return result -class Test(object): - def __init__(self, runConcurrent=False): - ''' - 'runConcurrent' controls whether this test will - execute it's work (i.e. __doRunWork) on the calling thread - (i.e. the main thread) or from the ConcurrentTestPool threads. - ''' - self.runConcurrent = runConcurrent - self.skip_test = False - - # This is a hook for doing some testing on execute right before - # self.run is called. - self._test_hook_execute_run = lambda: None - - def run(self): - raise NotImplementedError - - def execute(self, env, path, log, json_writer, dmesg): - ''' - Run the test. - - :path: - Fully qualified test name as a string. For example, - ``spec/glsl-1.30/preprocessor/compiler/keywords/void.frag``. - ''' - log_current = log.pre_log(path if env.verbose else None) - - # Run the test - if env.execute: - try: - time_start = time.time() - dmesg.update_dmesg() - self._test_hook_execute_run() - result = self.run(env) - result = dmesg.update_result(result) - time_end = time.time() - if 'time' not in result: - result['time'] = time_end - time_start - if 'result' not in result: - result['result'] = 'fail' - if not isinstance(result, TestResult): - result = TestResult(result) - result['result'] = 'warn' - result['note'] = 'Result not returned as an instance ' \ - 'of TestResult' - except: - result = TestResult() - result['result'] = 'fail' - result['exception'] = str(sys.exc_info()[0]) + \ - str(sys.exc_info()[1]) - result['traceback'] = \ - "".join(traceback.format_tb(sys.exc_info()[2])) - - log.log(path, result['result']) - log.post_log(log_current, result['result']) - - if 'subtest' in result and len(result['subtest']) > 1: - for test in result['subtest']: - result['result'] = result['subtest'][test] - json_writer.write_dict_item(os.path.join(path, test), result) - else: - json_writer.write_dict_item(path, result) - else: - log.log(path, 'dry-run') - log.post_log(log_current, 'dry-run') - - class Group(dict): pass diff --git a/framework/exectest.py b/framework/exectest.py index 4f88dbc..aef4197 100644 --- a/framework/exectest.py +++ b/framework/exectest.py @@ -24,8 +24,11 @@ import errno import os import subprocess import shlex +import time +import sys +import traceback -from .core import Test, testBinDir, TestResult +from .core import testBinDir, TestResult # Platform global variables @@ -35,6 +38,73 @@ else: PIGLIT_PLATFORM = '' +class Test(object): + def __init__(self, runConcurrent=False): + ''' + 'runConcurrent' controls whether this test will + execute it's work (i.e. __doRunWork) on the calling thread + (i.e. the main thread) or from the ConcurrentTestPool threads. + ''' + self.runConcurrent = runConcurrent + self.skip_test = False + + # This is a hook for doing some testing on execute right before + # self.run is called. + self._test_hook_execute_run = lambda: None + + def run(self): + raise NotImplementedError + + def execute(self, env, path, log, json_writer, dmesg): + ''' + Run the test. + + :path: + Fully qualified test name as a string. For example, + ``spec/glsl-1.30/preprocessor/compiler/keywords/void.frag``. + ''' + log_current = log.pre_log(path if env.verbose else None) + + # Run the test + if env.execute: + try: + time_start = time.time() + dmesg.update_dmesg() + self._test_hook_execute_run() + result = self.run(env) + result = dmesg.update_result(result) + time_end = time.time() + if 'time' not in result: + result['time'] = time_end - time_start + if 'result' not in result: + result['result'] = 'fail' + if not isinstance(result, TestResult): + result = TestResult(result) + result['result'] = 'warn' + result['note'] = 'Result not returned as an instance ' \ + 'of TestResult' + except: + result = TestResult() + result['result'] = 'fail' + result['exception'] = str(sys.exc_info()[0]) + \ + str(sys.exc_info()[1]) + result['traceback'] = \ + "".join(traceback.format_tb(sys.exc_info()[2])) + + log.log(path, result['result']) + log.post_log(log_current, result['result']) + + if 'subtest' in result and len(result['subtest']) > 1: + for test in result['subtest']: + result['result'] = result['subtest'][test] + json_writer.write_dict_item(os.path.join(path, test), result) + else: + json_writer.write_dict_item(path, result) + else: + log.log(path, 'dry-run') + log.post_log(log_current, 'dry-run') + + # ExecTest: A shared base class for tests that simply runs an executable. class ExecTest(Test): def __init__(self, command): diff --git a/framework/tests/core_tests.py b/framework/tests/core_tests.py index f63184e..4fa9296 100644 --- a/framework/tests/core_tests.py +++ b/framework/tests/core_tests.py @@ -49,7 +49,7 @@ def test_generate_initialize(): """ yieldable = check_initialize - for target in [core.TestProfile, core.Group, core.Test, core.Environment, + for target in [core.TestProfile, core.Group, core.Environment, core.TestrunResult, core.TestResult, core.PiglitJSONEncoder]: yieldable.description = "Test that {} initializes".format( diff --git a/framework/tests/exectest_test.py b/framework/tests/exectest_test.py index 6c22a07..064edcf 100644 --- a/framework/tests/exectest_test.py +++ b/framework/tests/exectest_test.py @@ -20,10 +20,19 @@ """ Tests for the exectest module """ -from framework.exectest import PlainExecTest +from framework.exectest import PlainExecTest, ExecTest, Test + + +def test_initialize_test(): + """ Test initializes """ + Test('/bin/true') + + +def test_initialize_exectest(): + """ ExecTest initializes """ + ExecTest('/bin/true') def test_initialize_plainexectest(): """ Test that PlainExecTest initializes correctly """ - test = PlainExecTest('/bin/true') - assert test + PlainExecTest('/bin/true') -- 1.9.1 _______________________________________________ Piglit mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/piglit
