From 4f4654a013de9d1f0c60eb3b96b8eebe42d5d6f6 Mon Sep 17 00:00:00 2001 From: Michal Majewski Date: Tue, 12 Dec 2017 13:29:36 +0100 Subject: [PATCH] [test] Deduplicate parsing source file flags. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bug: v8:6917 Cq-Include-Trybots: master.tryserver.v8:v8_linux_noi18n_rel_ng Change-Id: I12d62e28b8e22820d4358d0166fa5db5e09b8bc3 Reviewed-on: https://chromium-review.googlesource.com/819630 Commit-Queue: MichaƂ Majewski Reviewed-by: Sergiy Byelozyorov Reviewed-by: Michael Achenbach Cr-Commit-Position: refs/heads/master@{#50033} --- test/debugger/testcfg.py | 5 +---- test/inspector/testcfg.py | 8 +------- test/intl/testcfg.py | 8 +------- test/message/testcfg.py | 5 +---- test/mjsunit/testcfg.py | 5 +---- test/webkit/testcfg.py | 5 +---- tools/testrunner/local/testsuite.py | 16 ++++++++++++++-- 7 files changed, 20 insertions(+), 32 deletions(-) diff --git a/test/debugger/testcfg.py b/test/debugger/testcfg.py index ecedbb6760..045cb02b37 100644 --- a/test/debugger/testcfg.py +++ b/test/debugger/testcfg.py @@ -9,7 +9,6 @@ from testrunner.local import testsuite from testrunner.objects import testcase FILES_PATTERN = re.compile(r"//\s+Files:(.*)") -FLAGS_PATTERN = re.compile(r"//\s+Flags:(.*)") MODULE_PATTERN = re.compile(r"^// MODULE$", flags=re.MULTILINE) class DebuggerTestSuite(testsuite.TestSuite): @@ -40,9 +39,7 @@ class DebuggerTestSuite(testsuite.TestSuite): context.mode_flags ) source = self.GetSourceForTest(testcase) - flags_match = re.findall(FLAGS_PATTERN, source) - for match in flags_match: - flags += match.strip().split() + flags += self._parse_source_flags(testcase, source) files_list = [] # List of file names to append to command arguments. files_match = FILES_PATTERN.search(source); diff --git a/test/inspector/testcfg.py b/test/inspector/testcfg.py index f33384e1cf..f0d2f3d4bc 100644 --- a/test/inspector/testcfg.py +++ b/test/inspector/testcfg.py @@ -4,14 +4,11 @@ import itertools import os -import re -import shlex from testrunner.local import testsuite from testrunner.local import utils from testrunner.objects import testcase -FLAGS_PATTERN = re.compile(r"//\s+Flags:(.*)") PROTOCOL_TEST_JS = "protocol-test.js" EXPECTED_SUFFIX = "-expected.txt" RESOURCES_FOLDER = "resources" @@ -42,11 +39,8 @@ class InspectorProtocolTestSuite(testsuite.TestSuite): return 'inspector-test' def GetParametersForTestCase(self, testcase, context): - source = self.GetSourceForTest(testcase) flags = testcase.flags + context.mode_flags - flags_match = re.findall(FLAGS_PATTERN, source) - for match in flags_match: - flags += shlex.split(match.strip()) + flags += self._parse_source_flags(testcase) files = [ os.path.join(self.root, PROTOCOL_TEST_JS), os.path.join(self.root, testcase.path + self.suffix()), diff --git a/test/intl/testcfg.py b/test/intl/testcfg.py index 977dc11e2e..a2941aab5d 100644 --- a/test/intl/testcfg.py +++ b/test/intl/testcfg.py @@ -26,13 +26,10 @@ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. import os -import re from testrunner.local import testsuite from testrunner.objects import testcase -FLAGS_PATTERN = re.compile(r"//\s+Flags:(.*)") - class IntlTestSuite(testsuite.TestSuite): def __init__(self, name, root): @@ -57,11 +54,8 @@ class IntlTestSuite(testsuite.TestSuite): return tests def GetParametersForTestCase(self, testcase, context): - source = self.GetSourceForTest(testcase) flags = testcase.flags + ["--allow-natives-syntax"] + context.mode_flags - flags_match = re.findall(FLAGS_PATTERN, source) - for match in flags_match: - flags += match.strip().split() + flags += self._parse_source_flags(testcase) files = [] files.append(os.path.join(self.root, "assert.js")) diff --git a/test/message/testcfg.py b/test/message/testcfg.py index 28a1e641f6..f9ffe5d8c5 100644 --- a/test/message/testcfg.py +++ b/test/message/testcfg.py @@ -34,7 +34,6 @@ from testrunner.local import utils from testrunner.objects import testcase -FLAGS_PATTERN = re.compile(r"//\s+Flags:(.*)") INVALID_FLAGS = ["--enable-slow-asserts"] MODULE_PATTERN = re.compile(r"^// MODULE$", flags=re.MULTILINE) @@ -70,9 +69,7 @@ class MessageTestSuite(testsuite.TestSuite): files.append("--module") files.append(os.path.join(self.root, testcase.path + ".js")) flags = testcase.flags + context.mode_flags - flags_match = re.findall(FLAGS_PATTERN, source) - for match in flags_match: - flags += match.strip().split() + flags += self._parse_source_flags(testcase, source) flags = [x for x in flags if x not in INVALID_FLAGS] return files, flags, {} diff --git a/test/mjsunit/testcfg.py b/test/mjsunit/testcfg.py index aa1e0928d7..c8087c3b27 100644 --- a/test/mjsunit/testcfg.py +++ b/test/mjsunit/testcfg.py @@ -31,7 +31,6 @@ import re from testrunner.local import testsuite from testrunner.objects import testcase -FLAGS_PATTERN = re.compile(r"//\s+Flags:(.*)") FILES_PATTERN = re.compile(r"//\s+Files:(.*)") ENV_PATTERN = re.compile(r"//\s+Environment Variables:(.*)") SELF_SCRIPT_PATTERN = re.compile(r"//\s+Env: TEST_FILE_NAME") @@ -66,9 +65,7 @@ class MjsunitTestSuite(testsuite.TestSuite): flags = testcase.flags + context.mode_flags env = self._get_env(source) - flags_match = re.findall(FLAGS_PATTERN, source) - for match in flags_match: - flags += match.strip().split() + flags += self._parse_source_flags(testcase, source) files_list = [] # List of file names to append to command arguments. files_match = FILES_PATTERN.search(source); diff --git a/test/webkit/testcfg.py b/test/webkit/testcfg.py index 855a1327ba..95c3443461 100644 --- a/test/webkit/testcfg.py +++ b/test/webkit/testcfg.py @@ -32,7 +32,6 @@ import re from testrunner.local import testsuite from testrunner.objects import testcase -FLAGS_PATTERN = re.compile(r"//\s+Flags:(.*)") FILES_PATTERN = re.compile(r"//\s+Files:(.*)") SELF_SCRIPT_PATTERN = re.compile(r"//\s+Env: TEST_FILE_NAME") @@ -65,9 +64,7 @@ class WebkitTestSuite(testsuite.TestSuite): def GetParametersForTestCase(self, testcase, context): source = self.GetSourceForTest(testcase) flags = testcase.flags + context.mode_flags - flags_match = re.findall(FLAGS_PATTERN, source) - for match in flags_match: - flags += match.strip().split() + flags += self._parse_source_flags(testcase, source) files_list = [] # List of file names to append to command arguments. files_match = FILES_PATTERN.search(source); diff --git a/tools/testrunner/local/testsuite.py b/tools/testrunner/local/testsuite.py index 7662beeae5..c2d62f492a 100644 --- a/tools/testrunner/local/testsuite.py +++ b/tools/testrunner/local/testsuite.py @@ -29,17 +29,20 @@ import fnmatch import imp import os +import re +import shlex from . import command from . import statusfile from . import utils -from ..objects import testcase from variants import ALL_VARIANTS, ALL_VARIANT_FLAGS, FAST_VARIANT_FLAGS FAST_VARIANTS = set(["default", "turbofan"]) STANDARD_VARIANT = set(["default"]) +FLAGS_PATTERN = re.compile(r"//\s+Flags:(.*)") + class VariantGenerator(object): def __init__(self, suite, variants): @@ -69,7 +72,7 @@ class VariantGenerator(object): class TestSuite(object): @staticmethod - def LoadTestSuite(root): + def LoadTestSuite(root, global_init=True): name = root.split(os.path.sep)[-1] f = None try: @@ -345,6 +348,15 @@ class TestSuite(object): """Returns a tuple of (files, flags, env) for this test case.""" raise NotImplementedError + def _parse_source_flags(self, test, source=None): + if not source: + source = self.GetSourceForTest(test) + + flags = [] + for match in re.findall(FLAGS_PATTERN, source): + flags += shlex.split(match.strip()) + return flags + def GetSourceForTest(self, testcase): return "(no source available)"