blob: 5d6ab8466396847aeb9040cd99e9095302d92761 [file] [log] [blame]
Steve Blocka7e24c12009-10-30 11:49:00 +00001# 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 Murdochb8a8cc12014-11-26 15:28:44 +000028import itertools
Steve Blocka7e24c12009-10-30 11:49:00 +000029import os
Steve Blocka7e24c12009-10-30 11:49:00 +000030import re
31
Ben Murdochb8a8cc12014-11-26 15:28:44 +000032from testrunner.local import testsuite
33from testrunner.local import utils
34from testrunner.objects import testcase
35
36
Steve Blocka7e24c12009-10-30 11:49:00 +000037FLAGS_PATTERN = re.compile(r"//\s+Flags:(.*)")
Ben Murdochb8a8cc12014-11-26 15:28:44 +000038INVALID_FLAGS = ["--enable-slow-asserts"]
Steve Blocka7e24c12009-10-30 11:49:00 +000039
Steve Blocka7e24c12009-10-30 11:49:00 +000040
Ben Murdochb8a8cc12014-11-26 15:28:44 +000041class MessageTestSuite(testsuite.TestSuite):
42 def __init__(self, name, root):
43 super(MessageTestSuite, self).__init__(name, root)
Steve Blocka7e24c12009-10-30 11:49:00 +000044
Ben Murdochb8a8cc12014-11-26 15:28:44 +000045 def ListTests(self, context):
46 tests = []
47 for dirname, dirs, files in os.walk(self.root):
48 for dotted in [x for x in dirs if x.startswith('.')]:
49 dirs.remove(dotted)
50 dirs.sort()
51 files.sort()
52 for filename in files:
53 if filename.endswith(".js"):
54 testname = os.path.join(dirname[len(self.root) + 1:], filename[:-3])
55 test = testcase.TestCase(self, testname)
56 tests.append(test)
57 return tests
Steve Blocka7e24c12009-10-30 11:49:00 +000058
Ben Murdochb8a8cc12014-11-26 15:28:44 +000059 def GetFlagsForTestCase(self, testcase, context):
60 source = self.GetSourceForTest(testcase)
61 result = []
62 flags_match = re.findall(FLAGS_PATTERN, source)
63 for match in flags_match:
64 result += match.strip().split()
65 result += context.mode_flags
66 result = [x for x in result if x not in INVALID_FLAGS]
67 result.append(os.path.join(self.root, testcase.path + ".js"))
68 return testcase.flags + result
69
70 def GetSourceForTest(self, testcase):
71 filename = os.path.join(self.root, testcase.path + self.suffix())
72 with open(filename) as f:
73 return f.read()
74
75 def _IgnoreLine(self, string):
76 """Ignore empty lines, valgrind output, Android output."""
77 if not string: return True
Emily Bernierd0a1eb72015-03-24 16:35:39 -040078 if not string.strip(): return True
Ben Murdochb8a8cc12014-11-26 15:28:44 +000079 return (string.startswith("==") or string.startswith("**") or
80 string.startswith("ANDROID") or
81 # These five patterns appear in normal Native Client output.
82 string.startswith("DEBUG MODE ENABLED") or
83 string.startswith("tools/nacl-run.py") or
84 string.find("BYPASSING ALL ACL CHECKS") > 0 or
85 string.find("Native Client module will be loaded") > 0 or
86 string.find("NaClHostDescOpen:") > 0)
87
88 def IsFailureOutput(self, output, testpath):
89 expected_path = os.path.join(self.root, testpath + ".out")
90 expected_lines = []
91 # Can't use utils.ReadLinesFrom() here because it strips whitespace.
92 with open(expected_path) as f:
93 for line in f:
94 if line.startswith("#") or not line.strip(): continue
95 expected_lines.append(line)
96 raw_lines = output.stdout.splitlines()
97 actual_lines = [ s for s in raw_lines if not self._IgnoreLine(s) ]
98 env = { "basename": os.path.basename(testpath + ".js") }
99 if len(expected_lines) != len(actual_lines):
Steve Blocka7e24c12009-10-30 11:49:00 +0000100 return True
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000101 for (expected, actual) in itertools.izip_longest(
102 expected_lines, actual_lines, fillvalue=''):
103 pattern = re.escape(expected.rstrip() % env)
104 pattern = pattern.replace("\\*", ".*")
105 pattern = "^%s$" % pattern
106 if not re.match(pattern, actual):
Steve Blocka7e24c12009-10-30 11:49:00 +0000107 return True
108 return False
109
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000110 def StripOutputForTransmit(self, testcase):
111 pass
Steve Blocka7e24c12009-10-30 11:49:00 +0000112
113
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000114def GetSuite(name, root):
115 return MessageTestSuite(name, root)