Commit 11e264ca authored by Dylan Baker's avatar Dylan Baker Committed by Jordan Justen

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's avatarDylan Baker <baker.dylan.c@gmail.com>
Reviewed-by: Jordan Justen's avatarJordan Justen <jordan.l.justen@intel.com>
parent 8eaa1106
......@@ -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:
......
......@@ -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 = ''
......
......@@ -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]))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment