2012-09-24 09:38:46 +00:00
|
|
|
# Copyright 2012 the V8 project authors. All rights reserved.
|
|
|
|
# Redistribution and use in source and binary forms, with or without
|
|
|
|
# modification, are permitted provided that the following conditions are
|
|
|
|
# met:
|
|
|
|
#
|
|
|
|
# * Redistributions of source code must retain the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer.
|
|
|
|
# * Redistributions in binary form must reproduce the above
|
|
|
|
# copyright notice, this list of conditions and the following
|
|
|
|
# disclaimer in the documentation and/or other materials provided
|
|
|
|
# with the distribution.
|
|
|
|
# * Neither the name of Google Inc. nor the names of its
|
|
|
|
# contributors may be used to endorse or promote products derived
|
|
|
|
# from this software without specific prior written permission.
|
|
|
|
#
|
|
|
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
|
|
|
|
import imp
|
|
|
|
import os
|
|
|
|
|
2014-09-02 11:18:47 +00:00
|
|
|
from . import commands
|
2012-09-24 09:38:46 +00:00
|
|
|
from . import statusfile
|
2013-01-18 14:55:23 +00:00
|
|
|
from . import utils
|
2014-09-02 12:46:27 +00:00
|
|
|
from ..objects import testcase
|
2016-08-04 14:41:09 +00:00
|
|
|
from variants import ALL_VARIANTS, ALL_VARIANT_FLAGS, FAST_VARIANT_FLAGS
|
|
|
|
|
2012-09-24 09:38:46 +00:00
|
|
|
|
2015-07-29 07:14:15 +00:00
|
|
|
FAST_VARIANTS = set(["default", "turbofan"])
|
|
|
|
STANDARD_VARIANT = set(["default"])
|
2016-05-02 09:22:35 +00:00
|
|
|
IGNITION_VARIANT = set(["ignition"])
|
2015-07-29 07:14:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
class VariantGenerator(object):
|
|
|
|
def __init__(self, suite, variants):
|
|
|
|
self.suite = suite
|
|
|
|
self.all_variants = ALL_VARIANTS & variants
|
|
|
|
self.fast_variants = FAST_VARIANTS & variants
|
|
|
|
self.standard_variant = STANDARD_VARIANT & variants
|
|
|
|
|
|
|
|
def FilterVariantsByTest(self, testcase):
|
2016-05-02 09:22:35 +00:00
|
|
|
result = self.all_variants
|
|
|
|
if testcase.outcomes:
|
|
|
|
if statusfile.OnlyStandardVariant(testcase.outcomes):
|
|
|
|
return self.standard_variant
|
|
|
|
if statusfile.OnlyFastVariants(testcase.outcomes):
|
|
|
|
result = self.fast_variants
|
|
|
|
if statusfile.NoIgnitionVariant(testcase.outcomes):
|
|
|
|
result = result - IGNITION_VARIANT
|
|
|
|
return result
|
2015-07-29 07:14:15 +00:00
|
|
|
|
|
|
|
def GetFlagSets(self, testcase, variant):
|
|
|
|
if testcase.outcomes and statusfile.OnlyFastVariants(testcase.outcomes):
|
|
|
|
return FAST_VARIANT_FLAGS[variant]
|
|
|
|
else:
|
|
|
|
return ALL_VARIANT_FLAGS[variant]
|
2014-11-05 13:05:28 +00:00
|
|
|
|
|
|
|
|
2012-09-24 09:38:46 +00:00
|
|
|
class TestSuite(object):
|
|
|
|
|
|
|
|
@staticmethod
|
2015-11-27 12:51:43 +00:00
|
|
|
def LoadTestSuite(root, global_init=True):
|
2012-09-24 09:38:46 +00:00
|
|
|
name = root.split(os.path.sep)[-1]
|
|
|
|
f = None
|
|
|
|
try:
|
|
|
|
(f, pathname, description) = imp.find_module("testcfg", [root])
|
|
|
|
module = imp.load_module("testcfg", f, pathname, description)
|
2014-09-02 09:21:03 +00:00
|
|
|
return module.GetSuite(name, root)
|
2015-11-25 12:20:37 +00:00
|
|
|
except ImportError:
|
2014-09-02 09:21:03 +00:00
|
|
|
# Use default if no testcfg is present.
|
|
|
|
return GoogleTestSuite(name, root)
|
2012-09-24 09:38:46 +00:00
|
|
|
finally:
|
|
|
|
if f:
|
|
|
|
f.close()
|
|
|
|
|
|
|
|
def __init__(self, name, root):
|
2015-11-27 12:51:43 +00:00
|
|
|
# Note: This might be called concurrently from different processes.
|
2012-09-24 09:38:46 +00:00
|
|
|
self.name = name # string
|
|
|
|
self.root = root # string containing path
|
|
|
|
self.tests = None # list of TestCase objects
|
|
|
|
self.rules = None # dictionary mapping test path to list of outcomes
|
|
|
|
self.wildcards = None # dictionary mapping test paths to list of outcomes
|
|
|
|
self.total_duration = None # float, assigned on demand
|
|
|
|
|
|
|
|
def shell(self):
|
|
|
|
return "d8"
|
|
|
|
|
|
|
|
def suffix(self):
|
|
|
|
return ".js"
|
|
|
|
|
|
|
|
def status_file(self):
|
|
|
|
return "%s/%s.status" % (self.root, self.name)
|
|
|
|
|
|
|
|
# Used in the status file and for stdout printing.
|
|
|
|
def CommonTestName(self, testcase):
|
2013-08-06 14:39:39 +00:00
|
|
|
if utils.IsWindows():
|
|
|
|
return testcase.path.replace("\\", "/")
|
|
|
|
else:
|
|
|
|
return testcase.path
|
2012-09-24 09:38:46 +00:00
|
|
|
|
|
|
|
def ListTests(self, context):
|
|
|
|
raise NotImplementedError
|
|
|
|
|
2015-07-29 07:14:15 +00:00
|
|
|
def _VariantGeneratorFactory(self):
|
|
|
|
"""The variant generator class to be used."""
|
|
|
|
return VariantGenerator
|
|
|
|
|
|
|
|
def CreateVariantGenerator(self, variants):
|
|
|
|
"""Return a generator for the testing variants of this suite.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
variants: List of variant names to be run as specified by the test
|
|
|
|
runner.
|
|
|
|
Returns: An object of type VariantGenerator.
|
|
|
|
"""
|
|
|
|
return self._VariantGeneratorFactory()(self, set(variants))
|
2012-09-24 09:38:46 +00:00
|
|
|
|
|
|
|
def DownloadData(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def ReadStatusFile(self, variables):
|
2016-08-04 14:41:09 +00:00
|
|
|
with open(self.status_file()) as f:
|
|
|
|
self.rules, self.wildcards = (
|
|
|
|
statusfile.ReadStatusFile(f.read(), variables))
|
2012-09-24 09:38:46 +00:00
|
|
|
|
|
|
|
def ReadTestCases(self, context):
|
|
|
|
self.tests = self.ListTests(context)
|
|
|
|
|
2013-11-25 17:34:52 +00:00
|
|
|
@staticmethod
|
|
|
|
def _FilterSlow(slow, mode):
|
|
|
|
return (mode == "run" and not slow) or (mode == "skip" and slow)
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def _FilterPassFail(pass_fail, mode):
|
|
|
|
return (mode == "run" and not pass_fail) or (mode == "skip" and pass_fail)
|
|
|
|
|
|
|
|
def FilterTestCasesByStatus(self, warn_unused_rules,
|
|
|
|
slow_tests="dontcare",
|
2016-08-04 14:41:09 +00:00
|
|
|
pass_fail_tests="dontcare",
|
|
|
|
variants=False):
|
|
|
|
|
|
|
|
# Use only variants-dependent rules and wildcards when filtering
|
|
|
|
# respective test cases and generic rules when filtering generic test
|
|
|
|
# cases.
|
|
|
|
if not variants:
|
|
|
|
rules = self.rules[""]
|
|
|
|
wildcards = self.wildcards[""]
|
|
|
|
else:
|
|
|
|
# We set rules and wildcards to a variant-specific version for each test
|
|
|
|
# below.
|
|
|
|
rules = {}
|
|
|
|
wildcards = {}
|
|
|
|
|
2012-09-24 09:38:46 +00:00
|
|
|
filtered = []
|
2016-08-04 14:41:09 +00:00
|
|
|
|
|
|
|
# Remember used rules as tuples of (rule, variant), where variant is "" for
|
|
|
|
# variant-independent rules.
|
2012-09-24 09:38:46 +00:00
|
|
|
used_rules = set()
|
2016-08-04 14:41:09 +00:00
|
|
|
|
2012-09-24 09:38:46 +00:00
|
|
|
for t in self.tests:
|
2013-11-25 17:34:52 +00:00
|
|
|
slow = False
|
|
|
|
pass_fail = False
|
2012-09-24 09:38:46 +00:00
|
|
|
testname = self.CommonTestName(t)
|
2016-08-04 14:41:09 +00:00
|
|
|
variant = t.variant or ""
|
|
|
|
if variants:
|
|
|
|
rules = self.rules[variant]
|
|
|
|
wildcards = self.wildcards[variant]
|
|
|
|
if testname in rules:
|
|
|
|
used_rules.add((testname, variant))
|
2013-08-06 14:39:39 +00:00
|
|
|
# Even for skipped tests, as the TestCase object stays around and
|
|
|
|
# PrintReport() uses it.
|
2016-08-05 11:51:20 +00:00
|
|
|
t.outcomes = t.outcomes | rules[testname]
|
2013-08-06 14:39:39 +00:00
|
|
|
if statusfile.DoSkip(t.outcomes):
|
2012-09-24 09:38:46 +00:00
|
|
|
continue # Don't add skipped tests to |filtered|.
|
2014-11-20 09:46:55 +00:00
|
|
|
for outcome in t.outcomes:
|
|
|
|
if outcome.startswith('Flags: '):
|
|
|
|
t.flags += outcome[7:].split()
|
2013-11-25 17:34:52 +00:00
|
|
|
slow = statusfile.IsSlow(t.outcomes)
|
|
|
|
pass_fail = statusfile.IsPassOrFail(t.outcomes)
|
2013-08-06 14:39:39 +00:00
|
|
|
skip = False
|
2016-08-04 14:41:09 +00:00
|
|
|
for rule in wildcards:
|
2013-08-06 14:39:39 +00:00
|
|
|
assert rule[-1] == '*'
|
|
|
|
if testname.startswith(rule[:-1]):
|
2016-08-04 14:41:09 +00:00
|
|
|
used_rules.add((rule, variant))
|
2016-08-05 11:51:20 +00:00
|
|
|
t.outcomes = t.outcomes | wildcards[rule]
|
2013-08-06 14:39:39 +00:00
|
|
|
if statusfile.DoSkip(t.outcomes):
|
|
|
|
skip = True
|
2016-08-04 14:41:09 +00:00
|
|
|
break # "for rule in wildcards"
|
2013-11-25 17:34:52 +00:00
|
|
|
slow = slow or statusfile.IsSlow(t.outcomes)
|
|
|
|
pass_fail = pass_fail or statusfile.IsPassOrFail(t.outcomes)
|
2016-03-16 07:34:03 +00:00
|
|
|
if (skip
|
2013-11-25 17:34:52 +00:00
|
|
|
or self._FilterSlow(slow, slow_tests)
|
|
|
|
or self._FilterPassFail(pass_fail, pass_fail_tests)):
|
2013-08-06 14:39:39 +00:00
|
|
|
continue # "for t in self.tests"
|
2012-09-24 09:38:46 +00:00
|
|
|
filtered.append(t)
|
|
|
|
self.tests = filtered
|
|
|
|
|
|
|
|
if not warn_unused_rules:
|
|
|
|
return
|
|
|
|
|
2016-08-04 14:41:09 +00:00
|
|
|
if not variants:
|
|
|
|
for rule in self.rules[""]:
|
|
|
|
if (rule, "") not in used_rules:
|
|
|
|
print("Unused rule: %s -> %s (variant independent)" % (
|
|
|
|
rule, self.rules[""][rule]))
|
|
|
|
for rule in self.wildcards[""]:
|
|
|
|
if (rule, "") not in used_rules:
|
|
|
|
print("Unused rule: %s -> %s (variant independent)" % (
|
|
|
|
rule, self.wildcards[""][rule]))
|
|
|
|
else:
|
|
|
|
for variant in ALL_VARIANTS:
|
|
|
|
for rule in self.rules[variant]:
|
|
|
|
if (rule, variant) not in used_rules:
|
|
|
|
print("Unused rule: %s -> %s (variant: %s)" % (
|
|
|
|
rule, self.rules[variant][rule], variant))
|
|
|
|
for rule in self.wildcards[variant]:
|
|
|
|
if (rule, variant) not in used_rules:
|
|
|
|
print("Unused rule: %s -> %s (variant: %s)" % (
|
|
|
|
rule, self.wildcards[variant][rule], variant))
|
|
|
|
|
2012-09-24 09:38:46 +00:00
|
|
|
|
|
|
|
def FilterTestCasesByArgs(self, args):
|
2015-07-23 13:01:15 +00:00
|
|
|
"""Filter test cases based on command-line arguments.
|
|
|
|
|
|
|
|
An argument with an asterisk in the end will match all test cases
|
|
|
|
that have the argument as a prefix. Without asterisk, only exact matches
|
|
|
|
will be used with the exeption of the test-suite name as argument.
|
|
|
|
"""
|
2012-09-24 09:38:46 +00:00
|
|
|
filtered = []
|
2015-07-23 13:01:15 +00:00
|
|
|
globs = []
|
|
|
|
exact_matches = []
|
2012-09-24 09:38:46 +00:00
|
|
|
for a in args:
|
2015-08-06 12:36:49 +00:00
|
|
|
argpath = a.split('/')
|
2012-09-24 09:38:46 +00:00
|
|
|
if argpath[0] != self.name:
|
|
|
|
continue
|
|
|
|
if len(argpath) == 1 or (len(argpath) == 2 and argpath[1] == '*'):
|
|
|
|
return # Don't filter, run all tests in this suite.
|
2015-09-17 13:00:57 +00:00
|
|
|
path = '/'.join(argpath[1:])
|
2012-09-24 09:38:46 +00:00
|
|
|
if path[-1] == '*':
|
|
|
|
path = path[:-1]
|
2015-07-23 13:01:15 +00:00
|
|
|
globs.append(path)
|
|
|
|
else:
|
|
|
|
exact_matches.append(path)
|
2012-09-24 09:38:46 +00:00
|
|
|
for t in self.tests:
|
2015-07-23 13:01:15 +00:00
|
|
|
for a in globs:
|
2012-09-24 09:38:46 +00:00
|
|
|
if t.path.startswith(a):
|
|
|
|
filtered.append(t)
|
|
|
|
break
|
2015-07-23 13:01:15 +00:00
|
|
|
for a in exact_matches:
|
|
|
|
if t.path == a:
|
|
|
|
filtered.append(t)
|
|
|
|
break
|
2012-09-24 09:38:46 +00:00
|
|
|
self.tests = filtered
|
|
|
|
|
|
|
|
def GetFlagsForTestCase(self, testcase, context):
|
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
def GetSourceForTest(self, testcase):
|
|
|
|
return "(no source available)"
|
|
|
|
|
2016-03-14 21:19:10 +00:00
|
|
|
def IsFailureOutput(self, testcase):
|
|
|
|
return testcase.output.exit_code != 0
|
2012-09-24 09:38:46 +00:00
|
|
|
|
|
|
|
def IsNegativeTest(self, testcase):
|
|
|
|
return False
|
|
|
|
|
|
|
|
def HasFailed(self, testcase):
|
2016-03-14 21:19:10 +00:00
|
|
|
execution_failed = self.IsFailureOutput(testcase)
|
2012-09-24 09:38:46 +00:00
|
|
|
if self.IsNegativeTest(testcase):
|
|
|
|
return not execution_failed
|
|
|
|
else:
|
|
|
|
return execution_failed
|
|
|
|
|
2014-07-03 09:33:22 +00:00
|
|
|
def GetOutcome(self, testcase):
|
2012-09-24 09:38:46 +00:00
|
|
|
if testcase.output.HasCrashed():
|
2014-07-03 09:33:22 +00:00
|
|
|
return statusfile.CRASH
|
2012-09-24 09:38:46 +00:00
|
|
|
elif testcase.output.HasTimedOut():
|
2014-07-03 09:33:22 +00:00
|
|
|
return statusfile.TIMEOUT
|
2012-09-24 09:38:46 +00:00
|
|
|
elif self.HasFailed(testcase):
|
2014-07-03 09:33:22 +00:00
|
|
|
return statusfile.FAIL
|
2012-09-24 09:38:46 +00:00
|
|
|
else:
|
2014-07-03 09:33:22 +00:00
|
|
|
return statusfile.PASS
|
|
|
|
|
|
|
|
def HasUnexpectedOutput(self, testcase):
|
|
|
|
outcome = self.GetOutcome(testcase)
|
|
|
|
return not outcome in (testcase.outcomes or [statusfile.PASS])
|
2012-09-24 09:38:46 +00:00
|
|
|
|
|
|
|
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
|
2014-09-02 09:21:03 +00:00
|
|
|
|
|
|
|
|
2015-07-29 07:14:15 +00:00
|
|
|
class StandardVariantGenerator(VariantGenerator):
|
|
|
|
def FilterVariantsByTest(self, testcase):
|
|
|
|
return self.standard_variant
|
|
|
|
|
|
|
|
|
2014-09-02 09:21:03 +00:00
|
|
|
class GoogleTestSuite(TestSuite):
|
|
|
|
def __init__(self, name, root):
|
|
|
|
super(GoogleTestSuite, self).__init__(name, root)
|
|
|
|
|
|
|
|
def ListTests(self, context):
|
|
|
|
shell = os.path.abspath(os.path.join(context.shell_dir, self.shell()))
|
|
|
|
if utils.IsWindows():
|
|
|
|
shell += ".exe"
|
|
|
|
output = commands.Execute(context.command_prefix +
|
|
|
|
[shell, "--gtest_list_tests"] +
|
|
|
|
context.extra_flags)
|
|
|
|
if output.exit_code != 0:
|
|
|
|
print output.stdout
|
|
|
|
print output.stderr
|
2014-09-26 13:46:22 +00:00
|
|
|
raise Exception("Test executable failed to list the tests.")
|
2014-09-02 09:21:03 +00:00
|
|
|
tests = []
|
|
|
|
test_case = ''
|
|
|
|
for line in output.stdout.splitlines():
|
|
|
|
test_desc = line.strip().split()[0]
|
|
|
|
if test_desc.endswith('.'):
|
|
|
|
test_case = test_desc
|
|
|
|
elif test_case and test_desc:
|
2016-03-02 13:12:59 +00:00
|
|
|
test = testcase.TestCase(self, test_case + test_desc)
|
2014-09-02 09:21:03 +00:00
|
|
|
tests.append(test)
|
2016-03-31 07:38:10 +00:00
|
|
|
tests.sort(key=lambda t: t.path)
|
2014-09-02 09:21:03 +00:00
|
|
|
return tests
|
|
|
|
|
|
|
|
def GetFlagsForTestCase(self, testcase, context):
|
|
|
|
return (testcase.flags + ["--gtest_filter=" + testcase.path] +
|
|
|
|
["--gtest_random_seed=%s" % context.random_seed] +
|
|
|
|
["--gtest_print_time=0"] +
|
|
|
|
context.mode_flags)
|
|
|
|
|
2015-07-29 07:14:15 +00:00
|
|
|
def _VariantGeneratorFactory(self):
|
|
|
|
return StandardVariantGenerator
|
2015-04-27 08:20:20 +00:00
|
|
|
|
2014-09-02 09:21:03 +00:00
|
|
|
def shell(self):
|
|
|
|
return self.name
|