Chris Masone | d6f38c8 | 2012-02-22 14:53:42 -0800 | [diff] [blame] | 1 | #!/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 | |
| 9 | Given an autotest root directory and a suite name (e.g., bvt, regression), this |
| 10 | tool will print out the name of each test in that suite, one per line. |
| 11 | |
| 12 | Example: |
| 13 | $ ./site_utils/suite_enumerator.py -a /usr/local/autotest bvt 2>/dev/null |
| 14 | login_LoginSuccess |
| 15 | logging_CrashSender |
| 16 | login_BadAuthentication |
| 17 | |
| 18 | This is intended for use only with Chrome OS test suits that leverage the |
| 19 | dynamic suite infrastructure in server/cros/dynamic_suite.py. |
| 20 | """ |
| 21 | |
| 22 | import optparse, os, sys, time |
| 23 | import common |
| 24 | from autotest_lib.server.cros import control_file_getter, dynamic_suite |
| 25 | |
| 26 | def 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 Behan | 849db05 | 2012-02-29 19:16:28 +0100 | [diff] [blame] | 37 | parser.add_option('-l', '--listall', |
| 38 | action='store_true', default=False, |
| 39 | help='Print a listing of all suites. Ignores all args.') |
Chris Masone | d6f38c8 | 2012-02-22 14:53:42 -0800 | [diff] [blame] | 40 | options, args = parser.parse_args() |
| 41 | return parser, options, args |
| 42 | |
| 43 | |
| 44 | def main(): |
| 45 | parser, options, args = parse_options() |
Zdenek Behan | 849db05 | 2012-02-29 19:16:28 +0100 | [diff] [blame] | 46 | 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 Masone | d6f38c8 | 2012-02-22 14:53:42 -0800 | [diff] [blame] | 51 | parser.print_help() |
| 52 | return |
| 53 | |
| 54 | fs_getter = dynamic_suite.Suite.create_fs_getter(options.autotest_dir) |
Zdenek Behan | 849db05 | 2012-02-29 19:16:28 +0100 | [diff] [blame] | 55 | |
| 56 | if options.listall: |
| 57 | for suite in dynamic_suite.Suite.list_all_suites('', fs_getter): |
| 58 | print suite |
| 59 | return |
| 60 | |
Chris Masone | d6f38c8 | 2012-02-22 14:53:42 -0800 | [diff] [blame] | 61 | suite = dynamic_suite.Suite.create_from_name(args[0], '', fs_getter) |
Chris Masone | 10c6063 | 2012-02-29 09:33:57 -0800 | [diff] [blame] | 62 | for test in suite.stable_tests(): |
Chris Masone | e8a4eff | 2012-02-28 16:33:43 -0800 | [diff] [blame] | 63 | print test.path |
Chris Masone | 10c6063 | 2012-02-29 09:33:57 -0800 | [diff] [blame] | 64 | if options.add_experimental: |
| 65 | for test in suite.unstable_tests(): |
| 66 | print test.path |
Chris Masone | d6f38c8 | 2012-02-22 14:53:42 -0800 | [diff] [blame] | 67 | |
| 68 | |
| 69 | if __name__ == "__main__": |
| 70 | sys.exit(main()) |