blob: f4ef3541f7af3b2ed0801194520b84ec63c376ea [file] [log] [blame]
Scott Zawalski20a9b582011-11-21 11:49:40 -08001#!/usr/bin/python
2#
3# Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
4# Use of this source code is governed by a BSD-style license that can be
5# found in the LICENSE file.
6
7"""Tool for running test groups against different ChromeOS boards and platforms.
8
9run_tests allows users to execute test groups against Autotest hosts. Will
10create Autotest jobs given a board, platform, and list of test groups. Test
11groups are configurable via a JSON configuration file.
12
13run_tests will create jobs using a specialized control file which will update
14the targeted hosts to a specific board type and build version before running
15jobs against them.
16"""
17
18__author__ = 'dalecurtis@google.com (Dale Curtis)'
19
20import logging
21import optparse
22
23from chromeos_test import autotest_util
24from chromeos_test import dev_server
25from chromeos_test import log_util
26from chromeos_test import test_config
27import test_scheduler
28
29
30def ParseOptions():
31 """Parse command line options. Returns 2-tuple of options and config."""
32 # If default config exists, parse it and use values for help screen.
33 config = test_config.TestConfig()
34
35 # If config is provided parse values to make help screen more useful.
36 boards, groups, platforms = config.ParseConfigGroups()
37
38 parser = optparse.OptionParser(
39 'usage: %prog --board <BOARD> --platform <PLATFORM> [options]')
40 parser.add_option('--board', dest='board',
41 help=('Run tests only on the specified board. Valid boards:'
42 ' %s' % boards))
43 parser.add_option('--build', dest='build',
44 help='Specify the build version to process.')
45 parser.add_option('--groups', dest='groups',
46 help=('Comma separated list of test groups. Valid groups:'
47 ' %s' % groups))
48 parser.add_option('--platform', dest='platform',
49 help=('Run tests on the specified platform. Valid platforms'
50 ': %s' % platforms))
51
52 # Add utility/helper class command line options.
53 test_config.AddOptions(parser)
54 autotest_util.AddOptions(parser, cli_only=True)
55
56 options = parser.parse_args()[0]
57
58 if not options.board or not options.platform:
Aviv Keshet7f76a162013-02-13 17:22:00 -080059 parser.error('A board, build, and platform must be provided.')
Scott Zawalski20a9b582011-11-21 11:49:40 -080060
61 # Load correct config file if alternate is specified.
62 if options.config != test_config.DEFAULT_CONFIG_FILE:
63 config = test_config.TestConfig(options.config)
64 boards, groups, platforms = config.ParseConfigGroups()
65
66 if not options.groups:
67 options.groups = config.GetConfig()['default_groups']
68 else:
69 options.groups = options.groups.split(',')
70
71 if not options.board in boards:
72 parser.error('Invalid board "%s" specified. Valid boards are: %s'
73 % (options.board, boards))
74
75 for group in options.groups:
76 if not group in groups:
77 parser.error('Invalid group "%s" specified. Valid groups are: %s'
78 % (group, groups))
79
80 if not options.platform in platforms:
81 parser.error('Invalid platform "%s" specified. Valid platforms are: %s'
82 % (options.platform, platforms))
83
84 return options, config.GetConfig()
85
86
87def main():
88 options, config = ParseOptions()
89
90 # Setup logger and enable verbose mode.
91 log_util.InitializeLogging(True)
92
93 logging.info('------------[ Processing board %s ]------------', options.board)
94
95 # Initialize Dev Server Utility class.
96 dev = dev_server.DevServer(**config['dev_server'])
97
98 # Get latest version for this board.
99 if options.build:
100 build = options.build
101 else:
Aviv Keshet7f76a162013-02-13 17:22:00 -0800102 raise NotImplementedException('You must pass in a build with the --build '
103 'flag. Detecting the latest build for a '
104 'board is no longer supported.')
Scott Zawalski20a9b582011-11-21 11:49:40 -0800105
106 logging.info('Latest build version available on Dev Server is %s.', build)
107
108 tr = test_scheduler.TestRunner(
109 board=options.board, build=build, cli=options.cli, config=config, dev=dev)
110
111 tr.RunTestGroups(groups=options.groups, lock=False, platform=options.platform)
112
113
114if __name__ == '__main__':
115 main()