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 | |
| 5 | import optparse |
Charlie Mooney | 985cf40 | 2015-01-08 15:15:59 -0800 | [diff] [blame] | 6 | import os |
Charlie Mooney | 3cca6ba | 2014-11-19 16:15:28 -0800 | [diff] [blame] | 7 | import sys |
| 8 | |
Charlie Mooney | e0d06c4 | 2015-01-27 11:32:51 -0800 | [diff] [blame^] | 9 | import mt |
| 10 | |
Charlie Mooney | 985cf40 | 2015-01-08 15:15:59 -0800 | [diff] [blame] | 11 | from report import Report |
Charlie Mooney | 3cca6ba | 2014-11-19 16:15:28 -0800 | [diff] [blame] | 12 | from test_suite import TestSuite |
| 13 | |
| 14 | |
| 15 | def parse_arguments(): |
Charlie Mooney | 985cf40 | 2015-01-08 15:15:59 -0800 | [diff] [blame] | 16 | VALID_DUT_TYPES = ['chromeos', 'android', 'replay'] |
Charlie Mooney | e0d06c4 | 2015-01-27 11:32:51 -0800 | [diff] [blame^] | 17 | VALID_PROTOCOLS = [mt.MTA, mt.MTB, 'auto'] |
Charlie Mooney | 3cca6ba | 2014-11-19 16:15:28 -0800 | [diff] [blame] | 18 | parser = optparse.OptionParser() |
| 19 | |
| 20 | # DUT specification information |
| 21 | parser.add_option('-a', '--addr', dest='addr', default=None, |
Charlie Mooney | e0d06c4 | 2015-01-27 11:32:51 -0800 | [diff] [blame^] | 22 | help=('The address of the DUT (ip for CrOS, Device ID ' |
Charlie Mooney | 985cf40 | 2015-01-08 15:15:59 -0800 | [diff] [blame] | 23 | 'for Android, or a filename to replay old results).')) |
Charlie Mooney | 3cca6ba | 2014-11-19 16:15:28 -0800 | [diff] [blame] | 24 | parser.add_option('-t', '--type', dest='dut_type', default=None, |
Charlie Mooney | 985cf40 | 2015-01-08 15:15:59 -0800 | [diff] [blame] | 25 | help='The type of DUT (android, chromeos, or replay).') |
Charlie Mooney | 3cca6ba | 2014-11-19 16:15:28 -0800 | [diff] [blame] | 26 | parser.add_option('--touchscreen', dest='is_touchscreen', |
| 27 | default=False, action='store_true', |
Charlie Mooney | e0d06c4 | 2015-01-27 11:32:51 -0800 | [diff] [blame^] | 28 | help=('Use the touchscreen (instead of touchpad) on ' |
Charlie Mooney | 3cca6ba | 2014-11-19 16:15:28 -0800 | [diff] [blame] | 29 | 'the device.')) |
| 30 | |
Charlie Mooney | e0d06c4 | 2015-01-27 11:32:51 -0800 | [diff] [blame^] | 31 | 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 Mooney | 3cca6ba | 2014-11-19 16:15:28 -0800 | [diff] [blame] | 37 | # Lab equipment specification |
| 38 | parser.add_option('-r', '--robot', dest='has_robot', |
| 39 | default=False, action='store_true', |
Charlie Mooney | e0d06c4 | 2015-01-27 11:32:51 -0800 | [diff] [blame^] | 40 | help=('Indicate that you have a Google Touchbot that ' |
Charlie Mooney | 3cca6ba | 2014-11-19 16:15:28 -0800 | [diff] [blame] | 41 | 'will perform your gestures for you.')) |
| 42 | parser.add_option('-f', '--fn_gen', dest='has_fn_gen', |
| 43 | default=False, action='store_true', |
Charlie Mooney | e0d06c4 | 2015-01-27 11:32:51 -0800 | [diff] [blame^] | 44 | help=('Indicate that you have an HP 33120A function ' |
Charlie Mooney | 3cca6ba | 2014-11-19 16:15:28 -0800 | [diff] [blame] | 45 | '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 Mooney | 985cf40 | 2015-01-08 15:15:59 -0800 | [diff] [blame] | 54 | 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 Mooney | 3cca6ba | 2014-11-19 16:15:28 -0800 | [diff] [blame] | 57 | if options.dut_type == 'chromeos' and not options.addr: |
Charlie Mooney | 985cf40 | 2015-01-08 15:15:59 -0800 | [diff] [blame] | 58 | print 'ERROR: You must supply an IP address for ChromeOS DUTs' |
| 59 | sys.exit(1) |
Charlie Mooney | e0d06c4 | 2015-01-27 11:32:51 -0800 | [diff] [blame^] | 60 | 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 Mooney | 3cca6ba | 2014-11-19 16:15:28 -0800 | [diff] [blame] | 64 | |
| 65 | return options, args |
| 66 | |
| 67 | |
Charlie Mooney | 985cf40 | 2015-01-08 15:15:59 -0800 | [diff] [blame] | 68 | |
Charlie Mooney | 3cca6ba | 2014-11-19 16:15:28 -0800 | [diff] [blame] | 69 | def main(): |
| 70 | # Parse and validate the command line arguments |
| 71 | options, args = parse_arguments() |
| 72 | |
Charlie Mooney | 985cf40 | 2015-01-08 15:15:59 -0800 | [diff] [blame] | 73 | 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 Mooney | 3cca6ba | 2014-11-19 16:15:28 -0800 | [diff] [blame] | 76 | |
Charlie Mooney | 985cf40 | 2015-01-08 15:15:59 -0800 | [diff] [blame] | 77 | # 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 Mooney | 3cca6ba | 2014-11-19 16:15:28 -0800 | [diff] [blame] | 97 | |
| 98 | return 0 |
| 99 | |
| 100 | |
| 101 | if __name__ == "__main__": |
| 102 | sys.exit(main()) |