Commit 22eac2e9 authored by Michal Majewski's avatar Michal Majewski Committed by Commit Bot

[test] Code cleanup in test suites.

Some refactor moved from
https://chromium-review.googlesource.com/c/v8/v8/+/798331.

Bug: v8:6917
Change-Id: I8cae6cfca7a0d7d8e234052c0ab0bfe252355e60
Reviewed-on: https://chromium-review.googlesource.com/819550
Commit-Queue: Michael Achenbach <machenbach@chromium.org>
Reviewed-by: 's avatarSergiy Byelozyorov <sergiyb@chromium.org>
Reviewed-by: 's avatarMichael Achenbach <machenbach@chromium.org>
Cr-Commit-Position: refs/heads/master@{#50020}
parent be3c2cdd
...@@ -55,8 +55,9 @@ class BenchmarksTestSuite(testsuite.TestSuite): ...@@ -55,8 +55,9 @@ class BenchmarksTestSuite(testsuite.TestSuite):
self.testroot = os.path.join(root, "data") self.testroot = os.path.join(root, "data")
def ListTests(self, context): def ListTests(self, context):
tests = [] def create_test(path):
for test in [ return testcase.TestCase(self, path)
tests = map(create_test, [
"kraken/ai-astar", "kraken/ai-astar",
"kraken/audio-beat-detection", "kraken/audio-beat-detection",
"kraken/audio-dft", "kraken/audio-dft",
...@@ -113,8 +114,7 @@ class BenchmarksTestSuite(testsuite.TestSuite): ...@@ -113,8 +114,7 @@ class BenchmarksTestSuite(testsuite.TestSuite):
"sunspider/string-fasta", "sunspider/string-fasta",
"sunspider/string-tagcloud", "sunspider/string-tagcloud",
"sunspider/string-unpack-code", "sunspider/string-unpack-code",
"sunspider/string-validate-input"]: "sunspider/string-validate-input"])
tests.append(testcase.TestCase(self, test))
return tests return tests
def GetParametersForTestCase(self, testcase, context): def GetParametersForTestCase(self, testcase, context):
......
...@@ -34,11 +34,15 @@ from testrunner.local import utils ...@@ -34,11 +34,15 @@ from testrunner.local import utils
from testrunner.objects import testcase from testrunner.objects import testcase
class CcTestSuite(testsuite.TestSuite): SHELL = 'cctest'
SHELL = 'cctest'
class CcTestSuite(testsuite.TestSuite):
def ListTests(self, context): def ListTests(self, context):
shell = os.path.abspath(os.path.join(context.shell_dir, self.SHELL)) def create_test(path):
return testcase.TestCase(self, path)
shell = os.path.abspath(os.path.join(context.shell_dir, SHELL))
if utils.IsWindows(): if utils.IsWindows():
shell += ".exe" shell += ".exe"
cmd = command.Command( cmd = command.Command(
...@@ -51,15 +55,12 @@ class CcTestSuite(testsuite.TestSuite): ...@@ -51,15 +55,12 @@ class CcTestSuite(testsuite.TestSuite):
print output.stdout print output.stdout
print output.stderr print output.stderr
return [] return []
tests = [] tests = map(create_test, output.stdout.strip().split())
for test_desc in output.stdout.strip().split():
test = testcase.TestCase(self, test_desc)
tests.append(test)
tests.sort(key=lambda t: t.path) tests.sort(key=lambda t: t.path)
return tests return tests
def GetShellForTestCase(self, testcase): def GetShellForTestCase(self, testcase):
return self.SHELL return SHELL
def GetParametersForTestCase(self, testcase, context): def GetParametersForTestCase(self, testcase, context):
return [testcase.path], testcase.flags + context.mode_flags, {} return [testcase.path], testcase.flags + context.mode_flags, {}
......
...@@ -55,7 +55,8 @@ class DebuggerTestSuite(testsuite.TestSuite): ...@@ -55,7 +55,8 @@ class DebuggerTestSuite(testsuite.TestSuite):
break break
files = [] files = []
files.append(os.path.normpath(os.path.join(self.root, "..", "mjsunit", "mjsunit.js"))) files.append(os.path.normpath(os.path.join(
self.root, "..", "mjsunit", "mjsunit.js")))
files.append(os.path.join(self.root, "test-api.js")) files.append(os.path.join(self.root, "test-api.js"))
files.extend([ os.path.normpath(os.path.join(self.root, '..', '..', f)) files.extend([ os.path.normpath(os.path.join(self.root, '..', '..', f))
for f in files_list ]) for f in files_list ])
......
...@@ -87,8 +87,8 @@ class MjsunitTestSuite(testsuite.TestSuite): ...@@ -87,8 +87,8 @@ class MjsunitTestSuite(testsuite.TestSuite):
["-e", "TEST_FILE_NAME=\"%s\"" % testfilename.replace("\\", "\\\\")] + ["-e", "TEST_FILE_NAME=\"%s\"" % testfilename.replace("\\", "\\\\")] +
files) files)
if not context.no_harness and not NO_HARNESS_PATTERN.search(source): if not context.no_harness:
files.append(os.path.join(self.root, "mjsunit.js")) files += self._get_mjsunit_files(source)
if MODULE_PATTERN.search(source): if MODULE_PATTERN.search(source):
files.append("--module") files.append("--module")
...@@ -109,6 +109,12 @@ class MjsunitTestSuite(testsuite.TestSuite): ...@@ -109,6 +109,12 @@ class MjsunitTestSuite(testsuite.TestSuite):
env[var] = value env[var] = value
return env return env
def _get_mjsunit_files(self, source):
if NO_HARNESS_PATTERN.search(source):
return []
else:
return [os.path.join(self.root, 'mjsunit.js')]
def GetSourceForTest(self, testcase): def GetSourceForTest(self, testcase):
filename = os.path.join(self.root, testcase.path + self.suffix()) filename = os.path.join(self.root, testcase.path + self.suffix())
with open(filename) as f: with open(filename) as f:
......
...@@ -9,18 +9,19 @@ from testrunner.local import testsuite ...@@ -9,18 +9,19 @@ from testrunner.local import testsuite
from testrunner.objects import testcase from testrunner.objects import testcase
class MkGrokdump(testsuite.TestSuite): SHELL = 'mkgrokdump'
SHELL = 'mkgrokdump'
class MkGrokdump(testsuite.TestSuite):
def __init__(self, name, root): def __init__(self, name, root):
super(MkGrokdump, self).__init__(name, root) super(MkGrokdump, self).__init__(name, root)
def ListTests(self, context): def ListTests(self, context):
test = testcase.TestCase(self, self.SHELL) test = testcase.TestCase(self, SHELL)
return [test] return [test]
def GetShellForTestCase(self, testcase): def GetShellForTestCase(self, testcase):
return self.SHELL return SHELL
def GetParametersForTestCase(self, testcase, context): def GetParametersForTestCase(self, testcase, context):
return [], [], {} return [], [], {}
......
...@@ -38,13 +38,13 @@ class PreparserTestSuite(testsuite.TestSuite): ...@@ -38,13 +38,13 @@ class PreparserTestSuite(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, extra_flags=[]): def Test(name, source, expectation, template_flags=[]):
source = source.replace("\n", " ") source = source.replace("\n", " ")
testname = os.path.join(filename, name) testname = os.path.join(filename, name)
flags = ["-e", source] flags = ["-e", source]
if expectation: if expectation:
flags += ["--throws"] flags += ["--throws"]
flags += extra_flags flags += template_flags
test = testcase.TestCase(self, testname, flags=flags) test = testcase.TestCase(self, testname, flags=flags)
result.append(test) result.append(test)
def Template(name, source): def Template(name, source):
......
...@@ -33,12 +33,12 @@ import shutil ...@@ -33,12 +33,12 @@ import shutil
import sys import sys
import time import time
from pool import Pool
from . import command from . import command
from . import perfdata from . import perfdata
from . import statusfile from . import statusfile
from . import utils from . import utils
from ..objects import output from ..objects import output
from pool import Pool
# Base dir of the v8 checkout. # Base dir of the v8 checkout.
......
...@@ -26,10 +26,10 @@ ...@@ -26,10 +26,10 @@
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import os
from os.path import exists from os.path import exists
from os.path import isdir from os.path import isdir
from os.path import join from os.path import join
import os
import platform import platform
import re import re
import subprocess import subprocess
......
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