diff options
author | Dylan Baker <dylanx.c.baker@intel.com> | 2014-10-03 16:02:04 -0700 |
---|---|---|
committer | Dylan Baker <dylanx.c.baker@intel.com> | 2014-10-14 14:16:52 -0700 |
commit | 85e382fe59104303394187afcdb7f0df4eb3e19e (patch) | |
tree | 60085cc4e715fa458154df71df69f20944a545a8 | |
parent | 122a4b4a3553b13737ee464ab61f90c6f85f940c (diff) | |
download | piglit-85e382fe59104303394187afcdb7f0df4eb3e19e.tar.gz |
framework tests: fix timeout tests
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 <dylanx.c.baker@intel.com>
-rw-r--r-- | framework/tests/exectest_test.py | 8 | ||||
-rw-r--r-- | 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 357925186..aaf86a388 100644 --- a/framework/tests/exectest_test.py +++ b/framework/tests/exectest_test.py @@ -25,6 +25,7 @@ import nose.tools as nt from framework.exectest import PiglitTest, Test from framework.log import LogManager from framework.dmesg import DummyDmesg +import framework.tests.utils as utils # Helpers @@ -61,25 +62,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 2694fabc8..3b13a1fee 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_)) |