blob: ac1605a7a17c6850c6b4d4e28593d31c0710ae3f [file] [log] [blame]
mblighbe630eb2008-08-01 16:41:48 +00001#
2# Copyright 2008 Google Inc. All Rights Reserved.
3
4"""
5The test module contains the objects and methods used to
6manage tests in Autotest.
7
8The valid action is:
9list: lists test(s)
10
11The common options are:
12--tlist / -T: file containing a list of tests
13
14See topic_common.py for a High Level Design and Algorithm.
15"""
16
17
18import os, sys
19
20from autotest_lib.cli import topic_common, action_common
21
22
23class 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
mbligh9deeefa2009-05-01 23:11:08 +000040 self.topic_parse_info = topic_common.item_parse_info(
41 attribute_name='tests',
42 filename_option='tlist',
43 use_leftover=True)
mblighbe630eb2008-08-01 16:41:48 +000044
45
46 def get_items(self):
47 return self.tests
48
49
50class test_help(test):
51 """Just here to get the atest logic working.
52 Usage is set by its parent"""
53 pass
54
55
56class test_list(action_common.atest_list, test):
mbligh140a23c2008-10-29 16:55:21 +000057 """atest test list [--description] [--experimental|--all] [<tests>]"""
mblighbe630eb2008-08-01 16:41:48 +000058 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)
mbligh140a23c2008-10-29 16:55:21 +000065 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)
mblighbe630eb2008-08-01 16:41:48 +000073
74
75 def parse(self):
76 (options, leftover) = super(test_list, self).parse()
77
mbligh140a23c2008-10-29 16:55:21 +000078 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
mblighbe630eb2008-08-01 16:41:48 +000082 self.description = options.description
mbligh140a23c2008-10-29 16:55:21 +000083 self.all = options.all
84 self.experimental = options.experimental
mblighbe630eb2008-08-01 16:41:48 +000085
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
mbligh140a23c2008-10-29 16:55:21 +000096 if not self.all:
97 filters['experimental'] = self.experimental
98 check_results['experimental'] = None
99
mblighbe630eb2008-08-01 16:41:48 +0000100 return super(test_list, self).execute(op='get_tests',
101 filters=filters,
102 check_results=check_results)
103
104
105 def output(self, results):
mbligh140a23c2008-10-29 16:55:21 +0000106 keys = ['name', 'test_type', 'test_class']
107
108 if self.all:
109 keys.append('experimental')
110
mblighbe630eb2008-08-01 16:41:48 +0000111 if self.verbose:
mbligh140a23c2008-10-29 16:55:21 +0000112 keys.append('path')
mblighbe630eb2008-08-01 16:41:48 +0000113
114 if self.description:
115 keys.append('description')
116
117 super(test_list, self).output(results, keys)