blob: f04bf19c8c95b34077e760fc5fca05287ee5f891 [file] [log] [blame]
Andrew Topef837fa2017-10-04 22:44:25 -07001# Copyright 2013 the V8 project authors. All rights reserved.
2# Redistribution and use in source and binary forms, with or without
3# modification, are permitted provided that the following conditions are
4# met:
5#
6# * Redistributions of source code must retain the above copyright
7# notice, this list of conditions and the following disclaimer.
8# * Redistributions in binary form must reproduce the above
9# copyright notice, this list of conditions and the following
10# disclaimer in the documentation and/or other materials provided
11# with the distribution.
12# * Neither the name of Google Inc. nor the names of its
13# contributors may be used to endorse or promote products derived
14# from this software without specific prior written permission.
15#
16# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28import os
Andrew Top63c7ad42019-11-25 16:10:13 -080029import re
Andrew Topef837fa2017-10-04 22:44:25 -070030
31from testrunner.local import testsuite
32from testrunner.objects import testcase
33
Andrew Top63c7ad42019-11-25 16:10:13 -080034ENV_PATTERN = re.compile(r"//\s+Environment Variables:(.*)")
35
36
37class TestLoader(testsuite.JSTestLoader):
38 @property
39 def excluded_files(self):
40 return {"assert.js", "utils.js"}
41
42
Mike Fleming3933d922018-04-02 10:53:08 -070043class TestSuite(testsuite.TestSuite):
Andrew Top63c7ad42019-11-25 16:10:13 -080044 def _test_loader_class(self):
45 return TestLoader
Andrew Topef837fa2017-10-04 22:44:25 -070046
Mike Fleming3933d922018-04-02 10:53:08 -070047 def _test_class(self):
48 return TestCase
Andrew Topef837fa2017-10-04 22:44:25 -070049
Andrew Topef837fa2017-10-04 22:44:25 -070050
Andrew Top63c7ad42019-11-25 16:10:13 -080051class TestCase(testcase.D8TestCase):
Mike Fleming3933d922018-04-02 10:53:08 -070052 def __init__(self, *args, **kwargs):
53 super(TestCase, self).__init__(*args, **kwargs)
Andrew Topef837fa2017-10-04 22:44:25 -070054
Mike Fleming3933d922018-04-02 10:53:08 -070055 self._source_flags = self._parse_source_flags()
Andrew Top63c7ad42019-11-25 16:10:13 -080056 source = self.get_source()
57 self._env = self._parse_source_env(source)
Andrew Topef837fa2017-10-04 22:44:25 -070058
Andrew Top63c7ad42019-11-25 16:10:13 -080059 def _parse_source_env(self, source):
60 env_match = ENV_PATTERN.search(source)
61 # https://crbug.com/v8/8845
62 if 'LC_ALL' in os.environ:
63 del os.environ['LC_ALL']
64 env = {}
65 if env_match:
66 for env_pair in env_match.group(1).strip().split():
67 var, value = env_pair.split('=')
68 env[var] = value
69 return env
70
71 def _get_cmd_env(self):
72 return self._env
73
74 def _get_files_params(self):
Mike Fleming3933d922018-04-02 10:53:08 -070075 files = map(lambda f: os.path.join(self.suite.root, f), [
76 'assert.js',
77 'utils.js',
Mike Fleming3933d922018-04-02 10:53:08 -070078 self.path + self._get_suffix(),
Mike Fleming3933d922018-04-02 10:53:08 -070079 ])
80
Andrew Top63c7ad42019-11-25 16:10:13 -080081 if self._test_config.isolates:
Mike Fleming3933d922018-04-02 10:53:08 -070082 files += ['--isolate'] + files
83 return files
84
85 def _get_source_flags(self):
86 return self._source_flags
87
Andrew Top63c7ad42019-11-25 16:10:13 -080088 def _get_suite_flags(self):
Mike Fleming3933d922018-04-02 10:53:08 -070089 return ['--allow-natives-syntax']
90
91 def _get_source_path(self):
92 return os.path.join(self.suite.root, self.path + self._get_suffix())
93
Andrew Topef837fa2017-10-04 22:44:25 -070094
Andrew Top63c7ad42019-11-25 16:10:13 -080095def GetSuite(*args, **kwargs):
96 return TestSuite(*args, **kwargs)