• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2020 The Chromium OS Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4"""
5USAGE: python generate_control_files.py
6
7Generates all the control files required to run the Tast-based storage qual full test.
8In particular, following test blocks are generated:
9- 00_setup_benchmarks: initial test benchmarks
10- 01-40_stress: 40 universal test blocks
11- 99_teardown_benchmarks: final test benchmarks
12
13Generated tests are executed by one of the four test suites, according to the required
14test length: storage_qual_v2_xs, storage_qual_v2_s, storage_qual_v2_m, storage_qual_v2_l
15and storage_qual_v2_xl for extra small, small, medium, large and extra-large test length.
16The difference is number of universal test blocks: 2, 10, 20, 30 or 40 respectively.
17"""
18import os
19
20STORAGE_QUAL_VERSION = 2
21HOUR_IN_SECS = 60 * 60
22SUITE = 'storage_qual_v2'
23TEST_PREFIX = 'storage.FullQualificationStress.'
24TEMPLATE_FILE = 'template.control.storage_qual'
25
26TESTS = [{
27        'test': 'setup',
28        'tast_name': 'setup_benchmarks',
29        'iterations': 1,
30        'duration': 1 * HOUR_IN_SECS,
31        'priority': 200,
32        'length': 'lengthy'
33}, {
34        'test': 'stress_{index:02n}',
35        'tast_name': 'stress',
36        'iterations': 40,
37        'duration': 5 * HOUR_IN_SECS,
38        'priority': 100,
39        'length': 'long'
40}, {
41        'test': 'teardown',
42        'tast_name': 'teardown_benchmarks',
43        'iterations': 1,
44        'duration': 1 * HOUR_IN_SECS,
45        'priority': 50,
46        'length': 'lengthy'
47}]
48
49
50def _get_suite_attributes(iteration):
51    attrs = ['suite:%s_xl' % SUITE]
52    if iteration < 30:
53        attrs += ['suite:%s_l' % SUITE]
54    if iteration < 20:
55        attrs += ['suite:%s_m' % SUITE]
56    if iteration < 10:
57        attrs += ['suite:%s_s' % SUITE]
58    if iteration < 2:
59        attrs += ['suite:%s_xs' % SUITE]
60    return attrs
61
62
63def _write_control_file(name, contents):
64    f = open(name, 'w')
65    f.write(contents)
66    f.close()
67
68
69def _read_template_file(filename):
70    f = open(filename)
71    d = f.read()
72    f.close()
73    return d
74
75
76template = _read_template_file(
77        os.path.join(os.path.dirname(os.path.realpath(__file__)),
78                     TEMPLATE_FILE))
79
80for test in TESTS:
81    for i in range(int(test['iterations'])):
82        test_name = test['test'].format(index=i + 1)
83        control_file = template.format(
84                name='_'.join([SUITE, test_name]),
85                priority=int(test['priority'] - i),
86                duration=int(test['duration']),
87                test_exprs=TEST_PREFIX + test['tast_name'],
88                length=test['length'],
89                version=STORAGE_QUAL_VERSION,
90                attributes=", ".join(_get_suite_attributes(i)),
91        )
92        control_file_name = 'control.' + '_'.join([SUITE, test_name])
93        _write_control_file(control_file_name, control_file)
94