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

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

Issue 566643002: [Android] JUnit test runner changes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@deps-changes
Patch Set: Created 6 years, 3 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
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 import collections 9 import collections
10 import logging 10 import logging
(...skipping 10 matching lines...) Expand all
21 from pylib import ports 21 from pylib import ports
22 from pylib.base import base_test_result 22 from pylib.base import base_test_result
23 from pylib.base import test_dispatcher 23 from pylib.base import test_dispatcher
24 from pylib.gtest import gtest_config 24 from pylib.gtest import gtest_config
25 from pylib.gtest import setup as gtest_setup 25 from pylib.gtest import setup as gtest_setup
26 from pylib.gtest import test_options as gtest_test_options 26 from pylib.gtest import test_options as gtest_test_options
27 from pylib.linker import setup as linker_setup 27 from pylib.linker import setup as linker_setup
28 from pylib.host_driven import setup as host_driven_setup 28 from pylib.host_driven import setup as host_driven_setup
29 from pylib.instrumentation import setup as instrumentation_setup 29 from pylib.instrumentation import setup as instrumentation_setup
30 from pylib.instrumentation import test_options as instrumentation_test_options 30 from pylib.instrumentation import test_options as instrumentation_test_options
31 from pylib.junit import setup as junit_setup
32 from pylib.junit import test_dispatcher as junit_dispatcher
31 from pylib.monkey import setup as monkey_setup 33 from pylib.monkey import setup as monkey_setup
32 from pylib.monkey import test_options as monkey_test_options 34 from pylib.monkey import test_options as monkey_test_options
33 from pylib.perf import setup as perf_setup 35 from pylib.perf import setup as perf_setup
34 from pylib.perf import test_options as perf_test_options 36 from pylib.perf import test_options as perf_test_options
35 from pylib.perf import test_runner as perf_test_runner 37 from pylib.perf import test_runner as perf_test_runner
36 from pylib.uiautomator import setup as uiautomator_setup 38 from pylib.uiautomator import setup as uiautomator_setup
37 from pylib.uiautomator import test_options as uiautomator_test_options 39 from pylib.uiautomator import test_options as uiautomator_test_options
38 from pylib.utils import apk_helper 40 from pylib.utils import apk_helper
39 from pylib.utils import command_option_parser 41 from pylib.utils import command_option_parser
40 from pylib.utils import report_results 42 from pylib.utils import report_results
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 options.exclude_annotations, 374 options.exclude_annotations,
373 options.test_filter, 375 options.test_filter,
374 options.test_data, 376 options.test_data,
375 options.save_perf_json, 377 options.save_perf_json,
376 options.screenshot_failures, 378 options.screenshot_failures,
377 options.uiautomator_jar, 379 options.uiautomator_jar,
378 options.uiautomator_info_jar, 380 options.uiautomator_info_jar,
379 options.package) 381 options.package)
380 382
381 383
384 def AddJUnitTestOptions(option_parser):
385 option_parser.usage = '%prog junit -s [test suite name]'
386 option_parser.commands_dict = {}
387
388 option_parser.add_option(
389 '-s', '--test-suite', dest='test_suite',
390 help=('JUnit test suite to run.'))
391 option_parser.add_option(
392 '-f', '--test-filter', dest='test_filter',
393 help='Filters tests googletest-style.')
394 option_parser.add_option(
395 '--package-filter', dest='package_filter',
396 help='Filters tests by package.')
397 option_parser.add_option(
398 '--runner-filter', dest='runner_filter',
399 help='Filters tests by runner class. Must be fully qualified.')
400 option_parser.add_option(
401 '--sdk-version', dest='sdk_version', type="int",
402 help='The Android SDK version.')
403 AddCommonOptions(option_parser)
404
405
406 def ProcessJUnitTestOptions(options, error_func):
407 """ Processes all JUnit test options. """
408 if not options.test_suite:
409 error_func('No test suite specified.')
410 return options
411
412
382 def AddMonkeyTestOptions(option_parser): 413 def AddMonkeyTestOptions(option_parser):
383 """Adds monkey test options to |option_parser|.""" 414 """Adds monkey test options to |option_parser|."""
384 415
385 option_parser.usage = '%prog monkey [options]' 416 option_parser.usage = '%prog monkey [options]'
386 option_parser.commands_dict = {} 417 option_parser.commands_dict = {}
387 option_parser.example = ( 418 option_parser.example = (
388 '%prog monkey --package=chrome_shell') 419 '%prog monkey --package=chrome_shell')
389 420
390 option_parser.add_option( 421 option_parser.add_option(
391 '--package', 422 '--package',
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
628 report_results.LogFull( 659 report_results.LogFull(
629 results=results, 660 results=results,
630 test_type='UIAutomator', 661 test_type='UIAutomator',
631 test_package=os.path.basename(options.test_jar), 662 test_package=os.path.basename(options.test_jar),
632 annotation=options.annotations, 663 annotation=options.annotations,
633 flakiness_server=options.flakiness_dashboard_server) 664 flakiness_server=options.flakiness_dashboard_server)
634 665
635 return exit_code 666 return exit_code
636 667
637 668
669 def _RunJUnitTests(options, error_func):
670 """Subcommand of RunTestsCommand which runs junit tests."""
671 junit_options = ProcessJUnitTestOptions(options, error_func)
672 runner_factory, tests = junit_setup.Setup(junit_options)
673 _, exit_code = junit_dispatcher.RunTests(tests, runner_factory)
674
675 return exit_code
676
677
638 def _RunMonkeyTests(options, error_func, devices): 678 def _RunMonkeyTests(options, error_func, devices):
639 """Subcommand of RunTestsCommands which runs monkey tests.""" 679 """Subcommand of RunTestsCommands which runs monkey tests."""
640 monkey_options = ProcessMonkeyTestOptions(options, error_func) 680 monkey_options = ProcessMonkeyTestOptions(options, error_func)
641 681
642 runner_factory, tests = monkey_setup.Setup(monkey_options) 682 runner_factory, tests = monkey_setup.Setup(monkey_options)
643 683
644 results, exit_code = test_dispatcher.RunTests( 684 results, exit_code = test_dispatcher.RunTests(
645 tests, runner_factory, devices, shard=False, test_timeout=None, 685 tests, runner_factory, devices, shard=False, test_timeout=None,
646 num_retries=options.num_retries) 686 num_retries=options.num_retries)
647 687
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
751 raise Exception('Failed to reset test server port.') 791 raise Exception('Failed to reset test server port.')
752 792
753 if command == 'gtest': 793 if command == 'gtest':
754 return _RunGTests(options, devices) 794 return _RunGTests(options, devices)
755 elif command == 'linker': 795 elif command == 'linker':
756 return _RunLinkerTests(options, devices) 796 return _RunLinkerTests(options, devices)
757 elif command == 'instrumentation': 797 elif command == 'instrumentation':
758 return _RunInstrumentationTests(options, option_parser.error, devices) 798 return _RunInstrumentationTests(options, option_parser.error, devices)
759 elif command == 'uiautomator': 799 elif command == 'uiautomator':
760 return _RunUIAutomatorTests(options, option_parser.error, devices) 800 return _RunUIAutomatorTests(options, option_parser.error, devices)
801 elif command == 'junit':
802 return _RunJUnitTests(options, option_parser.error)
761 elif command == 'monkey': 803 elif command == 'monkey':
762 return _RunMonkeyTests(options, option_parser.error, devices) 804 return _RunMonkeyTests(options, option_parser.error, devices)
763 elif command == 'perf': 805 elif command == 'perf':
764 return _RunPerfTests(options, args, option_parser.error) 806 return _RunPerfTests(options, args, option_parser.error)
765 else: 807 else:
766 raise Exception('Unknown test type.') 808 raise Exception('Unknown test type.')
767 809
768 810
769 def HelpCommand(command, _options, args, option_parser): 811 def HelpCommand(command, _options, args, option_parser):
770 """Display help for a certain command, or overall help. 812 """Display help for a certain command, or overall help.
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
811 # syntax is a bit prettier. The tuple is two functions: (add options, run 853 # syntax is a bit prettier. The tuple is two functions: (add options, run
812 # command). 854 # command).
813 CommandFunctionTuple = collections.namedtuple( 855 CommandFunctionTuple = collections.namedtuple(
814 'CommandFunctionTuple', ['add_options_func', 'run_command_func']) 856 'CommandFunctionTuple', ['add_options_func', 'run_command_func'])
815 VALID_COMMANDS = { 857 VALID_COMMANDS = {
816 'gtest': CommandFunctionTuple(AddGTestOptions, RunTestsCommand), 858 'gtest': CommandFunctionTuple(AddGTestOptions, RunTestsCommand),
817 'instrumentation': CommandFunctionTuple( 859 'instrumentation': CommandFunctionTuple(
818 AddInstrumentationTestOptions, RunTestsCommand), 860 AddInstrumentationTestOptions, RunTestsCommand),
819 'uiautomator': CommandFunctionTuple( 861 'uiautomator': CommandFunctionTuple(
820 AddUIAutomatorTestOptions, RunTestsCommand), 862 AddUIAutomatorTestOptions, RunTestsCommand),
863 'junit': CommandFunctionTuple(
864 AddJUnitTestOptions, RunTestsCommand),
821 'monkey': CommandFunctionTuple( 865 'monkey': CommandFunctionTuple(
822 AddMonkeyTestOptions, RunTestsCommand), 866 AddMonkeyTestOptions, RunTestsCommand),
823 'perf': CommandFunctionTuple( 867 'perf': CommandFunctionTuple(
824 AddPerfTestOptions, RunTestsCommand), 868 AddPerfTestOptions, RunTestsCommand),
825 'linker': CommandFunctionTuple( 869 'linker': CommandFunctionTuple(
826 AddLinkerTestOptions, RunTestsCommand), 870 AddLinkerTestOptions, RunTestsCommand),
827 'help': CommandFunctionTuple(lambda option_parser: None, HelpCommand) 871 'help': CommandFunctionTuple(lambda option_parser: None, HelpCommand)
828 } 872 }
829 873
830 874
831 def DumpThreadStacks(_signal, _frame): 875 def DumpThreadStacks(_signal, _frame):
832 for thread in threading.enumerate(): 876 for thread in threading.enumerate():
833 reraiser_thread.LogThreadStack(thread) 877 reraiser_thread.LogThreadStack(thread)
834 878
835 879
836 def main(): 880 def main():
837 signal.signal(signal.SIGUSR1, DumpThreadStacks) 881 signal.signal(signal.SIGUSR1, DumpThreadStacks)
838 option_parser = command_option_parser.CommandOptionParser( 882 option_parser = command_option_parser.CommandOptionParser(
839 commands_dict=VALID_COMMANDS) 883 commands_dict=VALID_COMMANDS)
840 return command_option_parser.ParseAndExecute(option_parser) 884 return command_option_parser.ParseAndExecute(option_parser)
841 885
842 886
843 if __name__ == '__main__': 887 if __name__ == '__main__':
844 sys.exit(main()) 888 sys.exit(main())
OLDNEW
« build/android/pylib/junit/test_runner.py ('K') | « build/android/pylib/junit/test_runner.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698