Changeset 77431 in webkit
- Timestamp:
- Feb 2, 2011 4:33:29 PM (13 years ago)
- Location:
- trunk/Tools
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Tools/ChangeLog
r77415 r77431 1 2011-02-02 Dirk Pranke <dpranke@chromium.org> 2 3 Reviewed by Tony Chang. 4 5 new-run-webkit-tests: support chromium code paths in mock_drt 6 7 https://bugs.webkit.org/show_bug.cgi?id=53471 8 9 * Scripts/webkitpy/layout_tests/port/mock_drt.py: 10 * Scripts/webkitpy/layout_tests/port/mock_drt_unittest.py: 11 1 12 2011-02-02 Adam Klein <adamk@chromium.org> 2 13 -
trunk/Tools/Scripts/webkitpy/layout_tests/port/mock_drt.py
r76982 r77431 38 38 import sys 39 39 40 from webkitpy.common.system import filesystem 41 40 42 from webkitpy.layout_tests.port import base 41 43 from webkitpy.layout_tests.port import factory … … 82 84 # in place of the actual path to the driver binary. 83 85 84 # FIXME: This doesn't yet work for Chromium test_shell ports.85 86 def overriding_cmd_line(): 86 87 cmd = self.__original_driver_cmd_line() … … 114 115 115 116 116 def main(argv, stdin, stdout, stderr):117 def main(argv, fs, stdin, stdout, stderr): 117 118 """Run the tests.""" 118 119 119 120 options, args = parse_options(argv) 120 drt = MockDRT(options, args, stdin, stdout, stderr) 121 if options.chromium: 122 drt = MockChromiumDRT(options, args, fs, stdin, stdout, stderr) 123 else: 124 drt = MockDRT(options, args, fs, stdin, stdout, stderr) 121 125 return drt.run() 122 126 123 127 124 128 def parse_options(argv): 125 # FIXME: We need to figure out how to handle variants that have 126 # different command-line conventions. 127 option_list = [ 128 optparse.make_option('--platform', action='store', 129 help='platform to emulate'), 130 optparse.make_option('--layout-tests', action='store_true', 131 default=True, help='run layout tests'), 132 optparse.make_option('--pixel-tests', action='store_true', 133 default=False, 134 help='output image for pixel tests'), 135 ] 136 option_parser = optparse.OptionParser(option_list=option_list) 137 return option_parser.parse_args(argv) 129 # FIXME: We have to do custom arg parsing instead of using the optparse 130 # module. First, Chromium and non-Chromium DRTs have a different argument 131 # syntax. Chromium uses --pixel-tests=<path>, and non-Chromium uses 132 # --pixel-tests as a boolean flag. Second, we don't want to have to list 133 # every command line flag DRT accepts, but optparse complains about 134 # unrecognized flags. At some point it might be good to share a common 135 # DRT options class between this file and webkit.py and chromium.py 136 # just to get better type checking. 137 platform_index = argv.index('--platform') 138 platform = argv[platform_index + 1] 139 140 pixel_tests = False 141 pixel_path = None 142 chromium = False 143 if platform.startswith('chromium'): 144 chromium = True 145 for arg in argv: 146 if arg.startswith('--pixel-tests'): 147 pixel_tests = True 148 pixel_path = arg[len('--pixel-tests='):] 149 else: 150 pixel_tests = '--pixel-tests' in argv 151 options = base.DummyOptions(chromium=chromium, 152 platform=platform, 153 pixel_tests=pixel_tests, 154 pixel_path=pixel_path) 155 return (options, []) 156 157 158 # FIXME: Should probably change this to use DriverInput after 159 # https://bugs.webkit.org/show_bug.cgi?id=53004 lands. 160 class _DRTInput(object): 161 def __init__(self, line): 162 vals = line.strip().split("'") 163 if len(vals) == 1: 164 self.uri = vals[0] 165 self.checksum = None 166 else: 167 self.uri = vals[0] 168 self.checksum = vals[1] 138 169 139 170 140 171 class MockDRT(object): 141 def __init__(self, options, args, stdin, stdout, stderr):172 def __init__(self, options, args, filesystem, stdin, stdout, stderr): 142 173 self._options = options 143 174 self._args = args 175 self._filesystem = filesystem 144 176 self._stdout = stdout 145 177 self._stdin = stdin … … 149 181 if options.platform: 150 182 port_name = options.platform 151 self._port = factory.get(port_name, options=options )183 self._port = factory.get(port_name, options=options, filesystem=filesystem) 152 184 153 185 def run(self): … … 156 188 if not line: 157 189 break 158 159 url, expected_checksum = self.parse_input(line) 160 self.run_one_test(url, expected_checksum) 190 self.run_one_test(self.parse_input(line)) 161 191 return 0 162 192 163 193 def parse_input(self, line): 164 line = line.strip() 165 if "'" in line: 166 return line.split("'", 1) 167 return (line, None) 168 169 def raw_bytes(self, unicode_str): 170 return unicode_str.encode('utf-8') 171 172 def run_one_test(self, url, expected_checksum): 194 return _DRTInput(line) 195 196 def run_one_test(self, test_input): 173 197 port = self._port 174 if url.startswith('http'):175 test_name = port.uri_to_test_name( url)176 test_path = port._filesystem.join(port.layout_tests_dir(), test_name)198 if test_input.uri.startswith('http'): 199 test_name = port.uri_to_test_name(test_input.uri) 200 test_path = self._filesystem.join(port.layout_tests_dir(), test_name) 177 201 else: 178 test_path = url179 180 actual_text _bytes = self.raw_bytes(port.expected_text(test_path))181 if self._options.pixel_tests and expected_checksum:182 actual_checksum _bytes = self.raw_bytes(port.expected_checksum(test_path))183 actual_image _bytes= port.expected_image(test_path)202 test_path = test_input.uri 203 204 actual_text = port.expected_text(test_path) 205 if self._options.pixel_tests and test_input.checksum: 206 actual_checksum = port.expected_checksum(test_path) 207 actual_image = port.expected_image(test_path) 184 208 185 209 self._stdout.write('Content-Type: text/plain\n') 186 self._stdout.write(actual_text_bytes) 210 211 # FIXME: Note that we don't ensure there is a trailing newline! 212 # This mirrors actual (Mac) DRT behavior but is a bug. 213 self._stdout.write(actual_text) 187 214 self._stdout.write('#EOF\n') 188 215 189 if self._options.pixel_tests and expected_checksum: 190 expected_checksum_bytes = self.raw_bytes(expected_checksum) 216 if self._options.pixel_tests and test_input.checksum: 191 217 self._stdout.write('\n') 192 self._stdout.write('ActualHash: %s\n' % actual_checksum _bytes)193 self._stdout.write('ExpectedHash: %s\n' % expected_checksum_bytes)194 if actual_checksum _bytes != expected_checksum_bytes:218 self._stdout.write('ActualHash: %s\n' % actual_checksum) 219 self._stdout.write('ExpectedHash: %s\n' % test_input.checksum) 220 if actual_checksum != test_input.checksum: 195 221 self._stdout.write('Content-Type: image/png\n') 196 self._stdout.write('Content-Length: %s\n\n' % len(actual_image _bytes))197 self._stdout.write(actual_image _bytes)222 self._stdout.write('Content-Length: %s\n\n' % len(actual_image)) 223 self._stdout.write(actual_image) 198 224 self._stdout.write('#EOF\n') 199 225 self._stdout.flush() … … 201 227 202 228 229 # FIXME: Should probably change this to use DriverInput after 230 # https://bugs.webkit.org/show_bug.cgi?id=53004 lands. 231 class _ChromiumDRTInput(_DRTInput): 232 def __init__(self, line): 233 vals = line.strip().split() 234 if len(vals) == 3: 235 self.uri, self.timeout, self.checksum = vals 236 else: 237 self.uri = vals[0] 238 self.timeout = vals[1] 239 self.checksum = None 240 241 242 class MockChromiumDRT(MockDRT): 243 def parse_input(self, line): 244 return _ChromiumDRTInput(line) 245 246 def run_one_test(self, test_input): 247 port = self._port 248 test_name = self._port.uri_to_test_name(test_input.uri) 249 test_path = self._filesystem.join(port.layout_tests_dir(), test_name) 250 251 actual_text = port.expected_text(test_path) 252 actual_image = '' 253 actual_checksum = '' 254 if self._options.pixel_tests and test_input.checksum: 255 actual_checksum = port.expected_checksum(test_path) 256 if actual_checksum != test_input.checksum: 257 actual_image = port.expected_image(test_path) 258 259 self._stdout.write("#URL:%s\n" % test_input.uri) 260 if self._options.pixel_tests and test_input.checksum: 261 self._stdout.write("#MD5:%s\n" % actual_checksum) 262 self._filesystem.write_binary_file(self._options.pixel_path, 263 actual_image) 264 self._stdout.write(actual_text) 265 266 # FIXME: (See above FIXME as well). Chromium DRT appears to always 267 # ensure the text output has a trailing newline. Mac DRT does not. 268 if not actual_text.endswith('\n'): 269 self._stdout.write('\n') 270 self._stdout.write('#EOF\n') 271 self._stdout.flush() 272 273 274 203 275 if __name__ == '__main__': 204 sys.exit(main(sys.argv[1:], sys.stdin, sys.stdout, sys.stderr)) 276 fs = filesystem.FileSystem() 277 sys.exit(main(sys.argv[1:], fs, sys.stdin, sys.stdout, sys.stderr)) -
trunk/Tools/Scripts/webkitpy/layout_tests/port/mock_drt_unittest.py
r77023 r77431 37 37 from webkitpy.layout_tests.port import factory 38 38 from webkitpy.layout_tests.port import port_testcase 39 from webkitpy.layout_tests.port import test 39 40 40 41 … … 88 89 89 90 class MockDRTTest(unittest.TestCase): 90 def setUp(self): 91 self._port = factory.get('test') 92 self._layout_tests_dir = self._port.layout_tests_dir() 93 94 def to_path(self, test_name): 95 return self._port._filesystem.join(self._layout_tests_dir, test_name) 96 97 def input_line(self, test_name, checksum=None): 98 url = self._port.filename_to_uri(self.to_path(test_name)) 91 def to_path(self, port, test_name): 92 return port._filesystem.join(port.layout_tests_dir(), test_name) 93 94 def input_line(self, port, test_name, checksum=None): 95 url = port.filename_to_uri(self.to_path(port, test_name)) 99 96 # FIXME: we shouldn't have to work around platform-specific issues 100 97 # here. … … 108 105 return url + '\n' 109 106 110 def make_drt(self, input_string, extra_args=None): 111 args = ['--platform', 'test', '-'] 112 extra_args = extra_args or [] 113 args += extra_args 114 stdin = newstringio.StringIO(input_string) 107 def extra_args(self, pixel_tests): 108 if pixel_tests: 109 return ['--pixel-tests', '-'] 110 return ['-'] 111 112 def make_drt(self, options, args, filesystem, stdin, stdout, stderr): 113 return mock_drt.MockDRT(options, args, filesystem, stdin, stdout, stderr) 114 115 def make_input_output(self, port, test_name, pixel_tests, 116 expected_checksum, drt_output, drt_input=None): 117 path = self.to_path(port, test_name) 118 if pixel_tests: 119 if not expected_checksum: 120 expected_checksum = port.expected_checksum(path) 121 if not drt_input: 122 drt_input = self.input_line(port, test_name, expected_checksum) 123 text_output = port.expected_text(path) 124 125 if not drt_output: 126 drt_output = self.expected_output(port, test_name, pixel_tests, 127 text_output, expected_checksum) 128 return (drt_input, drt_output) 129 130 def expected_output(self, port, test_name, pixel_tests, text_output, expected_checksum): 131 if pixel_tests and expected_checksum: 132 return ['Content-Type: text/plain\n', 133 text_output, 134 '#EOF\n', 135 '\n', 136 'ActualHash: %s\n' % expected_checksum, 137 'ExpectedHash: %s\n' % expected_checksum, 138 '#EOF\n'] 139 else: 140 return ['Content-Type: text/plain\n', 141 text_output, 142 '#EOF\n', 143 '#EOF\n'] 144 145 def assertTest(self, test_name, pixel_tests, expected_checksum=None, 146 drt_output=None, filesystem=None): 147 platform = 'test' 148 filesystem = filesystem or test.unit_test_filesystem() 149 port = factory.get(platform, filesystem=filesystem) 150 drt_input, drt_output = self.make_input_output(port, test_name, 151 pixel_tests, expected_checksum, drt_output) 152 153 args = ['--platform', 'test'] + self.extra_args(pixel_tests) 154 stdin = newstringio.StringIO(drt_input) 115 155 stdout = newstringio.StringIO() 116 156 stderr = newstringio.StringIO() 117 157 options, args = mock_drt.parse_options(args) 118 drt = mock_drt.MockDRT(options, args, stdin, stdout, stderr) 119 return (drt, stdout, stderr) 120 121 def make_input_output(self, test_name, pixel_tests, expected_checksum, 122 drt_output, drt_input=None): 123 path = self.to_path(test_name) 124 if pixel_tests: 125 if not expected_checksum: 126 expected_checksum = self._port.expected_checksum(path) 127 if not drt_input: 128 drt_input = self.input_line(test_name, expected_checksum) 129 text_output = self._port.expected_text(path) 130 131 if not drt_output: 132 if pixel_tests: 133 drt_output = [ 134 'Content-Type: text/plain\n', 135 text_output.encode('utf-8'), 136 '#EOF\n', 137 '\n', 138 'ActualHash: %s\n' % expected_checksum.encode('utf-8'), 139 'ExpectedHash: %s\n' % expected_checksum.encode('utf-8'), 140 '#EOF\n'] 141 else: 142 drt_output = [ 143 'Content-Type: text/plain\n', 144 text_output.encode('utf-8'), 145 '#EOF\n', 146 '#EOF\n'] 147 148 return (drt_input, drt_output) 149 150 def assertTest(self, test_name, pixel_tests, expected_checksum=None, drt_output=None): 151 drt_input, drt_output = self.make_input_output(test_name, pixel_tests, 152 expected_checksum, drt_output) 153 extra_args = [] 154 if pixel_tests: 155 extra_args = ['--pixel-tests'] 156 drt, stdout, stderr = self.make_drt(drt_input, extra_args) 158 159 drt = self.make_drt(options, args, filesystem, stdin, stdout, stderr) 157 160 res = drt.run() 161 158 162 self.assertEqual(res, 0) 159 163 … … 164 168 165 169 def test_main(self): 170 filesystem = test.unit_test_filesystem() 166 171 stdin = newstringio.StringIO() 167 172 stdout = newstringio.StringIO() 168 173 stderr = newstringio.StringIO() 169 res = mock_drt.main(['--platform', 'test', '-'], stdin, stdout, stderr) 174 res = mock_drt.main(['--platform', 'test'] + self.extra_args(False), 175 filesystem, stdin, stdout, stderr) 170 176 self.assertEqual(res, 0) 171 177 self.assertEqual(stdout.getvalue(), '') 172 178 self.assertEqual(stderr.getvalue(), '') 179 self.assertEqual(filesystem.written_files, {}) 173 180 174 181 def test_pixeltest_passes(self): … … 194 201 195 202 203 class MockChromiumDRTTest(MockDRTTest): 204 def extra_args(self, pixel_tests): 205 if pixel_tests: 206 return ['--pixel-tests=/tmp/png_result0.png'] 207 return [] 208 209 def make_drt(self, options, args, filesystem, stdin, stdout, stderr): 210 options.chromium = True 211 212 # We have to set these by hand because --platform test won't trigger 213 # the Chromium code paths. 214 options.pixel_path = '/tmp/png_result0.png' 215 options.pixel_tests = True 216 217 return mock_drt.MockChromiumDRT(options, args, filesystem, stdin, stdout, stderr) 218 219 def input_line(self, port, test_name, checksum=None): 220 url = port.filename_to_uri(self.to_path(port, test_name)) 221 if checksum: 222 return url + ' 6000 ' + checksum + '\n' 223 return url + ' 6000\n' 224 225 def expected_output(self, port, test_name, pixel_tests, text_output, expected_checksum): 226 url = port.filename_to_uri(self.to_path(port, test_name)) 227 if pixel_tests and expected_checksum: 228 return ['#URL:%s\n' % url, 229 '#MD5:%s\n' % expected_checksum, 230 text_output, 231 '\n', 232 '#EOF\n'] 233 else: 234 return ['#URL:%s\n' % url, 235 text_output, 236 '\n', 237 '#EOF\n'] 238 239 def test_pixeltest__fails(self): 240 filesystem = test.unit_test_filesystem() 241 self.assertTest('failures/expected/checksum.html', pixel_tests=True, 242 expected_checksum='wrong-checksum', 243 drt_output=['#URL:file:///test.checkout/LayoutTests/failures/expected/checksum.html\n', 244 '#MD5:checksum-checksum\n', 245 'checksum-txt', 246 '\n', 247 '#EOF\n'], 248 filesystem=filesystem) 249 self.assertEquals(filesystem.written_files, 250 {'/tmp/png_result0.png': 'checksum\x8a-png'}) 251 252 def test_chromium_parse_options(self): 253 options, args = mock_drt.parse_options(['--platform', 'chromium-mac', 254 '--pixel-tests=/tmp/png_result0.png']) 255 self.assertTrue(options.chromium) 256 self.assertTrue(options.pixel_tests) 257 self.assertEquals(options.pixel_path, '/tmp/png_result0.png') 258 259 196 260 if __name__ == '__main__': 197 261 unittest.main()
Note: See TracChangeset
for help on using the changeset viewer.