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