diff options
author | Dylan Baker <baker.dylan.c@gmail.com> | 2015-07-13 17:17:56 -0700 |
---|---|---|
committer | Dylan Baker <baker.dylan.c@gmail.com> | 2015-08-11 14:03:13 -0700 |
commit | d958bc8d0ebb669525f743e998dc71f9c48e8480 (patch) | |
tree | 22a504a7fbab5531566fa830d5160a8f97c2dc21 | |
parent | a5261b202be8eaee4110dc577ac23bd23c93560d (diff) |
framework tests: fix binary_check utility bug
This patch changes binary_check to work when a binary is present, but
doesn't work for some reason.
The example here is in the json content tests, where it looks for
glxinfo, but if X isn't running glxinfo provides no output, which will
cause a test to fail. This isn't useful, so instead of using the *nix
command 'which', call the command and allow an expected returncode to be
passed, if the returncode isn't that returncode, then skip.
Signed-off-by: Dylan Baker <dylanx.c.baker@intel.com>
-rw-r--r-- | framework/tests/base_tests.py | 2 | ||||
-rw-r--r-- | framework/tests/utils.py | 24 |
2 files changed, 20 insertions, 6 deletions
diff --git a/framework/tests/base_tests.py b/framework/tests/base_tests.py index a9e0e88c4..7b2920de9 100644 --- a/framework/tests/base_tests.py +++ b/framework/tests/base_tests.py @@ -57,7 +57,7 @@ def test_run_return_early(): def test_timeout(): """test.base.Test.run(): kills tests that exceed timeout when set""" - utils.binary_check('sleep') + utils.binary_check('sleep', 1) def helper(): if (test.result['returncode'] == 0): diff --git a/framework/tests/utils.py b/framework/tests/utils.py index 55d2b6ecf..58f8c2f27 100644 --- a/framework/tests/utils.py +++ b/framework/tests/utils.py @@ -32,6 +32,7 @@ import shutil import tempfile as tempfile_ import functools import subprocess +import errno from contextlib import contextmanager try: @@ -276,13 +277,26 @@ def privileged_test(func): return func -def binary_check(bin_): - """Check for the existance of a binary or raise SkipTest.""" +def binary_check(bin_, errno_=None): + """Check for the existance of a binary or raise SkipTest. + + If an errno_ is provided then a skip test will be raised unless the error + number provided is raised, or no error is raised. + + """ 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_)) + subprocess.check_call([bin_], stdout=null, stderr=null) + except OSError as e: + if e.errno == errno.ENOENT: + raise SkipTest('Binary {} not available'.format(bin_)) + except subprocess.CalledProcessError as e: + if errno_ is not None and e.returncode == errno_: + pass + else: + raise SkipTest( + 'Binary provided bad returncode of {} (wanted {})'.format( + e.returncode, errno_)) def platform_check(plat): |