Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 # Use of this source code is governed by a BSD-style license that can be | |
| 3 # found in the LICENSE file. | |
| 4 import logging | |
| 5 import os | |
| 6 import sys | |
| 7 | |
| 8 from telemetry import browser_finder | |
| 9 from telemetry import browser_options | |
| 10 from telemetry import discover | |
| 11 from telemetry import page_test | |
| 12 from telemetry import page_runner | |
| 13 from telemetry import page_set | |
| 14 | |
| 15 def Main(test_dir): | |
| 16 """Turns a PageTest into a command-line program. | |
| 17 | |
| 18 Args: | |
| 19 test_dir: Path to directory containing PageTests. | |
| 20 """ | |
| 21 tests = discover.Discover(test_dir, '', | |
| 22 page_test.PageTest) | |
| 23 | |
| 24 # Naively find the test. If we use the browser options parser, we run | |
| 25 # the risk of failing to parse if we use a test-specific parameter. | |
| 26 test_name = None | |
| 27 for arg in sys.argv: | |
| 28 if arg in tests: | |
| 29 test_name = arg | |
| 30 | |
| 31 options = browser_options.BrowserOptions() | |
| 32 parser = options.CreateParser('%prog [options] <test> <page_set>') | |
| 33 | |
| 34 page_runner.PageRunner.AddCommandLineOptions(parser) | |
| 35 | |
| 36 test = None | |
| 37 if test_name is not None: | |
| 38 test = tests[test_name]() | |
|
dtu
2013/02/13 23:54:23
Print a "test not found" message instead of crashi
| |
| 39 test.AddCommandLineOptions(parser) | |
| 40 | |
| 41 _, args = parser.parse_args() | |
| 42 | |
| 43 if test is None or len(args) != 2: | |
| 44 parser.print_usage() | |
| 45 import page_sets # pylint: disable=F0401 | |
|
dtu
2013/02/13 23:54:23
How does this import work? Also, tools/telemetry s
| |
| 46 print >> sys.stderr, 'Available tests:\n%s\n' % ',\n'.join( | |
| 47 sorted(tests.keys())) | |
| 48 print >> sys.stderr, 'Available page_sets:\n%s\n' % ',\n'.join( | |
| 49 sorted([os.path.relpath(f) | |
| 50 for f in page_sets.GetAllPageSetFilenames()])) | |
| 51 sys.exit(1) | |
| 52 | |
| 53 ps = page_set.PageSet.FromFile(args[1]) | |
| 54 | |
| 55 test.CustomizeBrowserOptions(options) | |
| 56 possible_browser = browser_finder.FindBrowser(options) | |
| 57 if not possible_browser: | |
| 58 print >> sys.stderr, """No browser found.\n | |
| 59 Use --browser=list to figure out which are available.\n""" | |
| 60 sys.exit(1) | |
| 61 | |
| 62 results = page_test.PageTestResults() | |
| 63 with page_runner.PageRunner(ps) as runner: | |
| 64 runner.Run(options, possible_browser, test, results) | |
| 65 | |
| 66 sys.stdout.write('%i pages succeed\n' % len(results.page_successes)) | |
|
dtu
2013/02/13 23:54:23
print
| |
| 67 if len(results.page_failures): | |
| 68 logging.warning('Failed pages: %s', '\n'.join( | |
| 69 [failure['page'].url for failure in results.page_failures])) | |
| 70 | |
| 71 if len(results.skipped_pages): | |
| 72 logging.warning('Skipped pages: %s', '\n'.join( | |
| 73 [skipped['page'].url for skipped in results.skipped_pages])) | |
| 74 return min(255, len(results.page_failures)) | |
| OLD | NEW |