OLD | NEW |
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 |
11 import optparse | 11 import optparse |
12 import os | 12 import os |
13 import shutil | 13 import shutil |
14 import signal | 14 import signal |
15 import sys | 15 import sys |
16 import threading | 16 import threading |
17 import traceback | |
18 | 17 |
19 from pylib import android_commands | 18 from pylib import android_commands |
20 from pylib import constants | 19 from pylib import constants |
21 from pylib import forwarder | 20 from pylib import forwarder |
22 from pylib import ports | 21 from pylib import ports |
23 from pylib.base import base_test_result | 22 from pylib.base import base_test_result |
24 from pylib.base import test_dispatcher | 23 from pylib.base import test_dispatcher |
25 from pylib.gtest import gtest_config | 24 from pylib.gtest import gtest_config |
26 from pylib.gtest import setup as gtest_setup | 25 from pylib.gtest import setup as gtest_setup |
27 from pylib.gtest import test_options as gtest_test_options | 26 from pylib.gtest import test_options as gtest_test_options |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 option_parser.add_option('--test_data', action='append', default=[], | 179 option_parser.add_option('--test_data', action='append', default=[], |
181 help=('Each instance defines a directory of test ' | 180 help=('Each instance defines a directory of test ' |
182 'data that should be copied to the target(s) ' | 181 'data that should be copied to the target(s) ' |
183 'before running the tests. The argument ' | 182 'before running the tests. The argument ' |
184 'should be of the form <target>:<source>, ' | 183 'should be of the form <target>:<source>, ' |
185 '<target> is relative to the device data' | 184 '<target> is relative to the device data' |
186 'directory, and <source> is relative to the ' | 185 'directory, and <source> is relative to the ' |
187 'chromium build directory.')) | 186 'chromium build directory.')) |
188 | 187 |
189 | 188 |
190 def ProcessJavaTestOptions(options, error_func): | 189 def ProcessJavaTestOptions(options): |
191 """Processes options/arguments and populates |options| with defaults.""" | 190 """Processes options/arguments and populates |options| with defaults.""" |
192 | 191 |
193 if options.annotation_str: | 192 if options.annotation_str: |
194 options.annotations = options.annotation_str.split(',') | 193 options.annotations = options.annotation_str.split(',') |
195 elif options.test_filter: | 194 elif options.test_filter: |
196 options.annotations = [] | 195 options.annotations = [] |
197 else: | 196 else: |
198 options.annotations = ['Smoke', 'SmallTest', 'MediumTest', 'LargeTest', | 197 options.annotations = ['Smoke', 'SmallTest', 'MediumTest', 'LargeTest', |
199 'EnormousTest'] | 198 'EnormousTest'] |
200 | 199 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 | 238 |
240 Args: | 239 Args: |
241 options: optparse.Options object. | 240 options: optparse.Options object. |
242 error_func: Function to call with the error message in case of an error. | 241 error_func: Function to call with the error message in case of an error. |
243 | 242 |
244 Returns: | 243 Returns: |
245 An InstrumentationOptions named tuple which contains all options relevant to | 244 An InstrumentationOptions named tuple which contains all options relevant to |
246 instrumentation tests. | 245 instrumentation tests. |
247 """ | 246 """ |
248 | 247 |
249 ProcessJavaTestOptions(options, error_func) | 248 ProcessJavaTestOptions(options) |
250 | 249 |
251 if options.java_only and options.python_only: | 250 if options.java_only and options.python_only: |
252 error_func('Options java_only (-j) and python_only (-p) ' | 251 error_func('Options java_only (-j) and python_only (-p) ' |
253 'are mutually exclusive.') | 252 'are mutually exclusive.') |
254 options.run_java_tests = True | 253 options.run_java_tests = True |
255 options.run_python_tests = True | 254 options.run_python_tests = True |
256 if options.java_only: | 255 if options.java_only: |
257 options.run_python_tests = False | 256 options.run_python_tests = False |
258 elif options.python_only: | 257 elif options.python_only: |
259 options.run_java_tests = False | 258 options.run_java_tests = False |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 | 316 |
318 Args: | 317 Args: |
319 options: optparse.Options object. | 318 options: optparse.Options object. |
320 error_func: Function to call with the error message in case of an error. | 319 error_func: Function to call with the error message in case of an error. |
321 | 320 |
322 Returns: | 321 Returns: |
323 A UIAutomatorOptions named tuple which contains all options relevant to | 322 A UIAutomatorOptions named tuple which contains all options relevant to |
324 uiautomator tests. | 323 uiautomator tests. |
325 """ | 324 """ |
326 | 325 |
327 ProcessJavaTestOptions(options, error_func) | 326 ProcessJavaTestOptions(options) |
328 | 327 |
329 if not options.package: | 328 if not options.package: |
330 error_func('--package is required.') | 329 error_func('--package is required.') |
331 | 330 |
332 if options.package not in constants.PACKAGE_INFO: | 331 if options.package not in constants.PACKAGE_INFO: |
333 error_func('Invalid package.') | 332 error_func('Invalid package.') |
334 | 333 |
335 if not options.test_jar: | 334 if not options.test_jar: |
336 error_func('--test-jar must be specified.') | 335 error_func('--test-jar must be specified.') |
337 | 336 |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
483 error_func('Please specify one of: --steps, --print-step, --single-step.') | 482 error_func('Please specify one of: --steps, --print-step, --single-step.') |
484 single_step = None | 483 single_step = None |
485 if options.single_step: | 484 if options.single_step: |
486 single_step = ' '.join(args[2:]) | 485 single_step = ' '.join(args[2:]) |
487 return perf_test_options.PerfOptions( | 486 return perf_test_options.PerfOptions( |
488 options.steps, options.flaky_steps, options.print_step, | 487 options.steps, options.flaky_steps, options.print_step, |
489 options.no_timeout, options.test_filter, options.dry_run, | 488 options.no_timeout, options.test_filter, options.dry_run, |
490 single_step) | 489 single_step) |
491 | 490 |
492 | 491 |
493 def _RunGTests(options, error_func, devices): | 492 def _RunGTests(options, devices): |
494 """Subcommand of RunTestsCommands which runs gtests.""" | 493 """Subcommand of RunTestsCommands which runs gtests.""" |
495 ProcessGTestOptions(options) | 494 ProcessGTestOptions(options) |
496 | 495 |
497 exit_code = 0 | 496 exit_code = 0 |
498 for suite_name in options.suite_name: | 497 for suite_name in options.suite_name: |
499 # TODO(gkanwar): Move this into ProcessGTestOptions once we require -s for | 498 # TODO(gkanwar): Move this into ProcessGTestOptions once we require -s for |
500 # the gtest command. | 499 # the gtest command. |
501 gtest_options = gtest_test_options.GTestOptions( | 500 gtest_options = gtest_test_options.GTestOptions( |
502 options.tool, | 501 options.tool, |
503 options.cleanup_test_files, | 502 options.cleanup_test_files, |
(...skipping 17 matching lines...) Expand all Loading... |
521 test_type='Unit test', | 520 test_type='Unit test', |
522 test_package=suite_name, | 521 test_package=suite_name, |
523 flakiness_server=options.flakiness_dashboard_server) | 522 flakiness_server=options.flakiness_dashboard_server) |
524 | 523 |
525 if os.path.isdir(constants.ISOLATE_DEPS_DIR): | 524 if os.path.isdir(constants.ISOLATE_DEPS_DIR): |
526 shutil.rmtree(constants.ISOLATE_DEPS_DIR) | 525 shutil.rmtree(constants.ISOLATE_DEPS_DIR) |
527 | 526 |
528 return exit_code | 527 return exit_code |
529 | 528 |
530 | 529 |
531 def _RunLinkerTests(options, error_func, devices): | 530 def _RunLinkerTests(options, devices): |
532 """Subcommand of RunTestsCommands which runs linker tests.""" | 531 """Subcommand of RunTestsCommands which runs linker tests.""" |
533 runner_factory, tests = linker_setup.Setup(options, devices) | 532 runner_factory, tests = linker_setup.Setup(options, devices) |
534 | 533 |
535 results, exit_code = test_dispatcher.RunTests( | 534 results, exit_code = test_dispatcher.RunTests( |
536 tests, runner_factory, devices, shard=True, test_timeout=60, | 535 tests, runner_factory, devices, shard=True, test_timeout=60, |
537 num_retries=options.num_retries) | 536 num_retries=options.num_retries) |
538 | 537 |
539 report_results.LogFull( | 538 report_results.LogFull( |
540 results=results, | 539 results=results, |
541 test_type='Linker test', | 540 test_type='Linker test', |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
707 | 706 |
708 ProcessCommonOptions(options) | 707 ProcessCommonOptions(options) |
709 | 708 |
710 devices = _GetAttachedDevices(options.test_device) | 709 devices = _GetAttachedDevices(options.test_device) |
711 | 710 |
712 forwarder.Forwarder.RemoveHostLog() | 711 forwarder.Forwarder.RemoveHostLog() |
713 if not ports.ResetTestServerPortAllocation(): | 712 if not ports.ResetTestServerPortAllocation(): |
714 raise Exception('Failed to reset test server port.') | 713 raise Exception('Failed to reset test server port.') |
715 | 714 |
716 if command == 'gtest': | 715 if command == 'gtest': |
717 return _RunGTests(options, option_parser.error, devices) | 716 return _RunGTests(options, devices) |
718 elif command == 'linker': | 717 elif command == 'linker': |
719 return _RunLinkerTests(options, option_parser.error, devices) | 718 return _RunLinkerTests(options, devices) |
720 elif command == 'instrumentation': | 719 elif command == 'instrumentation': |
721 return _RunInstrumentationTests(options, option_parser.error, devices) | 720 return _RunInstrumentationTests(options, option_parser.error, devices) |
722 elif command == 'uiautomator': | 721 elif command == 'uiautomator': |
723 return _RunUIAutomatorTests(options, option_parser.error, devices) | 722 return _RunUIAutomatorTests(options, option_parser.error, devices) |
724 elif command == 'monkey': | 723 elif command == 'monkey': |
725 return _RunMonkeyTests(options, option_parser.error, devices) | 724 return _RunMonkeyTests(options, option_parser.error, devices) |
726 elif command == 'perf': | 725 elif command == 'perf': |
727 return _RunPerfTests(options, args, option_parser.error, devices) | 726 return _RunPerfTests(options, args, option_parser.error, devices) |
728 else: | 727 else: |
729 raise Exception('Unknown test type.') | 728 raise Exception('Unknown test type.') |
730 | 729 |
731 | 730 |
732 def HelpCommand(command, options, args, option_parser): | 731 def HelpCommand(command, _options, args, option_parser): |
733 """Display help for a certain command, or overall help. | 732 """Display help for a certain command, or overall help. |
734 | 733 |
735 Args: | 734 Args: |
736 command: String indicating the command that was received to trigger | 735 command: String indicating the command that was received to trigger |
737 this function. | 736 this function. |
738 options: optparse options dictionary. | 737 options: optparse options dictionary. unused. |
739 args: List of extra args from optparse. | 738 args: List of extra args from optparse. |
740 option_parser: optparse.OptionParser object. | 739 option_parser: optparse.OptionParser object. |
741 | 740 |
742 Returns: | 741 Returns: |
743 Integer indicated exit code. | 742 Integer indicated exit code. |
744 """ | 743 """ |
745 # If we don't have any args, display overall help | 744 # If we don't have any args, display overall help |
746 if len(args) < 3: | 745 if len(args) < 3: |
747 option_parser.print_help() | 746 option_parser.print_help() |
748 return 0 | 747 return 0 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
784 'monkey': CommandFunctionTuple( | 783 'monkey': CommandFunctionTuple( |
785 AddMonkeyTestOptions, RunTestsCommand), | 784 AddMonkeyTestOptions, RunTestsCommand), |
786 'perf': CommandFunctionTuple( | 785 'perf': CommandFunctionTuple( |
787 AddPerfTestOptions, RunTestsCommand), | 786 AddPerfTestOptions, RunTestsCommand), |
788 'linker': CommandFunctionTuple( | 787 'linker': CommandFunctionTuple( |
789 AddLinkerTestOptions, RunTestsCommand), | 788 AddLinkerTestOptions, RunTestsCommand), |
790 'help': CommandFunctionTuple(lambda option_parser: None, HelpCommand) | 789 'help': CommandFunctionTuple(lambda option_parser: None, HelpCommand) |
791 } | 790 } |
792 | 791 |
793 | 792 |
794 def DumpThreadStacks(signal, frame): | 793 def DumpThreadStacks(_signal, _frame): |
795 for thread in threading.enumerate(): | 794 for thread in threading.enumerate(): |
796 reraiser_thread.LogThreadStack(thread) | 795 reraiser_thread.LogThreadStack(thread) |
797 | 796 |
798 | 797 |
799 def main(argv): | 798 def main(): |
800 signal.signal(signal.SIGUSR1, DumpThreadStacks) | 799 signal.signal(signal.SIGUSR1, DumpThreadStacks) |
801 option_parser = command_option_parser.CommandOptionParser( | 800 option_parser = command_option_parser.CommandOptionParser( |
802 commands_dict=VALID_COMMANDS) | 801 commands_dict=VALID_COMMANDS) |
803 return command_option_parser.ParseAndExecute(option_parser) | 802 return command_option_parser.ParseAndExecute(option_parser) |
804 | 803 |
805 | 804 |
806 if __name__ == '__main__': | 805 if __name__ == '__main__': |
807 sys.exit(main(sys.argv)) | 806 sys.exit(main()) |
OLD | NEW |