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 | |
Charlie Mooney | 4291c4e | 2015-06-15 10:15:30 -0700 | [diff] [blame] | 5 | import inspect |
Charlie Mooney | 3cca6ba | 2014-11-19 16:15:28 -0800 | [diff] [blame] | 6 | import optparse |
Charlie Mooney | 985cf40 | 2015-01-08 15:15:59 -0800 | [diff] [blame] | 7 | import os |
Charlie Mooney | 3cca6ba | 2014-11-19 16:15:28 -0800 | [diff] [blame] | 8 | import sys |
Charlie Mooney | 4291c4e | 2015-06-15 10:15:30 -0700 | [diff] [blame] | 9 | from subprocess import Popen, PIPE |
Charlie Mooney | 3cca6ba | 2014-11-19 16:15:28 -0800 | [diff] [blame] | 10 | |
Charlie Mooney | 389e1f3 | 2015-03-06 13:33:20 -0800 | [diff] [blame] | 11 | import colorama as color |
Charlie Mooney | e0d06c4 | 2015-01-27 11:32:51 -0800 | [diff] [blame] | 12 | |
Amirhossein Simjour | af7e16a | 2015-05-13 16:31:57 -0400 | [diff] [blame] | 13 | from remote import ChromeOSTouchDevice, AndroidTouchDevice, mt |
Amirhossein Simjour | 3f1774c | 2015-06-16 13:45:13 -0400 | [diff] [blame] | 14 | from remote import ElanTouchScreenDevice, ElanTouchDevice, SynapticsTouchDevice |
Charlie Mooney | 985cf40 | 2015-01-08 15:15:59 -0800 | [diff] [blame] | 15 | from report import Report |
Charlie Mooney | 3cca6ba | 2014-11-19 16:15:28 -0800 | [diff] [blame] | 16 | from test_suite import TestSuite |
| 17 | |
Charlie Mooney | ff8b332 | 2016-06-14 14:58:12 -0700 | [diff] [blame^] | 18 | REPORT_LOCATION_FORMAT = '%s_report.html' |
Charlie Mooney | 3cca6ba | 2014-11-19 16:15:28 -0800 | [diff] [blame] | 19 | |
| 20 | def parse_arguments(): |
Amirhossein Simjour | 3f1774c | 2015-06-16 13:45:13 -0400 | [diff] [blame] | 21 | VALID_DUT_TYPES = ['chromeos', 'android', 'elan_i2c', 'elan_ts_i2c', |
| 22 | 'synaptics_ts_i2c', 'replay'] |
Charlie Mooney | 7305176 | 2015-02-06 11:52:38 -0800 | [diff] [blame] | 23 | VALID_MODES = ['performance', 'noise', 'full'] |
Charlie Mooney | e0d06c4 | 2015-01-27 11:32:51 -0800 | [diff] [blame] | 24 | VALID_PROTOCOLS = [mt.MTA, mt.MTB, 'auto'] |
Charlie Mooney | 3cca6ba | 2014-11-19 16:15:28 -0800 | [diff] [blame] | 25 | parser = optparse.OptionParser() |
| 26 | |
| 27 | # DUT specification information |
| 28 | parser.add_option('-a', '--addr', dest='addr', default=None, |
Charlie Mooney | e0d06c4 | 2015-01-27 11:32:51 -0800 | [diff] [blame] | 29 | help=('The address of the DUT (ip for CrOS, Device ID ' |
Charlie Mooney | 985cf40 | 2015-01-08 15:15:59 -0800 | [diff] [blame] | 30 | 'for Android, or a filename to replay old results).')) |
Charlie Mooney | 3cca6ba | 2014-11-19 16:15:28 -0800 | [diff] [blame] | 31 | parser.add_option('-t', '--type', dest='dut_type', default=None, |
Charlie Mooney | 985cf40 | 2015-01-08 15:15:59 -0800 | [diff] [blame] | 32 | help='The type of DUT (android, chromeos, or replay).') |
Charlie Mooney | 63e30ba | 2015-10-21 14:35:43 -0700 | [diff] [blame] | 33 | parser.add_option('-d', '--device_num', dest='device_num', |
| 34 | default=None, type=int, |
| 35 | help='The device number of the touch sensor if you know it') |
Charlie Mooney | 3cca6ba | 2014-11-19 16:15:28 -0800 | [diff] [blame] | 36 | parser.add_option('--touchscreen', dest='is_touchscreen', |
| 37 | default=False, action='store_true', |
Charlie Mooney | e0d06c4 | 2015-01-27 11:32:51 -0800 | [diff] [blame] | 38 | help=('Use the touchscreen (instead of touchpad) on ' |
Charlie Mooney | 3cca6ba | 2014-11-19 16:15:28 -0800 | [diff] [blame] | 39 | 'the device.')) |
| 40 | |
Charlie Mooney | e0d06c4 | 2015-01-27 11:32:51 -0800 | [diff] [blame] | 41 | parser.add_option('--protocol', dest='protocol', default='auto', |
| 42 | help=('Manually specify the multitouch protocol for the ' |
| 43 | 'DUT. This should be detected automatically, but ' |
| 44 | 'in the event that fails, you may specify "mtb" or ' |
| 45 | '"mta" with this flag to over-ride it.')) |
Charlie Mooney | 0866191 | 2015-04-16 09:20:34 -0700 | [diff] [blame] | 46 | parser.add_option('-n', '--name', dest='name', default='unknown_device', |
| 47 | help='The name of this DUT. This is used by the robot to ' |
| 48 | 'store calibration data and is only needed if you are ' |
| 49 | 'using the touchbot. Simply keep the name consistent ' |
| 50 | 'across multiple tests on the same DUT to avoid ' |
| 51 | 'having to recalibrate the robot each time.') |
Charlie Mooney | e0d06c4 | 2015-01-27 11:32:51 -0800 | [diff] [blame] | 52 | |
Charlie Mooney | 3cca6ba | 2014-11-19 16:15:28 -0800 | [diff] [blame] | 53 | # Lab equipment specification |
| 54 | parser.add_option('-r', '--robot', dest='has_robot', |
| 55 | default=False, action='store_true', |
Charlie Mooney | e0d06c4 | 2015-01-27 11:32:51 -0800 | [diff] [blame] | 56 | help=('Indicate that you have a Google Touchbot that ' |
Charlie Mooney | 3cca6ba | 2014-11-19 16:15:28 -0800 | [diff] [blame] | 57 | 'will perform your gestures for you.')) |
| 58 | parser.add_option('-f', '--fn_gen', dest='has_fn_gen', |
| 59 | default=False, action='store_true', |
Charlie Mooney | e0d06c4 | 2015-01-27 11:32:51 -0800 | [diff] [blame] | 60 | help=('Indicate that you have an HP 33120A function ' |
Charlie Mooney | 3cca6ba | 2014-11-19 16:15:28 -0800 | [diff] [blame] | 61 | 'generator to automate the electric noise tests.')) |
Charlie Mooney | 7305176 | 2015-02-06 11:52:38 -0800 | [diff] [blame] | 62 | parser.add_option('-m', '--mode', dest='mode', default='performance', |
| 63 | help=('Which mode to run the test suite in. Options are ' |
| 64 | '(performance, noise, or full) with performance as ' |
| 65 | 'the default selection.')) |
Charlie Mooney | 3cca6ba | 2014-11-19 16:15:28 -0800 | [diff] [blame] | 66 | |
| 67 | # Test suite settings |
| 68 | parser.add_option('-i', '--iterations', dest='num_iterations', default=1, |
| 69 | type=int, help=('The number of test iterations to run.')) |
Charlie Mooney | 3d00bdc | 2015-05-08 12:58:35 -0700 | [diff] [blame] | 70 | parser.add_option('--title', dest='title', default=None, |
| 71 | help='An optional title to put at the top of the report.') |
Charlie Mooney | 4291c4e | 2015-06-15 10:15:30 -0700 | [diff] [blame] | 72 | parser.add_option('--test_version', dest='test_version', default=None, |
| 73 | help=('An optionally overridden test version string. This ' |
| 74 | 'string will appear at the top of the report. If ' |
| 75 | 'left undefined the most recent git commit hash is ' |
| 76 | 'used by default.')) |
Charlie Mooney | 3cca6ba | 2014-11-19 16:15:28 -0800 | [diff] [blame] | 77 | |
| 78 | (options, args) = parser.parse_args() |
| 79 | |
| 80 | if options.dut_type not in VALID_DUT_TYPES: |
Charlie Mooney | 985cf40 | 2015-01-08 15:15:59 -0800 | [diff] [blame] | 81 | print 'ERROR: invalid dut type "%s"' % options.dut_type |
| 82 | print 'valid dut types are: %s' % str(VALID_DUT_TYPES) |
| 83 | sys.exit(1) |
Charlie Mooney | db3ea55 | 2015-07-06 14:10:49 -0700 | [diff] [blame] | 84 | elif options.dut_type == 'chromeos' and not options.addr: |
Charlie Mooney | 985cf40 | 2015-01-08 15:15:59 -0800 | [diff] [blame] | 85 | print 'ERROR: You must supply an IP address for ChromeOS DUTs' |
| 86 | sys.exit(1) |
Amirhossein Simjour | 9e9ea2e | 2015-07-16 11:25:24 -0400 | [diff] [blame] | 87 | # Aardvark setup does not support the physical button |
| 88 | elif options.dut_type in ['android', 'elan_ts_i2c', |
| 89 | 'elan_i2c', 'synaptics_ts_i2c']: |
Charlie Mooney | db3ea55 | 2015-07-06 14:10:49 -0700 | [diff] [blame] | 90 | options.is_touchscreen = True |
| 91 | |
Charlie Mooney | e0d06c4 | 2015-01-27 11:32:51 -0800 | [diff] [blame] | 92 | if options.protocol not in VALID_PROTOCOLS: |
| 93 | print 'ERROR: invalid protocol "%s"' % options.protocol |
| 94 | print 'valid protocols are: %s' % str(VALID_PROTOCOLS) |
| 95 | sys.exit(1) |
Charlie Mooney | 7305176 | 2015-02-06 11:52:38 -0800 | [diff] [blame] | 96 | if options.mode not in VALID_MODES: |
| 97 | print 'ERROR: invalid mode "%s"' % options.mode |
| 98 | print 'valid modes are: %s' % str(VALID_MODES) |
| 99 | sys.exit(1) |
Charlie Mooney | 3cca6ba | 2014-11-19 16:15:28 -0800 | [diff] [blame] | 100 | |
Charlie Mooney | 4291c4e | 2015-06-15 10:15:30 -0700 | [diff] [blame] | 101 | # If they didn't manually specify a test_version string, generate the default |
| 102 | # By looking up the most recent commit in the touch_firmware_test git repo. |
| 103 | if options.test_version is None: |
| 104 | src_file = inspect.getfile(inspect.currentframe()) |
| 105 | root_path = os.path.dirname(os.path.realpath(src_file)) |
| 106 | git_path = os.path.join(root_path, '.git') |
| 107 | args = ['git', '--git-dir', git_path, 'log', '--oneline', '-n1'] |
| 108 | options.test_version = Popen(args, stdout=PIPE).communicate()[0] |
| 109 | |
Charlie Mooney | 3cca6ba | 2014-11-19 16:15:28 -0800 | [diff] [blame] | 110 | return options, args |
| 111 | |
| 112 | |
Charlie Mooney | d5712b8 | 2015-02-23 12:06:59 -0800 | [diff] [blame] | 113 | def initialize_touch_device(options): |
| 114 | """ Using the supplied options connect to the DUT """ |
| 115 | # Open a connection to the device specified |
Charlie Mooney | 389e1f3 | 2015-03-06 13:33:20 -0800 | [diff] [blame] | 116 | print (color.Style.DIM + color.Fore.RED + |
| 117 | 'Please do not touch the device until the test starts!') |
| 118 | print 'Connecting to remote touch device...' |
Charlie Mooney | d5712b8 | 2015-02-23 12:06:59 -0800 | [diff] [blame] | 119 | if options.dut_type == 'chromeos': |
Charlie Mooney | 389e1f3 | 2015-03-06 13:33:20 -0800 | [diff] [blame] | 120 | touch_dev = ChromeOSTouchDevice(options.addr, options.is_touchscreen, |
Charlie Mooney | feeb07c | 2015-12-16 11:43:48 -0800 | [diff] [blame] | 121 | options.protocol, |
| 122 | device_num=options.device_num) |
Charlie Mooney | d5712b8 | 2015-02-23 12:06:59 -0800 | [diff] [blame] | 123 | elif options.dut_type == 'android': |
Charlie Mooney | 63e30ba | 2015-10-21 14:35:43 -0700 | [diff] [blame] | 124 | touch_dev = AndroidTouchDevice(options.addr, True, options.protocol, |
| 125 | options.device_num) |
Amirhossein Simjour | 7a71f33 | 2015-04-10 15:18:37 -0400 | [diff] [blame] | 126 | elif options.dut_type == 'elan_i2c': |
Amirhossein Simjour | af7e16a | 2015-05-13 16:31:57 -0400 | [diff] [blame] | 127 | touch_dev = ElanTouchDevice(options.addr) |
| 128 | elif options.dut_type == 'elan_ts_i2c': |
| 129 | touch_dev = ElanTouchScreenDevice(options.addr) |
Amirhossein Simjour | 3f1774c | 2015-06-16 13:45:13 -0400 | [diff] [blame] | 130 | elif options.dut_type == 'synaptics_ts_i2c': |
| 131 | touch_dev = SynapticsTouchDevice(options.addr) |
Charlie Mooney | d5712b8 | 2015-02-23 12:06:59 -0800 | [diff] [blame] | 132 | else: |
| 133 | return None |
| 134 | |
Charlie Mooney | d5712b8 | 2015-02-23 12:06:59 -0800 | [diff] [blame] | 135 | return touch_dev |
Charlie Mooney | 985cf40 | 2015-01-08 15:15:59 -0800 | [diff] [blame] | 136 | |
Charlie Mooney | 3cca6ba | 2014-11-19 16:15:28 -0800 | [diff] [blame] | 137 | def main(): |
Charlie Mooney | 389e1f3 | 2015-03-06 13:33:20 -0800 | [diff] [blame] | 138 | color.init(autoreset=True) |
| 139 | |
Charlie Mooney | 3cca6ba | 2014-11-19 16:15:28 -0800 | [diff] [blame] | 140 | # Parse and validate the command line arguments |
| 141 | options, args = parse_arguments() |
| 142 | |
Charlie Mooney | 985cf40 | 2015-01-08 15:15:59 -0800 | [diff] [blame] | 143 | if options.dut_type != 'replay': |
Charlie Mooney | 818c60c | 2015-04-21 15:10:44 -0700 | [diff] [blame] | 144 | # Connect to the DUT |
| 145 | touch_dev = initialize_touch_device(options) |
| 146 | |
Charlie Mooney | 985cf40 | 2015-01-08 15:15:59 -0800 | [diff] [blame] | 147 | # 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] | 148 | test_suite = TestSuite(touch_dev, options, args) |
Charlie Mooney | 3cca6ba | 2014-11-19 16:15:28 -0800 | [diff] [blame] | 149 | |
Charlie Mooney | 985cf40 | 2015-01-08 15:15:59 -0800 | [diff] [blame] | 150 | # Run through the entire test suite in turn |
| 151 | while test_suite.RunNextTestAndVariation(): |
| 152 | pass |
Charlie Mooney | c68f9c3 | 2015-04-16 15:23:22 -0700 | [diff] [blame] | 153 | test_suite.StopPlotter() |
Charlie Mooney | 985cf40 | 2015-01-08 15:15:59 -0800 | [diff] [blame] | 154 | |
| 155 | # The test suite should have a fully populated Report object now, filled |
| 156 | # with the results of all the test runs. |
| 157 | report = test_suite.report |
| 158 | |
| 159 | # Save this report into a default location as a backup in case you want |
| 160 | # to replay it later. |
| 161 | report.SaveToDisk('last_report.p') |
| 162 | else: |
Charlie Mooney | 389e1f3 | 2015-03-06 13:33:20 -0800 | [diff] [blame] | 163 | # 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] | 164 | # directly from the specified file instead of running the test over again. |
| 165 | report = Report.FromFile(options.addr) |
| 166 | |
| 167 | # Generate an HTML version of the Report and write it to disk |
Charlie Mooney | ff8b332 | 2016-06-14 14:58:12 -0700 | [diff] [blame^] | 168 | report_filename = REPORT_LOCATION_FORMAT % options.mode |
Charlie Mooney | 74bad59 | 2015-05-21 12:38:02 -0700 | [diff] [blame] | 169 | print (color.Fore.MAGENTA + 'FW Testing Complete. Report is being generated ' |
Charlie Mooney | ff8b332 | 2016-06-14 14:58:12 -0700 | [diff] [blame^] | 170 | 'now, and will be stored on disk as "%s"' % report_filename) |
Charlie Mooney | 985cf40 | 2015-01-08 15:15:59 -0800 | [diff] [blame] | 171 | html_report = report.GenerateHtml() |
Charlie Mooney | ff8b332 | 2016-06-14 14:58:12 -0700 | [diff] [blame^] | 172 | with open(report_filename, 'w') as fo: |
Charlie Mooney | 985cf40 | 2015-01-08 15:15:59 -0800 | [diff] [blame] | 173 | fo.write(html_report) |
Charlie Mooney | 3cca6ba | 2014-11-19 16:15:28 -0800 | [diff] [blame] | 174 | |
| 175 | return 0 |
| 176 | |
| 177 | |
| 178 | if __name__ == "__main__": |
| 179 | sys.exit(main()) |