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.
|
|
|
|
|
|
|
|
|
2017-08-09 17:42:03 +00:00
|
|
|
import fnmatch
|
2012-09-24 09:38:46 +00:00
|
|
|
import imp
|
|
|
|
import os
|
|
|
|
|
2017-11-30 12:57:45 +00:00
|
|
|
from . import command
|
2012-09-24 09:38:46 +00:00
|
|
|
from . import statusfile
|
2013-01-18 14:55:23 +00:00
|
|
|
from . import utils
|
2017-12-12 21:33:16 +00:00
|
|
|
from ..objects.testcase import TestCase
|
2018-01-15 09:35:02 +00:00
|
|
|
from variants import ALL_VARIANTS, ALL_VARIANT_FLAGS
|
2016-08-04 14:41:09 +00:00
|
|
|
|
2012-09-24 09:38:46 +00:00
|
|
|
|
2015-07-29 07:14:15 +00:00
|
|
|
STANDARD_VARIANT = set(["default"])
|
|
|
|
|
|
|
|
|
2018-01-12 10:07:56 +00:00
|
|
|
class LegacyVariantsGenerator(object):
|
2015-07-29 07:14:15 +00:00
|
|
|
def __init__(self, suite, variants):
|
|
|
|
self.suite = suite
|
2018-01-26 13:41:12 +00:00
|
|
|
self.all_variants = variants
|
2015-07-29 07:14:15 +00:00
|
|
|
self.standard_variant = STANDARD_VARIANT & variants
|
|
|
|
|
2017-12-12 21:33:16 +00:00
|
|
|
def FilterVariantsByTest(self, test):
|
2017-12-18 17:07:40 +00:00
|
|
|
if test.only_standard_variant:
|
|
|
|
return self.standard_variant
|
|
|
|
return self.all_variants
|
2015-07-29 07:14:15 +00:00
|
|
|
|
2017-12-12 21:33:16 +00:00
|
|
|
def GetFlagSets(self, test, variant):
|
2018-01-15 09:35:02 +00:00
|
|
|
return ALL_VARIANT_FLAGS[variant]
|
2014-11-05 13:05:28 +00:00
|
|
|
|
|
|
|
|
2018-01-12 10:07:56 +00:00
|
|
|
class StandardLegacyVariantsGenerator(LegacyVariantsGenerator):
|
|
|
|
def FilterVariantsByTest(self, testcase):
|
|
|
|
return self.standard_variant
|
|
|
|
|
|
|
|
|
|
|
|
class VariantsGenerator(object):
|
|
|
|
def __init__(self, variants):
|
|
|
|
self._all_variants = [v for v in variants if v in ALL_VARIANTS]
|
|
|
|
self._standard_variant = [v for v in variants if v in STANDARD_VARIANT]
|
|
|
|
|
|
|
|
def gen(self, test):
|
|
|
|
"""Generator producing (variant, flags, procid suffix) tuples."""
|
|
|
|
flags_set = self._get_flags_set(test)
|
|
|
|
for n, variant in enumerate(self._get_variants(test)):
|
|
|
|
yield (variant, flags_set[variant][0], n)
|
|
|
|
|
|
|
|
def _get_flags_set(self, test):
|
2018-01-15 09:35:02 +00:00
|
|
|
return ALL_VARIANT_FLAGS
|
2018-01-12 10:07:56 +00:00
|
|
|
|
|
|
|
def _get_variants(self, test):
|
|
|
|
if test.only_standard_variant:
|
|
|
|
return self._standard_variant
|
|
|
|
return self._all_variants
|
|
|
|
|
|
|
|
|
2018-01-25 15:18:29 +00:00
|
|
|
class TestCombiner(object):
|
|
|
|
def get_group_key(self, test):
|
|
|
|
"""To indicate what tests can be combined with each other we define a group
|
|
|
|
key for each test. Tests with the same group key can be combined. Test
|
|
|
|
without a group key (None) is not combinable with any other test.
|
|
|
|
"""
|
|
|
|
raise NotImplementedError()
|
|
|
|
|
|
|
|
def combine(self, name, tests):
|
|
|
|
"""Returns test combined from `tests`. Since we identify tests by their
|
|
|
|
suite and name, `name` parameter should be unique within one suite.
|
|
|
|
"""
|
|
|
|
return self._combined_test_class()(name, tests)
|
|
|
|
|
|
|
|
def _combined_test_class(self):
|
|
|
|
raise NotImplementedError()
|
|
|
|
|
|
|
|
|
2012-09-24 09:38:46 +00:00
|
|
|
class TestSuite(object):
|
|
|
|
@staticmethod
|
2018-01-31 09:18:13 +00:00
|
|
|
def LoadTestSuite(root, test_config):
|
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])
|
2017-05-09 11:44:18 +00:00
|
|
|
module = imp.load_module(name + "_testcfg", f, pathname, description)
|
2018-01-31 09:18:13 +00:00
|
|
|
return module.GetSuite(name, root, test_config)
|
2012-09-24 09:38:46 +00:00
|
|
|
finally:
|
|
|
|
if f:
|
|
|
|
f.close()
|
|
|
|
|
2018-01-31 09:18:13 +00:00
|
|
|
def __init__(self, name, root, test_config):
|
2012-09-24 09:38:46 +00:00
|
|
|
self.name = name # string
|
|
|
|
self.root = root # string containing path
|
2018-01-31 09:18:13 +00:00
|
|
|
self.test_config = test_config
|
2012-09-24 09:38:46 +00:00
|
|
|
self.tests = None # list of TestCase objects
|
2017-12-19 14:23:45 +00:00
|
|
|
self.statusfile = None
|
2018-01-29 15:51:03 +00:00
|
|
|
self.suppress_internals = False
|
2012-09-24 09:38:46 +00:00
|
|
|
|
|
|
|
def status_file(self):
|
|
|
|
return "%s/%s.status" % (self.root, self.name)
|
|
|
|
|
2018-01-29 15:51:03 +00:00
|
|
|
def do_suppress_internals(self):
|
|
|
|
"""Specifies if this test suite should suppress asserts based on internals.
|
|
|
|
|
|
|
|
Internals are e.g. testing against the outcome of native runtime functions.
|
|
|
|
This is switched off on some fuzzers that violate these contracts.
|
|
|
|
"""
|
|
|
|
self.suppress_internals = True
|
|
|
|
|
2012-09-24 09:38:46 +00:00
|
|
|
def ListTests(self, context):
|
|
|
|
raise NotImplementedError
|
|
|
|
|
2018-01-12 10:07:56 +00:00
|
|
|
def _LegacyVariantsGeneratorFactory(self):
|
2015-07-29 07:14:15 +00:00
|
|
|
"""The variant generator class to be used."""
|
2018-01-12 10:07:56 +00:00
|
|
|
return LegacyVariantsGenerator
|
2015-07-29 07:14:15 +00:00
|
|
|
|
2018-01-12 10:07:56 +00:00
|
|
|
def CreateLegacyVariantsGenerator(self, variants):
|
2015-07-29 07:14:15 +00:00
|
|
|
"""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.
|
2018-01-12 10:07:56 +00:00
|
|
|
Returns: An object of type LegacyVariantsGenerator.
|
2015-07-29 07:14:15 +00:00
|
|
|
"""
|
2018-01-12 10:07:56 +00:00
|
|
|
return self._LegacyVariantsGeneratorFactory()(self, set(variants))
|
|
|
|
|
|
|
|
def get_variants_gen(self, variants):
|
|
|
|
return self._variants_gen_class()(variants)
|
|
|
|
|
|
|
|
def _variants_gen_class(self):
|
|
|
|
return VariantsGenerator
|
2012-09-24 09:38:46 +00:00
|
|
|
|
2018-01-25 15:18:29 +00:00
|
|
|
def test_combiner_available(self):
|
|
|
|
return bool(self._test_combiner_class())
|
|
|
|
|
|
|
|
def get_test_combiner(self):
|
|
|
|
cls = self._test_combiner_class()
|
|
|
|
if cls:
|
|
|
|
return cls()
|
|
|
|
return None
|
|
|
|
|
|
|
|
def _test_combiner_class(self):
|
|
|
|
"""Returns Combiner subclass. None if suite doesn't support combining
|
|
|
|
tests.
|
|
|
|
"""
|
|
|
|
return None
|
|
|
|
|
2012-09-24 09:38:46 +00:00
|
|
|
def ReadStatusFile(self, variables):
|
2017-12-19 14:23:45 +00:00
|
|
|
self.statusfile = statusfile.StatusFile(self.status_file(), variables)
|
2012-09-24 09:38:46 +00:00
|
|
|
|
|
|
|
def ReadTestCases(self, context):
|
|
|
|
self.tests = self.ListTests(context)
|
|
|
|
|
2016-08-04 14:41:09 +00:00
|
|
|
|
2017-11-20 21:42:13 +00:00
|
|
|
def FilterTestCasesByStatus(self,
|
|
|
|
slow_tests_mode=None,
|
|
|
|
pass_fail_tests_mode=None):
|
|
|
|
"""Filters tests by outcomes from status file.
|
2016-08-04 14:41:09 +00:00
|
|
|
|
2017-11-20 21:42:13 +00:00
|
|
|
Status file has to be loaded before using this function.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
slow_tests_mode: What to do with slow tests.
|
|
|
|
pass_fail_tests_mode: What to do with pass or fail tests.
|
|
|
|
|
|
|
|
Mode options:
|
|
|
|
None (default) - don't skip
|
|
|
|
"skip" - skip if slow/pass_fail
|
|
|
|
"run" - skip if not slow/pass_fail
|
|
|
|
"""
|
|
|
|
def _skip_slow(is_slow, mode):
|
|
|
|
return (
|
|
|
|
(mode == 'run' and not is_slow) or
|
|
|
|
(mode == 'skip' and is_slow))
|
|
|
|
|
|
|
|
def _skip_pass_fail(pass_fail, mode):
|
|
|
|
return (
|
|
|
|
(mode == 'run' and not pass_fail) or
|
|
|
|
(mode == 'skip' and pass_fail))
|
|
|
|
|
|
|
|
def _compliant(test):
|
2017-12-18 17:07:40 +00:00
|
|
|
if test.do_skip:
|
2017-11-20 21:42:13 +00:00
|
|
|
return False
|
2017-12-18 17:07:40 +00:00
|
|
|
if _skip_slow(test.is_slow, slow_tests_mode):
|
2017-11-20 21:42:13 +00:00
|
|
|
return False
|
2017-12-18 17:07:40 +00:00
|
|
|
if _skip_pass_fail(test.is_pass_or_fail, pass_fail_tests_mode):
|
2017-11-20 21:42:13 +00:00
|
|
|
return False
|
|
|
|
return True
|
|
|
|
|
|
|
|
self.tests = filter(_compliant, self.tests)
|
|
|
|
|
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.
|
|
|
|
|
2017-08-09 17:42:03 +00:00
|
|
|
args can be a glob: asterisks in any position of the argument
|
|
|
|
represent zero or more characters. Without asterisks, only exact matches
|
2015-07-23 13:01:15 +00:00
|
|
|
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 = []
|
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:])
|
2017-08-09 17:42:03 +00:00
|
|
|
globs.append(path)
|
|
|
|
|
2012-09-24 09:38:46 +00:00
|
|
|
for t in self.tests:
|
2017-08-09 17:42:03 +00:00
|
|
|
for g in globs:
|
|
|
|
if fnmatch.fnmatch(t.path, g):
|
2015-07-23 13:01:15 +00:00
|
|
|
filtered.append(t)
|
|
|
|
break
|
2012-09-24 09:38:46 +00:00
|
|
|
self.tests = filtered
|
|
|
|
|
2017-12-12 21:33:16 +00:00
|
|
|
def _create_test(self, path, **kwargs):
|
2018-01-29 15:51:03 +00:00
|
|
|
if self.suppress_internals:
|
|
|
|
test_class = self._suppressed_test_class()
|
|
|
|
else:
|
|
|
|
test_class = self._test_class()
|
2018-01-31 09:18:13 +00:00
|
|
|
return test_class(self, path, self._path_to_name(path), self.test_config,
|
|
|
|
**kwargs)
|
2017-12-12 21:33:16 +00:00
|
|
|
|
2018-01-29 15:51:03 +00:00
|
|
|
def _suppressed_test_class(self):
|
|
|
|
"""Optional testcase that suppresses assertions. Used by fuzzers that are
|
|
|
|
only interested in dchecks or tsan and that might violate the assertions
|
|
|
|
through fuzzing.
|
|
|
|
"""
|
|
|
|
return self._test_class()
|
|
|
|
|
2017-12-12 21:33:16 +00:00
|
|
|
def _test_class(self):
|
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
def _path_to_name(self, path):
|
|
|
|
if utils.IsWindows():
|
|
|
|
return path.replace("\\", "/")
|
|
|
|
return path
|