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 40 self.topic_parse_info = topic_common.item_parse_info( 41 attribute_name='tests', 42 filename_option='tlist', 43 use_leftover=True) 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): 57 """atest test list [--description] [--experimental|--all] [<tests>]""" 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) 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) 73 74 75 def parse(self): 76 (options, leftover) = super(test_list, self).parse() 77 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 82 self.description = options.description 83 self.all = options.all 84 self.experimental = options.experimental 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 96 if not self.all: 97 filters['experimental'] = self.experimental 98 check_results['experimental'] = None 99 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): 106 keys = ['name', 'test_type', 'test_class'] 107 108 if self.all: 109 keys.append('experimental') 110 111 if self.verbose: 112 keys.append('path') 113 114 if self.description: 115 keys.append('description') 116 117 super(test_list, self).output(results, keys) 118