Charlie Mooney | 3cca6ba | 2014-11-19 16:15:28 -0800 | [diff] [blame] | 1 | # Copyright (c) 2014 The Chromium OS Authors. All rights reserved. |
| 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
| 4 | |
| 5 | import optparse |
Charlie Mooney | 985cf40 | 2015-01-08 15:15:59 -0800 | [diff] [blame] | 6 | import os |
Charlie Mooney | 3cca6ba | 2014-11-19 16:15:28 -0800 | [diff] [blame] | 7 | import sys |
| 8 | |
Charlie Mooney | e0d06c4 | 2015-01-27 11:32:51 -0800 | [diff] [blame] | 9 | import mt |
Charlie Mooney | d5712b8 | 2015-02-23 12:06:59 -0800 | [diff] [blame] | 10 | import plotter |
Charlie Mooney | e0d06c4 | 2015-01-27 11:32:51 -0800 | [diff] [blame] | 11 | |
Charlie Mooney | d5712b8 | 2015-02-23 12:06:59 -0800 | [diff] [blame] | 12 | from remote import ChromeOSTouchDevice, AndroidTouchDevice |
Charlie Mooney | 985cf40 | 2015-01-08 15:15:59 -0800 | [diff] [blame] | 13 | from report import Report |
Charlie Mooney | 3cca6ba | 2014-11-19 16:15:28 -0800 | [diff] [blame] | 14 | from test_suite import TestSuite |
| 15 | |
| 16 | |
| 17 | def parse_arguments(): |
Charlie Mooney | 985cf40 | 2015-01-08 15:15:59 -0800 | [diff] [blame] | 18 | VALID_DUT_TYPES = ['chromeos', 'android', 'replay'] |
Charlie Mooney | 7305176 | 2015-02-06 11:52:38 -0800 | [diff] [blame] | 19 | VALID_MODES = ['performance', 'noise', 'full'] |
Charlie Mooney | e0d06c4 | 2015-01-27 11:32:51 -0800 | [diff] [blame] | 20 | VALID_PROTOCOLS = [mt.MTA, mt.MTB, 'auto'] |
Charlie Mooney | 3cca6ba | 2014-11-19 16:15:28 -0800 | [diff] [blame] | 21 | parser = optparse.OptionParser() |
| 22 | |
| 23 | # DUT specification information |
| 24 | parser.add_option('-a', '--addr', dest='addr', default=None, |
Charlie Mooney | e0d06c4 | 2015-01-27 11:32:51 -0800 | [diff] [blame] | 25 | help=('The address of the DUT (ip for CrOS, Device ID ' |
Charlie Mooney | 985cf40 | 2015-01-08 15:15:59 -0800 | [diff] [blame] | 26 | 'for Android, or a filename to replay old results).')) |
Charlie Mooney | 3cca6ba | 2014-11-19 16:15:28 -0800 | [diff] [blame] | 27 | parser.add_option('-t', '--type', dest='dut_type', default=None, |
Charlie Mooney | 985cf40 | 2015-01-08 15:15:59 -0800 | [diff] [blame] | 28 | help='The type of DUT (android, chromeos, or replay).') |
Charlie Mooney | 3cca6ba | 2014-11-19 16:15:28 -0800 | [diff] [blame] | 29 | parser.add_option('--touchscreen', dest='is_touchscreen', |
| 30 | default=False, action='store_true', |
Charlie Mooney | e0d06c4 | 2015-01-27 11:32:51 -0800 | [diff] [blame] | 31 | help=('Use the touchscreen (instead of touchpad) on ' |
Charlie Mooney | 3cca6ba | 2014-11-19 16:15:28 -0800 | [diff] [blame] | 32 | 'the device.')) |
| 33 | |
Charlie Mooney | e0d06c4 | 2015-01-27 11:32:51 -0800 | [diff] [blame] | 34 | parser.add_option('--protocol', dest='protocol', default='auto', |
| 35 | help=('Manually specify the multitouch protocol for the ' |
| 36 | 'DUT. This should be detected automatically, but ' |
| 37 | 'in the event that fails, you may specify "mtb" or ' |
| 38 | '"mta" with this flag to over-ride it.')) |
| 39 | |
Charlie Mooney | 3cca6ba | 2014-11-19 16:15:28 -0800 | [diff] [blame] | 40 | # Lab equipment specification |
| 41 | parser.add_option('-r', '--robot', dest='has_robot', |
| 42 | default=False, action='store_true', |
Charlie Mooney | e0d06c4 | 2015-01-27 11:32:51 -0800 | [diff] [blame] | 43 | help=('Indicate that you have a Google Touchbot that ' |
Charlie Mooney | 3cca6ba | 2014-11-19 16:15:28 -0800 | [diff] [blame] | 44 | 'will perform your gestures for you.')) |
| 45 | parser.add_option('-f', '--fn_gen', dest='has_fn_gen', |
| 46 | default=False, action='store_true', |
Charlie Mooney | e0d06c4 | 2015-01-27 11:32:51 -0800 | [diff] [blame] | 47 | help=('Indicate that you have an HP 33120A function ' |
Charlie Mooney | 3cca6ba | 2014-11-19 16:15:28 -0800 | [diff] [blame] | 48 | 'generator to automate the electric noise tests.')) |
Charlie Mooney | 7305176 | 2015-02-06 11:52:38 -0800 | [diff] [blame] | 49 | parser.add_option('-m', '--mode', dest='mode', default='performance', |
| 50 | help=('Which mode to run the test suite in. Options are ' |
| 51 | '(performance, noise, or full) with performance as ' |
| 52 | 'the default selection.')) |
Charlie Mooney | 3cca6ba | 2014-11-19 16:15:28 -0800 | [diff] [blame] | 53 | |
| 54 | # Test suite settings |
| 55 | parser.add_option('-i', '--iterations', dest='num_iterations', default=1, |
| 56 | type=int, help=('The number of test iterations to run.')) |
Charlie Mooney | d5712b8 | 2015-02-23 12:06:59 -0800 | [diff] [blame] | 57 | parser.add_option('--plot_only', dest='plot_only', default=False, |
| 58 | action='store_true', |
| 59 | help=('Only plot touch evets. Do not run any tests.')) |
Charlie Mooney | 3cca6ba | 2014-11-19 16:15:28 -0800 | [diff] [blame] | 60 | |
| 61 | (options, args) = parser.parse_args() |
| 62 | |
| 63 | if options.dut_type not in VALID_DUT_TYPES: |
Charlie Mooney | 985cf40 | 2015-01-08 15:15:59 -0800 | [diff] [blame] | 64 | print 'ERROR: invalid dut type "%s"' % options.dut_type |
| 65 | print 'valid dut types are: %s' % str(VALID_DUT_TYPES) |
| 66 | sys.exit(1) |
Charlie Mooney | 3cca6ba | 2014-11-19 16:15:28 -0800 | [diff] [blame] | 67 | if options.dut_type == 'chromeos' and not options.addr: |
Charlie Mooney | 985cf40 | 2015-01-08 15:15:59 -0800 | [diff] [blame] | 68 | print 'ERROR: You must supply an IP address for ChromeOS DUTs' |
| 69 | sys.exit(1) |
Charlie Mooney | e0d06c4 | 2015-01-27 11:32:51 -0800 | [diff] [blame] | 70 | if options.protocol not in VALID_PROTOCOLS: |
| 71 | print 'ERROR: invalid protocol "%s"' % options.protocol |
| 72 | print 'valid protocols are: %s' % str(VALID_PROTOCOLS) |
| 73 | sys.exit(1) |
Charlie Mooney | 7305176 | 2015-02-06 11:52:38 -0800 | [diff] [blame] | 74 | if options.mode not in VALID_MODES: |
| 75 | print 'ERROR: invalid mode "%s"' % options.mode |
| 76 | print 'valid modes are: %s' % str(VALID_MODES) |
| 77 | sys.exit(1) |
Charlie Mooney | 3cca6ba | 2014-11-19 16:15:28 -0800 | [diff] [blame] | 78 | |
| 79 | return options, args |
| 80 | |
| 81 | |
Charlie Mooney | d5712b8 | 2015-02-23 12:06:59 -0800 | [diff] [blame] | 82 | def initialize_touch_device(options): |
| 83 | """ Using the supplied options connect to the DUT """ |
| 84 | # Open a connection to the device specified |
| 85 | if options.dut_type == 'chromeos': |
| 86 | touch_dev = ChromeOSTouchDevice(options.addr, options.is_touchscreen) |
| 87 | elif options.dut_type == 'android': |
| 88 | touch_dev = AndroidTouchDevice(options.addr, True) |
| 89 | else: |
| 90 | return None |
| 91 | |
| 92 | # If the user specified the device's mt protocol override it now |
| 93 | if options.protocol != 'auto': |
| 94 | touch_dev.protocol = options.protocol |
| 95 | |
| 96 | return touch_dev |
Charlie Mooney | 985cf40 | 2015-01-08 15:15:59 -0800 | [diff] [blame] | 97 | |
Charlie Mooney | 3cca6ba | 2014-11-19 16:15:28 -0800 | [diff] [blame] | 98 | def main(): |
| 99 | # Parse and validate the command line arguments |
| 100 | options, args = parse_arguments() |
| 101 | |
Charlie Mooney | d5712b8 | 2015-02-23 12:06:59 -0800 | [diff] [blame] | 102 | # Connect to the DUT |
| 103 | touch_dev = initialize_touch_device(options) |
| 104 | |
| 105 | if options.plot_only: |
| 106 | # Show the live events as they come in instead of running any tests |
| 107 | print 'Displaying live touch events from your DUT. Press Ctrl+C to stop.' |
| 108 | plotter.live_display(touch_dev) |
| 109 | return 0 |
| 110 | |
Charlie Mooney | 985cf40 | 2015-01-08 15:15:59 -0800 | [diff] [blame] | 111 | if options.dut_type != 'replay': |
| 112 | # Create a test flow object that will run the test step by step |
Charlie Mooney | d5712b8 | 2015-02-23 12:06:59 -0800 | [diff] [blame] | 113 | test_suite = TestSuite(touch_dev, options, args) |
Charlie Mooney | 3cca6ba | 2014-11-19 16:15:28 -0800 | [diff] [blame] | 114 | |
Charlie Mooney | 985cf40 | 2015-01-08 15:15:59 -0800 | [diff] [blame] | 115 | # Run through the entire test suite in turn |
| 116 | while test_suite.RunNextTestAndVariation(): |
| 117 | pass |
| 118 | |
| 119 | # The test suite should have a fully populated Report object now, filled |
| 120 | # with the results of all the test runs. |
| 121 | report = test_suite.report |
| 122 | |
| 123 | # Save this report into a default location as a backup in case you want |
| 124 | # to replay it later. |
| 125 | report.SaveToDisk('last_report.p') |
| 126 | else: |
| 127 | # We are trying to replay an old report from a file on disk. Load the Report |
| 128 | # directly from the specified file instead of running the test over again. |
| 129 | report = Report.FromFile(options.addr) |
| 130 | |
| 131 | # Generate an HTML version of the Report and write it to disk |
| 132 | html_report = report.GenerateHtml() |
| 133 | with open('report.html', 'w') as fo: |
| 134 | fo.write(html_report) |
Charlie Mooney | 3cca6ba | 2014-11-19 16:15:28 -0800 | [diff] [blame] | 135 | |
| 136 | return 0 |
| 137 | |
| 138 | |
| 139 | if __name__ == "__main__": |
| 140 | sys.exit(main()) |