[Piglit] [PATCH 1/2] framework: Add required option to deqp.get_option

Dylan Baker dylan at pnwbakers.com
Thu Jul 21 23:23:51 UTC 2016


Some options in deqp are essential, but we don't enforce that. Which
leads to the deqp profile being unable to get it's binary (for example)
and failing through until the framework excepts importing the suite.

This patch lays the ground-work for fixing that by adding a required
keyword argument, which when set to True causes a FatalError to be
raised if that option falls through to the default.

Signed-off-by: Dylan Baker <dylanx.c.baker at intel.com>
---
 framework/test/deqp.py  | 6 +++++-
 unittests/deqp_tests.py | 8 ++++++++
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/framework/test/deqp.py b/framework/test/deqp.py
index c75577a..4f9bf14 100644
--- a/framework/test/deqp.py
+++ b/framework/test/deqp.py
@@ -41,7 +41,7 @@ __all__ = [
 ]
 
 
-def get_option(env_varname, config_option, default=None):
+def get_option(env_varname, config_option, default=None, required=False):
     """Query the given environment variable and then piglit.conf for the option.
 
     Return the value of the default argument if opt is None.
@@ -53,6 +53,10 @@ def get_option(env_varname, config_option, default=None):
 
     opt = core.PIGLIT_CONFIG.safe_get(config_option[0], config_option[1])
 
+    if required and not opt:
+        raise exceptions.PiglitFatalError(
+            'Cannot get env "{}" or conf value "{}:{}"'.format(
+                env_varname, config_option[0], config_option[1]))
     return opt or default
 
 
diff --git a/unittests/deqp_tests.py b/unittests/deqp_tests.py
index 7c1bd86..e3cd5d5 100644
--- a/unittests/deqp_tests.py
+++ b/unittests/deqp_tests.py
@@ -95,6 +95,14 @@ def test_get_option_conf_no_option():
            None)
 
 
+ at mock.patch.dict('os.environ', {}, True)
+ at nt.raises(exceptions.PiglitFatalError)
+def test_get_option_required():
+    """deqp.get_option: dies if a required option cannot be retrieved."""
+    deqp.get_option('NOT_REAL', ('fake', 'fake'), default='', required=True)
+
+
+
 class TestMakeProfile(object):
     """Test deqp.make_profile."""
     @classmethod
-- 
2.9.0



More information about the Piglit mailing list