OLD | NEW |
(Empty) | |
| 1 # Copyright 2016 the V8 project authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. |
| 4 |
| 5 import itertools |
| 6 import os |
| 7 import re |
| 8 |
| 9 from testrunner.local import testsuite |
| 10 from testrunner.local import utils |
| 11 from testrunner.objects import testcase |
| 12 |
| 13 FLAGS_PATTERN = re.compile(r"//\s+Flags:(.*)") |
| 14 PROTOCOL_TEST_JS = "protocol-test.js" |
| 15 EXPECTED_SUFFIX = "-expected.txt" |
| 16 |
| 17 class InspectorProtocolTestSuite(testsuite.TestSuite): |
| 18 |
| 19 def __init__(self, name, root): |
| 20 super(InspectorProtocolTestSuite, self).__init__(name, root) |
| 21 |
| 22 def ListTests(self, context): |
| 23 tests = [] |
| 24 for dirname, dirs, files in os.walk(os.path.join(self.root), followlinks=Tru
e): |
| 25 for dotted in [x for x in dirs if x.startswith('.')]: |
| 26 dirs.remove(dotted) |
| 27 dirs.sort() |
| 28 files.sort() |
| 29 for filename in files: |
| 30 if filename.endswith(".js") and filename != PROTOCOL_TEST_JS: |
| 31 fullpath = os.path.join(dirname, filename) |
| 32 relpath = fullpath[len(self.root) + 1 : -3] |
| 33 testname = relpath.replace(os.path.sep, "/") |
| 34 test = testcase.TestCase(self, testname) |
| 35 tests.append(test) |
| 36 return tests |
| 37 |
| 38 def GetFlagsForTestCase(self, testcase, context): |
| 39 source = self.GetSourceForTest(testcase) |
| 40 flags_match = re.findall(FLAGS_PATTERN, source) |
| 41 flags = [] |
| 42 for match in flags_match: |
| 43 flags += match.strip().split() |
| 44 testname = testcase.path.split(os.path.sep)[-1] |
| 45 testfilename = os.path.join(self.root, testcase.path + self.suffix()) |
| 46 protocoltestfilename = os.path.join(self.root, PROTOCOL_TEST_JS) |
| 47 return [ protocoltestfilename, testfilename ] + flags |
| 48 |
| 49 def GetSourceForTest(self, testcase): |
| 50 filename = os.path.join(self.root, testcase.path + self.suffix()) |
| 51 with open(filename) as f: |
| 52 return f.read() |
| 53 |
| 54 def shell(self): |
| 55 return "inspector-test" |
| 56 |
| 57 def _IgnoreLine(self, string): |
| 58 """Ignore empty lines, valgrind output and Android output.""" |
| 59 if not string: return True |
| 60 return (string.startswith("==") or string.startswith("**") or |
| 61 string.startswith("ANDROID") or |
| 62 # FIXME(machenbach): The test driver shouldn't try to use slow |
| 63 # asserts if they weren't compiled. This fails in optdebug=2. |
| 64 string == "Warning: unknown flag --enable-slow-asserts." or |
| 65 string == "Try --help for options") |
| 66 |
| 67 def IsFailureOutput(self, testcase): |
| 68 file_name = os.path.join(self.root, testcase.path) + EXPECTED_SUFFIX |
| 69 with file(file_name, "r") as expected: |
| 70 expected_lines = expected.readlines() |
| 71 |
| 72 def ExpIterator(): |
| 73 for line in expected_lines: |
| 74 if line.startswith("#") or not line.strip(): continue |
| 75 yield line.strip() |
| 76 |
| 77 def ActIterator(lines): |
| 78 for line in lines: |
| 79 if self._IgnoreLine(line.strip()): continue |
| 80 yield line.strip() |
| 81 |
| 82 def ActBlockIterator(): |
| 83 """Iterates over blocks of actual output lines.""" |
| 84 lines = testcase.output.stdout.splitlines() |
| 85 start_index = 0 |
| 86 found_eqeq = False |
| 87 for index, line in enumerate(lines): |
| 88 # If a stress test separator is found: |
| 89 if line.startswith("=="): |
| 90 # Iterate over all lines before a separator except the first. |
| 91 if not found_eqeq: |
| 92 found_eqeq = True |
| 93 else: |
| 94 yield ActIterator(lines[start_index:index]) |
| 95 # The next block of output lines starts after the separator. |
| 96 start_index = index + 1 |
| 97 # Iterate over complete output if no separator was found. |
| 98 if not found_eqeq: |
| 99 yield ActIterator(lines) |
| 100 |
| 101 for act_iterator in ActBlockIterator(): |
| 102 for (expected, actual) in itertools.izip_longest( |
| 103 ExpIterator(), act_iterator, fillvalue=''): |
| 104 if expected != actual: |
| 105 return True |
| 106 return False |
| 107 |
| 108 def GetSuite(name, root): |
| 109 return InspectorProtocolTestSuite(name, root) |
OLD | NEW |