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 |
Chris Masone | a7dbfbc | 2014-02-06 14:24:22 -0800 | [diff] [blame] | 14 | login_LoginSuccess |
Chris Masone | d6f38c8 | 2012-02-22 14:53:42 -0800 | [diff] [blame] | 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 | |
J. Richard Barnette | 6b355f1 | 2014-07-22 17:35:37 -0700 | [diff] [blame] | 22 | import logging |
Dan Shi | 11d36bc | 2013-02-25 16:23:02 -0800 | [diff] [blame] | 23 | import optparse, os, sys |
J. Richard Barnette | 6b355f1 | 2014-07-22 17:35:37 -0700 | [diff] [blame] | 24 | |
| 25 | # Silence messages relating to imports of missing, unneeded |
| 26 | # modules. |
| 27 | logging.basicConfig(level=logging.INFO) |
| 28 | |
Chris Masone | d6f38c8 | 2012-02-22 14:53:42 -0800 | [diff] [blame] | 29 | import common |
Mike Mason | 00280b9 | 2017-04-24 11:27:45 -0700 | [diff] [blame] | 30 | import autotest_lib.client.common_lib.cros as cros_lib |
| 31 | import autotest_lib.server.cros.dynamic_suite.suite as suite_lib |
| 32 | |
Chris Masone | d6f38c8 | 2012-02-22 14:53:42 -0800 | [diff] [blame] | 33 | |
| 34 | def parse_options(): |
Dan Shi | 11d36bc | 2013-02-25 16:23:02 -0800 | [diff] [blame] | 35 | """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 Masone | d6f38c8 | 2012-02-22 14:53:42 -0800 | [diff] [blame] | 38 | 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 Barnette | 6b355f1 | 2014-07-22 17:35:37 -0700 | [diff] [blame] | 42 | os.path.join(os.path.dirname(__file__), |
| 43 | os.pardir)), |
Chris Masone | d6f38c8 | 2012-02-22 14:53:42 -0800 | [diff] [blame] | 44 | help='Directory under which to search for tests.'\ |
| 45 | ' (e.g. /usr/local/autotest)') |
Zdenek Behan | 849db05 | 2012-02-29 19:16:28 +0100 | [diff] [blame] | 46 | parser.add_option('-l', '--listall', |
| 47 | action='store_true', default=False, |
| 48 | help='Print a listing of all suites. Ignores all args.') |
Chris Masone | d6f38c8 | 2012-02-22 14:53:42 -0800 | [diff] [blame] | 49 | options, args = parser.parse_args() |
| 50 | return parser, options, args |
| 51 | |
| 52 | |
| 53 | def main(): |
Dan Shi | 11d36bc | 2013-02-25 16:23:02 -0800 | [diff] [blame] | 54 | """Entry point to run the suite enumerator command.""" |
Chris Masone | d6f38c8 | 2012-02-22 14:53:42 -0800 | [diff] [blame] | 55 | parser, options, args = parse_options() |
Zdenek Behan | 849db05 | 2012-02-29 19:16:28 +0100 | [diff] [blame] | 56 | 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 Masone | d6f38c8 | 2012-02-22 14:53:42 -0800 | [diff] [blame] | 61 | parser.print_help() |
| 62 | return |
| 63 | |
Mike Mason | 00280b9 | 2017-04-24 11:27:45 -0700 | [diff] [blame] | 64 | fs_getter = suite_lib.create_fs_getter(options.autotest_dir) |
| 65 | devserver = cros_lib.dev_server.ImageServer('') |
Zdenek Behan | 849db05 | 2012-02-29 19:16:28 +0100 | [diff] [blame] | 66 | if options.listall: |
Mike Mason | 00280b9 | 2017-04-24 11:27:45 -0700 | [diff] [blame] | 67 | for suite in suite_lib.list_all_suites('', devserver, fs_getter): |
Zdenek Behan | 849db05 | 2012-02-29 19:16:28 +0100 | [diff] [blame] | 68 | print suite |
| 69 | return |
| 70 | |
Mike Mason | 00280b9 | 2017-04-24 11:27:45 -0700 | [diff] [blame] | 71 | suite = suite_lib.Suite.create_from_name(args[0], {}, '', devserver, |
| 72 | fs_getter) |
Yusuf Mohsinally | 610911d | 2012-11-08 15:59:43 -0800 | [diff] [blame] | 73 | # 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 Mason | 00280b9 | 2017-04-24 11:27:45 -0700 | [diff] [blame] | 78 | PRETEST_LIST, suite.tests): |
Yusuf Mohsinally | 610911d | 2012-11-08 15:59:43 -0800 | [diff] [blame] | 79 | print test.path |
| 80 | for test in filter(lambda test: test.name not in \ |
Mike Mason | 00280b9 | 2017-04-24 11:27:45 -0700 | [diff] [blame] | 81 | PRETEST_LIST, suite.tests): |
Chris Masone | e8a4eff | 2012-02-28 16:33:43 -0800 | [diff] [blame] | 82 | print test.path |
J. Richard Barnette | 6b355f1 | 2014-07-22 17:35:37 -0700 | [diff] [blame] | 83 | |
Dan Shi | 11d36bc | 2013-02-25 16:23:02 -0800 | [diff] [blame] | 84 | # Check if test_suites/control.suite_name exists. |
J. Richard Barnette | 6b355f1 | 2014-07-22 17:35:37 -0700 | [diff] [blame] | 85 | 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 Masone | d6f38c8 | 2012-02-22 14:53:42 -0800 | [diff] [blame] | 90 | |
| 91 | |
| 92 | if __name__ == "__main__": |
| 93 | sys.exit(main()) |