[Piglit] [PATCH 11/18] framework: Fix order of precedence for cmdline opts and env vars

Dylan Baker baker.dylan.c at gmail.com
Fri Jul 11 11:32:31 PDT 2014


From: Chad Versace <chad.versace at linux.intel.com>

Setup the environment for each test by taking  Environment variables
from the following sources, listed in order of increasing precedence:

  1. This process's current environment.
  2. Global test options. (Some of these are command line options to
     Piglit's runner script).
  3. Per-test environment variables set in all.py.

Piglit chooses this order because Unix tradition dictates that
command line options (2) override environment variables (1); and
Piglit considers environment variables set in all.py (3) to be test
requirements.

Pre-patch, the order was 2,1,3, which caused environment variables to
override command line options.

Some python changes made by Dylan Baker

Signed-off-by: Dylan Baker <baker.dylan.c at gmail.com>
Signed-off-by: Chad Versace <chad.versace at linux.intel.com>
---
 framework/exectest.py     | 24 +++++++++++++++++-------
 framework/programs/run.py | 11 +++++++----
 2 files changed, 24 insertions(+), 11 deletions(-)

diff --git a/framework/exectest.py b/framework/exectest.py
index 3a916db..5ffb94d 100644
--- a/framework/exectest.py
+++ b/framework/exectest.py
@@ -221,13 +221,23 @@ class Test(object):
         executable isn't found it sets the result to skip.
 
         """
-        # Set the environment for the tests. Use the default settings created
-        # in the Options constructor first, then use any user defined
-        # variables, finally, use any variables set for the test in the test
-        # profile
-        fullenv = self.OPTS.env.copy()
-        for key, value in itertools.chain(self.env.iteritems(),
-                                          os.environ.iteritems()):
+        # Setup the environment for the test. Environment variables are taken
+        # from the following sources, listed in order of increasing precedence:
+        #
+        #   1. This process's current environment.
+        #   2. Global test options. (Some of these are command line options to
+        #      Piglit's runner script).
+        #   3. Per-test environment variables set in all.py.
+        #
+        # Piglit chooses this order because Unix tradition dictates that
+        # command line options (2) override environment variables (1); and
+        # Piglit considers environment variables set in all.py (3) to be test
+        # requirements.
+        #
+        fullenv = dict()
+        for key, value in itertools.chain(os.environ.iteritems(),
+                                          self.OPTS.env.iteritems(),
+                                          self.env.iteritems()):
             fullenv[key] = str(value)
 
         try:
diff --git a/framework/programs/run.py b/framework/programs/run.py
index 0622063..b4031bb 100644
--- a/framework/programs/run.py
+++ b/framework/programs/run.py
@@ -73,6 +73,11 @@ def run(input_):
     parser.add_argument("-p", "--platform",
                         choices=["glx", "xegl", "x11_egl", "wayland", "gbm",
                                  "gl=>glx,gles=>xegl"],
+                        # If an explicit choice isn't made check the
+                        # environment, and if that fails select the glx/xegl
+                        # mixed profile
+                        default=os.environ.get("PIGLIT_PLATFORM",
+                                               "gl=>glx,gles=>xegl"),
                         help="Name of windows system passed to waffle")
     parser.add_argument("-f", "--config",
                         dest="config_file",
@@ -136,8 +141,7 @@ def run(input_):
                         verbose=args.verbose)
 
     # Set the platform to pass to waffle
-    if args.platform:
-        opts.env['PIGLIT_PLATFORM'] = args.platform
+    opts.env['PIGLIT_PLATFORM'] = args.platform
 
     # Change working directory to the root of the piglit directory
     piglit_dir = path.dirname(path.realpath(sys.argv[0]))
@@ -216,8 +220,7 @@ def resume(input_):
 
     _get_config(args.config_file)
 
-    if results.options.get('platform'):
-        opts.env['PIGLIT_PLATFORM'] = results.options['platform']
+    opts.env['PIGLIT_PLATFORM'] = results.options['platform']
 
     results_path = path.join(args.results_path, 'results.json')
     json_writer = framework.results.JSONWriter(open(results_path, 'w+'))
-- 
2.0.0



More information about the Piglit mailing list