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 | 7305176 | 2015-02-06 11:52:38 -0800 | [diff] [blame] | 17 | VALID_MODES = ['performance', 'noise', 'full'] |
Charlie Mooney | e0d06c4 | 2015-01-27 11:32:51 -0800 | [diff] [blame] | 18 | VALID_PROTOCOLS = [mt.MTA, mt.MTB, 'auto'] |
Charlie Mooney | 3cca6ba | 2014-11-19 16:15:28 -0800 | [diff] [blame] | 19 | parser = optparse.OptionParser() |
| 20 | |
| 21 | # DUT specification information |
| 22 | parser.add_option('-a', '--addr', dest='addr', default=None, |
Charlie Mooney | e0d06c4 | 2015-01-27 11:32:51 -0800 | [diff] [blame] | 23 | help=('The address of the DUT (ip for CrOS, Device ID ' |
Charlie Mooney | 985cf40 | 2015-01-08 15:15:59 -0800 | [diff] [blame] | 24 | 'for Android, or a filename to replay old results).')) |
Charlie Mooney | 3cca6ba | 2014-11-19 16:15:28 -0800 | [diff] [blame] | 25 | parser.add_option('-t', '--type', dest='dut_type', default=None, |
Charlie Mooney | 985cf40 | 2015-01-08 15:15:59 -0800 | [diff] [blame] | 26 | help='The type of DUT (android, chromeos, or replay).') |
Charlie Mooney | 3cca6ba | 2014-11-19 16:15:28 -0800 | [diff] [blame] | 27 | parser.add_option('--touchscreen', dest='is_touchscreen', |
| 28 | default=False, action='store_true', |
Charlie Mooney | e0d06c4 | 2015-01-27 11:32:51 -0800 | [diff] [blame] | 29 | help=('Use the touchscreen (instead of touchpad) on ' |
Charlie Mooney | 3cca6ba | 2014-11-19 16:15:28 -0800 | [diff] [blame] | 30 | 'the device.')) |
| 31 | |
Charlie Mooney | e0d06c4 | 2015-01-27 11:32:51 -0800 | [diff] [blame] | 32 | 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 Mooney | 3cca6ba | 2014-11-19 16:15:28 -0800 | [diff] [blame] | 38 | # Lab equipment specification |
| 39 | parser.add_option('-r', '--robot', dest='has_robot', |
| 40 | default=False, action='store_true', |
Charlie Mooney | e0d06c4 | 2015-01-27 11:32:51 -0800 | [diff] [blame] | 41 | help=('Indicate that you have a Google Touchbot that ' |
Charlie Mooney | 3cca6ba | 2014-11-19 16:15:28 -0800 | [diff] [blame] | 42 | 'will perform your gestures for you.')) |
| 43 | parser.add_option('-f', '--fn_gen', dest='has_fn_gen', |
| 44 | default=False, action='store_true', |
Charlie Mooney | e0d06c4 | 2015-01-27 11:32:51 -0800 | [diff] [blame] | 45 | help=('Indicate that you have an HP 33120A function ' |
Charlie Mooney | 3cca6ba | 2014-11-19 16:15:28 -0800 | [diff] [blame] | 46 | 'generator to automate the electric noise tests.')) |
Charlie Mooney | 7305176 | 2015-02-06 11:52:38 -0800 | [diff] [blame] | 47 | 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 Mooney | 3cca6ba | 2014-11-19 16:15:28 -0800 | [diff] [blame] | 51 | |
| 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 Mooney | 985cf40 | 2015-01-08 15:15:59 -0800 | [diff] [blame] | 59 | 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 Mooney | 3cca6ba | 2014-11-19 16:15:28 -0800 | [diff] [blame] | 62 | if options.dut_type == 'chromeos' and not options.addr: |
Charlie Mooney | 985cf40 | 2015-01-08 15:15:59 -0800 | [diff] [blame] | 63 | print 'ERROR: You must supply an IP address for ChromeOS DUTs' |
| 64 | sys.exit(1) |
Charlie Mooney | e0d06c4 | 2015-01-27 11:32:51 -0800 | [diff] [blame] | 65 | 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 Mooney | 7305176 | 2015-02-06 11:52:38 -0800 | [diff] [blame] | 69 | 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 Mooney | 3cca6ba | 2014-11-19 16:15:28 -0800 | [diff] [blame] | 73 | |
| 74 | return options, args |
| 75 | |
| 76 | |
Charlie Mooney | 985cf40 | 2015-01-08 15:15:59 -0800 | [diff] [blame] | 77 | |
Charlie Mooney | 3cca6ba | 2014-11-19 16:15:28 -0800 | [diff] [blame] | 78 | def main(): |
| 79 | # Parse and validate the command line arguments |
| 80 | options, args = parse_arguments() |
| 81 | |
Charlie Mooney | 985cf40 | 2015-01-08 15:15:59 -0800 | [diff] [blame] | 82 | 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 Mooney | 3cca6ba | 2014-11-19 16:15:28 -0800 | [diff] [blame] | 85 | |
Charlie Mooney | 985cf40 | 2015-01-08 15:15:59 -0800 | [diff] [blame] | 86 | # 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 Mooney | 3cca6ba | 2014-11-19 16:15:28 -0800 | [diff] [blame] | 106 | |
| 107 | return 0 |
| 108 | |
| 109 | |
| 110 | if __name__ == "__main__": |
| 111 | sys.exit(main()) |