xref: /aosp_15_r20/external/autotest/server/site_tests/telemetry_Benchmarks/generate_controlfiles.py (revision 9c5db1993ded3edbeafc8092d69fe5de2ee02df7)
1# Lint as: python2, python3
2#!/usr/bin/env python3
3
4"""
5This file generates all telemetry_Benchmarks control files from a main list.
6"""
7
8
9
10from datetime import datetime
11import os
12import re
13
14# This test list is a subset of telemetry benchmark tests. The full list can be
15# obtained by executing
16# /build/${BOARD}/usr/local/telemetry/src/tools/perf/list_benchmarks
17
18# PLEASE READ THIS:
19
20# PERF_TESTS: these tests run on each build: tot, tot-1, tot-2 and expensive to
21# run.
22
23# PERF_DAILY_RUN_TESTS: these tests run on a nightly build: tot. If you are
24# trying to gain confidence for a new test, adding your test in this list is a
25# good start.
26
27# For adding a new test to any of these lists, please add rohitbm, lafeenstra,
28# haddowk in the change.
29
30PERF_PER_BUILD_TESTS = (
31    'loading.desktop',
32    'rendering.desktop',
33    'speedometer2',
34)
35
36PERF_DAILY_RUN_TESTS = (
37    'blink_perf.image_decoder',
38)
39
40ALL_TESTS = (PERF_PER_BUILD_TESTS + PERF_DAILY_RUN_TESTS)
41
42EXTRA_ARGS_MAP = {
43    'loading.desktop': '--story-tag-filter=typical',
44    'rendering.desktop': '--story-tag-filter=top_real_world_desktop',
45}
46
47DEFAULT_YEAR = str(datetime.now().year)
48
49DEFAULT_AUTHOR = 'ChromeOS Team'
50
51CONTROLFILE_TEMPLATE = (
52        """# Copyright {year} The Chromium OS Authors. All rights reserved.
53# Use of this source code is governed by a BSD-style license that can be
54# found in the LICENSE file.
55
56# Do not edit this file! It was created by generate_controlfiles.py.
57
58from autotest_lib.client.common_lib import utils
59
60AUTHOR = '{author}'
61NAME = 'telemetry_Benchmarks.{test}'
62{attributes}
63TIME = 'LONG'
64TEST_CATEGORY = 'Benchmark'
65TEST_CLASS = 'performance'
66TEST_TYPE = 'server'
67PY_VERSION = 3
68
69DOC = '''
70This server side test suite executes the Telemetry Benchmark:
71{test}
72This is part of Chrome for ChromeOS performance testing.
73
74Pass local=True to run with local telemetry and no AFE server.
75'''
76
77def run_benchmark(machine):
78    host = hosts.create_host(machine)
79    dargs = utils.args_to_dict(args)
80    dargs['extra_args'] = '{extra_args}'.split()
81    job.run_test('telemetry_Benchmarks', host=host,
82                 benchmark='{test}',
83                 tag='{test}',
84                 args=dargs)
85
86parallel_simple(run_benchmark, machines)""")
87
88
89def _get_suite(test):
90    if test in PERF_PER_BUILD_TESTS:
91        return 'ATTRIBUTES = \'suite:crosbolt_perf_perbuild\''
92    elif test in PERF_DAILY_RUN_TESTS:
93        return 'ATTRIBUTES = \'suite:crosbolt_perf_nightly\''
94    return ''
95
96
97def get_existing_fields(filename):
98    """Returns the existing copyright year and author of the control file."""
99    if not os.path.isfile(filename):
100        return (DEFAULT_YEAR, DEFAULT_AUTHOR)
101
102    copyright_year = DEFAULT_YEAR
103    author = DEFAULT_AUTHOR
104    copyright_pattern = re.compile(
105            '# Copyright (\d+) The Chromium OS Authors.')
106    author_pattern = re.compile("AUTHOR = '(.+)'")
107    with open(filename) as f:
108        for line in f:
109            match_year = copyright_pattern.match(line)
110            if match_year:
111                copyright_year = match_year.group(1)
112            match_author = author_pattern.match(line)
113            if match_author:
114                author = match_author.group(1)
115    return (copyright_year, author)
116
117
118def generate_control(test):
119    """Generates control file from the template."""
120    filename = 'control.%s' % test
121    copyright_year, author = get_existing_fields(filename)
122    extra_args = EXTRA_ARGS_MAP.get(test, '')
123
124    with open(filename, 'w+') as f:
125        content = CONTROLFILE_TEMPLATE.format(
126                attributes=_get_suite(test),
127                author=author,
128                extra_args=extra_args,
129                test=test,
130                year=copyright_year)
131        f.write(content)
132
133
134def check_unmanaged_control_files():
135    """Prints warning if there is unmanaged control file."""
136    for filename in os.listdir('.'):
137        if not filename.startswith('control.'):
138            continue
139        test = filename[len('control.'):]
140        if test not in ALL_TESTS:
141            print('warning, unmanaged control file:', test)
142
143
144def main():
145    """The main function."""
146    for test in ALL_TESTS:
147        generate_control(test)
148    check_unmanaged_control_files()
149
150
151if __name__ == "__main__":
152    main()
153