[Piglit] [PATCH 1/3] framework/core.py: Add a config parser

Tom Stellard tom at stellard.net
Wed Jan 22 10:19:27 PST 2014


From: Dylan Baker <baker.dylan.c at gmail.com>

The config parser will read options from a file called piglit.conf
in the root of piglit's source directory or from a file specified
by the -f option to piglit-run.py

Tom Stellard:
  - Added command-line option
---
 framework/core.py |  7 ++++++-
 piglit-run.py     | 13 +++++++++++++
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/framework/core.py b/framework/core.py
index 33946a7..6a25781 100644
--- a/framework/core.py
+++ b/framework/core.py
@@ -39,6 +39,8 @@ from threads import synchronized_self
 import multiprocessing
 import multiprocessing.dummy
 import importlib
+# TODO: ConfigParser is known as configparser in python3
+import ConfigParser
 try:
     import simplejson as json
 except ImportError:
@@ -46,7 +48,8 @@ except ImportError:
 
 import status
 
-__all__ = ['Environment',
+__all__ = ['PIGLIT_CONFIG',
+           'Environment',
            'checkDir',
            'loadTestProfile',
            'TestrunResult',
@@ -58,6 +61,8 @@ __all__ = ['Environment',
            'testBinDir']
 
 
+PIGLIT_CONFIG = ConfigParser.SafeConfigParser()
+
 class PiglitJSONEncoder(json.JSONEncoder):
     def default(self, o):
         if isinstance(o, status.Status):
diff --git a/piglit-run.py b/piglit-run.py
index cf19073..f9cca04 100755
--- a/piglit-run.py
+++ b/piglit-run.py
@@ -31,6 +31,7 @@ import traceback
 
 sys.path.append(path.dirname(path.realpath(sys.argv[0])))
 import framework.core as core
+from framework.core import PIGLIT_CONFIG
 from framework.threads import synchronized_self
 
 
@@ -72,6 +73,11 @@ def main():
     parser.add_argument("-p", "--platform",
                         choices=["glx", "x11_egl", "wayland", "gbm"],
                         help="Name of windows system passed to waffle")
+    parser.add_argument("-f", "--config",
+                        dest="config_file",
+                        type=argparse.FileType("r"),
+                        help="Optionally specify a piglit config file to use. "
+                             "Default is piglit.conf")
     parser.add_argument("--valgrind",
                         action="store_true",
                         help="Run tests in valgrind's memcheck")
@@ -93,6 +99,13 @@ def main():
     if args.platform:
         os.environ['PIGLIT_PLATFORM'] = args.platform
 
+    # Read the config file
+    if args.config_file:
+        PIGLIT_CONFIG.readfp(args.config_file)
+        args.config_file.close()
+    else:
+        PIGLIT_CONFIG.read(os.path.join(os.path.dirname(__file__), 'piglit.conf'))
+
     # Pass arguments into Environment
     env = core.Environment(concurrent=args.concurrency,
                            exclude_filter=args.exclude_tests,
-- 
1.8.1.4



More information about the Piglit mailing list