Currently the timeout tests rely on /usr/bin/sleep and /usr/bin/true. This is very fragile, since on my (Gentoo) system true is in /bin. The better solution is to rely on either a shell built-in or to just find the binary in path.
This of course still has some fragility, so this patch also introduces a new utility function, binary_check. This function looks for a command using which (not window safe of course, but most of the unit tests aren't) or it raises a SkipTest. Signed-off-by: Dylan Baker <[email protected]> --- framework/tests/exectest_test.py | 8 ++++++-- framework/tests/utils.py | 11 +++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/framework/tests/exectest_test.py b/framework/tests/exectest_test.py index 3610093..831e29b 100644 --- a/framework/tests/exectest_test.py +++ b/framework/tests/exectest_test.py @@ -22,6 +22,7 @@ import nose.tools as nt from framework.exectest import PiglitTest, Test +import framework.tests.utils as utils # Helpers @@ -58,25 +59,28 @@ def test_run_return_early(): def test_timeout(): """ Test that Test.timeout works correctly """ + utils.binary_check('sleep') def helper(): if (test.result['returncode'] == 0): test.result['result'] = "pass" - test = TestTest("/usr/bin/sleep 60") + test = TestTest("sleep 60") test.test_interpret_result = helper test.timeout = 1 test.run() assert test.result['result'] == 'timeout' + def test_timeout_pass(): """ Test that the correct result is returned if a test does not timeout """ + utils.binary_check('true') def helper(): if (test.result['returncode'] == 0): test.result['result'] = "pass" - test = TestTest("/usr/bin/true") + test = TestTest("true") test.test_interpret_result = helper test.timeout = 1 test.run() diff --git a/framework/tests/utils.py b/framework/tests/utils.py index 2694fab..3b13a1f 100644 --- a/framework/tests/utils.py +++ b/framework/tests/utils.py @@ -29,11 +29,13 @@ import os import shutil import tempfile import functools +import subprocess from contextlib import contextmanager try: import simplejson as json except ImportError: import json +from nose.plugins.skip import SkipTest import nose.tools as nt import framework.results @@ -252,3 +254,12 @@ class StaticDirectory(object): def teardown_class(cls): """ Remove the temporary directory """ shutil.rmtree(cls.tdir) + + +def binary_check(bin_): + """Check for the existance of a binary or raise SkipTest.""" + with open(os.devnull, 'w') as null: + try: + subprocess.check_call(['which', bin_], stdout=null, stderr=null) + except subprocess.CalledProcessError: + raise SkipTest('Binary {} not available'.format(bin_)) -- 2.1.2 _______________________________________________ Piglit mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/piglit
