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 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
709 | 708 |
710 ProcessCommonOptions(options) | 709 ProcessCommonOptions(options) |
711 | 710 |
712 devices = _GetAttachedDevices(options.test_device) | 711 devices = _GetAttachedDevices(options.test_device) |
713 | 712 |
714 forwarder.Forwarder.RemoveHostLog() | 713 forwarder.Forwarder.RemoveHostLog() |
715 if not ports.ResetTestServerPortAllocation(): | 714 if not ports.ResetTestServerPortAllocation(): |
716 raise Exception('Failed to reset test server port.') | 715 raise Exception('Failed to reset test server port.') |
717 | 716 |
718 if command == 'gtest': | 717 if command == 'gtest': |
719 return _RunGTests(options, option_parser.error, devices) | 718 return _RunGTests(options, devices) |
720 elif command == 'linker': | 719 elif command == 'linker': |
721 return _RunLinkerTests(options, option_parser.error, devices) | 720 return _RunLinkerTests(options, devices) |
722 elif command == 'instrumentation': | 721 elif command == 'instrumentation': |
723 return _RunInstrumentationTests(options, option_parser.error, devices) | 722 return _RunInstrumentationTests(options, option_parser.error, devices) |
724 elif command == 'uiautomator': | 723 elif command == 'uiautomator': |
725 return _RunUIAutomatorTests(options, option_parser.error, devices) | 724 return _RunUIAutomatorTests(options, option_parser.error, devices) |
726 elif command == 'monkey': | 725 elif command == 'monkey': |
727 return _RunMonkeyTests(options, option_parser.error, devices) | 726 return _RunMonkeyTests(options, option_parser.error, devices) |
728 elif command == 'perf': | 727 elif command == 'perf': |
729 return _RunPerfTests(options, args, option_parser.error, devices) | 728 return _RunPerfTests(options, args, option_parser.error, devices) |
730 else: | 729 else: |
731 raise Exception('Unknown test type.') | 730 raise Exception('Unknown test type.') |
732 | 731 |
733 | 732 |
734 def HelpCommand(command, options, args, option_parser): | 733 def HelpCommand(command, _options, args, option_parser): |
735 """Display help for a certain command, or overall help. | 734 """Display help for a certain command, or overall help. |
736 | 735 |
737 Args: | 736 Args: |
738 command: String indicating the command that was received to trigger | 737 command: String indicating the command that was received to trigger |
739 this function. | 738 this function. |
740 options: optparse options dictionary. | 739 options: optparse options dictionary. unused. |
741 args: List of extra args from optparse. | 740 args: List of extra args from optparse. |
742 option_parser: optparse.OptionParser object. | 741 option_parser: optparse.OptionParser object. |
743 | 742 |
744 Returns: | 743 Returns: |
745 Integer indicated exit code. | 744 Integer indicated exit code. |
746 """ | 745 """ |
747 # If we don't have any args, display overall help | 746 # If we don't have any args, display overall help |
748 if len(args) < 3: | 747 if len(args) < 3: |
749 option_parser.print_help() | 748 option_parser.print_help() |
750 return 0 | 749 return 0 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
786 'monkey': CommandFunctionTuple( | 785 'monkey': CommandFunctionTuple( |
787 AddMonkeyTestOptions, RunTestsCommand), | 786 AddMonkeyTestOptions, RunTestsCommand), |
788 'perf': CommandFunctionTuple( | 787 'perf': CommandFunctionTuple( |
789 AddPerfTestOptions, RunTestsCommand), | 788 AddPerfTestOptions, RunTestsCommand), |
790 'linker': CommandFunctionTuple( | 789 'linker': CommandFunctionTuple( |
791 AddLinkerTestOptions, RunTestsCommand), | 790 AddLinkerTestOptions, RunTestsCommand), |
792 'help': CommandFunctionTuple(lambda option_parser: None, HelpCommand) | 791 'help': CommandFunctionTuple(lambda option_parser: None, HelpCommand) |
793 } | 792 } |
794 | 793 |
795 | 794 |
796 def DumpThreadStacks(signal, frame): | 795 def DumpThreadStacks(_signal, _frame): |
797 for thread in threading.enumerate(): | 796 for thread in threading.enumerate(): |
798 reraiser_thread.LogThreadStack(thread) | 797 reraiser_thread.LogThreadStack(thread) |
799 | 798 |
800 | 799 |
801 def main(argv): | 800 def main(): |
802 signal.signal(signal.SIGUSR1, DumpThreadStacks) | 801 signal.signal(signal.SIGUSR1, DumpThreadStacks) |
803 option_parser = command_option_parser.CommandOptionParser( | 802 option_parser = command_option_parser.CommandOptionParser( |
804 commands_dict=VALID_COMMANDS) | 803 commands_dict=VALID_COMMANDS) |
805 return command_option_parser.ParseAndExecute(option_parser) | 804 return command_option_parser.ParseAndExecute(option_parser) |
806 | 805 |
807 | 806 |
808 if __name__ == '__main__': | 807 if __name__ == '__main__': |
809 sys.exit(main(sys.argv)) | 808 sys.exit(main()) |
OLD | NEW |