blob: 7b07a08f8c893384c2e6535f2dd7fdc30dbe02b8 [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
14login_LoginSuccess
15logging_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
22import optparse, os, sys, time
23import common
24from autotest_lib.server.cros import control_file_getter, dynamic_suite
25
26def parse_options():
27 usage = "usage: %prog [options] suite_name"
28 parser = optparse.OptionParser(usage=usage)
29 parser.add_option('-a', '--autotest_dir', dest='autotest_dir',
30 default=os.path.abspath(
31 os.path.join('..', os.path.dirname(__file__))),
32 help='Directory under which to search for tests.'\
33 ' (e.g. /usr/local/autotest)')
34 parser.add_option('-s', '--stable_only', dest='add_experimental',
35 action='store_false', default=True,
36 help='List only tests that are not labeled experimental.')
Zdenek Behan849db052012-02-29 19:16:28 +010037 parser.add_option('-l', '--listall',
38 action='store_true', default=False,
39 help='Print a listing of all suites. Ignores all args.')
Chris Masoned6f38c82012-02-22 14:53:42 -080040 options, args = parser.parse_args()
41 return parser, options, args
42
43
44def main():
45 parser, options, args = parse_options()
Zdenek Behan849db052012-02-29 19:16:28 +010046 if options.listall:
47 if args:
48 print 'Cannot use suite_name with --listall'
49 parser.print_help()
50 elif not args or len(args) != 1:
Chris Masoned6f38c82012-02-22 14:53:42 -080051 parser.print_help()
52 return
53
54 fs_getter = dynamic_suite.Suite.create_fs_getter(options.autotest_dir)
Zdenek Behan849db052012-02-29 19:16:28 +010055
56 if options.listall:
57 for suite in dynamic_suite.Suite.list_all_suites('', fs_getter):
58 print suite
59 return
60
Chris Masoned6f38c82012-02-22 14:53:42 -080061 suite = dynamic_suite.Suite.create_from_name(args[0], '', fs_getter)
Chris Masone10c60632012-02-29 09:33:57 -080062 for test in suite.stable_tests():
Chris Masonee8a4eff2012-02-28 16:33:43 -080063 print test.path
Chris Masone10c60632012-02-29 09:33:57 -080064 if options.add_experimental:
65 for test in suite.unstable_tests():
66 print test.path
Chris Masoned6f38c82012-02-22 14:53:42 -080067
68
69if __name__ == "__main__":
70 sys.exit(main())