aboutsummaryrefslogtreecommitdiff
path: root/server/site_tests/hardware_StorageQualV2/generate_control_files.py
blob: 8fdc87f249e6d8ec74d43c911b2671c28e58ed6a (plain)
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
# Copyright 2020 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.
"""
USAGE: python generate_control_files.py

Generates all the control files required to run the Tast-based storage qual full test.
In particular, following test blocks are generated:
- 00_setup_benchmarks: initial test benchmarks
- 01-40_stress: 40 universal test blocks
- 99_teardown_benchmarks: final test benchmarks

Generated tests are executed by one of the four test suites, according to the required
test length: storage_qual_v2_xs, storage_qual_v2_s, storage_qual_v2_m, storage_qual_v2_l
and storage_qual_v2_xl for extra small, small, medium, large and extra-large test length.
The difference is number of universal test blocks: 2, 10, 20, 30 or 40 respectively.
"""
import os

STORAGE_QUAL_VERSION = 2
HOUR_IN_SECS = 60 * 60
SUITE = 'storage_qual_v2'
TEST_PREFIX = 'storage.FullQualificationStress.'
TEMPLATE_FILE = 'template.control.storage_qual'

TESTS = [{
        'test': 'setup',
        'tast_name': 'setup_benchmarks',
        'iterations': 1,
        'duration': 1 * HOUR_IN_SECS,
        'priority': 200,
        'length': 'lengthy'
}, {
        'test': 'stress_{index:02n}',
        'tast_name': 'stress',
        'iterations': 40,
        'duration': 5 * HOUR_IN_SECS,
        'priority': 100,
        'length': 'long'
}, {
        'test': 'teardown',
        'tast_name': 'teardown_benchmarks',
        'iterations': 1,
        'duration': 1 * HOUR_IN_SECS,
        'priority': 50,
        'length': 'lengthy'
}]


def _get_suite_attributes(iteration):
    attrs = ['suite:%s_xl' % SUITE]
    if iteration < 30:
        attrs += ['suite:%s_l' % SUITE]
    if iteration < 20:
        attrs += ['suite:%s_m' % SUITE]
    if iteration < 10:
        attrs += ['suite:%s_s' % SUITE]
    if iteration < 2:
        attrs += ['suite:%s_xs' % SUITE]
    return attrs


def _write_control_file(name, contents):
    f = open(name, 'w')
    f.write(contents)
    f.close()


def _read_template_file(filename):
    f = open(filename)
    d = f.read()
    f.close()
    return d


template = _read_template_file(
        os.path.join(os.path.dirname(os.path.realpath(__file__)),
                     TEMPLATE_FILE))

for test in TESTS:
    for i in range(int(test['iterations'])):
        test_name = test['test'].format(index=i + 1)
        control_file = template.format(
                name='_'.join([SUITE, test_name]),
                priority=int(test['priority'] - i),
                duration=int(test['duration']),
                test_exprs=TEST_PREFIX + test['tast_name'],
                length=test['length'],
                version=STORAGE_QUAL_VERSION,
                attributes=", ".join(_get_suite_attributes(i)),
        )
        control_file_name = 'control.' + '_'.join([SUITE, test_name])
        _write_control_file(control_file_name, control_file)