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