|
| 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 | + |
| 28 | +import test |
| 29 | +import os |
| 30 | +from os.path import join, exists, basename, isdir |
| 31 | +import re |
| 32 | +import utils |
| 33 | + |
| 34 | +FLAGS_PATTERN = re.compile(r"//\s+Flags:(.*)") |
| 35 | + |
| 36 | +class TTYTestCase(test.TestCase): |
| 37 | + |
| 38 | + def __init__(self, path, file, expected, arch, mode, context, config): |
| 39 | + super(TTYTestCase, self).__init__(context, path, arch, mode) |
| 40 | + self.file = file |
| 41 | + self.expected = expected |
| 42 | + self.config = config |
| 43 | + self.arch = arch |
| 44 | + self.mode = mode |
| 45 | + |
| 46 | + def IgnoreLine(self, str): |
| 47 | + """Ignore empty lines and valgrind output.""" |
| 48 | + if not str.strip(): return True |
| 49 | + else: return str.startswith('==') or str.startswith('**') |
| 50 | + |
| 51 | + def IsFailureOutput(self, output): |
| 52 | + f = file(self.expected) |
| 53 | + # Convert output lines to regexps that we can match |
| 54 | + env = { 'basename': basename(self.file) } |
| 55 | + patterns = [ ] |
| 56 | + for line in f: |
| 57 | + if not line.strip(): |
| 58 | + continue |
| 59 | + pattern = re.escape(line.rstrip() % env) |
| 60 | + pattern = pattern.replace('\\*', '.*') |
| 61 | + pattern = '^%s$' % pattern |
| 62 | + patterns.append(pattern) |
| 63 | + # Compare actual output with the expected |
| 64 | + raw_lines = (output.stdout + output.stderr).split('\n') |
| 65 | + outlines = [ s.strip() for s in raw_lines if not self.IgnoreLine(s) ] |
| 66 | + if len(outlines) != len(patterns): |
| 67 | + print "length differs." |
| 68 | + print "expect=%d" % len(patterns) |
| 69 | + print "actual=%d" % len(outlines) |
| 70 | + print "patterns:" |
| 71 | + for i in xrange(len(patterns)): |
| 72 | + print "pattern = %s" % patterns[i] |
| 73 | + print "outlines:" |
| 74 | + for i in xrange(len(outlines)): |
| 75 | + print "outline = %s" % outlines[i] |
| 76 | + return True |
| 77 | + for i in xrange(len(patterns)): |
| 78 | + if not re.match(patterns[i], outlines[i]): |
| 79 | + print "match failed" |
| 80 | + print "line=%d" % i |
| 81 | + print "expect=%s" % patterns[i] |
| 82 | + print "actual=%s" % outlines[i] |
| 83 | + return True |
| 84 | + return False |
| 85 | + |
| 86 | + def GetLabel(self): |
| 87 | + return "%s %s" % (self.mode, self.GetName()) |
| 88 | + |
| 89 | + def GetName(self): |
| 90 | + return self.path[-1] |
| 91 | + |
| 92 | + def GetCommand(self): |
| 93 | + result = [self.config.context.GetVm(self.arch, self.mode)] |
| 94 | + source = open(self.file).read() |
| 95 | + flags_match = FLAGS_PATTERN.search(source) |
| 96 | + if flags_match: |
| 97 | + result += flags_match.group(1).strip().split() |
| 98 | + result.append(self.file) |
| 99 | + return result |
| 100 | + |
| 101 | + def GetSource(self): |
| 102 | + return (open(self.file).read() |
| 103 | + + "\n--- expected output ---\n" |
| 104 | + + open(self.expected).read()) |
| 105 | + |
| 106 | + def RunCommand(self, command, env): |
| 107 | + full_command = self.context.processor(command) |
| 108 | + output = test.Execute(full_command, |
| 109 | + self.context, |
| 110 | + self.context.GetTimeout(self.mode), |
| 111 | + env, |
| 112 | + True) |
| 113 | + self.Cleanup() |
| 114 | + return test.TestOutput(self, |
| 115 | + full_command, |
| 116 | + output, |
| 117 | + self.context.store_unexpected_output) |
| 118 | + |
| 119 | + |
| 120 | +class TTYTestConfiguration(test.TestConfiguration): |
| 121 | + |
| 122 | + def __init__(self, context, root): |
| 123 | + super(TTYTestConfiguration, self).__init__(context, root) |
| 124 | + |
| 125 | + def Ls(self, path): |
| 126 | + if isdir(path): |
| 127 | + return [f[:-3] for f in os.listdir(path) if f.endswith('.js')] |
| 128 | + else: |
| 129 | + return [] |
| 130 | + |
| 131 | + def ListTests(self, current_path, path, arch, mode): |
| 132 | + all_tests = [current_path + [t] for t in self.Ls(self.root)] |
| 133 | + result = [] |
| 134 | + # Skip these tests on Windows, as pseudo terminals are not available |
| 135 | + if utils.IsWindows(): |
| 136 | + print ("Skipping pseudo-tty tests, as pseudo terminals are not available" |
| 137 | + " on Windows.") |
| 138 | + return result |
| 139 | + for test in all_tests: |
| 140 | + if self.Contains(path, test): |
| 141 | + file_prefix = join(self.root, reduce(join, test[1:], "")) |
| 142 | + file_path = file_prefix + ".js" |
| 143 | + output_path = file_prefix + ".out" |
| 144 | + if not exists(output_path): |
| 145 | + print "Could not find %s" % output_path |
| 146 | + continue |
| 147 | + result.append(TTYTestCase(test, file_path, output_path, |
| 148 | + arch, mode, self.context, self)) |
| 149 | + return result |
| 150 | + |
| 151 | + def GetBuildRequirements(self): |
| 152 | + return ['sample', 'sample=shell'] |
| 153 | + |
| 154 | + def GetTestStatus(self, sections, defs): |
| 155 | + status_file = join(self.root, 'message.status') |
| 156 | + if exists(status_file): |
| 157 | + test.ReadConfigurationInto(status_file, sections, defs) |
| 158 | + |
| 159 | + |
| 160 | +def GetConfiguration(context, root): |
| 161 | + return TTYTestConfiguration(context, root) |
0 commit comments