[Piglit] [PATCH 1/2] framework/test/base.py: Move some logic from Test.run to Test.interpret_result
Dylan Baker
baker.dylan.c at gmail.com
Mon Aug 3 15:06:20 PDT 2015
This refactors the Test.run() method, making it simpler, and moving
result interpretation logic into the more natural interpret_result()
method.
This is purely a refactor, and doesn't change the code at all.
Signed-off-by: Dylan Baker <dylanx.c.baker at intel.com>
---
framework/test/base.py | 19 +++++++++----------
framework/test/piglit_test.py | 2 ++
framework/tests/base_tests.py | 9 ++++-----
framework/tests/piglit_test_tests.py | 3 +++
4 files changed, 18 insertions(+), 15 deletions(-)
diff --git a/framework/test/base.py b/framework/test/base.py
index b4ee4ad..4030a82 100644
--- a/framework/test/base.py
+++ b/framework/test/base.py
@@ -204,8 +204,16 @@ class Test(object):
@abc.abstractmethod
def interpret_result(self):
- """ Convert the raw output of the test into a form piglit understands
+ """Convert the raw output of the test into a form piglit understands.
"""
+ if _is_crash_returncode(self.result['returncode']):
+ # check if the process was terminated by the timeout
+ if self.timeout > 0 and self.__proc_timeout.join() > 0:
+ self.result['result'] = 'timeout'
+ else:
+ self.result['result'] = 'crash'
+ elif self.result['returncode'] != 0 and self.result['result'] == 'pass':
+ self.result['result'] = 'warn'
def run(self):
"""
@@ -242,15 +250,6 @@ class Test(object):
self.interpret_result()
- if _is_crash_returncode(self.result['returncode']):
- # check if the process was terminated by the timeout
- if self.timeout > 0 and self.__proc_timeout.join() > 0:
- self.result['result'] = 'timeout'
- else:
- self.result['result'] = 'crash'
- elif self.result['returncode'] != 0 and self.result['result'] == 'pass':
- self.result['result'] = 'warn'
-
if self.OPTS.valgrind:
# If the underlying test failed, simply report
# 'skip' for this valgrind test.
diff --git a/framework/test/piglit_test.py b/framework/test/piglit_test.py
index a4d3c8d..cf74f30 100644
--- a/framework/test/piglit_test.py
+++ b/framework/test/piglit_test.py
@@ -82,6 +82,8 @@ class PiglitBaseTest(Test):
self.result['out'] = '\n'.join(
s for s in outlines if not s.startswith('PIGLIT:'))
+ super(PiglitBaseTest, self).interpret_result()
+
class PiglitGLTest(WindowResizeMixin, PiglitBaseTest):
""" OpenGL specific Piglit test class
diff --git a/framework/tests/base_tests.py b/framework/tests/base_tests.py
index a9e0e88..e5b9f29 100644
--- a/framework/tests/base_tests.py
+++ b/framework/tests/base_tests.py
@@ -59,12 +59,11 @@ def test_timeout():
"""test.base.Test.run(): kills tests that exceed timeout when set"""
utils.binary_check('sleep')
- def helper():
- if (test.result['returncode'] == 0):
- test.result['result'] = "pass"
+ class _Test(Test):
+ def interpret_result(self):
+ super(_Test, self).interpret_result()
- test = TestTest(['sleep', '60'])
- test.test_interpret_result = helper
+ test = _Test(['sleep', '60'])
test.timeout = 1
test.run()
assert test.result['result'] == 'timeout'
diff --git a/framework/tests/piglit_test_tests.py b/framework/tests/piglit_test_tests.py
index c21f1fe..95386b2 100644
--- a/framework/tests/piglit_test_tests.py
+++ b/framework/tests/piglit_test_tests.py
@@ -46,6 +46,7 @@ def test_piglittest_interpret_result():
"""test.piglit_test.PiglitBaseTest.interpret_result(): works no subtests"""
test = PiglitBaseTest(['foo'])
test.result['out'] = 'PIGLIT: {"result": "pass"}\n'
+ test.result['returncode'] = 0
test.interpret_result()
assert test.result['result'] == 'pass'
@@ -55,6 +56,7 @@ def test_piglittest_interpret_result_subtest():
test = PiglitBaseTest(['foo'])
test.result['out'] = ('PIGLIT: {"result": "pass"}\n'
'PIGLIT: {"subtest": {"subtest": "pass"}}\n')
+ test.result['returncode'] = 0
test.interpret_result()
assert test.result['subtest']['subtest'] == 'pass'
@@ -67,6 +69,7 @@ def test_piglitest_no_clobber():
'PIGLIT: {"subtest": {"test1": "pass"}}\n'
'PIGLIT: {"subtest": {"test2": "pass"}}\n'
)
+ test.result['returncode'] = 0
test.interpret_result()
nt.assert_dict_equal(test.result['subtest'],
--
2.5.0
More information about the Piglit
mailing list