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 | 985cf40 | 2015-01-08 15:15:59 -0800 | [diff] [blame] | 9 | from report import Report |
Charlie Mooney | 3cca6ba | 2014-11-19 16:15:28 -0800 | [diff] [blame] | 10 | from test_suite import TestSuite |
| 11 | |
| 12 | |
| 13 | def parse_arguments(): |
Charlie Mooney | 985cf40 | 2015-01-08 15:15:59 -0800 | [diff] [blame] | 14 | VALID_DUT_TYPES = ['chromeos', 'android', 'replay'] |
Charlie Mooney | 3cca6ba | 2014-11-19 16:15:28 -0800 | [diff] [blame] | 15 | |
| 16 | parser = optparse.OptionParser() |
| 17 | |
| 18 | # DUT specification information |
| 19 | parser.add_option('-a', '--addr', dest='addr', default=None, |
| 20 | help=('The address of the DUT (ip for CrOS, Device ID ' + |
Charlie Mooney | 985cf40 | 2015-01-08 15:15:59 -0800 | [diff] [blame] | 21 | 'for Android, or a filename to replay old results).')) |
Charlie Mooney | 3cca6ba | 2014-11-19 16:15:28 -0800 | [diff] [blame] | 22 | parser.add_option('-t', '--type', dest='dut_type', default=None, |
Charlie Mooney | 985cf40 | 2015-01-08 15:15:59 -0800 | [diff] [blame] | 23 | help='The type of DUT (android, chromeos, or replay).') |
Charlie Mooney | 3cca6ba | 2014-11-19 16:15:28 -0800 | [diff] [blame] | 24 | parser.add_option('--touchscreen', dest='is_touchscreen', |
| 25 | default=False, action='store_true', |
| 26 | help=('Use the touchscreen (instead of touchpad) on ' + |
| 27 | 'the device.')) |
| 28 | |
| 29 | # Lab equipment specification |
| 30 | parser.add_option('-r', '--robot', dest='has_robot', |
| 31 | default=False, action='store_true', |
| 32 | help=('Indicate that you have a Google Touchbot that ' + |
| 33 | 'will perform your gestures for you.')) |
| 34 | parser.add_option('-f', '--fn_gen', dest='has_fn_gen', |
| 35 | default=False, action='store_true', |
| 36 | help=('Indicate that you have an HP 33120A function ' + |
| 37 | 'generator to automate the electric noise tests.')) |
| 38 | |
| 39 | # Test suite settings |
| 40 | parser.add_option('-i', '--iterations', dest='num_iterations', default=1, |
| 41 | type=int, help=('The number of test iterations to run.')) |
| 42 | |
| 43 | (options, args) = parser.parse_args() |
| 44 | |
| 45 | if options.dut_type not in VALID_DUT_TYPES: |
Charlie Mooney | 985cf40 | 2015-01-08 15:15:59 -0800 | [diff] [blame] | 46 | print 'ERROR: invalid dut type "%s"' % options.dut_type |
| 47 | print 'valid dut types are: %s' % str(VALID_DUT_TYPES) |
| 48 | sys.exit(1) |
Charlie Mooney | 3cca6ba | 2014-11-19 16:15:28 -0800 | [diff] [blame] | 49 | if options.dut_type == 'chromeos' and not options.addr: |
Charlie Mooney | 985cf40 | 2015-01-08 15:15:59 -0800 | [diff] [blame] | 50 | print 'ERROR: You must supply an IP address for ChromeOS DUTs' |
| 51 | sys.exit(1) |
Charlie Mooney | 3cca6ba | 2014-11-19 16:15:28 -0800 | [diff] [blame] | 52 | |
| 53 | return options, args |
| 54 | |
| 55 | |
Charlie Mooney | 985cf40 | 2015-01-08 15:15:59 -0800 | [diff] [blame] | 56 | |
Charlie Mooney | 3cca6ba | 2014-11-19 16:15:28 -0800 | [diff] [blame] | 57 | def main(): |
| 58 | # Parse and validate the command line arguments |
| 59 | options, args = parse_arguments() |
| 60 | |
Charlie Mooney | 985cf40 | 2015-01-08 15:15:59 -0800 | [diff] [blame] | 61 | if options.dut_type != 'replay': |
| 62 | # Create a test flow object that will run the test step by step |
| 63 | test_suite = TestSuite(options, args) |
Charlie Mooney | 3cca6ba | 2014-11-19 16:15:28 -0800 | [diff] [blame] | 64 | |
Charlie Mooney | 985cf40 | 2015-01-08 15:15:59 -0800 | [diff] [blame] | 65 | # Run through the entire test suite in turn |
| 66 | while test_suite.RunNextTestAndVariation(): |
| 67 | pass |
| 68 | |
| 69 | # The test suite should have a fully populated Report object now, filled |
| 70 | # with the results of all the test runs. |
| 71 | report = test_suite.report |
| 72 | |
| 73 | # Save this report into a default location as a backup in case you want |
| 74 | # to replay it later. |
| 75 | report.SaveToDisk('last_report.p') |
| 76 | else: |
| 77 | # We are trying to replay an old report from a file on disk. Load the Report |
| 78 | # directly from the specified file instead of running the test over again. |
| 79 | report = Report.FromFile(options.addr) |
| 80 | |
| 81 | # Generate an HTML version of the Report and write it to disk |
| 82 | html_report = report.GenerateHtml() |
| 83 | with open('report.html', 'w') as fo: |
| 84 | fo.write(html_report) |
Charlie Mooney | 3cca6ba | 2014-11-19 16:15:28 -0800 | [diff] [blame] | 85 | |
| 86 | return 0 |
| 87 | |
| 88 | |
| 89 | if __name__ == "__main__": |
| 90 | sys.exit(main()) |