blob: 22a75c58f184ba8347628a4fd51b800424103c57 [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
Charlie Mooney389e1f32015-03-06 13:33:20 -080011import plotter
12from remote import ChromeOSTouchDevice, AndroidTouchDevice, mt
Charlie Mooney985cf402015-01-08 15:15:59 -080013from report import Report
Charlie Mooney3cca6ba2014-11-19 16:15:28 -080014from test_suite import TestSuite
15
16
17def parse_arguments():
Charlie Mooney985cf402015-01-08 15:15:59 -080018 VALID_DUT_TYPES = ['chromeos', 'android', 'replay']
Charlie Mooney73051762015-02-06 11:52:38 -080019 VALID_MODES = ['performance', 'noise', 'full']
Charlie Mooneye0d06c42015-01-27 11:32:51 -080020 VALID_PROTOCOLS = [mt.MTA, mt.MTB, 'auto']
Charlie Mooney3cca6ba2014-11-19 16:15:28 -080021 parser = optparse.OptionParser()
22
23 # DUT specification information
24 parser.add_option('-a', '--addr', dest='addr', default=None,
Charlie Mooneye0d06c42015-01-27 11:32:51 -080025 help=('The address of the DUT (ip for CrOS, Device ID '
Charlie Mooney985cf402015-01-08 15:15:59 -080026 'for Android, or a filename to replay old results).'))
Charlie Mooney3cca6ba2014-11-19 16:15:28 -080027 parser.add_option('-t', '--type', dest='dut_type', default=None,
Charlie Mooney985cf402015-01-08 15:15:59 -080028 help='The type of DUT (android, chromeos, or replay).')
Charlie Mooney3cca6ba2014-11-19 16:15:28 -080029 parser.add_option('--touchscreen', dest='is_touchscreen',
30 default=False, action='store_true',
Charlie Mooneye0d06c42015-01-27 11:32:51 -080031 help=('Use the touchscreen (instead of touchpad) on '
Charlie Mooney3cca6ba2014-11-19 16:15:28 -080032 'the device.'))
33
Charlie Mooneye0d06c42015-01-27 11:32:51 -080034 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.'))
Charlie Mooney08661912015-04-16 09:20:34 -070039 parser.add_option('-n', '--name', dest='name', default='unknown_device',
40 help='The name of this DUT. This is used by the robot to '
41 'store calibration data and is only needed if you are '
42 'using the touchbot. Simply keep the name consistent '
43 'across multiple tests on the same DUT to avoid '
44 'having to recalibrate the robot each time.')
Charlie Mooneye0d06c42015-01-27 11:32:51 -080045
Charlie Mooney3cca6ba2014-11-19 16:15:28 -080046 # Lab equipment specification
47 parser.add_option('-r', '--robot', dest='has_robot',
48 default=False, action='store_true',
Charlie Mooneye0d06c42015-01-27 11:32:51 -080049 help=('Indicate that you have a Google Touchbot that '
Charlie Mooney3cca6ba2014-11-19 16:15:28 -080050 'will perform your gestures for you.'))
51 parser.add_option('-f', '--fn_gen', dest='has_fn_gen',
52 default=False, action='store_true',
Charlie Mooneye0d06c42015-01-27 11:32:51 -080053 help=('Indicate that you have an HP 33120A function '
Charlie Mooney3cca6ba2014-11-19 16:15:28 -080054 'generator to automate the electric noise tests.'))
Charlie Mooney73051762015-02-06 11:52:38 -080055 parser.add_option('-m', '--mode', dest='mode', default='performance',
56 help=('Which mode to run the test suite in. Options are '
57 '(performance, noise, or full) with performance as '
58 'the default selection.'))
Charlie Mooney3cca6ba2014-11-19 16:15:28 -080059
60 # Test suite settings
61 parser.add_option('-i', '--iterations', dest='num_iterations', default=1,
62 type=int, help=('The number of test iterations to run.'))
Charlie Mooneyd5712b82015-02-23 12:06:59 -080063 parser.add_option('--plot_only', dest='plot_only', default=False,
64 action='store_true',
65 help=('Only plot touch evets. Do not run any tests.'))
Charlie Mooney3cca6ba2014-11-19 16:15:28 -080066
67 (options, args) = parser.parse_args()
68
69 if options.dut_type not in VALID_DUT_TYPES:
Charlie Mooney985cf402015-01-08 15:15:59 -080070 print 'ERROR: invalid dut type "%s"' % options.dut_type
71 print 'valid dut types are: %s' % str(VALID_DUT_TYPES)
72 sys.exit(1)
Charlie Mooney3cca6ba2014-11-19 16:15:28 -080073 if options.dut_type == 'chromeos' and not options.addr:
Charlie Mooney985cf402015-01-08 15:15:59 -080074 print 'ERROR: You must supply an IP address for ChromeOS DUTs'
75 sys.exit(1)
Charlie Mooneye0d06c42015-01-27 11:32:51 -080076 if options.protocol not in VALID_PROTOCOLS:
77 print 'ERROR: invalid protocol "%s"' % options.protocol
78 print 'valid protocols are: %s' % str(VALID_PROTOCOLS)
79 sys.exit(1)
Charlie Mooney73051762015-02-06 11:52:38 -080080 if options.mode not in VALID_MODES:
81 print 'ERROR: invalid mode "%s"' % options.mode
82 print 'valid modes are: %s' % str(VALID_MODES)
83 sys.exit(1)
Charlie Mooney3cca6ba2014-11-19 16:15:28 -080084
85 return options, args
86
87
Charlie Mooneyd5712b82015-02-23 12:06:59 -080088def initialize_touch_device(options):
89 """ Using the supplied options connect to the DUT """
90 # Open a connection to the device specified
Charlie Mooney389e1f32015-03-06 13:33:20 -080091 print (color.Style.DIM + color.Fore.RED +
92 'Please do not touch the device until the test starts!')
93 print 'Connecting to remote touch device...'
Charlie Mooneyd5712b82015-02-23 12:06:59 -080094 if options.dut_type == 'chromeos':
Charlie Mooney389e1f32015-03-06 13:33:20 -080095 touch_dev = ChromeOSTouchDevice(options.addr, options.is_touchscreen,
96 options.protocol)
Charlie Mooneyd5712b82015-02-23 12:06:59 -080097 elif options.dut_type == 'android':
Charlie Mooney389e1f32015-03-06 13:33:20 -080098 touch_dev = AndroidTouchDevice(options.addr, True, options.protocol)
Charlie Mooneyd5712b82015-02-23 12:06:59 -080099 else:
100 return None
101
Charlie Mooneyd5712b82015-02-23 12:06:59 -0800102 return touch_dev
Charlie Mooney985cf402015-01-08 15:15:59 -0800103
Charlie Mooney3cca6ba2014-11-19 16:15:28 -0800104def main():
Charlie Mooney389e1f32015-03-06 13:33:20 -0800105 color.init(autoreset=True)
106
Charlie Mooney3cca6ba2014-11-19 16:15:28 -0800107 # Parse and validate the command line arguments
108 options, args = parse_arguments()
109
Charlie Mooneyd5712b82015-02-23 12:06:59 -0800110 # Connect to the DUT
111 touch_dev = initialize_touch_device(options)
112
113 if options.plot_only:
114 # Show the live events as they come in instead of running any tests
Charlie Mooneyd5712b82015-02-23 12:06:59 -0800115 plotter.live_display(touch_dev)
116 return 0
117
Charlie Mooney985cf402015-01-08 15:15:59 -0800118 if options.dut_type != 'replay':
119 # Create a test flow object that will run the test step by step
Charlie Mooneyd5712b82015-02-23 12:06:59 -0800120 test_suite = TestSuite(touch_dev, options, args)
Charlie Mooney3cca6ba2014-11-19 16:15:28 -0800121
Charlie Mooney985cf402015-01-08 15:15:59 -0800122 # Run through the entire test suite in turn
123 while test_suite.RunNextTestAndVariation():
124 pass
125
126 # The test suite should have a fully populated Report object now, filled
127 # with the results of all the test runs.
128 report = test_suite.report
129
130 # Save this report into a default location as a backup in case you want
131 # to replay it later.
132 report.SaveToDisk('last_report.p')
133 else:
Charlie Mooney389e1f32015-03-06 13:33:20 -0800134 # We are trying to replay an old report from a file on disk. Load it
Charlie Mooney985cf402015-01-08 15:15:59 -0800135 # directly from the specified file instead of running the test over again.
136 report = Report.FromFile(options.addr)
137
138 # Generate an HTML version of the Report and write it to disk
139 html_report = report.GenerateHtml()
140 with open('report.html', 'w') as fo:
141 fo.write(html_report)
Charlie Mooney3cca6ba2014-11-19 16:15:28 -0800142
143 return 0
144
145
146if __name__ == "__main__":
147 sys.exit(main())