blob: ea80d9a303e9706f72833dc0fbafcf18bfd19d8b [file] [log] [blame]
Chris Masoned6f38c82012-02-22 14:53:42 -08001#!/usr/bin/python
2#
3# Copyright (c) 2012 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 enumerating the tests in a given suite.
8
9Given an autotest root directory and a suite name (e.g., bvt, regression), this
10tool will print out the name of each test in that suite, one per line.
11
12Example:
13$ ./site_utils/suite_enumerator.py -a /usr/local/autotest bvt 2>/dev/null
Chris Masonea7dbfbc2014-02-06 14:24:22 -080014login_LoginSuccess
Chris Masoned6f38c82012-02-22 14:53:42 -080015logging_CrashSender
16login_BadAuthentication
17
18This is intended for use only with Chrome OS test suits that leverage the
19dynamic suite infrastructure in server/cros/dynamic_suite.py.
20"""
21
J. Richard Barnette6b355f12014-07-22 17:35:37 -070022import logging
Dan Shi11d36bc2013-02-25 16:23:02 -080023import optparse, os, sys
J. Richard Barnette6b355f12014-07-22 17:35:37 -070024
25# Silence messages relating to imports of missing, unneeded
26# modules.
27logging.basicConfig(level=logging.INFO)
28
Chris Masoned6f38c82012-02-22 14:53:42 -080029import common
Mike Mason00280b92017-04-24 11:27:45 -070030import autotest_lib.client.common_lib.cros as cros_lib
31import autotest_lib.server.cros.dynamic_suite.suite as suite_lib
32
Chris Masoned6f38c82012-02-22 14:53:42 -080033
34def parse_options():
Dan Shi11d36bc2013-02-25 16:23:02 -080035 """Parse command line for arguments including autotest directory, suite
36 name, if to list stable tests only, and if to list all available suites.
37 """
Chris Masoned6f38c82012-02-22 14:53:42 -080038 usage = "usage: %prog [options] suite_name"
39 parser = optparse.OptionParser(usage=usage)
40 parser.add_option('-a', '--autotest_dir', dest='autotest_dir',
41 default=os.path.abspath(
J. Richard Barnette6b355f12014-07-22 17:35:37 -070042 os.path.join(os.path.dirname(__file__),
43 os.pardir)),
Chris Masoned6f38c82012-02-22 14:53:42 -080044 help='Directory under which to search for tests.'\
45 ' (e.g. /usr/local/autotest)')
Zdenek Behan849db052012-02-29 19:16:28 +010046 parser.add_option('-l', '--listall',
47 action='store_true', default=False,
48 help='Print a listing of all suites. Ignores all args.')
Chris Masoned6f38c82012-02-22 14:53:42 -080049 options, args = parser.parse_args()
50 return parser, options, args
51
52
53def main():
Dan Shi11d36bc2013-02-25 16:23:02 -080054 """Entry point to run the suite enumerator command."""
Chris Masoned6f38c82012-02-22 14:53:42 -080055 parser, options, args = parse_options()
Zdenek Behan849db052012-02-29 19:16:28 +010056 if options.listall:
57 if args:
58 print 'Cannot use suite_name with --listall'
59 parser.print_help()
60 elif not args or len(args) != 1:
Chris Masoned6f38c82012-02-22 14:53:42 -080061 parser.print_help()
62 return
63
Mike Mason00280b92017-04-24 11:27:45 -070064 fs_getter = suite_lib.create_fs_getter(options.autotest_dir)
65 devserver = cros_lib.dev_server.ImageServer('')
Zdenek Behan849db052012-02-29 19:16:28 +010066 if options.listall:
Mike Mason00280b92017-04-24 11:27:45 -070067 for suite in suite_lib.list_all_suites('', devserver, fs_getter):
Zdenek Behan849db052012-02-29 19:16:28 +010068 print suite
69 return
70
Mike Mason00280b92017-04-24 11:27:45 -070071 suite = suite_lib.Suite.create_from_name(args[0], {}, '', devserver,
72 fs_getter)
Yusuf Mohsinally610911d2012-11-08 15:59:43 -080073 # If in test list, print firmware_FAFTSetup before other tests
74 # NOTE: the test.name value can be *different* from the directory
75 # name that appears in test.path
76 PRETEST_LIST = ['firmware_FAFTSetup',]
77 for test in filter(lambda test: test.name in \
Mike Mason00280b92017-04-24 11:27:45 -070078 PRETEST_LIST, suite.tests):
Yusuf Mohsinally610911d2012-11-08 15:59:43 -080079 print test.path
80 for test in filter(lambda test: test.name not in \
Mike Mason00280b92017-04-24 11:27:45 -070081 PRETEST_LIST, suite.tests):
Chris Masonee8a4eff2012-02-28 16:33:43 -080082 print test.path
J. Richard Barnette6b355f12014-07-22 17:35:37 -070083
Dan Shi11d36bc2013-02-25 16:23:02 -080084 # Check if test_suites/control.suite_name exists.
J. Richard Barnette6b355f12014-07-22 17:35:37 -070085 control_path = os.path.join(options.autotest_dir, 'test_suites',
86 'control.' + args[0])
87 if not os.path.exists(control_path):
88 print >> sys.stderr, ('Warning! control file is missing: %s' %
89 control_path)
Chris Masoned6f38c82012-02-22 14:53:42 -080090
91
92if __name__ == "__main__":
93 sys.exit(main())