blob: 21c017c7f19aaeda493d062a3e077366d46fcb29 [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 Mooneye0d06c42015-01-27 11:32:51 -08009import mt
10
Charlie Mooney985cf402015-01-08 15:15:59 -080011from report import Report
Charlie Mooney3cca6ba2014-11-19 16:15:28 -080012from test_suite import TestSuite
13
14
15def parse_arguments():
Charlie Mooney985cf402015-01-08 15:15:59 -080016 VALID_DUT_TYPES = ['chromeos', 'android', 'replay']
Charlie Mooney73051762015-02-06 11:52:38 -080017 VALID_MODES = ['performance', 'noise', 'full']
Charlie Mooneye0d06c42015-01-27 11:32:51 -080018 VALID_PROTOCOLS = [mt.MTA, mt.MTB, 'auto']
Charlie Mooney3cca6ba2014-11-19 16:15:28 -080019 parser = optparse.OptionParser()
20
21 # DUT specification information
22 parser.add_option('-a', '--addr', dest='addr', default=None,
Charlie Mooneye0d06c42015-01-27 11:32:51 -080023 help=('The address of the DUT (ip for CrOS, Device ID '
Charlie Mooney985cf402015-01-08 15:15:59 -080024 'for Android, or a filename to replay old results).'))
Charlie Mooney3cca6ba2014-11-19 16:15:28 -080025 parser.add_option('-t', '--type', dest='dut_type', default=None,
Charlie Mooney985cf402015-01-08 15:15:59 -080026 help='The type of DUT (android, chromeos, or replay).')
Charlie Mooney3cca6ba2014-11-19 16:15:28 -080027 parser.add_option('--touchscreen', dest='is_touchscreen',
28 default=False, action='store_true',
Charlie Mooneye0d06c42015-01-27 11:32:51 -080029 help=('Use the touchscreen (instead of touchpad) on '
Charlie Mooney3cca6ba2014-11-19 16:15:28 -080030 'the device.'))
31
Charlie Mooneye0d06c42015-01-27 11:32:51 -080032 parser.add_option('--protocol', dest='protocol', default='auto',
33 help=('Manually specify the multitouch protocol for the '
34 'DUT. This should be detected automatically, but '
35 'in the event that fails, you may specify "mtb" or '
36 '"mta" with this flag to over-ride it.'))
37
Charlie Mooney3cca6ba2014-11-19 16:15:28 -080038 # Lab equipment specification
39 parser.add_option('-r', '--robot', dest='has_robot',
40 default=False, action='store_true',
Charlie Mooneye0d06c42015-01-27 11:32:51 -080041 help=('Indicate that you have a Google Touchbot that '
Charlie Mooney3cca6ba2014-11-19 16:15:28 -080042 'will perform your gestures for you.'))
43 parser.add_option('-f', '--fn_gen', dest='has_fn_gen',
44 default=False, action='store_true',
Charlie Mooneye0d06c42015-01-27 11:32:51 -080045 help=('Indicate that you have an HP 33120A function '
Charlie Mooney3cca6ba2014-11-19 16:15:28 -080046 'generator to automate the electric noise tests.'))
Charlie Mooney73051762015-02-06 11:52:38 -080047 parser.add_option('-m', '--mode', dest='mode', default='performance',
48 help=('Which mode to run the test suite in. Options are '
49 '(performance, noise, or full) with performance as '
50 'the default selection.'))
Charlie Mooney3cca6ba2014-11-19 16:15:28 -080051
52 # Test suite settings
53 parser.add_option('-i', '--iterations', dest='num_iterations', default=1,
54 type=int, help=('The number of test iterations to run.'))
55
56 (options, args) = parser.parse_args()
57
58 if options.dut_type not in VALID_DUT_TYPES:
Charlie Mooney985cf402015-01-08 15:15:59 -080059 print 'ERROR: invalid dut type "%s"' % options.dut_type
60 print 'valid dut types are: %s' % str(VALID_DUT_TYPES)
61 sys.exit(1)
Charlie Mooney3cca6ba2014-11-19 16:15:28 -080062 if options.dut_type == 'chromeos' and not options.addr:
Charlie Mooney985cf402015-01-08 15:15:59 -080063 print 'ERROR: You must supply an IP address for ChromeOS DUTs'
64 sys.exit(1)
Charlie Mooneye0d06c42015-01-27 11:32:51 -080065 if options.protocol not in VALID_PROTOCOLS:
66 print 'ERROR: invalid protocol "%s"' % options.protocol
67 print 'valid protocols are: %s' % str(VALID_PROTOCOLS)
68 sys.exit(1)
Charlie Mooney73051762015-02-06 11:52:38 -080069 if options.mode not in VALID_MODES:
70 print 'ERROR: invalid mode "%s"' % options.mode
71 print 'valid modes are: %s' % str(VALID_MODES)
72 sys.exit(1)
Charlie Mooney3cca6ba2014-11-19 16:15:28 -080073
74 return options, args
75
76
Charlie Mooney985cf402015-01-08 15:15:59 -080077
Charlie Mooney3cca6ba2014-11-19 16:15:28 -080078def main():
79 # Parse and validate the command line arguments
80 options, args = parse_arguments()
81
Charlie Mooney985cf402015-01-08 15:15:59 -080082 if options.dut_type != 'replay':
83 # Create a test flow object that will run the test step by step
84 test_suite = TestSuite(options, args)
Charlie Mooney3cca6ba2014-11-19 16:15:28 -080085
Charlie Mooney985cf402015-01-08 15:15:59 -080086 # Run through the entire test suite in turn
87 while test_suite.RunNextTestAndVariation():
88 pass
89
90 # The test suite should have a fully populated Report object now, filled
91 # with the results of all the test runs.
92 report = test_suite.report
93
94 # Save this report into a default location as a backup in case you want
95 # to replay it later.
96 report.SaveToDisk('last_report.p')
97 else:
98 # We are trying to replay an old report from a file on disk. Load the Report
99 # directly from the specified file instead of running the test over again.
100 report = Report.FromFile(options.addr)
101
102 # Generate an HTML version of the Report and write it to disk
103 html_report = report.GenerateHtml()
104 with open('report.html', 'w') as fo:
105 fo.write(html_report)
Charlie Mooney3cca6ba2014-11-19 16:15:28 -0800106
107 return 0
108
109
110if __name__ == "__main__":
111 sys.exit(main())