Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1 | # Copyright 2008 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 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 28 | import itertools |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 29 | import os |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 30 | import re |
| 31 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 32 | from testrunner.local import testsuite |
| 33 | from testrunner.local import utils |
| 34 | from testrunner.objects import testcase |
| 35 | |
| 36 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 37 | FLAGS_PATTERN = re.compile(r"//\s+Flags:(.*)") |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 38 | INVALID_FLAGS = ["--enable-slow-asserts"] |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 39 | MODULE_PATTERN = re.compile(r"^// MODULE$", flags=re.MULTILINE) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 40 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 41 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 42 | class MessageTestSuite(testsuite.TestSuite): |
| 43 | def __init__(self, name, root): |
| 44 | super(MessageTestSuite, self).__init__(name, root) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 45 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 46 | def ListTests(self, context): |
| 47 | tests = [] |
| 48 | for dirname, dirs, files in os.walk(self.root): |
| 49 | for dotted in [x for x in dirs if x.startswith('.')]: |
| 50 | dirs.remove(dotted) |
| 51 | dirs.sort() |
| 52 | files.sort() |
| 53 | for filename in files: |
| 54 | if filename.endswith(".js"): |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 55 | fullpath = os.path.join(dirname, filename) |
| 56 | relpath = fullpath[len(self.root) + 1 : -3] |
| 57 | testname = relpath.replace(os.path.sep, "/") |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 58 | test = testcase.TestCase(self, testname) |
| 59 | tests.append(test) |
| 60 | return tests |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 61 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 62 | def CreateVariantGenerator(self, variants): |
| 63 | return super(MessageTestSuite, self).CreateVariantGenerator( |
| 64 | variants + ["preparser"]) |
| 65 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 66 | def GetFlagsForTestCase(self, testcase, context): |
| 67 | source = self.GetSourceForTest(testcase) |
| 68 | result = [] |
| 69 | flags_match = re.findall(FLAGS_PATTERN, source) |
| 70 | for match in flags_match: |
| 71 | result += match.strip().split() |
| 72 | result += context.mode_flags |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 73 | if MODULE_PATTERN.search(source): |
| 74 | result.append("--module") |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 75 | result = [x for x in result if x not in INVALID_FLAGS] |
| 76 | result.append(os.path.join(self.root, testcase.path + ".js")) |
| 77 | return testcase.flags + result |
| 78 | |
| 79 | def GetSourceForTest(self, testcase): |
| 80 | filename = os.path.join(self.root, testcase.path + self.suffix()) |
| 81 | with open(filename) as f: |
| 82 | return f.read() |
| 83 | |
| 84 | def _IgnoreLine(self, string): |
| 85 | """Ignore empty lines, valgrind output, Android output.""" |
| 86 | if not string: return True |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 87 | if not string.strip(): return True |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 88 | return (string.startswith("==") or string.startswith("**") or |
| 89 | string.startswith("ANDROID") or |
| 90 | # These five patterns appear in normal Native Client output. |
| 91 | string.startswith("DEBUG MODE ENABLED") or |
| 92 | string.startswith("tools/nacl-run.py") or |
| 93 | string.find("BYPASSING ALL ACL CHECKS") > 0 or |
| 94 | string.find("Native Client module will be loaded") > 0 or |
| 95 | string.find("NaClHostDescOpen:") > 0) |
| 96 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 97 | def IsFailureOutput(self, testcase): |
| 98 | output = testcase.output |
| 99 | testpath = testcase.path |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 100 | expected_path = os.path.join(self.root, testpath + ".out") |
| 101 | expected_lines = [] |
| 102 | # Can't use utils.ReadLinesFrom() here because it strips whitespace. |
| 103 | with open(expected_path) as f: |
| 104 | for line in f: |
| 105 | if line.startswith("#") or not line.strip(): continue |
| 106 | expected_lines.append(line) |
| 107 | raw_lines = output.stdout.splitlines() |
| 108 | actual_lines = [ s for s in raw_lines if not self._IgnoreLine(s) ] |
| 109 | env = { "basename": os.path.basename(testpath + ".js") } |
| 110 | if len(expected_lines) != len(actual_lines): |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 111 | return True |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 112 | for (expected, actual) in itertools.izip_longest( |
| 113 | expected_lines, actual_lines, fillvalue=''): |
| 114 | pattern = re.escape(expected.rstrip() % env) |
| 115 | pattern = pattern.replace("\\*", ".*") |
| 116 | pattern = "^%s$" % pattern |
| 117 | if not re.match(pattern, actual): |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 118 | return True |
| 119 | return False |
| 120 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 121 | def StripOutputForTransmit(self, testcase): |
| 122 | pass |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 123 | |
| 124 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 125 | def GetSuite(name, root): |
| 126 | return MessageTestSuite(name, root) |