queries.py 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577
  1. # Copyright (c) 2009 Google Inc. All rights reserved.
  2. # Copyright (c) 2009 Apple Inc. All rights reserved.
  3. # Copyright (c) 2012 Intel Corporation. All rights reserved.
  4. #
  5. # Redistribution and use in source and binary forms, with or without
  6. # modification, are permitted provided that the following conditions are
  7. # met:
  8. #
  9. # * Redistributions of source code must retain the above copyright
  10. # notice, this list of conditions and the following disclaimer.
  11. # * Redistributions in binary form must reproduce the above
  12. # copyright notice, this list of conditions and the following disclaimer
  13. # in the documentation and/or other materials provided with the
  14. # distribution.
  15. # * Neither the name of Google Inc. nor the names of its
  16. # contributors may be used to endorse or promote products derived from
  17. # this software without specific prior written permission.
  18. #
  19. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  20. # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  22. # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  23. # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  24. # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  25. # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  26. # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  27. # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  28. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  29. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30. import fnmatch
  31. import logging
  32. import re
  33. from datetime import datetime
  34. from optparse import make_option
  35. from webkitpy.tool import steps
  36. from webkitpy.common.checkout.commitinfo import CommitInfo
  37. from webkitpy.common.config.committers import CommitterList
  38. import webkitpy.common.config.urls as config_urls
  39. from webkitpy.common.net.buildbot import BuildBot
  40. from webkitpy.common.net.regressionwindow import RegressionWindow
  41. from webkitpy.common.system.crashlogs import CrashLogs
  42. from webkitpy.common.system.user import User
  43. from webkitpy.tool.commands.abstractsequencedcommand import AbstractSequencedCommand
  44. from webkitpy.tool.grammar import pluralize
  45. from webkitpy.tool.multicommandtool import Command
  46. from webkitpy.layout_tests.models.test_expectations import TestExpectations
  47. from webkitpy.port import platform_options, configuration_options
  48. _log = logging.getLogger(__name__)
  49. class SuggestReviewers(AbstractSequencedCommand):
  50. name = "suggest-reviewers"
  51. help_text = "Suggest reviewers for a patch based on recent changes to the modified files."
  52. steps = [
  53. steps.SuggestReviewers,
  54. ]
  55. def _prepare_state(self, options, args, tool):
  56. options.suggest_reviewers = True
  57. class BugsToCommit(Command):
  58. name = "bugs-to-commit"
  59. help_text = "List bugs in the commit-queue"
  60. def execute(self, options, args, tool):
  61. # FIXME: This command is poorly named. It's fetching the commit-queue list here. The name implies it's fetching pending-commit (all r+'d patches).
  62. bug_ids = tool.bugs.queries.fetch_bug_ids_from_commit_queue()
  63. for bug_id in bug_ids:
  64. print "%s" % bug_id
  65. class PatchesInCommitQueue(Command):
  66. name = "patches-in-commit-queue"
  67. help_text = "List patches in the commit-queue"
  68. def execute(self, options, args, tool):
  69. patches = tool.bugs.queries.fetch_patches_from_commit_queue()
  70. _log.info("Patches in commit queue:")
  71. for patch in patches:
  72. print patch.url()
  73. class PatchesToCommitQueue(Command):
  74. name = "patches-to-commit-queue"
  75. help_text = "Patches which should be added to the commit queue"
  76. def __init__(self):
  77. options = [
  78. make_option("--bugs", action="store_true", dest="bugs", help="Output bug links instead of patch links"),
  79. ]
  80. Command.__init__(self, options=options)
  81. @staticmethod
  82. def _needs_commit_queue(patch):
  83. if patch.commit_queue() == "+": # If it's already cq+, ignore the patch.
  84. _log.info("%s already has cq=%s" % (patch.id(), patch.commit_queue()))
  85. return False
  86. # We only need to worry about patches from contributers who are not yet committers.
  87. committer_record = CommitterList().committer_by_email(patch.attacher_email())
  88. if committer_record:
  89. _log.info("%s committer = %s" % (patch.id(), committer_record))
  90. return not committer_record
  91. def execute(self, options, args, tool):
  92. patches = tool.bugs.queries.fetch_patches_from_pending_commit_list()
  93. patches_needing_cq = filter(self._needs_commit_queue, patches)
  94. if options.bugs:
  95. bugs_needing_cq = map(lambda patch: patch.bug_id(), patches_needing_cq)
  96. bugs_needing_cq = sorted(set(bugs_needing_cq))
  97. for bug_id in bugs_needing_cq:
  98. print "%s" % tool.bugs.bug_url_for_bug_id(bug_id)
  99. else:
  100. for patch in patches_needing_cq:
  101. print "%s" % tool.bugs.attachment_url_for_id(patch.id(), action="edit")
  102. class PatchesToReview(Command):
  103. name = "patches-to-review"
  104. help_text = "List bugs which have attachments pending review"
  105. def __init__(self):
  106. options = [
  107. make_option("--all", action="store_true",
  108. help="Show all bugs regardless of who is on CC (it might take a while)"),
  109. make_option("--include-cq-denied", action="store_true",
  110. help="By default, r? patches with cq- are omitted unless this option is set"),
  111. make_option("--cc-email",
  112. help="Specifies the email on the CC field (defaults to your bugzilla login email)"),
  113. ]
  114. Command.__init__(self, options=options)
  115. def _print_report(self, report, cc_email, print_all):
  116. if print_all:
  117. print "Bugs with attachments pending review:"
  118. else:
  119. print "Bugs with attachments pending review that has %s in the CC list:" % cc_email
  120. print "http://webkit.org/b/bugid Description (age in days)"
  121. for row in report:
  122. print "%s (%d)" % (row[1], row[0])
  123. print "Total: %d" % len(report)
  124. def _generate_report(self, bugs, include_cq_denied):
  125. report = []
  126. for bug in bugs:
  127. patch = bug.unreviewed_patches()[-1]
  128. if not include_cq_denied and patch.commit_queue() == "-":
  129. continue
  130. age_in_days = (datetime.today() - patch.attach_date()).days
  131. report.append((age_in_days, "http://webkit.org/b/%-7s %s" % (bug.id(), bug.title())))
  132. report.sort()
  133. return report
  134. def execute(self, options, args, tool):
  135. tool.bugs.authenticate()
  136. cc_email = options.cc_email
  137. if not cc_email and not options.all:
  138. cc_email = tool.bugs.username
  139. bugs = tool.bugs.queries.fetch_bugs_from_review_queue(cc_email=cc_email)
  140. report = self._generate_report(bugs, options.include_cq_denied)
  141. self._print_report(report, cc_email, options.all)
  142. class WhatBroke(Command):
  143. name = "what-broke"
  144. help_text = "Print failing buildbots (%s) and what revisions broke them" % config_urls.buildbot_url
  145. def _print_builder_line(self, builder_name, max_name_width, status_message):
  146. print "%s : %s" % (builder_name.ljust(max_name_width), status_message)
  147. def _print_blame_information_for_builder(self, builder_status, name_width, avoid_flakey_tests=True):
  148. builder = self._tool.buildbot.builder_with_name(builder_status["name"])
  149. red_build = builder.build(builder_status["build_number"])
  150. regression_window = builder.find_regression_window(red_build)
  151. if not regression_window.failing_build():
  152. self._print_builder_line(builder.name(), name_width, "FAIL (error loading build information)")
  153. return
  154. if not regression_window.build_before_failure():
  155. self._print_builder_line(builder.name(), name_width, "FAIL (blame-list: sometime before %s?)" % regression_window.failing_build().revision())
  156. return
  157. revisions = regression_window.revisions()
  158. first_failure_message = ""
  159. if (regression_window.failing_build() == builder.build(builder_status["build_number"])):
  160. first_failure_message = " FIRST FAILURE, possibly a flaky test"
  161. self._print_builder_line(builder.name(), name_width, "FAIL (blame-list: %s%s)" % (revisions, first_failure_message))
  162. for revision in revisions:
  163. commit_info = self._tool.checkout().commit_info_for_revision(revision)
  164. if commit_info:
  165. print commit_info.blame_string(self._tool.bugs)
  166. else:
  167. print "FAILED to fetch CommitInfo for r%s, likely missing ChangeLog" % revision
  168. def execute(self, options, args, tool):
  169. builder_statuses = tool.buildbot.builder_statuses()
  170. longest_builder_name = max(map(len, map(lambda builder: builder["name"], builder_statuses)))
  171. failing_builders = 0
  172. for builder_status in builder_statuses:
  173. # If the builder is green, print OK, exit.
  174. if builder_status["is_green"]:
  175. continue
  176. self._print_blame_information_for_builder(builder_status, name_width=longest_builder_name)
  177. failing_builders += 1
  178. if failing_builders:
  179. print "%s of %s are failing" % (failing_builders, pluralize("builder", len(builder_statuses)))
  180. else:
  181. print "All builders are passing!"
  182. class ResultsFor(Command):
  183. name = "results-for"
  184. help_text = "Print a list of failures for the passed revision from bots on %s" % config_urls.buildbot_url
  185. argument_names = "REVISION"
  186. def _print_layout_test_results(self, results):
  187. if not results:
  188. print " No results."
  189. return
  190. for title, files in results.parsed_results().items():
  191. print " %s" % title
  192. for filename in files:
  193. print " %s" % filename
  194. def execute(self, options, args, tool):
  195. builders = self._tool.buildbot.builders()
  196. for builder in builders:
  197. print "%s:" % builder.name()
  198. build = builder.build_for_revision(args[0], allow_failed_lookups=True)
  199. self._print_layout_test_results(build.layout_test_results())
  200. class FailureReason(Command):
  201. name = "failure-reason"
  202. help_text = "Lists revisions where individual test failures started at %s" % config_urls.buildbot_url
  203. def _blame_line_for_revision(self, revision):
  204. try:
  205. commit_info = self._tool.checkout().commit_info_for_revision(revision)
  206. except Exception, e:
  207. return "FAILED to fetch CommitInfo for r%s, exception: %s" % (revision, e)
  208. if not commit_info:
  209. return "FAILED to fetch CommitInfo for r%s, likely missing ChangeLog" % revision
  210. return commit_info.blame_string(self._tool.bugs)
  211. def _print_blame_information_for_transition(self, regression_window, failing_tests):
  212. red_build = regression_window.failing_build()
  213. print "SUCCESS: Build %s (r%s) was the first to show failures: %s" % (red_build._number, red_build.revision(), failing_tests)
  214. print "Suspect revisions:"
  215. for revision in regression_window.revisions():
  216. print self._blame_line_for_revision(revision)
  217. def _explain_failures_for_builder(self, builder, start_revision):
  218. print "Examining failures for \"%s\", starting at r%s" % (builder.name(), start_revision)
  219. revision_to_test = start_revision
  220. build = builder.build_for_revision(revision_to_test, allow_failed_lookups=True)
  221. layout_test_results = build.layout_test_results()
  222. if not layout_test_results:
  223. # FIXME: This could be made more user friendly.
  224. print "Failed to load layout test results from %s; can't continue. (start revision = r%s)" % (build.results_url(), start_revision)
  225. return 1
  226. results_to_explain = set(layout_test_results.failing_tests())
  227. last_build_with_results = build
  228. print "Starting at %s" % revision_to_test
  229. while results_to_explain:
  230. revision_to_test -= 1
  231. new_build = builder.build_for_revision(revision_to_test, allow_failed_lookups=True)
  232. if not new_build:
  233. print "No build for %s" % revision_to_test
  234. continue
  235. build = new_build
  236. latest_results = build.layout_test_results()
  237. if not latest_results:
  238. print "No results build %s (r%s)" % (build._number, build.revision())
  239. continue
  240. failures = set(latest_results.failing_tests())
  241. if len(failures) >= 20:
  242. # FIXME: We may need to move this logic into the LayoutTestResults class.
  243. # The buildbot stops runs after 20 failures so we don't have full results to work with here.
  244. print "Too many failures in build %s (r%s), ignoring." % (build._number, build.revision())
  245. continue
  246. fixed_results = results_to_explain - failures
  247. if not fixed_results:
  248. print "No change in build %s (r%s), %s unexplained failures (%s in this build)" % (build._number, build.revision(), len(results_to_explain), len(failures))
  249. last_build_with_results = build
  250. continue
  251. regression_window = RegressionWindow(build, last_build_with_results)
  252. self._print_blame_information_for_transition(regression_window, fixed_results)
  253. last_build_with_results = build
  254. results_to_explain -= fixed_results
  255. if results_to_explain:
  256. print "Failed to explain failures: %s" % results_to_explain
  257. return 1
  258. print "Explained all results for %s" % builder.name()
  259. return 0
  260. def _builder_to_explain(self):
  261. builder_statuses = self._tool.buildbot.builder_statuses()
  262. red_statuses = [status for status in builder_statuses if not status["is_green"]]
  263. print "%s failing" % (pluralize("builder", len(red_statuses)))
  264. builder_choices = [status["name"] for status in red_statuses]
  265. # We could offer an "All" choice here.
  266. chosen_name = self._tool.user.prompt_with_list("Which builder to diagnose:", builder_choices)
  267. # FIXME: prompt_with_list should really take a set of objects and a set of names and then return the object.
  268. for status in red_statuses:
  269. if status["name"] == chosen_name:
  270. return (self._tool.buildbot.builder_with_name(chosen_name), status["built_revision"])
  271. def execute(self, options, args, tool):
  272. (builder, latest_revision) = self._builder_to_explain()
  273. start_revision = self._tool.user.prompt("Revision to walk backwards from? [%s] " % latest_revision) or latest_revision
  274. if not start_revision:
  275. print "Revision required."
  276. return 1
  277. return self._explain_failures_for_builder(builder, start_revision=int(start_revision))
  278. class FindFlakyTests(Command):
  279. name = "find-flaky-tests"
  280. help_text = "Lists tests that often fail for a single build at %s" % config_urls.buildbot_url
  281. def _find_failures(self, builder, revision):
  282. build = builder.build_for_revision(revision, allow_failed_lookups=True)
  283. if not build:
  284. print "No build for %s" % revision
  285. return (None, None)
  286. results = build.layout_test_results()
  287. if not results:
  288. print "No results build %s (r%s)" % (build._number, build.revision())
  289. return (None, None)
  290. failures = set(results.failing_tests())
  291. if len(failures) >= 20:
  292. # FIXME: We may need to move this logic into the LayoutTestResults class.
  293. # The buildbot stops runs after 20 failures so we don't have full results to work with here.
  294. print "Too many failures in build %s (r%s), ignoring." % (build._number, build.revision())
  295. return (None, None)
  296. return (build, failures)
  297. def _increment_statistics(self, flaky_tests, flaky_test_statistics):
  298. for test in flaky_tests:
  299. count = flaky_test_statistics.get(test, 0)
  300. flaky_test_statistics[test] = count + 1
  301. def _print_statistics(self, statistics):
  302. print "=== Results ==="
  303. print "Occurances Test name"
  304. for value, key in sorted([(value, key) for key, value in statistics.items()]):
  305. print "%10d %s" % (value, key)
  306. def _walk_backwards_from(self, builder, start_revision, limit):
  307. flaky_test_statistics = {}
  308. all_previous_failures = set([])
  309. one_time_previous_failures = set([])
  310. previous_build = None
  311. for i in range(limit):
  312. revision = start_revision - i
  313. print "Analyzing %s ... " % revision,
  314. (build, failures) = self._find_failures(builder, revision)
  315. if failures == None:
  316. # Notice that we don't loop on the empty set!
  317. continue
  318. print "has %s failures" % len(failures)
  319. flaky_tests = one_time_previous_failures - failures
  320. if flaky_tests:
  321. print "Flaky tests: %s %s" % (sorted(flaky_tests),
  322. previous_build.results_url())
  323. self._increment_statistics(flaky_tests, flaky_test_statistics)
  324. one_time_previous_failures = failures - all_previous_failures
  325. all_previous_failures = failures
  326. previous_build = build
  327. self._print_statistics(flaky_test_statistics)
  328. def _builder_to_analyze(self):
  329. statuses = self._tool.buildbot.builder_statuses()
  330. choices = [status["name"] for status in statuses]
  331. chosen_name = self._tool.user.prompt_with_list("Which builder to analyze:", choices)
  332. for status in statuses:
  333. if status["name"] == chosen_name:
  334. return (self._tool.buildbot.builder_with_name(chosen_name), status["built_revision"])
  335. def execute(self, options, args, tool):
  336. (builder, latest_revision) = self._builder_to_analyze()
  337. limit = self._tool.user.prompt("How many revisions to look through? [10000] ") or 10000
  338. return self._walk_backwards_from(builder, latest_revision, limit=int(limit))
  339. class TreeStatus(Command):
  340. name = "tree-status"
  341. help_text = "Print the status of the %s buildbots" % config_urls.buildbot_url
  342. long_help = """Fetches build status from http://build.webkit.org/one_box_per_builder
  343. and displayes the status of each builder."""
  344. def execute(self, options, args, tool):
  345. for builder in tool.buildbot.builder_statuses():
  346. status_string = "ok" if builder["is_green"] else "FAIL"
  347. print "%s : %s" % (status_string.ljust(4), builder["name"])
  348. class CrashLog(Command):
  349. name = "crash-log"
  350. help_text = "Print the newest crash log for the given process"
  351. long_help = """Finds the newest crash log matching the given process name
  352. and PID and prints it to stdout."""
  353. argument_names = "PROCESS_NAME [PID]"
  354. def execute(self, options, args, tool):
  355. crash_logs = CrashLogs(tool)
  356. pid = None
  357. if len(args) > 1:
  358. pid = int(args[1])
  359. print crash_logs.find_newest_log(args[0], pid)
  360. class PrintExpectations(Command):
  361. name = 'print-expectations'
  362. help_text = 'Print the expected result for the given test(s) on the given port(s)'
  363. def __init__(self):
  364. options = [
  365. make_option('--all', action='store_true', default=False,
  366. help='display the expectations for *all* tests'),
  367. make_option('-x', '--exclude-keyword', action='append', default=[],
  368. help='limit to tests not matching the given keyword (for example, "skip", "slow", or "crash". May specify multiple times'),
  369. make_option('-i', '--include-keyword', action='append', default=[],
  370. help='limit to tests with the given keyword (for example, "skip", "slow", or "crash". May specify multiple times'),
  371. make_option('--csv', action='store_true', default=False,
  372. help='Print a CSV-style report that includes the port name, modifiers, tests, and expectations'),
  373. make_option('-f', '--full', action='store_true', default=False,
  374. help='Print a full TestExpectations-style line for every match'),
  375. make_option('--paths', action='store_true', default=False,
  376. help='display the paths for all applicable expectation files'),
  377. ] + platform_options(use_globs=True)
  378. Command.__init__(self, options=options)
  379. self._expectation_models = {}
  380. def execute(self, options, args, tool):
  381. if not options.paths and not args and not options.all:
  382. print "You must either specify one or more test paths or --all."
  383. return
  384. if options.platform:
  385. port_names = fnmatch.filter(tool.port_factory.all_port_names(), options.platform)
  386. if not port_names:
  387. default_port = tool.port_factory.get(options.platform)
  388. if default_port:
  389. port_names = [default_port.name()]
  390. else:
  391. print "No port names match '%s'" % options.platform
  392. return
  393. else:
  394. default_port = tool.port_factory.get(port_names[0])
  395. else:
  396. default_port = tool.port_factory.get(options=options)
  397. port_names = [default_port.name()]
  398. if options.paths:
  399. files = default_port.expectations_files()
  400. layout_tests_dir = default_port.layout_tests_dir()
  401. for file in files:
  402. if file.startswith(layout_tests_dir):
  403. file = file.replace(layout_tests_dir, 'LayoutTests')
  404. print file
  405. return
  406. tests = set(default_port.tests(args))
  407. for port_name in port_names:
  408. model = self._model(options, port_name, tests)
  409. tests_to_print = self._filter_tests(options, model, tests)
  410. lines = [model.get_expectation_line(test) for test in sorted(tests_to_print)]
  411. if port_name != port_names[0]:
  412. print
  413. print '\n'.join(self._format_lines(options, port_name, lines))
  414. def _filter_tests(self, options, model, tests):
  415. filtered_tests = set()
  416. if options.include_keyword:
  417. for keyword in options.include_keyword:
  418. filtered_tests.update(model.get_test_set_for_keyword(keyword))
  419. else:
  420. filtered_tests = tests
  421. for keyword in options.exclude_keyword:
  422. filtered_tests.difference_update(model.get_test_set_for_keyword(keyword))
  423. return filtered_tests
  424. def _format_lines(self, options, port_name, lines):
  425. output = []
  426. if options.csv:
  427. for line in lines:
  428. output.append("%s,%s" % (port_name, line.to_csv()))
  429. elif lines:
  430. include_modifiers = options.full
  431. include_expectations = options.full or len(options.include_keyword) != 1 or len(options.exclude_keyword)
  432. output.append("// For %s" % port_name)
  433. for line in lines:
  434. output.append("%s" % line.to_string(None, include_modifiers, include_expectations, include_comment=False))
  435. return output
  436. def _model(self, options, port_name, tests):
  437. port = self._tool.port_factory.get(port_name, options)
  438. return TestExpectations(port, tests).model()
  439. class PrintBaselines(Command):
  440. name = 'print-baselines'
  441. help_text = 'Prints the baseline locations for given test(s) on the given port(s)'
  442. def __init__(self):
  443. options = [
  444. make_option('--all', action='store_true', default=False,
  445. help='display the baselines for *all* tests'),
  446. make_option('--csv', action='store_true', default=False,
  447. help='Print a CSV-style report that includes the port name, test_name, test platform, baseline type, baseline location, and baseline platform'),
  448. make_option('--include-virtual-tests', action='store_true',
  449. help='Include virtual tests'),
  450. ] + platform_options(use_globs=True)
  451. Command.__init__(self, options=options)
  452. self._platform_regexp = re.compile('platform/([^\/]+)/(.+)')
  453. def execute(self, options, args, tool):
  454. if not args and not options.all:
  455. print "You must either specify one or more test paths or --all."
  456. return
  457. default_port = tool.port_factory.get()
  458. if options.platform:
  459. port_names = fnmatch.filter(tool.port_factory.all_port_names(), options.platform)
  460. if not port_names:
  461. print "No port names match '%s'" % options.platform
  462. else:
  463. port_names = [default_port.name()]
  464. if options.include_virtual_tests:
  465. tests = sorted(default_port.tests(args))
  466. else:
  467. # FIXME: make real_tests() a public method.
  468. tests = sorted(default_port._real_tests(args))
  469. for port_name in port_names:
  470. if port_name != port_names[0]:
  471. print
  472. if not options.csv:
  473. print "// For %s" % port_name
  474. port = tool.port_factory.get(port_name)
  475. for test_name in tests:
  476. self._print_baselines(options, port_name, test_name, port.expected_baselines_by_extension(test_name))
  477. def _print_baselines(self, options, port_name, test_name, baselines):
  478. for extension in sorted(baselines.keys()):
  479. baseline_location = baselines[extension]
  480. if baseline_location:
  481. if options.csv:
  482. print "%s,%s,%s,%s,%s,%s" % (port_name, test_name, self._platform_for_path(test_name),
  483. extension[1:], baseline_location, self._platform_for_path(baseline_location))
  484. else:
  485. print baseline_location
  486. def _platform_for_path(self, relpath):
  487. platform_matchobj = self._platform_regexp.match(relpath)
  488. if platform_matchobj:
  489. return platform_matchobj.group(1)
  490. return None