blob: 5e1f612a0c334140f3fde4782007e69593963a8f [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 Mooneye0d06c42015-01-27 11:32:51 -080017 VALID_PROTOCOLS = [mt.MTA, mt.MTB, 'auto']
Charlie Mooney3cca6ba2014-11-19 16:15:28 -080018 parser = optparse.OptionParser()
19
20 # DUT specification information
21 parser.add_option('-a', '--addr', dest='addr', default=None,
Charlie Mooneye0d06c42015-01-27 11:32:51 -080022 help=('The address of the DUT (ip for CrOS, Device ID '
Charlie Mooney985cf402015-01-08 15:15:59 -080023 'for Android, or a filename to replay old results).'))
Charlie Mooney3cca6ba2014-11-19 16:15:28 -080024 parser.add_option('-t', '--type', dest='dut_type', default=None,
Charlie Mooney985cf402015-01-08 15:15:59 -080025 help='The type of DUT (android, chromeos, or replay).')
Charlie Mooney3cca6ba2014-11-19 16:15:28 -080026 parser.add_option('--touchscreen', dest='is_touchscreen',
27 default=False, action='store_true',
Charlie Mooneye0d06c42015-01-27 11:32:51 -080028 help=('Use the touchscreen (instead of touchpad) on '
Charlie Mooney3cca6ba2014-11-19 16:15:28 -080029 'the device.'))
30
Charlie Mooneye0d06c42015-01-27 11:32:51 -080031 parser.add_option('--protocol', dest='protocol', default='auto',
32 help=('Manually specify the multitouch protocol for the '
33 'DUT. This should be detected automatically, but '
34 'in the event that fails, you may specify "mtb" or '
35 '"mta" with this flag to over-ride it.'))
36
Charlie Mooney3cca6ba2014-11-19 16:15:28 -080037 # Lab equipment specification
38 parser.add_option('-r', '--robot', dest='has_robot',
39 default=False, action='store_true',
Charlie Mooneye0d06c42015-01-27 11:32:51 -080040 help=('Indicate that you have a Google Touchbot that '
Charlie Mooney3cca6ba2014-11-19 16:15:28 -080041 'will perform your gestures for you.'))
42 parser.add_option('-f', '--fn_gen', dest='has_fn_gen',
43 default=False, action='store_true',
Charlie Mooneye0d06c42015-01-27 11:32:51 -080044 help=('Indicate that you have an HP 33120A function '
Charlie Mooney3cca6ba2014-11-19 16:15:28 -080045 'generator to automate the electric noise tests.'))
46
47 # Test suite settings
48 parser.add_option('-i', '--iterations', dest='num_iterations', default=1,
49 type=int, help=('The number of test iterations to run.'))
50
51 (options, args) = parser.parse_args()
52
53 if options.dut_type not in VALID_DUT_TYPES:
Charlie Mooney985cf402015-01-08 15:15:59 -080054 print 'ERROR: invalid dut type "%s"' % options.dut_type
55 print 'valid dut types are: %s' % str(VALID_DUT_TYPES)
56 sys.exit(1)
Charlie Mooney3cca6ba2014-11-19 16:15:28 -080057 if options.dut_type == 'chromeos' and not options.addr:
Charlie Mooney985cf402015-01-08 15:15:59 -080058 print 'ERROR: You must supply an IP address for ChromeOS DUTs'
59 sys.exit(1)
Charlie Mooneye0d06c42015-01-27 11:32:51 -080060 if options.protocol not in VALID_PROTOCOLS:
61 print 'ERROR: invalid protocol "%s"' % options.protocol
62 print 'valid protocols are: %s' % str(VALID_PROTOCOLS)
63 sys.exit(1)
Charlie Mooney3cca6ba2014-11-19 16:15:28 -080064
65 return options, args
66
67
Charlie Mooney985cf402015-01-08 15:15:59 -080068
Charlie Mooney3cca6ba2014-11-19 16:15:28 -080069def main():
70 # Parse and validate the command line arguments
71 options, args = parse_arguments()
72
Charlie Mooney985cf402015-01-08 15:15:59 -080073 if options.dut_type != 'replay':
74 # Create a test flow object that will run the test step by step
75 test_suite = TestSuite(options, args)
Charlie Mooney3cca6ba2014-11-19 16:15:28 -080076
Charlie Mooney985cf402015-01-08 15:15:59 -080077 # Run through the entire test suite in turn
78 while test_suite.RunNextTestAndVariation():
79 pass
80
81 # The test suite should have a fully populated Report object now, filled
82 # with the results of all the test runs.
83 report = test_suite.report
84
85 # Save this report into a default location as a backup in case you want
86 # to replay it later.
87 report.SaveToDisk('last_report.p')
88 else:
89 # We are trying to replay an old report from a file on disk. Load the Report
90 # directly from the specified file instead of running the test over again.
91 report = Report.FromFile(options.addr)
92
93 # Generate an HTML version of the Report and write it to disk
94 html_report = report.GenerateHtml()
95 with open('report.html', 'w') as fo:
96 fo.write(html_report)
Charlie Mooney3cca6ba2014-11-19 16:15:28 -080097
98 return 0
99
100
101if __name__ == "__main__":
102 sys.exit(main())