Commit c8102945 authored by Michal Majewski's avatar Michal Majewski Committed by Commit Bot

[test] Code cleanup in testcfg.py

- All testcase/testsuite/variant generator subclasses renamed to
  just TestCase/TestSuite/VariantGenerator since they're private
  implementation.
- All `testcase` variables renamed to `test` to not conflict with
  a module name.
- No more two statements in the same line.
- Removed some unused testsuite methods.

Bug: v8:6917
Cq-Include-Trybots: master.tryserver.v8:v8_linux_noi18n_rel_ng
Change-Id: I7710f3419f738a5f9ddca73765dd2cad2e35b952
Reviewed-on: https://chromium-review.googlesource.com/823964Reviewed-by: 's avatarSergiy Byelozyorov <sergiyb@chromium.org>
Reviewed-by: 's avatarMichael Achenbach <machenbach@chromium.org>
Commit-Queue: Michał Majewski <majeski@google.com>
Cr-Commit-Position: refs/heads/master@{#50076}
parent 3b0049e3
...@@ -31,10 +31,10 @@ import shutil ...@@ -31,10 +31,10 @@ import shutil
from testrunner.local import statusfile from testrunner.local import statusfile
from testrunner.local import testsuite from testrunner.local import testsuite
from testrunner.objects.testcase import TestCase from testrunner.objects import testcase
class BenchmarksVariantGenerator(testsuite.VariantGenerator): class VariantGenerator(testsuite.VariantGenerator):
# Both --noopt and --stressopt are very slow. Add TF but without # Both --noopt and --stressopt are very slow. Add TF but without
# always opt to match the way the benchmarks are run for performance # always opt to match the way the benchmarks are run for performance
# testing. # testing.
...@@ -44,13 +44,13 @@ class BenchmarksVariantGenerator(testsuite.VariantGenerator): ...@@ -44,13 +44,13 @@ class BenchmarksVariantGenerator(testsuite.VariantGenerator):
return self.standard_variant return self.standard_variant
return self.fast_variants return self.fast_variants
def GetFlagSets(self, testcase, variant): def GetFlagSets(self, test, variant):
return testsuite.FAST_VARIANT_FLAGS[variant] return testsuite.FAST_VARIANT_FLAGS[variant]
class BenchmarksTestSuite(testsuite.TestSuite): class TestSuite(testsuite.TestSuite):
def __init__(self, name, root): def __init__(self, name, root):
super(BenchmarksTestSuite, self).__init__(name, root) super(TestSuite, self).__init__(name, root)
self.testroot = os.path.join(root, "data") self.testroot = os.path.join(root, "data")
def ListTests(self, context): def ListTests(self, context):
...@@ -116,13 +116,13 @@ class BenchmarksTestSuite(testsuite.TestSuite): ...@@ -116,13 +116,13 @@ class BenchmarksTestSuite(testsuite.TestSuite):
return tests return tests
def _test_class(self): def _test_class(self):
return BenchmarksTestCase return TestCase
def _VariantGeneratorFactory(self): def _VariantGeneratorFactory(self):
return BenchmarksVariantGenerator return VariantGenerator
class BenchmarksTestCase(TestCase): class TestCase(testcase.TestCase):
def _get_files_params(self, ctx): def _get_files_params(self, ctx):
path = self.path path = self.path
testroot = self.suite.testroot testroot = self.suite.testroot
...@@ -151,4 +151,4 @@ class BenchmarksTestCase(TestCase): ...@@ -151,4 +151,4 @@ class BenchmarksTestCase(TestCase):
def GetSuite(name, root): def GetSuite(name, root):
return BenchmarksTestSuite(name, root) return TestSuite(name, root)
...@@ -31,12 +31,12 @@ import shutil ...@@ -31,12 +31,12 @@ import shutil
from testrunner.local import command from testrunner.local import command
from testrunner.local import testsuite from testrunner.local import testsuite
from testrunner.local import utils from testrunner.local import utils
from testrunner.objects.testcase import TestCase from testrunner.objects import testcase
SHELL = 'cctest' SHELL = 'cctest'
class CcTestSuite(testsuite.TestSuite): class TestSuite(testsuite.TestSuite):
def ListTests(self, context): def ListTests(self, context):
shell = os.path.abspath(os.path.join(context.shell_dir, SHELL)) shell = os.path.abspath(os.path.join(context.shell_dir, SHELL))
if utils.IsWindows(): if utils.IsWindows():
...@@ -56,10 +56,10 @@ class CcTestSuite(testsuite.TestSuite): ...@@ -56,10 +56,10 @@ class CcTestSuite(testsuite.TestSuite):
return tests return tests
def _test_class(self): def _test_class(self):
return CcTestCase return TestCase
class CcTestCase(TestCase): class TestCase(testcase.TestCase):
def _get_shell(self): def _get_shell(self):
return SHELL return SHELL
...@@ -68,4 +68,4 @@ class CcTestCase(TestCase): ...@@ -68,4 +68,4 @@ class CcTestCase(TestCase):
def GetSuite(name, root): def GetSuite(name, root):
return CcTestSuite(name, root) return TestSuite(name, root)
...@@ -6,12 +6,12 @@ import os ...@@ -6,12 +6,12 @@ import os
import re import re
from testrunner.local import testsuite from testrunner.local import testsuite
from testrunner.objects.testcase import TestCase from testrunner.objects import testcase
FILES_PATTERN = re.compile(r"//\s+Files:(.*)") FILES_PATTERN = re.compile(r"//\s+Files:(.*)")
MODULE_PATTERN = re.compile(r"^// MODULE$", flags=re.MULTILINE) MODULE_PATTERN = re.compile(r"^// MODULE$", flags=re.MULTILINE)
class DebuggerTestSuite(testsuite.TestSuite): class TestSuite(testsuite.TestSuite):
def ListTests(self, context): def ListTests(self, context):
tests = [] tests = []
for dirname, dirs, files in os.walk(self.root): for dirname, dirs, files in os.walk(self.root):
...@@ -29,12 +29,12 @@ class DebuggerTestSuite(testsuite.TestSuite): ...@@ -29,12 +29,12 @@ class DebuggerTestSuite(testsuite.TestSuite):
return tests return tests
def _test_class(self): def _test_class(self):
return DebuggerTestCase return TestCase
class DebuggerTestCase(TestCase): class TestCase(testcase.TestCase):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(DebuggerTestCase, self).__init__(*args, **kwargs) super(TestCase, self).__init__(*args, **kwargs)
# precomputed # precomputed
self._source_files = None self._source_files = None
...@@ -46,7 +46,7 @@ class DebuggerTestCase(TestCase): ...@@ -46,7 +46,7 @@ class DebuggerTestCase(TestCase):
self._source_flags = self._parse_source_flags(source) self._source_flags = self._parse_source_flags(source)
def _copy(self): def _copy(self):
copy = super(DebuggerTestCase, self)._copy() copy = super(TestCase, self)._copy()
copy._source_files = self._source_files copy._source_files = self._source_files
copy._source_flags = self._source_flags copy._source_flags = self._source_flags
return copy return copy
...@@ -90,4 +90,4 @@ class DebuggerTestCase(TestCase): ...@@ -90,4 +90,4 @@ class DebuggerTestCase(TestCase):
def GetSuite(name, root): def GetSuite(name, root):
return DebuggerTestSuite(name, root) return TestSuite(name, root)
...@@ -5,10 +5,10 @@ ...@@ -5,10 +5,10 @@
import os import os
from testrunner.local import testsuite from testrunner.local import testsuite
from testrunner.objects.testcase import TestCase from testrunner.objects import testcase
class FuzzerVariantGenerator(testsuite.VariantGenerator): class VariantGenerator(testsuite.VariantGenerator):
# Only run the fuzzer with standard variant. # Only run the fuzzer with standard variant.
def FilterVariantsByTest(self, test): def FilterVariantsByTest(self, test):
return self.standard_variant return self.standard_variant
...@@ -17,7 +17,7 @@ class FuzzerVariantGenerator(testsuite.VariantGenerator): ...@@ -17,7 +17,7 @@ class FuzzerVariantGenerator(testsuite.VariantGenerator):
return testsuite.FAST_VARIANT_FLAGS[variant] return testsuite.FAST_VARIANT_FLAGS[variant]
class FuzzerTestSuite(testsuite.TestSuite): class TestSuite(testsuite.TestSuite):
SUB_TESTS = ( 'json', 'parser', 'regexp', 'wasm', 'wasm_async', SUB_TESTS = ( 'json', 'parser', 'regexp', 'wasm', 'wasm_async',
'wasm_call', 'wasm_code', 'wasm_compile', 'wasm_data_section', 'wasm_call', 'wasm_code', 'wasm_compile', 'wasm_data_section',
'wasm_function_sigs_section', 'wasm_globals_section', 'wasm_function_sigs_section', 'wasm_globals_section',
...@@ -26,7 +26,7 @@ class FuzzerTestSuite(testsuite.TestSuite): ...@@ -26,7 +26,7 @@ class FuzzerTestSuite(testsuite.TestSuite):
def ListTests(self, context): def ListTests(self, context):
tests = [] tests = []
for subtest in FuzzerTestSuite.SUB_TESTS: for subtest in TestSuite.SUB_TESTS:
for fname in os.listdir(os.path.join(self.root, subtest)): for fname in os.listdir(os.path.join(self.root, subtest)):
if not os.path.isfile(os.path.join(self.root, subtest, fname)): if not os.path.isfile(os.path.join(self.root, subtest, fname)):
continue continue
...@@ -36,13 +36,13 @@ class FuzzerTestSuite(testsuite.TestSuite): ...@@ -36,13 +36,13 @@ class FuzzerTestSuite(testsuite.TestSuite):
return tests return tests
def _test_class(self): def _test_class(self):
return FuzzerTestCase return TestCase
def _VariantGeneratorFactory(self): def _VariantGeneratorFactory(self):
return FuzzerVariantGenerator return VariantGenerator
class FuzzerTestCase(TestCase): class TestCase(testcase.TestCase):
def _get_files_params(self, ctx): def _get_files_params(self, ctx):
suite, name = self.path.split('/') suite, name = self.path.split('/')
return [os.path.join(self.suite.root, suite, name)] return [os.path.join(self.suite.root, suite, name)]
...@@ -62,4 +62,4 @@ class FuzzerTestCase(TestCase): ...@@ -62,4 +62,4 @@ class FuzzerTestCase(TestCase):
def GetSuite(name, root): def GetSuite(name, root):
return FuzzerTestSuite(name, root) return TestSuite(name, root)
...@@ -7,16 +7,17 @@ import os ...@@ -7,16 +7,17 @@ import os
from testrunner.local import testsuite from testrunner.local import testsuite
from testrunner.local import utils from testrunner.local import utils
from testrunner.objects.testcase import TestCase from testrunner.objects import testcase
PROTOCOL_TEST_JS = "protocol-test.js" PROTOCOL_TEST_JS = "protocol-test.js"
EXPECTED_SUFFIX = "-expected.txt" EXPECTED_SUFFIX = "-expected.txt"
RESOURCES_FOLDER = "resources" RESOURCES_FOLDER = "resources"
class InspectorProtocolTestSuite(testsuite.TestSuite): class TestSuite(testsuite.TestSuite):
def ListTests(self, context): def ListTests(self, context):
tests = [] tests = []
for dirname, dirs, files in os.walk(os.path.join(self.root), followlinks=True): for dirname, dirs, files in os.walk(
os.path.join(self.root), followlinks=True):
for dotted in [x for x in dirs if x.startswith('.')]: for dotted in [x for x in dirs if x.startswith('.')]:
dirs.remove(dotted) dirs.remove(dotted)
if dirname.endswith(os.path.sep + RESOURCES_FOLDER): if dirname.endswith(os.path.sep + RESOURCES_FOLDER):
...@@ -33,11 +34,12 @@ class InspectorProtocolTestSuite(testsuite.TestSuite): ...@@ -33,11 +34,12 @@ class InspectorProtocolTestSuite(testsuite.TestSuite):
return tests return tests
def _test_class(self): def _test_class(self):
return InspectorTestCase return TestCase
def _IgnoreLine(self, string): def _IgnoreLine(self, string):
"""Ignore empty lines, valgrind output and Android output.""" """Ignore empty lines, valgrind output and Android output."""
if not string: return True if not string:
return True
return (string.startswith("==") or string.startswith("**") or return (string.startswith("==") or string.startswith("**") or
string.startswith("ANDROID") or string.startswith("ANDROID") or
# FIXME(machenbach): The test driver shouldn't try to use slow # FIXME(machenbach): The test driver shouldn't try to use slow
...@@ -45,24 +47,26 @@ class InspectorProtocolTestSuite(testsuite.TestSuite): ...@@ -45,24 +47,26 @@ class InspectorProtocolTestSuite(testsuite.TestSuite):
string == "Warning: unknown flag --enable-slow-asserts." or string == "Warning: unknown flag --enable-slow-asserts." or
string == "Try --help for options") string == "Try --help for options")
def IsFailureOutput(self, testcase): def IsFailureOutput(self, test):
file_name = os.path.join(self.root, testcase.path) + EXPECTED_SUFFIX file_name = os.path.join(self.root, test.path) + EXPECTED_SUFFIX
with file(file_name, "r") as expected: with file(file_name, "r") as expected:
expected_lines = expected.readlines() expected_lines = expected.readlines()
def ExpIterator(): def ExpIterator():
for line in expected_lines: for line in expected_lines:
if not line.strip(): continue if not line.strip():
continue
yield line.strip() yield line.strip()
def ActIterator(lines): def ActIterator(lines):
for line in lines: for line in lines:
if self._IgnoreLine(line.strip()): continue if self._IgnoreLine(line.strip()):
continue
yield line.strip() yield line.strip()
def ActBlockIterator(): def ActBlockIterator():
"""Iterates over blocks of actual output lines.""" """Iterates over blocks of actual output lines."""
lines = testcase.output.stdout.splitlines() lines = test.output.stdout.splitlines()
start_index = 0 start_index = 0
found_eqeq = False found_eqeq = False
for index, line in enumerate(lines): for index, line in enumerate(lines):
...@@ -87,9 +91,9 @@ class InspectorProtocolTestSuite(testsuite.TestSuite): ...@@ -87,9 +91,9 @@ class InspectorProtocolTestSuite(testsuite.TestSuite):
return False return False
class InspectorTestCase(TestCase): class TestCase(testcase.TestCase):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(InspectorTestCase, self).__init__(*args, **kwargs) super(TestCase, self).__init__(*args, **kwargs)
# precomputed # precomputed
self._source_flags = None self._source_flags = None
...@@ -98,7 +102,7 @@ class InspectorTestCase(TestCase): ...@@ -98,7 +102,7 @@ class InspectorTestCase(TestCase):
self._source_flags = self._parse_source_flags() self._source_flags = self._parse_source_flags()
def _copy(self): def _copy(self):
copy = super(InspectorTestCase, self)._copy() copy = super(TestCase, self)._copy()
copy._source_flags = self._source_flags copy._source_flags = self._source_flags
return copy return copy
...@@ -119,4 +123,4 @@ class InspectorTestCase(TestCase): ...@@ -119,4 +123,4 @@ class InspectorTestCase(TestCase):
def GetSuite(name, root): def GetSuite(name, root):
return InspectorProtocolTestSuite(name, root) return TestSuite(name, root)
...@@ -28,9 +28,9 @@ ...@@ -28,9 +28,9 @@
import os import os
from testrunner.local import testsuite from testrunner.local import testsuite
from testrunner.objects.testcase import TestCase from testrunner.objects import testcase
class IntlTestSuite(testsuite.TestSuite): class TestSuite(testsuite.TestSuite):
def ListTests(self, context): def ListTests(self, context):
tests = [] tests = []
for dirname, dirs, files in os.walk(self.root): for dirname, dirs, files in os.walk(self.root):
...@@ -50,12 +50,12 @@ class IntlTestSuite(testsuite.TestSuite): ...@@ -50,12 +50,12 @@ class IntlTestSuite(testsuite.TestSuite):
return tests return tests
def _test_class(self): def _test_class(self):
return IntlTestCase return TestCase
class IntlTestCase(TestCase): class TestCase(testcase.TestCase):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(IntlTestCase, self).__init__(*args, **kwargs) super(TestCase, self).__init__(*args, **kwargs)
# precomputed # precomputed
self._source_flags = None self._source_flags = None
...@@ -64,7 +64,7 @@ class IntlTestCase(TestCase): ...@@ -64,7 +64,7 @@ class IntlTestCase(TestCase):
self._source_flags = self._parse_source_flags() self._source_flags = self._parse_source_flags()
def _copy(self): def _copy(self):
copy = super(IntlTestCase, self)._copy() copy = super(TestCase, self)._copy()
copy._source_flags = self._source_flags copy._source_flags = self._source_flags
return copy return copy
...@@ -92,4 +92,4 @@ class IntlTestCase(TestCase): ...@@ -92,4 +92,4 @@ class IntlTestCase(TestCase):
def GetSuite(name, root): def GetSuite(name, root):
return IntlTestSuite(name, root) return TestSuite(name, root)
...@@ -31,14 +31,14 @@ import re ...@@ -31,14 +31,14 @@ import re
from testrunner.local import testsuite from testrunner.local import testsuite
from testrunner.local import utils from testrunner.local import utils
from testrunner.objects.testcase import TestCase from testrunner.objects import testcase
INVALID_FLAGS = ["--enable-slow-asserts"] INVALID_FLAGS = ["--enable-slow-asserts"]
MODULE_PATTERN = re.compile(r"^// MODULE$", flags=re.MULTILINE) MODULE_PATTERN = re.compile(r"^// MODULE$", flags=re.MULTILINE)
class MessageTestSuite(testsuite.TestSuite): class TestSuite(testsuite.TestSuite):
def ListTests(self, context): def ListTests(self, context):
tests = [] tests = []
for dirname, dirs, files in os.walk(self.root): for dirname, dirs, files in os.walk(self.root):
...@@ -56,21 +56,24 @@ class MessageTestSuite(testsuite.TestSuite): ...@@ -56,21 +56,24 @@ class MessageTestSuite(testsuite.TestSuite):
return tests return tests
def _test_class(self): def _test_class(self):
return MessageTestCase return TestCase
def CreateVariantGenerator(self, variants): def CreateVariantGenerator(self, variants):
return super(MessageTestSuite, self).CreateVariantGenerator( return super(TestSuite, self).CreateVariantGenerator(
variants + ["preparser"]) variants + ["preparser"])
def _IgnoreLine(self, string): def _IgnoreLine(self, string):
"""Ignore empty lines, valgrind output, Android output.""" """Ignore empty lines, valgrind output, Android output."""
if not string: return True return (
if not string.strip(): return True not string or
return (string.startswith("==") or string.startswith("**") or not string.strip() or
string.startswith("ANDROID")) string.startswith("==") or
string.startswith("**") or
def _GetExpectedFail(self, testcase): string.startswith("ANDROID")
path = testcase.path )
def _GetExpectedFail(self, test):
path = test.path
while path: while path:
(head, tail) = os.path.split(path) (head, tail) = os.path.split(path)
if tail == "fail": if tail == "fail":
...@@ -78,11 +81,11 @@ class MessageTestSuite(testsuite.TestSuite): ...@@ -78,11 +81,11 @@ class MessageTestSuite(testsuite.TestSuite):
path = head path = head
return False return False
def IsFailureOutput(self, testcase): def IsFailureOutput(self, test):
output = testcase.output output = test.output
testpath = testcase.path testpath = test.path
expected_fail = self._GetExpectedFail(testcase) expected_fail = self._GetExpectedFail(test)
fail = testcase.output.exit_code != 0 fail = test.output.exit_code != 0
if expected_fail != fail: if expected_fail != fail:
return True return True
expected_path = os.path.join(self.root, testpath + ".out") expected_path = os.path.join(self.root, testpath + ".out")
...@@ -90,7 +93,8 @@ class MessageTestSuite(testsuite.TestSuite): ...@@ -90,7 +93,8 @@ class MessageTestSuite(testsuite.TestSuite):
# Can't use utils.ReadLinesFrom() here because it strips whitespace. # Can't use utils.ReadLinesFrom() here because it strips whitespace.
with open(expected_path) as f: with open(expected_path) as f:
for line in f: for line in f:
if line.startswith("#") or not line.strip(): continue if line.startswith("#") or not line.strip():
continue
expected_lines.append(line) expected_lines.append(line)
raw_lines = output.stdout.splitlines() raw_lines = output.stdout.splitlines()
actual_lines = [ s for s in raw_lines if not self._IgnoreLine(s) ] actual_lines = [ s for s in raw_lines if not self._IgnoreLine(s) ]
...@@ -107,13 +111,10 @@ class MessageTestSuite(testsuite.TestSuite): ...@@ -107,13 +111,10 @@ class MessageTestSuite(testsuite.TestSuite):
return True return True
return False return False
def StripOutputForTransmit(self, testcase):
pass
class MessageTestCase(TestCase): class TestCase(testcase.TestCase):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(MessageTestCase, self).__init__(*args, **kwargs) super(TestCase, self).__init__(*args, **kwargs)
# precomputed # precomputed
self._source_files = None self._source_files = None
...@@ -125,7 +126,7 @@ class MessageTestCase(TestCase): ...@@ -125,7 +126,7 @@ class MessageTestCase(TestCase):
self._source_flags = self._parse_source_flags(source) self._source_flags = self._parse_source_flags(source)
def _copy(self): def _copy(self):
copy = super(MessageTestCase, self)._copy() copy = super(TestCase, self)._copy()
copy._source_files = self._source_files copy._source_files = self._source_files
copy._source_flags = self._source_flags copy._source_flags = self._source_flags
return copy return copy
...@@ -138,7 +139,7 @@ class MessageTestCase(TestCase): ...@@ -138,7 +139,7 @@ class MessageTestCase(TestCase):
return files return files
def _get_cmd_params(self, ctx): def _get_cmd_params(self, ctx):
params = super(MessageTestCase, self)._get_cmd_params(ctx) params = super(TestCase, self)._get_cmd_params(ctx)
return [p for p in params if p not in INVALID_FLAGS] return [p for p in params if p not in INVALID_FLAGS]
def _get_files_params(self, ctx): def _get_files_params(self, ctx):
...@@ -151,4 +152,4 @@ class MessageTestCase(TestCase): ...@@ -151,4 +152,4 @@ class MessageTestCase(TestCase):
return os.path.join(self.suite.root, self.path + self._get_suffix()) return os.path.join(self.suite.root, self.path + self._get_suffix())
def GetSuite(name, root): def GetSuite(name, root):
return MessageTestSuite(name, root) return TestSuite(name, root)
...@@ -29,7 +29,7 @@ import os ...@@ -29,7 +29,7 @@ import os
import re import re
from testrunner.local import testsuite from testrunner.local import testsuite
from testrunner.objects.testcase import TestCase from testrunner.objects import testcase
FILES_PATTERN = re.compile(r"//\s+Files:(.*)") FILES_PATTERN = re.compile(r"//\s+Files:(.*)")
ENV_PATTERN = re.compile(r"//\s+Environment Variables:(.*)") ENV_PATTERN = re.compile(r"//\s+Environment Variables:(.*)")
...@@ -38,7 +38,7 @@ MODULE_PATTERN = re.compile(r"^// MODULE$", flags=re.MULTILINE) ...@@ -38,7 +38,7 @@ MODULE_PATTERN = re.compile(r"^// MODULE$", flags=re.MULTILINE)
NO_HARNESS_PATTERN = re.compile(r"^// NO HARNESS$", flags=re.MULTILINE) NO_HARNESS_PATTERN = re.compile(r"^// NO HARNESS$", flags=re.MULTILINE)
class MjsunitTestSuite(testsuite.TestSuite): class TestSuite(testsuite.TestSuite):
def ListTests(self, context): def ListTests(self, context):
tests = [] tests = []
for dirname, dirs, files in os.walk(self.root, followlinks=True): for dirname, dirs, files in os.walk(self.root, followlinks=True):
...@@ -56,12 +56,12 @@ class MjsunitTestSuite(testsuite.TestSuite): ...@@ -56,12 +56,12 @@ class MjsunitTestSuite(testsuite.TestSuite):
return tests return tests
def _test_class(self): def _test_class(self):
return MjsunitTestCase return TestCase
class MjsunitTestCase(TestCase): class TestCase(testcase.TestCase):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(MjsunitTestCase, self).__init__(*args, **kwargs) super(TestCase, self).__init__(*args, **kwargs)
# precomputed # precomputed
self._source_files = None self._source_files = None
...@@ -107,7 +107,7 @@ class MjsunitTestCase(TestCase): ...@@ -107,7 +107,7 @@ class MjsunitTestCase(TestCase):
self._env = self._parse_source_env(source) self._env = self._parse_source_env(source)
def _copy(self): def _copy(self):
copy = super(MjsunitTestCase, self)._copy() copy = super(TestCase, self)._copy()
copy._source_files = self._source_files copy._source_files = self._source_files
copy._source_flags = self._source_flags copy._source_flags = self._source_flags
copy._mjsunit_files = self._mjsunit_files copy._mjsunit_files = self._mjsunit_files
...@@ -145,4 +145,4 @@ class MjsunitTestCase(TestCase): ...@@ -145,4 +145,4 @@ class MjsunitTestCase(TestCase):
def GetSuite(name, root): def GetSuite(name, root):
return MjsunitTestSuite(name, root) return TestSuite(name, root)
...@@ -6,21 +6,21 @@ import os ...@@ -6,21 +6,21 @@ import os
import difflib import difflib
from testrunner.local import testsuite from testrunner.local import testsuite
from testrunner.objects.testcase import TestCase from testrunner.objects import testcase
SHELL = 'mkgrokdump' SHELL = 'mkgrokdump'
class MkGrokdump(testsuite.TestSuite): class TestSuite(testsuite.TestSuite):
def ListTests(self, context): def ListTests(self, context):
test = self._create_test(SHELL) test = self._create_test(SHELL)
return [test] return [test]
def _test_class(self): def _test_class(self):
return MkGrokTestCase return TestCase
def IsFailureOutput(self, testcase): def IsFailureOutput(self, test):
output = testcase.output output = test.output
v8_path = os.path.dirname(os.path.dirname(os.path.abspath(self.root))) v8_path = os.path.dirname(os.path.dirname(os.path.abspath(self.root)))
expected_path = os.path.join(v8_path, "tools", "v8heapconst.py") expected_path = os.path.join(v8_path, "tools", "v8heapconst.py")
with open(expected_path) as f: with open(expected_path) as f:
...@@ -41,7 +41,7 @@ class MkGrokdump(testsuite.TestSuite): ...@@ -41,7 +41,7 @@ class MkGrokdump(testsuite.TestSuite):
return False return False
class MkGrokTestCase(TestCase): class TestCase(testcase.TestCase):
def _get_variant_flags(self): def _get_variant_flags(self):
return [] return []
...@@ -56,4 +56,4 @@ class MkGrokTestCase(TestCase): ...@@ -56,4 +56,4 @@ class MkGrokTestCase(TestCase):
def GetSuite(name, root): def GetSuite(name, root):
return MkGrokdump(name, root) return TestSuite(name, root)
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
import os import os
from testrunner.local import testsuite from testrunner.local import testsuite
from testrunner.objects.testcase import TestCase from testrunner.objects import testcase
EXCLUDED = ["CVS", ".svn"] EXCLUDED = ["CVS", ".svn"]
...@@ -54,9 +54,9 @@ TEST_DIRS = """ ...@@ -54,9 +54,9 @@ TEST_DIRS = """
""".split() """.split()
class MozillaTestSuite(testsuite.TestSuite): class TestSuite(testsuite.TestSuite):
def __init__(self, name, root): def __init__(self, name, root):
super(MozillaTestSuite, self).__init__(name, root) super(TestSuite, self).__init__(name, root)
self.testroot = os.path.join(root, "data") self.testroot = os.path.join(root, "data")
def ListTests(self, context): def ListTests(self, context):
...@@ -81,18 +81,18 @@ class MozillaTestSuite(testsuite.TestSuite): ...@@ -81,18 +81,18 @@ class MozillaTestSuite(testsuite.TestSuite):
return tests return tests
def _test_class(self): def _test_class(self):
return MozillaTestCase return TestCase
def IsNegativeTest(self, testcase): def IsNegativeTest(self, test):
return testcase.path.endswith("-n") return test.path.endswith("-n")
def IsFailureOutput(self, testcase): def IsFailureOutput(self, test):
if testcase.output.exit_code != 0: if test.output.exit_code != 0:
return True return True
return "FAILED!" in testcase.output.stdout return "FAILED!" in test.output.stdout
class MozillaTestCase(TestCase): class TestCase(testcase.TestCase):
def _get_files_params(self, ctx): def _get_files_params(self, ctx):
files = [os.path.join(self.suite.root, "mozilla-shell-emulation.js")] files = [os.path.join(self.suite.root, "mozilla-shell-emulation.js")]
testfilename = self.path + ".js" testfilename = self.path + ".js"
...@@ -115,4 +115,4 @@ class MozillaTestCase(TestCase): ...@@ -115,4 +115,4 @@ class MozillaTestCase(TestCase):
def GetSuite(name, root): def GetSuite(name, root):
return MozillaTestSuite(name, root) return TestSuite(name, root)
...@@ -29,10 +29,10 @@ ...@@ -29,10 +29,10 @@
import os import os
from testrunner.local import testsuite from testrunner.local import testsuite
from testrunner.objects.testcase import TestCase from testrunner.objects import testcase
class PreparserTestSuite(testsuite.TestSuite): class TestSuite(testsuite.TestSuite):
def _ParsePythonTestTemplates(self, result, filename): def _ParsePythonTestTemplates(self, result, filename):
pathname = os.path.join(self.root, filename + ".pyt") pathname = os.path.join(self.root, filename + ".pyt")
def Test(name, source, expectation): def Test(name, source, expectation):
...@@ -66,19 +66,19 @@ class PreparserTestSuite(testsuite.TestSuite): ...@@ -66,19 +66,19 @@ class PreparserTestSuite(testsuite.TestSuite):
return result return result
def _create_test(self, path, source, template_flags): def _create_test(self, path, source, template_flags):
return super(PreparserTestSuite, self)._create_test( return super(TestSuite, self)._create_test(
path, source=source, template_flags=template_flags) path, source=source, template_flags=template_flags)
def _test_class(self): def _test_class(self):
return PreparserTestCase return TestCase
def _VariantGeneratorFactory(self): def _VariantGeneratorFactory(self):
return testsuite.StandardVariantGenerator return testsuite.StandardVariantGenerator
class PreparserTestCase(TestCase): class TestCase(testcase.TestCase):
def __init__(self, suite, path, name, source, template_flags): def __init__(self, suite, path, name, source, template_flags):
super(PreparserTestCase, self).__init__(suite, path, name) super(TestCase, self).__init__(suite, path, name)
self._source = source self._source = source
self._template_flags = template_flags self._template_flags = template_flags
...@@ -109,4 +109,4 @@ class PreparserTestCase(TestCase): ...@@ -109,4 +109,4 @@ class PreparserTestCase(TestCase):
def GetSuite(name, root): def GetSuite(name, root):
return PreparserTestSuite(name, root) return TestSuite(name, root)
...@@ -37,7 +37,7 @@ import tarfile ...@@ -37,7 +37,7 @@ import tarfile
from testrunner.local import statusfile from testrunner.local import statusfile
from testrunner.local import testsuite from testrunner.local import testsuite
from testrunner.local import utils from testrunner.local import utils
from testrunner.objects.testcase import TestCase from testrunner.objects import testcase
# TODO(littledan): move the flag mapping into the status file # TODO(littledan): move the flag mapping into the status file
FEATURE_FLAGS = { FEATURE_FLAGS = {
...@@ -102,7 +102,7 @@ FAST_VARIANTS = { ...@@ -102,7 +102,7 @@ FAST_VARIANTS = {
'both': FAST_VARIANT_FLAGS_BOTH, 'both': FAST_VARIANT_FLAGS_BOTH,
} }
class Test262VariantGenerator(testsuite.VariantGenerator): class VariantGenerator(testsuite.VariantGenerator):
def GetFlagSets(self, test, variant): def GetFlagSets(self, test, variant):
outcomes = test.suite.GetStatusFileOutcomes(test.name, test.variant) outcomes = test.suite.GetStatusFileOutcomes(test.name, test.variant)
if outcomes and statusfile.OnlyFastVariants(outcomes): if outcomes and statusfile.OnlyFastVariants(outcomes):
...@@ -118,12 +118,12 @@ class Test262VariantGenerator(testsuite.VariantGenerator): ...@@ -118,12 +118,12 @@ class Test262VariantGenerator(testsuite.VariantGenerator):
return variant_flags["both"][variant] return variant_flags["both"][variant]
class Test262TestSuite(testsuite.TestSuite): class TestSuite(testsuite.TestSuite):
# Match the (...) in '/path/to/v8/test/test262/subdir/test/(...).js' # Match the (...) in '/path/to/v8/test/test262/subdir/test/(...).js'
# In practice, subdir is data or local-tests # In practice, subdir is data or local-tests
def __init__(self, name, root): def __init__(self, name, root):
super(Test262TestSuite, self).__init__(name, root) super(TestSuite, self).__init__(name, root)
self.testroot = os.path.join(self.root, *TEST_262_SUITE_PATH) self.testroot = os.path.join(self.root, *TEST_262_SUITE_PATH)
self.harnesspath = os.path.join(self.root, *TEST_262_HARNESS_PATH) self.harnesspath = os.path.join(self.root, *TEST_262_HARNESS_PATH)
self.harness = [os.path.join(self.harnesspath, f) self.harness = [os.path.join(self.harnesspath, f)
...@@ -188,29 +188,29 @@ class Test262TestSuite(testsuite.TestSuite): ...@@ -188,29 +188,29 @@ class Test262TestSuite(testsuite.TestSuite):
case.test_record.get("features", []))) == 0] case.test_record.get("features", []))) == 0]
def _test_class(self): def _test_class(self):
return Test262TestCase return TestCase
def IsFailureOutput(self, testcase): def IsFailureOutput(self, test):
output = testcase.output output = test.output
test_record = testcase.test_record test_record = test.test_record
if output.exit_code != 0: if output.exit_code != 0:
return True return True
if ("negative" in test_record and if ("negative" in test_record and
"type" in test_record["negative"] and "type" in test_record["negative"] and
self._ParseException(output.stdout, testcase) != self._ParseException(output.stdout, test) !=
test_record["negative"]["type"]): test_record["negative"]["type"]):
return True return True
return "FAILED!" in output.stdout return "FAILED!" in output.stdout
def _ParseException(self, str, testcase): def _ParseException(self, string, test):
# somefile:somelinenumber: someerror[: sometext] # somefile:somelinenumber: someerror[: sometext]
# somefile might include an optional drive letter on windows e.g. "e:". # somefile might include an optional drive letter on windows e.g. "e:".
match = re.search( match = re.search(
'^(?:\w:)?[^:]*:[0-9]+: ([^: ]+?)($|: )', str, re.MULTILINE) '^(?:\w:)?[^:]*:[0-9]+: ([^: ]+?)($|: )', string, re.MULTILINE)
if match: if match:
return match.group(1).strip() return match.group(1).strip()
else: else:
print "Error parsing exception for %s" % testcase print "Error parsing exception for %s" % test
return None return None
def GetExpectedOutcomes(self, test): def GetExpectedOutcomes(self, test):
...@@ -218,15 +218,15 @@ class Test262TestSuite(testsuite.TestSuite): ...@@ -218,15 +218,15 @@ class Test262TestSuite(testsuite.TestSuite):
if (statusfile.FAIL_SLOPPY in outcomes and if (statusfile.FAIL_SLOPPY in outcomes and
'--use-strict' not in test.cmd.args): '--use-strict' not in test.cmd.args):
return [statusfile.FAIL] return [statusfile.FAIL]
return super(Test262TestSuite, self).GetExpectedOutcomes(test) return super(TestSuite, self).GetExpectedOutcomes(test)
def _VariantGeneratorFactory(self): def _VariantGeneratorFactory(self):
return Test262VariantGenerator return VariantGenerator
class Test262TestCase(TestCase): class TestCase(testcase.TestCase):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(Test262TestCase, self).__init__(*args, **kwargs) super(TestCase, self).__init__(*args, **kwargs)
# precomputed # precomputed
self.test_record = None self.test_record = None
...@@ -236,7 +236,7 @@ class Test262TestCase(TestCase): ...@@ -236,7 +236,7 @@ class Test262TestCase(TestCase):
self.test_record = self.suite.parse_test_record(source, self.path) self.test_record = self.suite.parse_test_record(source, self.path)
def _copy(self): def _copy(self):
copy = super(Test262TestCase, self)._copy() copy = super(TestCase, self)._copy()
copy.test_record = self.test_record copy.test_record = self.test_record
return copy return copy
...@@ -279,4 +279,4 @@ class Test262TestCase(TestCase): ...@@ -279,4 +279,4 @@ class Test262TestCase(TestCase):
def GetSuite(name, root): def GetSuite(name, root):
return Test262TestSuite(name, root) return TestSuite(name, root)
...@@ -6,11 +6,11 @@ import os ...@@ -6,11 +6,11 @@ import os
from testrunner.local import command from testrunner.local import command
from testrunner.local import utils from testrunner.local import utils
from testrunner.local.testsuite import TestSuite, StandardVariantGenerator from testrunner.local import testsuite
from testrunner.objects.testcase import TestCase from testrunner.objects import testcase
class GoogleTestSuite(TestSuite): class TestSuite(testsuite.TestSuite):
def ListTests(self, context): def ListTests(self, context):
shell = os.path.abspath(os.path.join(context.shell_dir, self.name)) shell = os.path.abspath(os.path.join(context.shell_dir, self.name))
if utils.IsWindows(): if utils.IsWindows():
...@@ -48,13 +48,13 @@ class GoogleTestSuite(TestSuite): ...@@ -48,13 +48,13 @@ class GoogleTestSuite(TestSuite):
return tests return tests
def _test_class(self): def _test_class(self):
return GoogleTestCase return TestCase
def _VariantGeneratorFactory(self): def _VariantGeneratorFactory(self):
return StandardVariantGenerator return testsuite.StandardVariantGenerator
class GoogleTestCase(TestCase): class TestCase(testcase.TestCase):
def _get_suite_flags(self, ctx): def _get_suite_flags(self, ctx):
return ( return (
["--gtest_filter=" + self.path] + ["--gtest_filter=" + self.path] +
...@@ -67,4 +67,4 @@ class GoogleTestCase(TestCase): ...@@ -67,4 +67,4 @@ class GoogleTestCase(TestCase):
def GetSuite(name, root): def GetSuite(name, root):
return GoogleTestSuite(name, root) return TestSuite(name, root)
...@@ -5,9 +5,9 @@ ...@@ -5,9 +5,9 @@
import os import os
from testrunner.local import testsuite from testrunner.local import testsuite
from testrunner.objects.testcase import TestCase from testrunner.objects import testcase
class WasmSpecTestSuite(testsuite.TestSuite): class TestSuite(testsuite.TestSuite):
def ListTests(self, context): def ListTests(self, context):
tests = [] tests = []
for dirname, dirs, files in os.walk(self.root): for dirname, dirs, files in os.walk(self.root):
...@@ -23,13 +23,13 @@ class WasmSpecTestSuite(testsuite.TestSuite): ...@@ -23,13 +23,13 @@ class WasmSpecTestSuite(testsuite.TestSuite):
return tests return tests
def _test_class(self): def _test_class(self):
return WasmSpecTestCase return TestCase
class WasmSpecTestCase(TestCase): class TestCase(testcase.TestCase):
def _get_files_params(self, ctx): def _get_files_params(self, ctx):
return [os.path.join(self.suite.root, self.path + self._get_suffix())] return [os.path.join(self.suite.root, self.path + self._get_suffix())]
def GetSuite(name, root): def GetSuite(name, root):
return WasmSpecTestSuite(name, root) return TestSuite(name, root)
...@@ -30,14 +30,14 @@ import os ...@@ -30,14 +30,14 @@ import os
import re import re
from testrunner.local import testsuite from testrunner.local import testsuite
from testrunner.objects.testcase import TestCase from testrunner.objects import testcase
FILES_PATTERN = re.compile(r"//\s+Files:(.*)") FILES_PATTERN = re.compile(r"//\s+Files:(.*)")
SELF_SCRIPT_PATTERN = re.compile(r"//\s+Env: TEST_FILE_NAME") SELF_SCRIPT_PATTERN = re.compile(r"//\s+Env: TEST_FILE_NAME")
# TODO (machenbach): Share commonalities with mjstest. # TODO (machenbach): Share commonalities with mjstest.
class WebkitTestSuite(testsuite.TestSuite): class TestSuite(testsuite.TestSuite):
def ListTests(self, context): def ListTests(self, context):
tests = [] tests = []
for dirname, dirs, files in os.walk(self.root): for dirname, dirs, files in os.walk(self.root):
...@@ -58,13 +58,14 @@ class WebkitTestSuite(testsuite.TestSuite): ...@@ -58,13 +58,14 @@ class WebkitTestSuite(testsuite.TestSuite):
return tests return tests
def _test_class(self): def _test_class(self):
return WebkitTestCase return TestCase
# TODO(machenbach): Share with test/message/testcfg.py # TODO(machenbach): Share with test/message/testcfg.py
def _IgnoreLine(self, string): def _IgnoreLine(self, string):
"""Ignore empty lines, valgrind output, Android output and trace """Ignore empty lines, valgrind output, Android output and trace
incremental marking output.""" incremental marking output."""
if not string: return True if not string:
return True
return (string.startswith("==") or string.startswith("**") or return (string.startswith("==") or string.startswith("**") or
string.startswith("ANDROID") or "[IncrementalMarking]" in string or string.startswith("ANDROID") or "[IncrementalMarking]" in string or
# FIXME(machenbach): The test driver shouldn't try to use slow # FIXME(machenbach): The test driver shouldn't try to use slow
...@@ -72,26 +73,28 @@ class WebkitTestSuite(testsuite.TestSuite): ...@@ -72,26 +73,28 @@ class WebkitTestSuite(testsuite.TestSuite):
string == "Warning: unknown flag --enable-slow-asserts." or string == "Warning: unknown flag --enable-slow-asserts." or
string == "Try --help for options") string == "Try --help for options")
def IsFailureOutput(self, testcase): def IsFailureOutput(self, test):
if super(WebkitTestSuite, self).IsFailureOutput(testcase): if super(TestSuite, self).IsFailureOutput(test):
return True return True
file_name = os.path.join(self.root, testcase.path) + "-expected.txt" file_name = os.path.join(self.root, test.path) + "-expected.txt"
with file(file_name, "r") as expected: with file(file_name, "r") as expected:
expected_lines = expected.readlines() expected_lines = expected.readlines()
def ExpIterator(): def ExpIterator():
for line in expected_lines: for line in expected_lines:
if line.startswith("#") or not line.strip(): continue if line.startswith("#") or not line.strip():
continue
yield line.strip() yield line.strip()
def ActIterator(lines): def ActIterator(lines):
for line in lines: for line in lines:
if self._IgnoreLine(line.strip()): continue if self._IgnoreLine(line.strip()):
continue
yield line.strip() yield line.strip()
def ActBlockIterator(): def ActBlockIterator():
"""Iterates over blocks of actual output lines.""" """Iterates over blocks of actual output lines."""
lines = testcase.output.stdout.splitlines() lines = test.output.stdout.splitlines()
start_index = 0 start_index = 0
found_eqeq = False found_eqeq = False
for index, line in enumerate(lines): for index, line in enumerate(lines):
...@@ -116,9 +119,9 @@ class WebkitTestSuite(testsuite.TestSuite): ...@@ -116,9 +119,9 @@ class WebkitTestSuite(testsuite.TestSuite):
return False return False
class WebkitTestCase(TestCase): class TestCase(testcase.TestCase):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(WebkitTestCase, self).__init__(*args, **kwargs) super(TestCase, self).__init__(*args, **kwargs)
# precomputed # precomputed
self._source_files = None self._source_files = None
...@@ -130,7 +133,7 @@ class WebkitTestCase(TestCase): ...@@ -130,7 +133,7 @@ class WebkitTestCase(TestCase):
self._source_flags = self._parse_source_flags(source) self._source_flags = self._parse_source_flags(source)
def _copy(self): def _copy(self):
copy = super(WebkitTestCase, self)._copy() copy = super(TestCase, self)._copy()
copy._source_files = self._source_files copy._source_files = self._source_files
copy._source_flags = self._source_flags copy._source_flags = self._source_flags
return copy return copy
...@@ -170,4 +173,4 @@ class WebkitTestCase(TestCase): ...@@ -170,4 +173,4 @@ class WebkitTestCase(TestCase):
def GetSuite(name, root): def GetSuite(name, root):
return WebkitTestSuite(name, root) return TestSuite(name, root)
...@@ -90,9 +90,6 @@ class TestSuite(object): ...@@ -90,9 +90,6 @@ class TestSuite(object):
self._outcomes_cache = dict() self._outcomes_cache = dict()
def suffix(self):
return ".js"
def status_file(self): def status_file(self):
return "%s/%s.status" % (self.root, self.name) return "%s/%s.status" % (self.root, self.name)
...@@ -311,17 +308,6 @@ class TestSuite(object): ...@@ -311,17 +308,6 @@ class TestSuite(object):
return (self.GetOutcome(testcase, ctx) return (self.GetOutcome(testcase, ctx)
not in self.GetExpectedOutcomes(testcase)) not in self.GetExpectedOutcomes(testcase))
def StripOutputForTransmit(self, testcase):
if not self.HasUnexpectedOutput(testcase):
testcase.output.stdout = ""
testcase.output.stderr = ""
def CalculateTotalDuration(self):
self.total_duration = 0.0
for t in self.tests:
self.total_duration += t.duration
return self.total_duration
def _create_test(self, path, **kwargs): def _create_test(self, path, **kwargs):
test = self._test_class()(self, path, self._path_to_name(path), **kwargs) test = self._test_class()(self, path, self._path_to_name(path), **kwargs)
test.precompute() test.precompute()
......
...@@ -32,6 +32,8 @@ import shlex ...@@ -32,6 +32,8 @@ import shlex
from ..local import command from ..local import command
from ..local import utils from ..local import utils
FLAGS_PATTERN = re.compile(r"//\s+Flags:(.*)")
class TestCase(object): class TestCase(object):
def __init__(self, suite, path, name): def __init__(self, suite, path, name):
...@@ -172,13 +174,9 @@ class TestCase(object): ...@@ -172,13 +174,9 @@ class TestCase(object):
) )
def _parse_source_flags(self, source=None): def _parse_source_flags(self, source=None):
PATTERN = re.compile(r"//\s+Flags:(.*)") source = source or self.get_source()
if not source:
source = self.get_source()
flags = [] flags = []
for match in re.findall(PATTERN, source): for match in re.findall(FLAGS_PATTERN, source):
flags += shlex.split(match.strip()) flags += shlex.split(match.strip())
return flags return flags
......
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