Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(301)

Side by Side Diff: test/emscripten/testcfg.py

Issue 1101493002: [test] Initial import of an emscripten test suite. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/emscripten/emscripten.status ('k') | tools/presubmit.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2008 the V8 project authors. All rights reserved. 1 # Copyright 2015 the V8 project authors. All rights reserved.
2 # Redistribution and use in source and binary forms, with or without 2 # Use of this source code is governed by a BSD-style license that can be
3 # modification, are permitted provided that the following conditions are 3 # found in the LICENSE file.
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 4
28 import itertools 5 import itertools
29 import os 6 import os
30 import re 7 import re
31 8
32 from testrunner.local import testsuite 9 from testrunner.local import testsuite
33 from testrunner.local import utils 10 from testrunner.local import utils
34 from testrunner.objects import testcase 11 from testrunner.objects import testcase
35 12
36 13
37 FLAGS_PATTERN = re.compile(r"//\s+Flags:(.*)") 14 FLAGS_PATTERN = re.compile(r"//\s+Flags:(.*)")
38 INVALID_FLAGS = ["--enable-slow-asserts"] 15 INVALID_FLAGS = ["--enable-slow-asserts"]
39 MODULE_PATTERN = re.compile(r"^// MODULE$", flags=re.MULTILINE)
40 16
41 17
42 class MessageTestSuite(testsuite.TestSuite): 18 class MessageTestSuite(testsuite.TestSuite):
43 def __init__(self, name, root): 19 def __init__(self, name, root):
44 super(MessageTestSuite, self).__init__(name, root) 20 super(MessageTestSuite, self).__init__(name, root)
45 21
46 def ListTests(self, context): 22 def ListTests(self, context):
47 tests = [] 23 tests = []
48 for dirname, dirs, files in os.walk(self.root): 24 for dirname, dirs, files in os.walk(self.root):
49 for dotted in [x for x in dirs if x.startswith('.')]: 25 for dotted in [x for x in dirs if x.startswith('.')]:
50 dirs.remove(dotted) 26 dirs.remove(dotted)
51 dirs.sort() 27 dirs.sort()
52 files.sort() 28 files.sort()
53 for filename in files: 29 for filename in files:
54 if filename.endswith(".js"): 30 if filename.endswith(".js"):
55 testname = os.path.join(dirname[len(self.root) + 1:], filename[:-3]) 31 testname = os.path.join(dirname[len(self.root) + 1:], filename[:-3])
56 test = testcase.TestCase(self, testname) 32 test = testcase.TestCase(self, testname)
57 tests.append(test) 33 tests.append(test)
58 return tests 34 return tests
59 35
60 def GetFlagsForTestCase(self, testcase, context): 36 def GetFlagsForTestCase(self, testcase, context):
61 source = self.GetSourceForTest(testcase) 37 source = self.GetSourceForTest(testcase)
62 result = [] 38 result = []
63 flags_match = re.findall(FLAGS_PATTERN, source) 39 flags_match = re.findall(FLAGS_PATTERN, source)
64 for match in flags_match: 40 for match in flags_match:
65 result += match.strip().split() 41 result += match.strip().split()
66 result += context.mode_flags 42 result += context.mode_flags
67 if MODULE_PATTERN.search(source):
68 result.append("--module")
69 result = [x for x in result if x not in INVALID_FLAGS] 43 result = [x for x in result if x not in INVALID_FLAGS]
70 result.append(os.path.join(self.root, testcase.path + ".js")) 44 result.append(os.path.join(self.root, testcase.path + ".js"))
71 return testcase.flags + result 45 return testcase.flags + result
72 46
73 def GetSourceForTest(self, testcase): 47 def GetSourceForTest(self, testcase):
74 filename = os.path.join(self.root, testcase.path + self.suffix()) 48 filename = os.path.join(self.root, testcase.path + self.suffix())
75 with open(filename) as f: 49 with open(filename) as f:
76 return f.read() 50 return f.read()
77 51
78 def _IgnoreLine(self, string): 52 def _IgnoreLine(self, string):
79 """Ignore empty lines, valgrind output, Android output.""" 53 """Ignore valgrind, NaCl and Android output."""
80 if not string: return True
81 if not string.strip(): return True
82 return (string.startswith("==") or string.startswith("**") or 54 return (string.startswith("==") or string.startswith("**") or
83 string.startswith("ANDROID") or 55 string.startswith("ANDROID") or
84 # These five patterns appear in normal Native Client output. 56 # These five patterns appear in normal Native Client output.
85 string.startswith("DEBUG MODE ENABLED") or 57 string.startswith("DEBUG MODE ENABLED") or
86 string.startswith("tools/nacl-run.py") or 58 string.startswith("tools/nacl-run.py") or
87 string.find("BYPASSING ALL ACL CHECKS") > 0 or 59 string.find("BYPASSING ALL ACL CHECKS") > 0 or
88 string.find("Native Client module will be loaded") > 0 or 60 string.find("Native Client module will be loaded") > 0 or
89 string.find("NaClHostDescOpen:") > 0) 61 string.find("NaClHostDescOpen:") > 0)
90 62
91 def IsFailureOutput(self, output, testpath): 63 def IsFailureOutput(self, output, testpath):
92 expected_path = os.path.join(self.root, testpath + ".out") 64 expected_path = os.path.join(self.root, testpath + ".out")
93 expected_lines = [] 65 expected_lines = []
94 # Can't use utils.ReadLinesFrom() here because it strips whitespace. 66 # Can't use utils.ReadLinesFrom() here because it strips whitespace.
95 with open(expected_path) as f: 67 with open(expected_path) as expected:
96 for line in f: 68 expected_lines = expected.read().splitlines()
97 if line.startswith("#") or not line.strip(): continue
98 expected_lines.append(line)
99 raw_lines = output.stdout.splitlines() 69 raw_lines = output.stdout.splitlines()
100 actual_lines = [ s for s in raw_lines if not self._IgnoreLine(s) ] 70 actual_lines = [ s for s in raw_lines if not self._IgnoreLine(s) ]
101 env = { "basename": os.path.basename(testpath + ".js") } 71 env = { "basename": os.path.basename(testpath + ".js") }
102 if len(expected_lines) != len(actual_lines): 72 if len(expected_lines) != len(actual_lines):
103 return True 73 return True
104 for (expected, actual) in itertools.izip_longest( 74 for (expected, actual) in itertools.izip_longest(
105 expected_lines, actual_lines, fillvalue=''): 75 expected_lines, actual_lines, fillvalue=''):
106 pattern = re.escape(expected.rstrip() % env) 76 if expected != actual:
107 pattern = pattern.replace("\\*", ".*")
108 pattern = "^%s$" % pattern
109 if not re.match(pattern, actual):
110 return True 77 return True
111 return False 78 return False
112 79
113 def StripOutputForTransmit(self, testcase): 80 def StripOutputForTransmit(self, testcase):
114 pass 81 pass
115 82
116 83
117 def GetSuite(name, root): 84 def GetSuite(name, root):
118 return MessageTestSuite(name, root) 85 return MessageTestSuite(name, root)
OLDNEW
« no previous file with comments | « test/emscripten/emscripten.status ('k') | tools/presubmit.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698