mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 1 | # |
| 2 | # Copyright 2008 Google Inc. All Rights Reserved. |
| 3 | |
| 4 | """ |
| 5 | The test module contains the objects and methods used to |
| 6 | manage tests in Autotest. |
| 7 | |
| 8 | The valid action is: |
| 9 | list: lists test(s) |
| 10 | |
| 11 | The common options are: |
| 12 | --tlist / -T: file containing a list of tests |
| 13 | |
| 14 | See topic_common.py for a High Level Design and Algorithm. |
| 15 | """ |
| 16 | |
| 17 | |
| 18 | import os, sys |
| 19 | |
| 20 | from autotest_lib.cli import topic_common, action_common |
| 21 | |
| 22 | |
| 23 | class test(topic_common.atest): |
| 24 | """Test class |
| 25 | atest test list <options>""" |
| 26 | usage_action = 'list' |
| 27 | topic = msg_topic = 'test' |
| 28 | msg_items = '[tests]' |
| 29 | |
| 30 | def __init__(self): |
| 31 | """Add to the parser the options common to all the test actions""" |
| 32 | super(test, self).__init__() |
| 33 | |
| 34 | self.parser.add_option('-T', '--tlist', |
| 35 | help='File listing the tests', |
| 36 | type='string', |
| 37 | default=None, |
| 38 | metavar='TEST_FLIST') |
| 39 | |
mbligh | 9deeefa | 2009-05-01 23:11:08 +0000 | [diff] [blame] | 40 | self.topic_parse_info = topic_common.item_parse_info( |
| 41 | attribute_name='tests', |
| 42 | filename_option='tlist', |
| 43 | use_leftover=True) |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 44 | |
| 45 | |
| 46 | def get_items(self): |
| 47 | return self.tests |
| 48 | |
| 49 | |
| 50 | class test_help(test): |
| 51 | """Just here to get the atest logic working. |
| 52 | Usage is set by its parent""" |
| 53 | pass |
| 54 | |
| 55 | |
| 56 | class test_list(action_common.atest_list, test): |
mbligh | 140a23c | 2008-10-29 16:55:21 +0000 | [diff] [blame] | 57 | """atest test list [--description] [--experimental|--all] [<tests>]""" |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 58 | def __init__(self): |
| 59 | super(test_list, self).__init__() |
| 60 | |
| 61 | self.parser.add_option('-d', '--description', |
| 62 | help='Display the test descriptions', |
| 63 | action='store_true', |
| 64 | default=False) |
mbligh | 140a23c | 2008-10-29 16:55:21 +0000 | [diff] [blame] | 65 | self.parser.add_option('--all', |
| 66 | help='Display all the tests', |
| 67 | action='store_true', |
| 68 | default=False) |
| 69 | self.parser.add_option('-e', '--experimental', |
| 70 | help='Display the experimental tests only', |
| 71 | action='store_true', |
| 72 | default=False) |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 73 | |
| 74 | |
| 75 | def parse(self): |
| 76 | (options, leftover) = super(test_list, self).parse() |
| 77 | |
mbligh | 140a23c | 2008-10-29 16:55:21 +0000 | [diff] [blame] | 78 | if self.tests and (options.experimental or options.all): |
| 79 | self.invalid_syntax('Do not specify a test name with --all or ' |
| 80 | '--experimental') |
| 81 | |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 82 | self.description = options.description |
mbligh | 140a23c | 2008-10-29 16:55:21 +0000 | [diff] [blame] | 83 | self.all = options.all |
| 84 | self.experimental = options.experimental |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 85 | |
| 86 | return (options, leftover) |
| 87 | |
| 88 | |
| 89 | def execute(self): |
| 90 | filters = {} |
| 91 | check_results = {} |
| 92 | if self.tests: |
| 93 | filters['name__in'] = self.tests |
| 94 | check_results['name__in'] = 'name' |
| 95 | |
mbligh | 140a23c | 2008-10-29 16:55:21 +0000 | [diff] [blame] | 96 | if not self.all: |
| 97 | filters['experimental'] = self.experimental |
| 98 | check_results['experimental'] = None |
| 99 | |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 100 | return super(test_list, self).execute(op='get_tests', |
| 101 | filters=filters, |
| 102 | check_results=check_results) |
| 103 | |
| 104 | |
| 105 | def output(self, results): |
mbligh | 140a23c | 2008-10-29 16:55:21 +0000 | [diff] [blame] | 106 | keys = ['name', 'test_type', 'test_class'] |
| 107 | |
| 108 | if self.all: |
| 109 | keys.append('experimental') |
| 110 | |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 111 | if self.verbose: |
mbligh | 140a23c | 2008-10-29 16:55:21 +0000 | [diff] [blame] | 112 | keys.append('path') |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 113 | |
| 114 | if self.description: |
| 115 | keys.append('description') |
| 116 | |
| 117 | super(test_list, self).output(results, keys) |