diff options
author | Dylan Baker <baker.dylan.c@gmail.com> | 2013-03-08 11:46:44 -0800 |
---|---|---|
committer | Jordan Justen <jordan.l.justen@intel.com> | 2013-03-10 15:20:27 -0700 |
commit | 11e264ca913415d26c0dadd72e75c810691b1230 (patch) | |
tree | 4b479e752a8a399645eb52bbcecc998fd0df5199 | |
parent | 8eaa110624660a60c882e66ea95c004e2ea27ae2 (diff) |
Move re.compile for regex into Core
Move the re.compile into the core.Enivironment constructor, which
reduces code duplication. It also allows us to pass environment data on
initilization of the object, rather that having edit it's attributes
individually.
V2: - Does not remove deprecated options, only marks them as such
V3: - Fixes deperecated warning for tests from V2 always being triggered
Signed-off-by: Dylan Baker <baker.dylan.c@gmail.com>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
-rw-r--r-- | framework/core.py | 26 | ||||
-rwxr-xr-x | piglit-print-commands.py | 27 | ||||
-rwxr-xr-x | piglit-run.py | 60 |
3 files changed, 57 insertions, 56 deletions
diff --git a/framework/core.py b/framework/core.py index 645598f1..3856ddfd 100644 --- a/framework/core.py +++ b/framework/core.py @@ -371,14 +371,26 @@ class TestrunResult: ############################################################################# class Environment: - def __init__(self): - # If disabled, runs all tests serially from the main thread. - self.concurrent = True - self.execute = True - self.filter = [] + def __init__(self, concurrent=True, execute=True, include_filter=[], + exclude_filter=[], valgrind=False): + self.concurrent = concurrent + self.execute = execute + self.filter = [] self.exclude_filter = [] - self.exclude_tests = set() - self.valgrind = False + self.exclude_tests = set() + self.valgrind = valgrind + + """ + The filter lists that are read in should be a list of string objects, + however, the filters need to be a list or regex object. + + This code uses re.compile to rebuild the lists and set self.filter + """ + for each in include_filter: + self.filter.append(re.compile(each)) + for each in exclude_filter: + self.exclude_filter.append(re.compile(each)) + def run(self, command): try: diff --git a/piglit-print-commands.py b/piglit-print-commands.py index 2d8ed8b2..228ac84b 100755 --- a/piglit-print-commands.py +++ b/piglit-print-commands.py @@ -24,7 +24,6 @@ import argparse import os.path as path -import re import sys, os import time import traceback @@ -64,25 +63,25 @@ def main(): args = parser.parse_args() - env = core.Environment() - - # If --tests is called warn that it is deprecated + # Deprecated + # --include-tests is the standard going forward, but for backwards + # compatability merge args.tests into args.include_tests and drop + # duplicates if args.tests != []: - print "Warning: Option --tests is deprecated. Use --include-tests" - - # Append includes and excludes to env - for each in args.include_tests: - env.filter.append(re.compile(each)) - for each in args.tests: - env.filter.append(re.compile(each)) - for each in args.exclude_tests: - env.exclude_filter.append(re.compile(each)) + print "Warnings: Option --tests is deprecated, use --include-tests" + args.include_tests = list(set(args.include_tests + args.tests)) + + # Set the environment, pass in the included and excluded tests + env = core.Environment( + exclude_filter=args.exclude_tests, + include_filter=args.include_tests, + ) # Change to the piglit's path piglit_dir = path.dirname(path.realpath(sys.argv[0])) os.chdir(piglit_dir) - profile = core.loadTestProfile(args.testFile) + profile = core.loadTestProfile(args.testProfile) def getCommand(test): command = '' diff --git a/piglit-run.py b/piglit-run.py index e5e38226..6d6ec770 100755 --- a/piglit-run.py +++ b/piglit-run.py @@ -24,7 +24,6 @@ import argparse import os.path as path -import re import sys, os import time import traceback @@ -39,11 +38,8 @@ from framework.threads import synchronized_self ############################################################################# def main(): - env = core.Environment() - parser = argparse.ArgumentParser(sys.argv) - # Either require that a name for the test is passed or that # resume is requested excGroup1 = parser.add_mutually_exclusive_group() @@ -55,8 +51,10 @@ def main(): action = "store_true", help = "Resume an interupted test run") + # Setting the --dry-run flag is equivalent to env.execute=false parser.add_argument("-d", "--dry-run", - action = "store_true", + action = "store_false", + dest = "execute", help = "Do not execute the tests") parser.add_argument("-t", "--include-tests", default = [], @@ -81,7 +79,8 @@ def main(): # supplied, or it throws an error excGroup2 = parser.add_mutually_exclusive_group() excGroup2.add_argument("--no-concurrency", - action = "store_true", + action = "store_false", + dest = "concurrency", help = "Disable concurrent test runs") excGroup2.add_argument("-c", "--concurrent", action = "store", @@ -109,33 +108,26 @@ def main(): if args.platform is not None: os.environ['PIGLIT_PLATFORM'] = args.platform - # Set dry-run - if args.dry_run is True: - env.execute = False - - # Set valgrind - if args.valgrind is True: - env.valgrind = True - - # Turn concurency off if requested - # Deprecated + # Deprecated: + # If the deprecated -c, --concurrent flag is passed, override + # args.concurrency (which would otherwise be set by the --no-concurrency) + # flag and print a warning. if args.concurrent is not None: if (args.concurrent == '1' or args.concurrent == 'on'): - env.concurrent = True + args.concurrency = True print "Warning: Option -c, --concurrent is deprecated, " \ "concurrent test runs are on by default" elif (args.concurrent == '0' or args.concurrent == 'off'): - env.concurrent = False + args.concurrency = False print "Warning: Option -c, --concurrent is deprecated, " \ "use --no-concurrency for non-concurrent test runs" # Ne need for else, since argparse restricts the arguments allowed - # Not deprecated - elif args.no_concurrency is True: - env.concurrent = False - # If the deprecated tests option was passed print a warning if args.tests != []: + # This merges any options passed into the --tests option into the + # ones passed into -t or --tests-include and throws out duplicates + args.include_tests = list(set(args.include_tests + args.tests)) print "Warning: Option --tests is deprecated, use " \ "--include-tests instead" @@ -147,25 +139,23 @@ def main(): # Load settings from the old results JSON old_results = core.loadTestResults(resultsDir) profileFilename = old_results.options['profile'] - for value in old_results.options['filter']: - test_filter.append(value) - env.filter.append(re.compile(value)) - for value in old_results.options['exclude_filter']: - exclude_filter.append(value) - env.exclude_filter.append(re.compile(value)) + + # Changing the args to the old args allows us to set them + # all in one places down the way + args.exclude_tests = old_results.options['exclude_filter'] + args.include_tests = old_results.options['filter'] # Otherwise parse additional settings from the command line else: profileFilename = args.testProfile resultsDir = args.resultsPath - # Set the excluded and included tests regex - for each in args.include_tests: - env.filter.append(re.compile(each)) - for each in args.tests: - env.filter.append(re.compile(each)) - for each in args.exclude_tests: - env.exclude_filter.append(re.compile(each)) + # Pass arguments into Environment + env = core.Environment(concurrent=args.concurrency, + exclude_filter=args.exclude_tests, + include_filter=args.include_tests, + execute=args.execute, + valgrind=args.valgrind) # Change working directory to the root of the piglit directory piglit_dir = path.dirname(path.realpath(sys.argv[0])) |