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 | 389e1f3 | 2015-03-06 13:33:20 -0800 | [diff] [blame] | 9 | import colorama as color |
Charlie Mooney | e0d06c4 | 2015-01-27 11:32:51 -0800 | [diff] [blame] | 10 | |
Amirhossein Simjour | 7a71f33 | 2015-04-10 15:18:37 -0400 | [diff] [blame] | 11 | from remote import ChromeOSTouchDevice, AndroidTouchDevice, ElanTouchDevice, mt |
Charlie Mooney | 985cf40 | 2015-01-08 15:15:59 -0800 | [diff] [blame] | 12 | from report import Report |
Charlie Mooney | 3cca6ba | 2014-11-19 16:15:28 -0800 | [diff] [blame] | 13 | from test_suite import TestSuite |
| 14 | |
| 15 | |
| 16 | def parse_arguments(): |
Amirhossein Simjour | 7a71f33 | 2015-04-10 15:18:37 -0400 | [diff] [blame] | 17 | VALID_DUT_TYPES = ['chromeos', 'android', 'elan_i2c', 'replay'] |
Charlie Mooney | 7305176 | 2015-02-06 11:52:38 -0800 | [diff] [blame] | 18 | VALID_MODES = ['performance', 'noise', 'full'] |
Charlie Mooney | e0d06c4 | 2015-01-27 11:32:51 -0800 | [diff] [blame] | 19 | VALID_PROTOCOLS = [mt.MTA, mt.MTB, 'auto'] |
Charlie Mooney | 3cca6ba | 2014-11-19 16:15:28 -0800 | [diff] [blame] | 20 | parser = optparse.OptionParser() |
| 21 | |
| 22 | # DUT specification information |
| 23 | parser.add_option('-a', '--addr', dest='addr', default=None, |
Charlie Mooney | e0d06c4 | 2015-01-27 11:32:51 -0800 | [diff] [blame] | 24 | help=('The address of the DUT (ip for CrOS, Device ID ' |
Charlie Mooney | 985cf40 | 2015-01-08 15:15:59 -0800 | [diff] [blame] | 25 | 'for Android, or a filename to replay old results).')) |
Charlie Mooney | 3cca6ba | 2014-11-19 16:15:28 -0800 | [diff] [blame] | 26 | parser.add_option('-t', '--type', dest='dut_type', default=None, |
Charlie Mooney | 985cf40 | 2015-01-08 15:15:59 -0800 | [diff] [blame] | 27 | help='The type of DUT (android, chromeos, or replay).') |
Charlie Mooney | 3cca6ba | 2014-11-19 16:15:28 -0800 | [diff] [blame] | 28 | parser.add_option('--touchscreen', dest='is_touchscreen', |
| 29 | default=False, action='store_true', |
Charlie Mooney | e0d06c4 | 2015-01-27 11:32:51 -0800 | [diff] [blame] | 30 | help=('Use the touchscreen (instead of touchpad) on ' |
Charlie Mooney | 3cca6ba | 2014-11-19 16:15:28 -0800 | [diff] [blame] | 31 | 'the device.')) |
| 32 | |
Charlie Mooney | e0d06c4 | 2015-01-27 11:32:51 -0800 | [diff] [blame] | 33 | parser.add_option('--protocol', dest='protocol', default='auto', |
| 34 | help=('Manually specify the multitouch protocol for the ' |
| 35 | 'DUT. This should be detected automatically, but ' |
| 36 | 'in the event that fails, you may specify "mtb" or ' |
| 37 | '"mta" with this flag to over-ride it.')) |
Charlie Mooney | 0866191 | 2015-04-16 09:20:34 -0700 | [diff] [blame] | 38 | parser.add_option('-n', '--name', dest='name', default='unknown_device', |
| 39 | help='The name of this DUT. This is used by the robot to ' |
| 40 | 'store calibration data and is only needed if you are ' |
| 41 | 'using the touchbot. Simply keep the name consistent ' |
| 42 | 'across multiple tests on the same DUT to avoid ' |
| 43 | 'having to recalibrate the robot each time.') |
Charlie Mooney | e0d06c4 | 2015-01-27 11:32:51 -0800 | [diff] [blame] | 44 | |
Charlie Mooney | 3cca6ba | 2014-11-19 16:15:28 -0800 | [diff] [blame] | 45 | # Lab equipment specification |
| 46 | parser.add_option('-r', '--robot', dest='has_robot', |
| 47 | default=False, action='store_true', |
Charlie Mooney | e0d06c4 | 2015-01-27 11:32:51 -0800 | [diff] [blame] | 48 | help=('Indicate that you have a Google Touchbot that ' |
Charlie Mooney | 3cca6ba | 2014-11-19 16:15:28 -0800 | [diff] [blame] | 49 | 'will perform your gestures for you.')) |
| 50 | parser.add_option('-f', '--fn_gen', dest='has_fn_gen', |
| 51 | default=False, action='store_true', |
Charlie Mooney | e0d06c4 | 2015-01-27 11:32:51 -0800 | [diff] [blame] | 52 | help=('Indicate that you have an HP 33120A function ' |
Charlie Mooney | 3cca6ba | 2014-11-19 16:15:28 -0800 | [diff] [blame] | 53 | 'generator to automate the electric noise tests.')) |
Charlie Mooney | 7305176 | 2015-02-06 11:52:38 -0800 | [diff] [blame] | 54 | parser.add_option('-m', '--mode', dest='mode', default='performance', |
| 55 | help=('Which mode to run the test suite in. Options are ' |
| 56 | '(performance, noise, or full) with performance as ' |
| 57 | 'the default selection.')) |
Charlie Mooney | 3cca6ba | 2014-11-19 16:15:28 -0800 | [diff] [blame] | 58 | |
| 59 | # Test suite settings |
| 60 | parser.add_option('-i', '--iterations', dest='num_iterations', default=1, |
| 61 | type=int, help=('The number of test iterations to run.')) |
Charlie Mooney | 3d00bdc | 2015-05-08 12:58:35 -0700 | [diff] [blame^] | 62 | parser.add_option('--title', dest='title', default=None, |
| 63 | help='An optional title to put at the top of the report.') |
Charlie Mooney | 3cca6ba | 2014-11-19 16:15:28 -0800 | [diff] [blame] | 64 | |
| 65 | (options, args) = parser.parse_args() |
| 66 | |
| 67 | if options.dut_type not in VALID_DUT_TYPES: |
Charlie Mooney | 985cf40 | 2015-01-08 15:15:59 -0800 | [diff] [blame] | 68 | print 'ERROR: invalid dut type "%s"' % options.dut_type |
| 69 | print 'valid dut types are: %s' % str(VALID_DUT_TYPES) |
| 70 | sys.exit(1) |
Charlie Mooney | 3cca6ba | 2014-11-19 16:15:28 -0800 | [diff] [blame] | 71 | if options.dut_type == 'chromeos' and not options.addr: |
Charlie Mooney | 985cf40 | 2015-01-08 15:15:59 -0800 | [diff] [blame] | 72 | print 'ERROR: You must supply an IP address for ChromeOS DUTs' |
| 73 | sys.exit(1) |
Charlie Mooney | e0d06c4 | 2015-01-27 11:32:51 -0800 | [diff] [blame] | 74 | if options.protocol not in VALID_PROTOCOLS: |
| 75 | print 'ERROR: invalid protocol "%s"' % options.protocol |
| 76 | print 'valid protocols are: %s' % str(VALID_PROTOCOLS) |
| 77 | sys.exit(1) |
Charlie Mooney | 7305176 | 2015-02-06 11:52:38 -0800 | [diff] [blame] | 78 | if options.mode not in VALID_MODES: |
| 79 | print 'ERROR: invalid mode "%s"' % options.mode |
| 80 | print 'valid modes are: %s' % str(VALID_MODES) |
| 81 | sys.exit(1) |
Charlie Mooney | 3cca6ba | 2014-11-19 16:15:28 -0800 | [diff] [blame] | 82 | |
| 83 | return options, args |
| 84 | |
| 85 | |
Charlie Mooney | d5712b8 | 2015-02-23 12:06:59 -0800 | [diff] [blame] | 86 | def initialize_touch_device(options): |
| 87 | """ Using the supplied options connect to the DUT """ |
| 88 | # Open a connection to the device specified |
Charlie Mooney | 389e1f3 | 2015-03-06 13:33:20 -0800 | [diff] [blame] | 89 | print (color.Style.DIM + color.Fore.RED + |
| 90 | 'Please do not touch the device until the test starts!') |
| 91 | print 'Connecting to remote touch device...' |
Charlie Mooney | d5712b8 | 2015-02-23 12:06:59 -0800 | [diff] [blame] | 92 | if options.dut_type == 'chromeos': |
Charlie Mooney | 389e1f3 | 2015-03-06 13:33:20 -0800 | [diff] [blame] | 93 | touch_dev = ChromeOSTouchDevice(options.addr, options.is_touchscreen, |
| 94 | options.protocol) |
Charlie Mooney | d5712b8 | 2015-02-23 12:06:59 -0800 | [diff] [blame] | 95 | elif options.dut_type == 'android': |
Charlie Mooney | 389e1f3 | 2015-03-06 13:33:20 -0800 | [diff] [blame] | 96 | touch_dev = AndroidTouchDevice(options.addr, True, options.protocol) |
Amirhossein Simjour | 7a71f33 | 2015-04-10 15:18:37 -0400 | [diff] [blame] | 97 | elif options.dut_type == 'elan_i2c': |
| 98 | touch_dev = ElanTouchDevice(options.addr, True) |
Charlie Mooney | d5712b8 | 2015-02-23 12:06:59 -0800 | [diff] [blame] | 99 | else: |
| 100 | return None |
| 101 | |
Charlie Mooney | d5712b8 | 2015-02-23 12:06:59 -0800 | [diff] [blame] | 102 | return touch_dev |
Charlie Mooney | 985cf40 | 2015-01-08 15:15:59 -0800 | [diff] [blame] | 103 | |
Charlie Mooney | 3cca6ba | 2014-11-19 16:15:28 -0800 | [diff] [blame] | 104 | def main(): |
Charlie Mooney | 389e1f3 | 2015-03-06 13:33:20 -0800 | [diff] [blame] | 105 | color.init(autoreset=True) |
| 106 | |
Charlie Mooney | 3cca6ba | 2014-11-19 16:15:28 -0800 | [diff] [blame] | 107 | # Parse and validate the command line arguments |
| 108 | options, args = parse_arguments() |
| 109 | |
Charlie Mooney | 985cf40 | 2015-01-08 15:15:59 -0800 | [diff] [blame] | 110 | if options.dut_type != 'replay': |
Charlie Mooney | 818c60c | 2015-04-21 15:10:44 -0700 | [diff] [blame] | 111 | # Connect to the DUT |
| 112 | touch_dev = initialize_touch_device(options) |
| 113 | |
Charlie Mooney | 985cf40 | 2015-01-08 15:15:59 -0800 | [diff] [blame] | 114 | # 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] | 115 | test_suite = TestSuite(touch_dev, options, args) |
Charlie Mooney | 3cca6ba | 2014-11-19 16:15:28 -0800 | [diff] [blame] | 116 | |
Charlie Mooney | 985cf40 | 2015-01-08 15:15:59 -0800 | [diff] [blame] | 117 | # Run through the entire test suite in turn |
| 118 | while test_suite.RunNextTestAndVariation(): |
| 119 | pass |
Charlie Mooney | c68f9c3 | 2015-04-16 15:23:22 -0700 | [diff] [blame] | 120 | test_suite.StopPlotter() |
Charlie Mooney | 985cf40 | 2015-01-08 15:15:59 -0800 | [diff] [blame] | 121 | |
| 122 | # The test suite should have a fully populated Report object now, filled |
| 123 | # with the results of all the test runs. |
| 124 | report = test_suite.report |
| 125 | |
| 126 | # Save this report into a default location as a backup in case you want |
| 127 | # to replay it later. |
| 128 | report.SaveToDisk('last_report.p') |
| 129 | else: |
Charlie Mooney | 389e1f3 | 2015-03-06 13:33:20 -0800 | [diff] [blame] | 130 | # We are trying to replay an old report from a file on disk. Load it |
Charlie Mooney | 985cf40 | 2015-01-08 15:15:59 -0800 | [diff] [blame] | 131 | # directly from the specified file instead of running the test over again. |
| 132 | report = Report.FromFile(options.addr) |
| 133 | |
| 134 | # Generate an HTML version of the Report and write it to disk |
| 135 | html_report = report.GenerateHtml() |
| 136 | with open('report.html', 'w') as fo: |
| 137 | fo.write(html_report) |
Charlie Mooney | 3cca6ba | 2014-11-19 16:15:28 -0800 | [diff] [blame] | 138 | |
| 139 | return 0 |
| 140 | |
| 141 | |
| 142 | if __name__ == "__main__": |
| 143 | sys.exit(main()) |