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