xref: /aosp_15_r20/external/autotest/autotest_lib/metadata/utils/find_tests.py (revision 9c5db1993ded3edbeafc8092d69fe5de2ee02df7)
1# Lint as: python3
2# Copyright 2020 The Chromium OS Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6import glob
7import os
8
9# Relative to .star root (in autotest/files).
10OUTPUT_FILE = "metadata/tests.star"
11
12HEADER = """# Copyright 2020 The Chromium OS Authors. All rights reserved.
13# Use of this source code is governed by a BSD-style license that can be
14# found in the LICENSE file.
15
16TESTS = []
17def _append_tests(tests):
18    for t in tests:
19        TESTS.append(t)
20"""
21
22TEMPLATE = """
23load("//{path}", {unique_name} = "TESTS")
24_append_tests({unique_name})
25"""
26
27def main():
28  """Main entry point of this script."""
29  root_dir = os.path.realpath(
30      os.path.join(os.path.realpath(__file__), "../../.."))
31  os.chdir(root_dir)
32  output = HEADER
33  for test_type in ["client", "server"]:
34    for path in glob.iglob(test_type + "/site_tests/*/*.star"):
35      head, file_name = os.path.split(path)
36      head, test_folder = os.path.split(head)
37      unique_name = "_".join(
38          [test_type, test_folder, file_name[:-len(".star")]])
39      output += TEMPLATE.format(path=path, unique_name=unique_name)
40
41  with open(OUTPUT_FILE, 'w') as fh:
42    fh.write(output)
43  print("Wrote output to", OUTPUT_FILE)
44
45
46if __name__ == '__main__':
47  main()
48