blob: 012a062a651ae43c6e9408f457717585194bb062 [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 Mooney985cf402015-01-08 15:15:59 -08009from report import Report
Charlie Mooney3cca6ba2014-11-19 16:15:28 -080010from test_suite import TestSuite
11
12
13def parse_arguments():
Charlie Mooney985cf402015-01-08 15:15:59 -080014 VALID_DUT_TYPES = ['chromeos', 'android', 'replay']
Charlie Mooney3cca6ba2014-11-19 16:15:28 -080015
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 Mooney985cf402015-01-08 15:15:59 -080021 'for Android, or a filename to replay old results).'))
Charlie Mooney3cca6ba2014-11-19 16:15:28 -080022 parser.add_option('-t', '--type', dest='dut_type', default=None,
Charlie Mooney985cf402015-01-08 15:15:59 -080023 help='The type of DUT (android, chromeos, or replay).')
Charlie Mooney3cca6ba2014-11-19 16:15:28 -080024 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 Mooney985cf402015-01-08 15:15:59 -080046 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 Mooney3cca6ba2014-11-19 16:15:28 -080049 if options.dut_type == 'chromeos' and not options.addr:
Charlie Mooney985cf402015-01-08 15:15:59 -080050 print 'ERROR: You must supply an IP address for ChromeOS DUTs'
51 sys.exit(1)
Charlie Mooney3cca6ba2014-11-19 16:15:28 -080052
53 return options, args
54
55
Charlie Mooney985cf402015-01-08 15:15:59 -080056
Charlie Mooney3cca6ba2014-11-19 16:15:28 -080057def main():
58 # Parse and validate the command line arguments
59 options, args = parse_arguments()
60
Charlie Mooney985cf402015-01-08 15:15:59 -080061 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 Mooney3cca6ba2014-11-19 16:15:28 -080064
Charlie Mooney985cf402015-01-08 15:15:59 -080065 # 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 Mooney3cca6ba2014-11-19 16:15:28 -080085
86 return 0
87
88
89if __name__ == "__main__":
90 sys.exit(main())