driver.py 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566
  1. # Copyright (C) 2011 Google Inc. All rights reserved.
  2. #
  3. # Redistribution and use in source and binary forms, with or without
  4. # modification, are permitted provided that the following conditions are
  5. # met:
  6. #
  7. # * Redistributions of source code must retain the above copyright
  8. # notice, this list of conditions and the following disclaimer.
  9. # * Redistributions in binary form must reproduce the above
  10. # copyright notice, this list of conditions and the following disclaimer
  11. # in the documentation and/or other materials provided with the
  12. # distribution.
  13. # * Neither the Google name nor the names of its
  14. # contributors may be used to endorse or promote products derived from
  15. # this software without specific prior written permission.
  16. #
  17. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  18. # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  19. # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  20. # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  21. # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  22. # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  23. # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  24. # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  25. # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  27. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. import base64
  29. import copy
  30. import logging
  31. import re
  32. import shlex
  33. import sys
  34. import time
  35. import os
  36. from webkitpy.common.system import path
  37. from webkitpy.common.system.profiler import ProfilerFactory
  38. _log = logging.getLogger(__name__)
  39. class DriverInput(object):
  40. def __init__(self, test_name, timeout, image_hash, should_run_pixel_test, args=None):
  41. self.test_name = test_name
  42. self.timeout = timeout # in ms
  43. self.image_hash = image_hash
  44. self.should_run_pixel_test = should_run_pixel_test
  45. self.args = args or []
  46. class DriverOutput(object):
  47. """Groups information about a output from driver for easy passing
  48. and post-processing of data."""
  49. strip_patterns = []
  50. strip_patterns.append((re.compile('at \(-?[0-9]+,-?[0-9]+\) *'), ''))
  51. strip_patterns.append((re.compile('size -?[0-9]+x-?[0-9]+ *'), ''))
  52. strip_patterns.append((re.compile('text run width -?[0-9]+: '), ''))
  53. strip_patterns.append((re.compile('text run width -?[0-9]+ [a-zA-Z ]+: '), ''))
  54. strip_patterns.append((re.compile('RenderButton {BUTTON} .*'), 'RenderButton {BUTTON}'))
  55. strip_patterns.append((re.compile('RenderImage {INPUT} .*'), 'RenderImage {INPUT}'))
  56. strip_patterns.append((re.compile('RenderBlock {INPUT} .*'), 'RenderBlock {INPUT}'))
  57. strip_patterns.append((re.compile('RenderTextControl {INPUT} .*'), 'RenderTextControl {INPUT}'))
  58. strip_patterns.append((re.compile('\([0-9]+px'), 'px'))
  59. strip_patterns.append((re.compile(' *" *\n +" *'), ' '))
  60. strip_patterns.append((re.compile('" +$'), '"'))
  61. strip_patterns.append((re.compile('- '), '-'))
  62. strip_patterns.append((re.compile('\n( *)"\s+'), '\n\g<1>"'))
  63. strip_patterns.append((re.compile('\s+"\n'), '"\n'))
  64. strip_patterns.append((re.compile('scrollWidth [0-9]+'), 'scrollWidth'))
  65. strip_patterns.append((re.compile('scrollHeight [0-9]+'), 'scrollHeight'))
  66. strip_patterns.append((re.compile('scrollX [0-9]+'), 'scrollX'))
  67. strip_patterns.append((re.compile('scrollY [0-9]+'), 'scrollY'))
  68. strip_patterns.append((re.compile('scrolled to [0-9]+,[0-9]+'), 'scrolled'))
  69. def __init__(self, text, image, image_hash, audio, crash=False,
  70. test_time=0, measurements=None, timeout=False, error='', crashed_process_name='??',
  71. crashed_pid=None, crash_log=None, pid=None):
  72. # FIXME: Args could be renamed to better clarify what they do.
  73. self.text = text
  74. self.image = image # May be empty-string if the test crashes.
  75. self.image_hash = image_hash
  76. self.image_diff = None # image_diff gets filled in after construction.
  77. self.audio = audio # Binary format is port-dependent.
  78. self.crash = crash
  79. self.crashed_process_name = crashed_process_name
  80. self.crashed_pid = crashed_pid
  81. self.crash_log = crash_log
  82. self.test_time = test_time
  83. self.measurements = measurements
  84. self.timeout = timeout
  85. self.error = error # stderr output
  86. self.pid = pid
  87. def has_stderr(self):
  88. return bool(self.error)
  89. def strip_metrics(self):
  90. if not self.text:
  91. return
  92. for pattern in self.strip_patterns:
  93. self.text = re.sub(pattern[0], pattern[1], self.text)
  94. class Driver(object):
  95. """object for running test(s) using DumpRenderTree/WebKitTestRunner."""
  96. def __init__(self, port, worker_number, pixel_tests, no_timeout=False):
  97. """Initialize a Driver to subsequently run tests.
  98. Typically this routine will spawn DumpRenderTree in a config
  99. ready for subsequent input.
  100. port - reference back to the port object.
  101. worker_number - identifier for a particular worker/driver instance
  102. """
  103. self._port = port
  104. self._worker_number = worker_number
  105. self._no_timeout = no_timeout
  106. self._driver_tempdir = None
  107. # WebKitTestRunner can report back subprocess crashes by printing
  108. # "#CRASHED - PROCESSNAME". Since those can happen at any time
  109. # and ServerProcess won't be aware of them (since the actual tool
  110. # didn't crash, just a subprocess) we record the crashed subprocess name here.
  111. self._crashed_process_name = None
  112. self._crashed_pid = None
  113. # WebKitTestRunner can report back subprocesses that became unresponsive
  114. # This could mean they crashed.
  115. self._subprocess_was_unresponsive = False
  116. # stderr reading is scoped on a per-test (not per-block) basis, so we store the accumulated
  117. # stderr output, as well as if we've seen #EOF on this driver instance.
  118. # FIXME: We should probably remove _read_first_block and _read_optional_image_block and
  119. # instead scope these locally in run_test.
  120. self.error_from_test = str()
  121. self.err_seen_eof = False
  122. self._server_process = None
  123. self._measurements = {}
  124. if self._port.get_option("profile"):
  125. profiler_name = self._port.get_option("profiler")
  126. self._profiler = ProfilerFactory.create_profiler(self._port.host,
  127. self._port._path_to_driver(), self._port.results_directory(), profiler_name)
  128. else:
  129. self._profiler = None
  130. def __del__(self):
  131. self.stop()
  132. def run_test(self, driver_input, stop_when_done):
  133. """Run a single test and return the results.
  134. Note that it is okay if a test times out or crashes and leaves
  135. the driver in an indeterminate state. The upper layers of the program
  136. are responsible for cleaning up and ensuring things are okay.
  137. Returns a DriverOutput object.
  138. """
  139. start_time = time.time()
  140. self.start(driver_input.should_run_pixel_test, driver_input.args)
  141. test_begin_time = time.time()
  142. self.error_from_test = str()
  143. self.err_seen_eof = False
  144. command = self._command_from_driver_input(driver_input)
  145. deadline = test_begin_time + int(driver_input.timeout) / 1000.0
  146. self._server_process.write(command)
  147. text, audio = self._read_first_block(deadline) # First block is either text or audio
  148. image, actual_image_hash = self._read_optional_image_block(deadline) # The second (optional) block is image data.
  149. crashed = self.has_crashed()
  150. timed_out = self._server_process.timed_out
  151. pid = self._server_process.pid()
  152. if stop_when_done or crashed or timed_out:
  153. # We call stop() even if we crashed or timed out in order to get any remaining stdout/stderr output.
  154. # In the timeout case, we kill the hung process as well.
  155. out, err = self._server_process.stop(self._port.driver_stop_timeout() if stop_when_done else 0.0)
  156. if out:
  157. text += out
  158. if err:
  159. self.error_from_test += err
  160. self._server_process = None
  161. crash_log = None
  162. if crashed:
  163. self.error_from_test, crash_log = self._get_crash_log(text, self.error_from_test, newer_than=start_time)
  164. # If we don't find a crash log use a placeholder error message instead.
  165. if not crash_log:
  166. pid_str = str(self._crashed_pid) if self._crashed_pid else "unknown pid"
  167. crash_log = 'No crash log found for %s:%s.\n' % (self._crashed_process_name, pid_str)
  168. # If we were unresponsive append a message informing there may not have been a crash.
  169. if self._subprocess_was_unresponsive:
  170. crash_log += 'Process failed to become responsive before timing out.\n'
  171. # Print stdout and stderr to the placeholder crash log; we want as much context as possible.
  172. if self.error_from_test:
  173. crash_log += '\nstdout:\n%s\nstderr:\n%s\n' % (text, self.error_from_test)
  174. return DriverOutput(text, image, actual_image_hash, audio,
  175. crash=crashed, test_time=time.time() - test_begin_time, measurements=self._measurements,
  176. timeout=timed_out, error=self.error_from_test,
  177. crashed_process_name=self._crashed_process_name,
  178. crashed_pid=self._crashed_pid, crash_log=crash_log, pid=pid)
  179. def _get_crash_log(self, stdout, stderr, newer_than):
  180. return self._port._get_crash_log(self._crashed_process_name, self._crashed_pid, stdout, stderr, newer_than)
  181. # FIXME: Seems this could just be inlined into callers.
  182. @classmethod
  183. def _command_wrapper(cls, wrapper_option):
  184. # Hook for injecting valgrind or other runtime instrumentation,
  185. # used by e.g. tools/valgrind/valgrind_tests.py.
  186. return shlex.split(wrapper_option) if wrapper_option else []
  187. HTTP_DIR = "http/tests/"
  188. HTTP_LOCAL_DIR = "http/tests/local/"
  189. def is_http_test(self, test_name):
  190. return test_name.startswith(self.HTTP_DIR) and not test_name.startswith(self.HTTP_LOCAL_DIR)
  191. def test_to_uri(self, test_name):
  192. """Convert a test name to a URI."""
  193. if not self.is_http_test(test_name):
  194. return path.abspath_to_uri(self._port.host.platform, self._port.abspath_for_test(test_name))
  195. relative_path = test_name[len(self.HTTP_DIR):]
  196. # TODO(dpranke): remove the SSL reference?
  197. if relative_path.startswith("ssl/"):
  198. return "https://127.0.0.1:8443/" + relative_path
  199. return "http://127.0.0.1:8000/" + relative_path
  200. def uri_to_test(self, uri):
  201. """Return the base layout test name for a given URI.
  202. This returns the test name for a given URI, e.g., if you passed in
  203. "file:///src/LayoutTests/fast/html/keygen.html" it would return
  204. "fast/html/keygen.html".
  205. """
  206. if uri.startswith("file:///"):
  207. prefix = path.abspath_to_uri(self._port.host.platform, self._port.layout_tests_dir())
  208. if not prefix.endswith('/'):
  209. prefix += '/'
  210. return uri[len(prefix):]
  211. if uri.startswith("http://"):
  212. return uri.replace('http://127.0.0.1:8000/', self.HTTP_DIR)
  213. if uri.startswith("https://"):
  214. return uri.replace('https://127.0.0.1:8443/', self.HTTP_DIR)
  215. raise NotImplementedError('unknown url type: %s' % uri)
  216. def has_crashed(self):
  217. if self._server_process is None:
  218. return False
  219. if self._crashed_process_name:
  220. return True
  221. if self._server_process.has_crashed():
  222. self._crashed_process_name = self._server_process.name()
  223. self._crashed_pid = self._server_process.pid()
  224. return True
  225. return False
  226. def start(self, pixel_tests, per_test_args):
  227. # FIXME: Callers shouldn't normally call this, since this routine
  228. # may not be specifying the correct combination of pixel test and
  229. # per_test args.
  230. #
  231. # The only reason we have this routine at all is so the perftestrunner
  232. # can pause before running a test; it might be better to push that
  233. # into run_test() directly.
  234. if not self._server_process:
  235. self._start(pixel_tests, per_test_args)
  236. self._run_post_start_tasks()
  237. def _setup_environ_for_driver(self, environment):
  238. environment['DYLD_LIBRARY_PATH'] = self._port._build_path()
  239. environment['DYLD_FRAMEWORK_PATH'] = self._port._build_path()
  240. # FIXME: We're assuming that WebKitTestRunner checks this DumpRenderTree-named environment variable.
  241. # FIXME: Commented out for now to avoid tests breaking. Re-enable after
  242. # we cut over to NRWT
  243. #environment['DUMPRENDERTREE_TEMP'] = str(self._port._driver_tempdir_for_environment())
  244. environment['DUMPRENDERTREE_TEMP'] = str(self._driver_tempdir)
  245. environment['LOCAL_RESOURCE_ROOT'] = self._port.layout_tests_dir()
  246. if 'WEBKITOUTPUTDIR' in os.environ:
  247. environment['WEBKITOUTPUTDIR'] = os.environ['WEBKITOUTPUTDIR']
  248. if self._profiler:
  249. environment = self._profiler.adjusted_environment(environment)
  250. return environment
  251. def _start(self, pixel_tests, per_test_args):
  252. self.stop()
  253. self._driver_tempdir = self._port._driver_tempdir()
  254. server_name = self._port.driver_name()
  255. environment = self._port.setup_environ_for_server(server_name)
  256. environment = self._setup_environ_for_driver(environment)
  257. self._crashed_process_name = None
  258. self._crashed_pid = None
  259. self._server_process = self._port._server_process_constructor(self._port, server_name, self.cmd_line(pixel_tests, per_test_args), environment)
  260. self._server_process.start()
  261. def _run_post_start_tasks(self):
  262. # Remote drivers may override this to delay post-start tasks until the server has ack'd.
  263. if self._profiler:
  264. self._profiler.attach_to_pid(self._pid_on_target())
  265. def _pid_on_target(self):
  266. # Remote drivers will override this method to return the pid on the device.
  267. return self._server_process.pid()
  268. def stop(self):
  269. if self._server_process:
  270. self._server_process.stop(self._port.driver_stop_timeout())
  271. self._server_process = None
  272. if self._profiler:
  273. self._profiler.profile_after_exit()
  274. if self._driver_tempdir:
  275. self._port._filesystem.rmtree(str(self._driver_tempdir))
  276. self._driver_tempdir = None
  277. def cmd_line(self, pixel_tests, per_test_args):
  278. cmd = self._command_wrapper(self._port.get_option('wrapper'))
  279. cmd.append(self._port._path_to_driver())
  280. if self._port.get_option('gc_between_tests'):
  281. cmd.append('--gc-between-tests')
  282. if self._port.get_option('complex_text'):
  283. cmd.append('--complex-text')
  284. if self._port.get_option('threaded'):
  285. cmd.append('--threaded')
  286. if self._no_timeout:
  287. cmd.append('--no-timeout')
  288. # FIXME: We need to pass --timeout=SECONDS to WebKitTestRunner for WebKit2.
  289. cmd.extend(self._port.get_option('additional_drt_flag', []))
  290. cmd.extend(self._port.additional_drt_flag())
  291. cmd.extend(per_test_args)
  292. cmd.append('-')
  293. return cmd
  294. def _check_for_driver_crash(self, error_line):
  295. if error_line == "#CRASHED\n":
  296. # This is used on Windows to report that the process has crashed
  297. # See http://trac.webkit.org/changeset/65537.
  298. self._crashed_process_name = self._server_process.name()
  299. self._crashed_pid = self._server_process.pid()
  300. elif (error_line.startswith("#CRASHED - ")
  301. or error_line.startswith("#PROCESS UNRESPONSIVE - ")):
  302. # WebKitTestRunner uses this to report that the WebProcess subprocess crashed.
  303. match = re.match('#(?:CRASHED|PROCESS UNRESPONSIVE) - (\S+)', error_line)
  304. self._crashed_process_name = match.group(1) if match else 'WebProcess'
  305. match = re.search('pid (\d+)', error_line)
  306. pid = int(match.group(1)) if match else None
  307. self._crashed_pid = pid
  308. # FIXME: delete this after we're sure this code is working :)
  309. _log.debug('%s crash, pid = %s, error_line = %s' % (self._crashed_process_name, str(pid), error_line))
  310. if error_line.startswith("#PROCESS UNRESPONSIVE - "):
  311. self._subprocess_was_unresponsive = True
  312. self._port.sample_process(self._crashed_process_name, self._crashed_pid)
  313. # We want to show this since it's not a regular crash and probably we don't have a crash log.
  314. self.error_from_test += error_line
  315. return True
  316. return self.has_crashed()
  317. def _command_from_driver_input(self, driver_input):
  318. # FIXME: performance tests pass in full URLs instead of test names.
  319. if driver_input.test_name.startswith('http://') or driver_input.test_name.startswith('https://') or driver_input.test_name == ('about:blank'):
  320. command = driver_input.test_name
  321. elif self.is_http_test(driver_input.test_name):
  322. command = self.test_to_uri(driver_input.test_name)
  323. else:
  324. command = self._port.abspath_for_test(driver_input.test_name)
  325. if sys.platform == 'cygwin':
  326. command = path.cygpath(command)
  327. assert not driver_input.image_hash or driver_input.should_run_pixel_test
  328. # ' is the separator between arguments.
  329. if self._port.supports_per_test_timeout():
  330. command += "'--timeout'%s" % driver_input.timeout
  331. if driver_input.should_run_pixel_test:
  332. command += "'--pixel-test"
  333. if driver_input.image_hash:
  334. command += "'" + driver_input.image_hash
  335. return command + "\n"
  336. def _read_first_block(self, deadline):
  337. # returns (text_content, audio_content)
  338. block = self._read_block(deadline)
  339. if block.malloc:
  340. self._measurements['Malloc'] = float(block.malloc)
  341. if block.js_heap:
  342. self._measurements['JSHeap'] = float(block.js_heap)
  343. if block.content_type == 'audio/wav':
  344. return (None, block.decoded_content)
  345. return (block.decoded_content, None)
  346. def _read_optional_image_block(self, deadline):
  347. # returns (image, actual_image_hash)
  348. block = self._read_block(deadline, wait_for_stderr_eof=True)
  349. if block.content and block.content_type == 'image/png':
  350. return (block.decoded_content, block.content_hash)
  351. return (None, block.content_hash)
  352. def _read_header(self, block, line, header_text, header_attr, header_filter=None):
  353. if line.startswith(header_text) and getattr(block, header_attr) is None:
  354. value = line.split()[1]
  355. if header_filter:
  356. value = header_filter(value)
  357. setattr(block, header_attr, value)
  358. return True
  359. return False
  360. def _process_stdout_line(self, block, line):
  361. if (self._read_header(block, line, 'Content-Type: ', 'content_type')
  362. or self._read_header(block, line, 'Content-Transfer-Encoding: ', 'encoding')
  363. or self._read_header(block, line, 'Content-Length: ', '_content_length', int)
  364. or self._read_header(block, line, 'ActualHash: ', 'content_hash')
  365. or self._read_header(block, line, 'DumpMalloc: ', 'malloc')
  366. or self._read_header(block, line, 'DumpJSHeap: ', 'js_heap')):
  367. return
  368. # Note, we're not reading ExpectedHash: here, but we could.
  369. # If the line wasn't a header, we just append it to the content.
  370. block.content += line
  371. def _strip_eof(self, line):
  372. if line and line.endswith("#EOF\n"):
  373. return line[:-5], True
  374. return line, False
  375. def _read_block(self, deadline, wait_for_stderr_eof=False):
  376. block = ContentBlock()
  377. out_seen_eof = False
  378. while not self.has_crashed():
  379. if out_seen_eof and (self.err_seen_eof or not wait_for_stderr_eof):
  380. break
  381. if self.err_seen_eof:
  382. out_line = self._server_process.read_stdout_line(deadline)
  383. err_line = None
  384. elif out_seen_eof:
  385. out_line = None
  386. err_line = self._server_process.read_stderr_line(deadline)
  387. else:
  388. out_line, err_line = self._server_process.read_either_stdout_or_stderr_line(deadline)
  389. if self._server_process.timed_out or self.has_crashed():
  390. break
  391. if out_line:
  392. assert not out_seen_eof
  393. out_line, out_seen_eof = self._strip_eof(out_line)
  394. if err_line:
  395. assert not self.err_seen_eof
  396. err_line, self.err_seen_eof = self._strip_eof(err_line)
  397. if out_line:
  398. if out_line[-1] != "\n":
  399. _log.error("Last character read from DRT stdout line was not a newline! This indicates either a NRWT or DRT bug.")
  400. content_length_before_header_check = block._content_length
  401. self._process_stdout_line(block, out_line)
  402. # FIXME: Unlike HTTP, DRT dumps the content right after printing a Content-Length header.
  403. # Don't wait until we're done with headers, just read the binary blob right now.
  404. if content_length_before_header_check != block._content_length:
  405. block.content = self._server_process.read_stdout(deadline, block._content_length)
  406. if err_line:
  407. if self._check_for_driver_crash(err_line):
  408. break
  409. self.error_from_test += err_line
  410. block.decode_content()
  411. return block
  412. class ContentBlock(object):
  413. def __init__(self):
  414. self.content_type = None
  415. self.encoding = None
  416. self.content_hash = None
  417. self._content_length = None
  418. # Content is treated as binary data even though the text output is usually UTF-8.
  419. self.content = str() # FIXME: Should be bytearray() once we require Python 2.6.
  420. self.decoded_content = None
  421. self.malloc = None
  422. self.js_heap = None
  423. def decode_content(self):
  424. if self.encoding == 'base64' and self.content is not None:
  425. self.decoded_content = base64.b64decode(self.content)
  426. else:
  427. self.decoded_content = self.content
  428. class DriverProxy(object):
  429. """A wrapper for managing two Driver instances, one with pixel tests and
  430. one without. This allows us to handle plain text tests and ref tests with a
  431. single driver."""
  432. def __init__(self, port, worker_number, driver_instance_constructor, pixel_tests, no_timeout):
  433. self._port = port
  434. self._worker_number = worker_number
  435. self._driver_instance_constructor = driver_instance_constructor
  436. self._no_timeout = no_timeout
  437. # FIXME: We shouldn't need to create a driver until we actually run a test.
  438. self._driver = self._make_driver(pixel_tests)
  439. self._driver_cmd_line = None
  440. def _make_driver(self, pixel_tests):
  441. return self._driver_instance_constructor(self._port, self._worker_number, pixel_tests, self._no_timeout)
  442. # FIXME: this should be a @classmethod (or implemented on Port instead).
  443. def is_http_test(self, test_name):
  444. return self._driver.is_http_test(test_name)
  445. # FIXME: this should be a @classmethod (or implemented on Port instead).
  446. def test_to_uri(self, test_name):
  447. return self._driver.test_to_uri(test_name)
  448. # FIXME: this should be a @classmethod (or implemented on Port instead).
  449. def uri_to_test(self, uri):
  450. return self._driver.uri_to_test(uri)
  451. def run_test(self, driver_input, stop_when_done):
  452. base = self._port.lookup_virtual_test_base(driver_input.test_name)
  453. if base:
  454. virtual_driver_input = copy.copy(driver_input)
  455. virtual_driver_input.test_name = base
  456. virtual_driver_input.args = self._port.lookup_virtual_test_args(driver_input.test_name)
  457. return self.run_test(virtual_driver_input, stop_when_done)
  458. pixel_tests_needed = driver_input.should_run_pixel_test
  459. cmd_line_key = self._cmd_line_as_key(pixel_tests_needed, driver_input.args)
  460. if cmd_line_key != self._driver_cmd_line:
  461. self._driver.stop()
  462. self._driver = self._make_driver(pixel_tests_needed)
  463. self._driver_cmd_line = cmd_line_key
  464. return self._driver.run_test(driver_input, stop_when_done)
  465. def run_multiple_tests(self, driver_input, stop_when_done):
  466. return self._driver.run_multiple_tests(driver_input, stop_when_done)
  467. def has_crashed(self):
  468. return self._driver.has_crashed()
  469. def stop(self):
  470. self._driver.stop()
  471. # FIXME: this should be a @classmethod (or implemented on Port instead).
  472. def cmd_line(self, pixel_tests=None, per_test_args=None):
  473. return self._driver.cmd_line(pixel_tests, per_test_args or [])
  474. def _cmd_line_as_key(self, pixel_tests, per_test_args):
  475. return ' '.join(self.cmd_line(pixel_tests, per_test_args))