Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(590)

Side by Side Diff: build/android/test_runner.py

Issue 22854004: Android: first step into making "perf tests" reuse the functional test infra. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: copyright notice Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « build/android/pylib/perf/test_runner.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # 2 #
3 # Copyright 2013 The Chromium Authors. All rights reserved. 3 # Copyright 2013 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be 4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file. 5 # found in the LICENSE file.
6 6
7 """Runs all types of tests from one unified interface. 7 """Runs all types of tests from one unified interface.
8 8
9 TODO(gkanwar): 9 TODO(gkanwar):
10 * Add options to run Monkey tests. 10 * Add options to run Monkey tests.
(...skipping 10 matching lines...) Expand all
21 from pylib.base import base_test_result 21 from pylib.base import base_test_result
22 from pylib.base import test_dispatcher 22 from pylib.base import test_dispatcher
23 from pylib.gtest import gtest_config 23 from pylib.gtest import gtest_config
24 from pylib.gtest import setup as gtest_setup 24 from pylib.gtest import setup as gtest_setup
25 from pylib.gtest import test_options as gtest_test_options 25 from pylib.gtest import test_options as gtest_test_options
26 from pylib.host_driven import setup as host_driven_setup 26 from pylib.host_driven import setup as host_driven_setup
27 from pylib.instrumentation import setup as instrumentation_setup 27 from pylib.instrumentation import setup as instrumentation_setup
28 from pylib.instrumentation import test_options as instrumentation_test_options 28 from pylib.instrumentation import test_options as instrumentation_test_options
29 from pylib.monkey import setup as monkey_setup 29 from pylib.monkey import setup as monkey_setup
30 from pylib.monkey import test_options as monkey_test_options 30 from pylib.monkey import test_options as monkey_test_options
31 from pylib.perf import setup as perf_setup
32 from pylib.perf import test_options as perf_test_options
33 from pylib.perf import test_runner as perf_test_runner
31 from pylib.uiautomator import setup as uiautomator_setup 34 from pylib.uiautomator import setup as uiautomator_setup
32 from pylib.uiautomator import test_options as uiautomator_test_options 35 from pylib.uiautomator import test_options as uiautomator_test_options
33 from pylib.utils import report_results 36 from pylib.utils import report_results
34 from pylib.utils import run_tests_helper 37 from pylib.utils import run_tests_helper
35 38
36 39
37 _SDK_OUT_DIR = os.path.join(constants.DIR_SOURCE_ROOT, 'out') 40 _SDK_OUT_DIR = os.path.join(constants.DIR_SOURCE_ROOT, 'out')
38 41
39 42
40 def AddBuildTypeOption(option_parser): 43 def AddBuildTypeOption(option_parser):
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 options.verbose_count, 414 options.verbose_count,
412 options.package_name, 415 options.package_name,
413 options.activity_name, 416 options.activity_name,
414 options.event_count, 417 options.event_count,
415 category, 418 category,
416 options.throttle, 419 options.throttle,
417 options.seed, 420 options.seed,
418 options.extra_args) 421 options.extra_args)
419 422
420 423
424 def AddPerfTestOptions(option_parser):
425 """Adds perf test options to |option_parser|."""
426
427 option_parser.usage = '%prog perf [options]'
428 option_parser.command_list = []
429 option_parser.example = ('%prog perf --steps perf_steps.json')
430
431 option_parser.add_option('--steps', help='JSON file containing the list '
432 'of perf steps to run.')
433 option_parser.add_option('--flaky-steps',
434 help='A JSON file containing steps that are flaky '
435 'and will have its exit code ignored.')
436 option_parser.add_option('--print-step', help='The name of a previously '
437 'executed perf step to print.')
438
439 AddCommonOptions(option_parser)
440
441
442 def ProcessPerfTestOptions(options, error_func):
443 """Processes all perf test options.
444
445 Args:
446 options: optparse.Options object.
447 error_func: Function to call with the error message in case of an error.
448
449 Returns:
450 A PerfOptions named tuple which contains all options relevant to
451 perf tests.
452 """
453 if not options.steps and not options.print_step:
454 error_func('Please specify --steps or --print-step')
455 return perf_test_options.PerfOptions(
456 options.steps, options.flaky_steps, options.print_step)
457
458
459
421 def _RunGTests(options, error_func): 460 def _RunGTests(options, error_func):
422 """Subcommand of RunTestsCommands which runs gtests.""" 461 """Subcommand of RunTestsCommands which runs gtests."""
423 ProcessGTestOptions(options) 462 ProcessGTestOptions(options)
424 463
425 exit_code = 0 464 exit_code = 0
426 for suite_name in options.suite_name: 465 for suite_name in options.suite_name:
427 # TODO(gkanwar): Move this into ProcessGTestOptions once we require -s for 466 # TODO(gkanwar): Move this into ProcessGTestOptions once we require -s for
428 # the gtest command. 467 # the gtest command.
429 gtest_options = gtest_test_options.GTestOptions( 468 gtest_options = gtest_test_options.GTestOptions(
430 options.build_type, 469 options.build_type,
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
546 585
547 report_results.LogFull( 586 report_results.LogFull(
548 results=results, 587 results=results,
549 test_type='Monkey', 588 test_type='Monkey',
550 test_package='Monkey', 589 test_package='Monkey',
551 build_type=options.build_type) 590 build_type=options.build_type)
552 591
553 return exit_code 592 return exit_code
554 593
555 594
595 def _RunPerfTests(options, error_func):
596 """Subcommand of RunTestsCommands which runs perf tests."""
597 perf_options = ProcessPerfTestOptions(options, error_func)
598 # Just print the results from a single previously executed step.
599 if perf_options.print_step:
600 return perf_test_runner.PrintTestOutput(perf_options.print_step)
601
602 runner_factory, tests = perf_setup.Setup(perf_options)
603
604 results, exit_code = test_dispatcher.RunTests(
605 tests, runner_factory, False, None, shard=True, test_timeout=None)
606
607 report_results.LogFull(
608 results=results,
609 test_type='Perf',
610 test_package='Perf',
611 build_type=options.build_type)
612
613 return exit_code
614
556 615
557 def RunTestsCommand(command, options, args, option_parser): 616 def RunTestsCommand(command, options, args, option_parser):
558 """Checks test type and dispatches to the appropriate function. 617 """Checks test type and dispatches to the appropriate function.
559 618
560 Args: 619 Args:
561 command: String indicating the command that was received to trigger 620 command: String indicating the command that was received to trigger
562 this function. 621 this function.
563 options: optparse options dictionary. 622 options: optparse options dictionary.
564 args: List of extra args from optparse. 623 args: List of extra args from optparse.
565 option_parser: optparse.OptionParser object. 624 option_parser: optparse.OptionParser object.
(...skipping 14 matching lines...) Expand all
580 ProcessCommonOptions(options) 639 ProcessCommonOptions(options)
581 640
582 if command == 'gtest': 641 if command == 'gtest':
583 return _RunGTests(options, option_parser.error) 642 return _RunGTests(options, option_parser.error)
584 elif command == 'instrumentation': 643 elif command == 'instrumentation':
585 return _RunInstrumentationTests(options, option_parser.error) 644 return _RunInstrumentationTests(options, option_parser.error)
586 elif command == 'uiautomator': 645 elif command == 'uiautomator':
587 return _RunUIAutomatorTests(options, option_parser.error) 646 return _RunUIAutomatorTests(options, option_parser.error)
588 elif command == 'monkey': 647 elif command == 'monkey':
589 return _RunMonkeyTests(options, option_parser.error) 648 return _RunMonkeyTests(options, option_parser.error)
649 elif command == 'perf':
650 return _RunPerfTests(options, option_parser.error)
590 else: 651 else:
591 raise Exception('Unknown test type.') 652 raise Exception('Unknown test type.')
592 653
593 654
594 def HelpCommand(command, options, args, option_parser): 655 def HelpCommand(command, options, args, option_parser):
595 """Display help for a certain command, or overall help. 656 """Display help for a certain command, or overall help.
596 657
597 Args: 658 Args:
598 command: String indicating the command that was received to trigger 659 command: String indicating the command that was received to trigger
599 this function. 660 this function.
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
638 CommandFunctionTuple = collections.namedtuple( 699 CommandFunctionTuple = collections.namedtuple(
639 'CommandFunctionTuple', ['add_options_func', 'run_command_func']) 700 'CommandFunctionTuple', ['add_options_func', 'run_command_func'])
640 VALID_COMMANDS = { 701 VALID_COMMANDS = {
641 'gtest': CommandFunctionTuple(AddGTestOptions, RunTestsCommand), 702 'gtest': CommandFunctionTuple(AddGTestOptions, RunTestsCommand),
642 'instrumentation': CommandFunctionTuple( 703 'instrumentation': CommandFunctionTuple(
643 AddInstrumentationTestOptions, RunTestsCommand), 704 AddInstrumentationTestOptions, RunTestsCommand),
644 'uiautomator': CommandFunctionTuple( 705 'uiautomator': CommandFunctionTuple(
645 AddUIAutomatorTestOptions, RunTestsCommand), 706 AddUIAutomatorTestOptions, RunTestsCommand),
646 'monkey': CommandFunctionTuple( 707 'monkey': CommandFunctionTuple(
647 AddMonkeyTestOptions, RunTestsCommand), 708 AddMonkeyTestOptions, RunTestsCommand),
709 'perf': CommandFunctionTuple(
710 AddPerfTestOptions, RunTestsCommand),
648 'help': CommandFunctionTuple(lambda option_parser: None, HelpCommand) 711 'help': CommandFunctionTuple(lambda option_parser: None, HelpCommand)
649 } 712 }
650 713
651 714
652 class CommandOptionParser(optparse.OptionParser): 715 class CommandOptionParser(optparse.OptionParser):
653 """Wrapper class for OptionParser to help with listing commands.""" 716 """Wrapper class for OptionParser to help with listing commands."""
654 717
655 def __init__(self, *args, **kwargs): 718 def __init__(self, *args, **kwargs):
656 self.command_list = kwargs.pop('command_list', []) 719 self.command_list = kwargs.pop('command_list', [])
657 self.example = kwargs.pop('example', '') 720 self.example = kwargs.pop('example', '')
(...skipping 27 matching lines...) Expand all
685 option_parser.error('Invalid command.') 748 option_parser.error('Invalid command.')
686 command = argv[1] 749 command = argv[1]
687 VALID_COMMANDS[command].add_options_func(option_parser) 750 VALID_COMMANDS[command].add_options_func(option_parser)
688 options, args = option_parser.parse_args(argv) 751 options, args = option_parser.parse_args(argv)
689 return VALID_COMMANDS[command].run_command_func( 752 return VALID_COMMANDS[command].run_command_func(
690 command, options, args, option_parser) 753 command, options, args, option_parser)
691 754
692 755
693 if __name__ == '__main__': 756 if __name__ == '__main__':
694 sys.exit(main(sys.argv)) 757 sys.exit(main(sys.argv))
OLDNEW
« no previous file with comments | « build/android/pylib/perf/test_runner.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698