[Piglit] [PATCH] framework tests: fix binary_check utility bug
Dylan Baker
baker.dylan.c at gmail.com
Mon Aug 3 14:45:39 PDT 2015
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 at intel.com>
---
framework/tests/base_tests.py | 2 +-
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 a9e0e88..7b2920d 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 55d2b6e..58f8c2f 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):
--
2.5.0
More information about the Piglit
mailing list