|
| 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 | +importtest |
| 29 | +importos |
| 30 | +fromos.pathimportjoin, exists, basename, isdir |
| 31 | +importre |
| 32 | +importutils |
| 33 | + |
| 34 | +FLAGS_PATTERN=re.compile(r"//\s+Flags:(.*)") |
| 35 | + |
| 36 | +classTTYTestCase(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 | +defIgnoreLine(self, str): |
| 47 | +"""Ignore empty lines and valgrind output.""" |
| 48 | +ifnotstr.strip(): returnTrue |
| 49 | +else: returnstr.startswith('==') orstr.startswith('**') |
| 50 | + |
| 51 | +defIsFailureOutput(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 | +forlineinf: |
| 57 | +ifnotline.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() forsinraw_linesifnotself.IgnoreLine(s) ] |
| 66 | +iflen(outlines) !=len(patterns): |
| 67 | +print"length differs." |
| 68 | +print"expect=%d"%len(patterns) |
| 69 | +print"actual=%d"%len(outlines) |
| 70 | +print"patterns:" |
| 71 | +foriinxrange(len(patterns)): |
| 72 | +print"pattern = %s"%patterns[i] |
| 73 | +print"outlines:" |
| 74 | +foriinxrange(len(outlines)): |
| 75 | +print"outline = %s"%outlines[i] |
| 76 | +returnTrue |
| 77 | +foriinxrange(len(patterns)): |
| 78 | +ifnotre.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 | +returnTrue |
| 84 | +returnFalse |
| 85 | + |
| 86 | +defGetLabel(self): |
| 87 | +return"%s %s"% (self.mode, self.GetName()) |
| 88 | + |
| 89 | +defGetName(self): |
| 90 | +returnself.path[-1] |
| 91 | + |
| 92 | +defGetCommand(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 | +ifflags_match: |
| 97 | +result+=flags_match.group(1).strip().split() |
| 98 | +result.append(self.file) |
| 99 | +returnresult |
| 100 | + |
| 101 | +defGetSource(self): |
| 102 | +return (open(self.file).read() |
| 103 | ++"\n--- expected output ---\n" |
| 104 | ++open(self.expected).read()) |
| 105 | + |
| 106 | +defRunCommand(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 | +returntest.TestOutput(self, |
| 115 | +full_command, |
| 116 | +output, |
| 117 | +self.context.store_unexpected_output) |
| 118 | + |
| 119 | + |
| 120 | +classTTYTestConfiguration(test.TestConfiguration): |
| 121 | + |
| 122 | +def__init__(self, context, root): |
| 123 | +super(TTYTestConfiguration, self).__init__(context, root) |
| 124 | + |
| 125 | +defLs(self, path): |
| 126 | +ifisdir(path): |
| 127 | +return [f[:-3] forfinos.listdir(path) iff.endswith('.js')] |
| 128 | +else: |
| 129 | +return [] |
| 130 | + |
| 131 | +defListTests(self, current_path, path, arch, mode): |
| 132 | +all_tests= [current_path+ [t] fortinself.Ls(self.root)] |
| 133 | +result= [] |
| 134 | +# Skip these tests on Windows, as pseudo terminals are not available |
| 135 | +ifutils.IsWindows(): |
| 136 | +print ("Skipping pseudo-tty tests, as pseudo terminals are not available" |
| 137 | +" on Windows.") |
| 138 | +returnresult |
| 139 | +fortestinall_tests: |
| 140 | +ifself.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 | +ifnotexists(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 | +returnresult |
| 150 | + |
| 151 | +defGetBuildRequirements(self): |
| 152 | +return ['sample', 'sample=shell'] |
| 153 | + |
| 154 | +defGetTestStatus(self, sections, defs): |
| 155 | +status_file=join(self.root, 'message.status') |
| 156 | +ifexists(status_file): |
| 157 | +test.ReadConfigurationInto(status_file, sections, defs) |
| 158 | + |
| 159 | + |
| 160 | +defGetConfiguration(context, root): |
| 161 | +returnTTYTestConfiguration(context, root) |
0 commit comments