Andrew Top | ef837fa | 2017-10-04 22:44:25 -0700 | [diff] [blame] | 1 | # 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 | |
| 28 | import os |
Andrew Top | 63c7ad4 | 2019-11-25 16:10:13 -0800 | [diff] [blame] | 29 | import re |
Andrew Top | ef837fa | 2017-10-04 22:44:25 -0700 | [diff] [blame] | 30 | |
| 31 | from testrunner.local import testsuite |
| 32 | from testrunner.objects import testcase |
| 33 | |
Andrew Top | 63c7ad4 | 2019-11-25 16:10:13 -0800 | [diff] [blame] | 34 | ENV_PATTERN = re.compile(r"//\s+Environment Variables:(.*)") |
| 35 | |
| 36 | |
| 37 | class TestLoader(testsuite.JSTestLoader): |
| 38 | @property |
| 39 | def excluded_files(self): |
| 40 | return {"assert.js", "utils.js"} |
| 41 | |
| 42 | |
Mike Fleming | 3933d92 | 2018-04-02 10:53:08 -0700 | [diff] [blame] | 43 | class TestSuite(testsuite.TestSuite): |
Andrew Top | 63c7ad4 | 2019-11-25 16:10:13 -0800 | [diff] [blame] | 44 | def _test_loader_class(self): |
| 45 | return TestLoader |
Andrew Top | ef837fa | 2017-10-04 22:44:25 -0700 | [diff] [blame] | 46 | |
Mike Fleming | 3933d92 | 2018-04-02 10:53:08 -0700 | [diff] [blame] | 47 | def _test_class(self): |
| 48 | return TestCase |
Andrew Top | ef837fa | 2017-10-04 22:44:25 -0700 | [diff] [blame] | 49 | |
Andrew Top | ef837fa | 2017-10-04 22:44:25 -0700 | [diff] [blame] | 50 | |
Andrew Top | 63c7ad4 | 2019-11-25 16:10:13 -0800 | [diff] [blame] | 51 | class TestCase(testcase.D8TestCase): |
Mike Fleming | 3933d92 | 2018-04-02 10:53:08 -0700 | [diff] [blame] | 52 | def __init__(self, *args, **kwargs): |
| 53 | super(TestCase, self).__init__(*args, **kwargs) |
Andrew Top | ef837fa | 2017-10-04 22:44:25 -0700 | [diff] [blame] | 54 | |
Mike Fleming | 3933d92 | 2018-04-02 10:53:08 -0700 | [diff] [blame] | 55 | self._source_flags = self._parse_source_flags() |
Andrew Top | 63c7ad4 | 2019-11-25 16:10:13 -0800 | [diff] [blame] | 56 | source = self.get_source() |
| 57 | self._env = self._parse_source_env(source) |
Andrew Top | ef837fa | 2017-10-04 22:44:25 -0700 | [diff] [blame] | 58 | |
Andrew Top | 63c7ad4 | 2019-11-25 16:10:13 -0800 | [diff] [blame] | 59 | 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 Fleming | 3933d92 | 2018-04-02 10:53:08 -0700 | [diff] [blame] | 75 | files = map(lambda f: os.path.join(self.suite.root, f), [ |
| 76 | 'assert.js', |
| 77 | 'utils.js', |
Mike Fleming | 3933d92 | 2018-04-02 10:53:08 -0700 | [diff] [blame] | 78 | self.path + self._get_suffix(), |
Mike Fleming | 3933d92 | 2018-04-02 10:53:08 -0700 | [diff] [blame] | 79 | ]) |
| 80 | |
Andrew Top | 63c7ad4 | 2019-11-25 16:10:13 -0800 | [diff] [blame] | 81 | if self._test_config.isolates: |
Mike Fleming | 3933d92 | 2018-04-02 10:53:08 -0700 | [diff] [blame] | 82 | files += ['--isolate'] + files |
| 83 | return files |
| 84 | |
| 85 | def _get_source_flags(self): |
| 86 | return self._source_flags |
| 87 | |
Andrew Top | 63c7ad4 | 2019-11-25 16:10:13 -0800 | [diff] [blame] | 88 | def _get_suite_flags(self): |
Mike Fleming | 3933d92 | 2018-04-02 10:53:08 -0700 | [diff] [blame] | 89 | 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 Top | ef837fa | 2017-10-04 22:44:25 -0700 | [diff] [blame] | 94 | |
Andrew Top | 63c7ad4 | 2019-11-25 16:10:13 -0800 | [diff] [blame] | 95 | def GetSuite(*args, **kwargs): |
| 96 | return TestSuite(*args, **kwargs) |