lin
2025-08-14 dae8bad597b6607a449b32bf76c523423f7720ed
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
#!/usr/bin/python
 
# Copyright (c) 2015 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
 
"""This script creates a whitelist of test attributes based on the 'suite' read
from test control files.
"""
import argparse
 
import common
from autotest_lib.client.common_lib.cros import dev_server
from autotest_lib.server.cros.dynamic_suite.suite import Suite
 
 
def main():
  """main script."""
  # Parse filepath from cmd line.
  parser = argparse.ArgumentParser(description='Create attribute whitelist.')
  parser.add_argument('path', metavar='WHITELIST_FILE_PATH',
                      help='Path to the file whitelist is written to. E.g. '
                           './attribute_whitelist.txt')
  args = parser.parse_args()
 
  # Get all the suites from current test control files, and order them.
  fs_getter = Suite.create_fs_getter(common.autotest_dir)
  devserver = dev_server.ImageServer('')
  suite_list = Suite.list_all_suites('', devserver, fs_getter)
  suite_list.sort(key = str.lower)
 
  # Parse attributes from suites, and write to a file
  whitelist = ['suite:' + x for x in suite_list]
  _WriteToFile(whitelist, args.path)
 
 
def _WriteToFile(whitelist, path):
  """"Write the whitelist to a file under the path.
 
  The format of the file used here is a list, which can be easily read to a list
  by using ast.literal_eval.
 
  Args:
    whitelist: a list contains all the allowed attributes.
    path: path to the file.
  """
  with open(path, 'wb') as attr_file:
    attr_file.write('\n'.join(whitelist))
 
 
if __name__ == '__main__':
  main()