def Main(benchmark_dir): benchmarks = discover.DiscoverClasses(benchmark_dir, os.path.join(benchmark_dir, '..'), page_benchmark.PageBenchmark) options = browser_options.BrowserOptions() parser = options.CreateParser('%prog <page_set>') page_runner.PageRunner.AddCommandLineOptions(parser) recorder = RecordPage(benchmarks) recorder.AddCommandLineOptions(parser) _, args = parser.parse_args() if len(args) != 1: parser.print_usage() sys.exit(1) ps = page_set.PageSet.FromFile(args[0]) # Set the archive path to something temporary. temp_target_wpr_file_path = tempfile.mkstemp()[1] ps.wpr_archive_info.AddNewTemporaryRecording(temp_target_wpr_file_path) # Do the actual recording. options.wpr_mode = wpr_modes.WPR_RECORD recorder.CustomizeBrowserOptions(options) possible_browser = browser_finder.FindBrowser(options) if not possible_browser: print >> sys.stderr, """No browser found.\n Use --browser=list to figure out which are available.\n""" sys.exit(1) results = page_test.PageTestResults() with page_runner.PageRunner(ps) as runner: runner.Run(options, possible_browser, recorder, results) if results.page_failures: logging.warning( 'Some pages failed. The recording has not been updated for ' 'these pages.') logging.warning( 'Failed pages: %s', '\n'.join( [failure['page'].url for failure in results.page_failures])) if results.skipped_pages: logging.warning('Some pages were skipped. The recording has not been ' 'updated for these pages.') logging.warning( 'Skipped pages: %s', '\n'.join( [skipped['page'].url for skipped in results.skipped_pages])) if results.page_successes: # Update the metadata for the pages which were recorded. ps.wpr_archive_info.AddRecordedPages( [page['page'] for page in results.page_successes]) else: os.remove(temp_target_wpr_file_path) return min(255, len(results.page_failures))
def GetTest(self, test_dir): tests = discover.DiscoverClasses(test_dir, os.path.join(test_dir, '..'), self.test_class) if len(self._args) < 1: error_message = 'No %s specified.\nAvailable %ss:\n' % ( self.test_class_name, self.test_class_name) test_list_string = ',\n'.join(sorted(tests.keys())) self.PrintParseError(error_message + test_list_string) test_name = self._args[0] if test_name not in tests: error_message = 'No %s named %s.\nAvailable %ss:\n' % ( self.test_class_name, self._args[0], self.test_class_name) test_list_string = ',\n'.join(sorted(tests.keys())) self.PrintParseError(error_message + test_list_string) return tests[test_name]()
def Main(test_dir, page_set_filenames): """Turns a PageTest into a command-line program. Args: test_dir: Path to directory containing PageTests. """ tests = discover.DiscoverClasses(test_dir, os.path.join(test_dir, '..'), page_test.PageTest) # Naively find the test. If we use the browser options parser, we run # the risk of failing to parse if we use a test-specific parameter. test_name = None for arg in sys.argv: if arg in tests: test_name = arg options = browser_options.BrowserOptions() parser = options.CreateParser('%prog [options] <test> <page_set>') page_runner.PageRunner.AddCommandLineOptions(parser) test = None if test_name is not None: if test_name not in tests: sys.stderr.write('No test name %s found' % test_name) sys.exit(1) test = tests[test_name]() test.AddCommandLineOptions(parser) _, args = parser.parse_args() if test is None or len(args) != 2: parser.print_usage() print >> sys.stderr, 'Available tests:\n%s\n' % ',\n'.join( sorted(tests.keys())) print >> sys.stderr, 'Available page_sets:\n%s\n' % ',\n'.join( sorted([os.path.relpath(f) for f in page_set_filenames])) sys.exit(1) ps = page_set.PageSet.FromFile(args[1]) results = page_test.PageTestResults() return RunTestOnPageSet(options, ps, test, results)
def AttemptToFindTest(self, args, test_dir): """Find the test by matching the arguments against the known test names. We can't use the optparse parser, because the test may add its own command-line options. If the user passed in any of those, the optparse parsing will fail. Returns: An instance of the test class on success. None on failure. """ tests = discover.DiscoverClasses(test_dir, os.path.join(test_dir, '..'), self.test_class) test_name = None for arg in args: if arg in tests: test_name = arg if test_name: return tests[test_name]() else: return None
def Main(benchmark_dir): """Turns a PageBenchmark into a command-line program. Args: benchmark_dir: Path to directory containing PageBenchmarks. """ benchmarks = discover.DiscoverClasses(benchmark_dir, os.path.join(benchmark_dir, '..'), page_benchmark.PageBenchmark) # Naively find the benchmark. If we use the browser options parser, we run # the risk of failing to parse if we use a benchmark-specific parameter. benchmark_name = None for arg in sys.argv: if arg in benchmarks: benchmark_name = arg options = browser_options.BrowserOptions() parser = options.CreateParser('%prog [options] <benchmark> <page_set>') page_runner.PageRunner.AddCommandLineOptions(parser) parser.add_option('--output-format', dest='output_format', default='csv', help='Output format. Can be "csv" or "block". ' 'Defaults to "%default".') parser.add_option('-o', '--output', dest='output_file', help='Redirects output to a file. Defaults to stdout.') parser.add_option('--output-trace-tag', dest='output_trace_tag', help='Append a tag to the key of each result trace.') benchmark = None if benchmark_name is not None: benchmark = benchmarks[benchmark_name]() benchmark.AddCommandLineOptions(parser) _, args = parser.parse_args() if benchmark is None or len(args) != 2: parser.print_usage() import page_sets # pylint: disable=F0401 print >> sys.stderr, 'Available benchmarks:\n%s\n' % ',\n'.join( sorted(benchmarks.keys())) print >> sys.stderr, 'Available page_sets:\n%s\n' % ',\n'.join( sorted([ os.path.relpath(f) for f in page_sets.GetAllPageSetFilenames() ])) sys.exit(1) ps = page_set.PageSet.FromFile(args[1]) benchmark.CustomizeBrowserOptions(options) possible_browser = browser_finder.FindBrowser(options) if not possible_browser: print >> sys.stderr, """No browser found.\n Use --browser=list to figure out which are available.\n""" sys.exit(1) if not options.output_file: output_file = sys.stdout elif options.output_file == '-': output_file = sys.stdout else: output_file = open(os.path.expanduser(options.output_file), 'w') if options.output_format == 'csv': results = csv_page_benchmark_results.CsvPageBenchmarkResults( csv.writer(output_file), benchmark.results_are_the_same_on_every_page) elif options.output_format in ('block', 'terminal-block'): results = block_page_benchmark_results.BlockPageBenchmarkResults( output_file) else: raise Exception( 'Invalid --output-format value: "%s". Valid values are ' '"csv" and "block".' % options.output_format) with page_runner.PageRunner(ps) as runner: runner.Run(options, possible_browser, benchmark, results) output_trace_tag = '' if options.output_trace_tag: output_trace_tag = options.output_trace_tag elif options.browser_executable: # When using an exact executable, assume it is a reference build for the # purpose of outputting the perf results. # TODO(tonyg): Remove this branch once the perfbots use --output-trace-tag. output_trace_tag = '_ref' results.PrintSummary(output_trace_tag) if len(results.page_failures): logging.warning( 'Failed pages: %s', '\n'.join( [failure['page'].url for failure in results.page_failures])) if len(results.skipped_pages): logging.warning( 'Skipped pages: %s', '\n'.join( [skipped['page'].url for skipped in results.skipped_pages])) return min(255, len(results.page_failures))
# Copyright (c) 2012 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. import os from telemetry.page.actions import page_action from telemetry.test import discover _page_action_classes = discover.DiscoverClasses( os.path.dirname(__file__), os.path.join(os.path.dirname(__file__), '..', '..', '..'), page_action.PageAction) def GetAllClasses(): return list(_page_action_classes.values()) def FindClassWithName(name): return _page_action_classes.get(name) def RegisterClassForTest(name, clazz): _page_action_classes[name] = clazz