blob: 00b4006c8a3232d4eac5e28d39c6752bb6862515 [file] [log] [blame]
Charlie Mooney3cca6ba2014-11-19 16:15:28 -08001# 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
5import optparse
Charlie Mooney985cf402015-01-08 15:15:59 -08006import os
Charlie Mooney3cca6ba2014-11-19 16:15:28 -08007import sys
8
Charlie Mooney389e1f32015-03-06 13:33:20 -08009import colorama as color
Charlie Mooneye0d06c42015-01-27 11:32:51 -080010
Amirhossein Simjour7a71f332015-04-10 15:18:37 -040011from remote import ChromeOSTouchDevice, AndroidTouchDevice, ElanTouchDevice, mt
Charlie Mooney985cf402015-01-08 15:15:59 -080012from report import Report
Charlie Mooney3cca6ba2014-11-19 16:15:28 -080013from test_suite import TestSuite
14
15
16def parse_arguments():
Amirhossein Simjour7a71f332015-04-10 15:18:37 -040017 VALID_DUT_TYPES = ['chromeos', 'android', 'elan_i2c', 'replay']
Charlie Mooney73051762015-02-06 11:52:38 -080018 VALID_MODES = ['performance', 'noise', 'full']
Charlie Mooneye0d06c42015-01-27 11:32:51 -080019 VALID_PROTOCOLS = [mt.MTA, mt.MTB, 'auto']
Charlie Mooney3cca6ba2014-11-19 16:15:28 -080020 parser = optparse.OptionParser()
21
22 # DUT specification information
23 parser.add_option('-a', '--addr', dest='addr', default=None,
Charlie Mooneye0d06c42015-01-27 11:32:51 -080024 help=('The address of the DUT (ip for CrOS, Device ID '
Charlie Mooney985cf402015-01-08 15:15:59 -080025 'for Android, or a filename to replay old results).'))
Charlie Mooney3cca6ba2014-11-19 16:15:28 -080026 parser.add_option('-t', '--type', dest='dut_type', default=None,
Charlie Mooney985cf402015-01-08 15:15:59 -080027 help='The type of DUT (android, chromeos, or replay).')
Charlie Mooney3cca6ba2014-11-19 16:15:28 -080028 parser.add_option('--touchscreen', dest='is_touchscreen',
29 default=False, action='store_true',
Charlie Mooneye0d06c42015-01-27 11:32:51 -080030 help=('Use the touchscreen (instead of touchpad) on '
Charlie Mooney3cca6ba2014-11-19 16:15:28 -080031 'the device.'))
32
Charlie Mooneye0d06c42015-01-27 11:32:51 -080033 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 Mooney08661912015-04-16 09:20:34 -070038 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 Mooneye0d06c42015-01-27 11:32:51 -080044
Charlie Mooney3cca6ba2014-11-19 16:15:28 -080045 # Lab equipment specification
46 parser.add_option('-r', '--robot', dest='has_robot',
47 default=False, action='store_true',
Charlie Mooneye0d06c42015-01-27 11:32:51 -080048 help=('Indicate that you have a Google Touchbot that '
Charlie Mooney3cca6ba2014-11-19 16:15:28 -080049 'will perform your gestures for you.'))
50 parser.add_option('-f', '--fn_gen', dest='has_fn_gen',
51 default=False, action='store_true',
Charlie Mooneye0d06c42015-01-27 11:32:51 -080052 help=('Indicate that you have an HP 33120A function '
Charlie Mooney3cca6ba2014-11-19 16:15:28 -080053 'generator to automate the electric noise tests.'))
Charlie Mooney73051762015-02-06 11:52:38 -080054 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 Mooney3cca6ba2014-11-19 16:15:28 -080058
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.'))
62
63 (options, args) = parser.parse_args()
64
65 if options.dut_type not in VALID_DUT_TYPES:
Charlie Mooney985cf402015-01-08 15:15:59 -080066 print 'ERROR: invalid dut type "%s"' % options.dut_type
67 print 'valid dut types are: %s' % str(VALID_DUT_TYPES)
68 sys.exit(1)
Charlie Mooney3cca6ba2014-11-19 16:15:28 -080069 if options.dut_type == 'chromeos' and not options.addr:
Charlie Mooney985cf402015-01-08 15:15:59 -080070 print 'ERROR: You must supply an IP address for ChromeOS DUTs'
71 sys.exit(1)
Charlie Mooneye0d06c42015-01-27 11:32:51 -080072 if options.protocol not in VALID_PROTOCOLS:
73 print 'ERROR: invalid protocol "%s"' % options.protocol
74 print 'valid protocols are: %s' % str(VALID_PROTOCOLS)
75 sys.exit(1)
Charlie Mooney73051762015-02-06 11:52:38 -080076 if options.mode not in VALID_MODES:
77 print 'ERROR: invalid mode "%s"' % options.mode
78 print 'valid modes are: %s' % str(VALID_MODES)
79 sys.exit(1)
Charlie Mooney3cca6ba2014-11-19 16:15:28 -080080
81 return options, args
82
83
Charlie Mooneyd5712b82015-02-23 12:06:59 -080084def initialize_touch_device(options):
85 """ Using the supplied options connect to the DUT """
86 # Open a connection to the device specified
Charlie Mooney389e1f32015-03-06 13:33:20 -080087 print (color.Style.DIM + color.Fore.RED +
88 'Please do not touch the device until the test starts!')
89 print 'Connecting to remote touch device...'
Charlie Mooneyd5712b82015-02-23 12:06:59 -080090 if options.dut_type == 'chromeos':
Charlie Mooney389e1f32015-03-06 13:33:20 -080091 touch_dev = ChromeOSTouchDevice(options.addr, options.is_touchscreen,
92 options.protocol)
Charlie Mooneyd5712b82015-02-23 12:06:59 -080093 elif options.dut_type == 'android':
Charlie Mooney389e1f32015-03-06 13:33:20 -080094 touch_dev = AndroidTouchDevice(options.addr, True, options.protocol)
Amirhossein Simjour7a71f332015-04-10 15:18:37 -040095 elif options.dut_type == 'elan_i2c':
96 touch_dev = ElanTouchDevice(options.addr, True)
Charlie Mooneyd5712b82015-02-23 12:06:59 -080097 else:
98 return None
99
Charlie Mooneyd5712b82015-02-23 12:06:59 -0800100 return touch_dev
Charlie Mooney985cf402015-01-08 15:15:59 -0800101
Charlie Mooney3cca6ba2014-11-19 16:15:28 -0800102def main():
Charlie Mooney389e1f32015-03-06 13:33:20 -0800103 color.init(autoreset=True)
104
Charlie Mooney3cca6ba2014-11-19 16:15:28 -0800105 # Parse and validate the command line arguments
106 options, args = parse_arguments()
107
Charlie Mooney985cf402015-01-08 15:15:59 -0800108 if options.dut_type != 'replay':
Charlie Mooney818c60c2015-04-21 15:10:44 -0700109 # Connect to the DUT
110 touch_dev = initialize_touch_device(options)
111
Charlie Mooney985cf402015-01-08 15:15:59 -0800112 # Create a test flow object that will run the test step by step
Charlie Mooneyd5712b82015-02-23 12:06:59 -0800113 test_suite = TestSuite(touch_dev, options, args)
Charlie Mooney3cca6ba2014-11-19 16:15:28 -0800114
Charlie Mooney985cf402015-01-08 15:15:59 -0800115 # Run through the entire test suite in turn
116 while test_suite.RunNextTestAndVariation():
117 pass
Charlie Mooneyc68f9c32015-04-16 15:23:22 -0700118 test_suite.StopPlotter()
Charlie Mooney985cf402015-01-08 15:15:59 -0800119
120 # The test suite should have a fully populated Report object now, filled
121 # with the results of all the test runs.
122 report = test_suite.report
123
124 # Save this report into a default location as a backup in case you want
125 # to replay it later.
126 report.SaveToDisk('last_report.p')
127 else:
Charlie Mooney389e1f32015-03-06 13:33:20 -0800128 # We are trying to replay an old report from a file on disk. Load it
Charlie Mooney985cf402015-01-08 15:15:59 -0800129 # directly from the specified file instead of running the test over again.
130 report = Report.FromFile(options.addr)
131
132 # Generate an HTML version of the Report and write it to disk
133 html_report = report.GenerateHtml()
134 with open('report.html', 'w') as fo:
135 fo.write(html_report)
Charlie Mooney3cca6ba2014-11-19 16:15:28 -0800136
137 return 0
138
139
140if __name__ == "__main__":
141 sys.exit(main())