5 # Test option parsing and functonality for fio's steady state detection feature.
7 # steadystate_tests.py ./fio file-for-read-testing file-for-write-testing
14 # only option parsing and read tests are carried out
15 # the read test fails when ss_ramp > timeout because it tries to calculate the stopping criterion and finds that
16 # it does not match what fio reports
18 # if ss attained: min runtime = ss_dur + ss_ramp
19 # if not attained: runtime = timeout
26 from scipy import stats
29 parser = argparse.ArgumentParser()
30 parser.add_argument('fio',
31 help='path to fio executable');
32 parser.add_argument('read',
33 help='target for read testing')
34 parser.add_argument('write',
35 help='target for write testing')
36 args = parser.parse_args()
41 def check(data, iops, slope, pct, limit, dur, criterion):
42 mean = sum(data) / len(data)
45 m, intercept, r_value, p_value, std_err = stats.linregress(x,data)
48 target = m / mean * 100
54 maxdev = max(abs(mean-x), maxdev)
56 target = maxdev / mean * 100
60 return (abs(target - criterion) / criterion < 0.001), target < limit, mean, target
63 if __name__ == '__main__':
69 parsing = [ { 'args': ["--parse-only", "--debug=parse", "--ss_dur=10s", "--ss=iops:10", "--ss_ramp=5"],
70 'output': "set steady state IOPS threshold to 10.000000" },
71 { 'args': ["--parse-only", "--debug=parse", "--ss_dur=10s", "--ss=iops:10%", "--ss_ramp=5"],
72 'output': "set steady state threshold to 10.000000%" },
73 { 'args': ["--parse-only", "--debug=parse", "--ss_dur=10s", "--ss=iops:.1%", "--ss_ramp=5"],
74 'output': "set steady state threshold to 0.100000%" },
75 { 'args': ["--parse-only", "--debug=parse", "--ss_dur=10s", "--ss=bw:10%", "--ss_ramp=5"],
76 'output': "set steady state threshold to 10.000000%" },
77 { 'args': ["--parse-only", "--debug=parse", "--ss_dur=10s", "--ss=bw:.1%", "--ss_ramp=5"],
78 'output': "set steady state threshold to 0.100000%" },
79 { 'args': ["--parse-only", "--debug=parse", "--ss_dur=10s", "--ss=bw:12", "--ss_ramp=5"],
80 'output': "set steady state BW threshold to 12" },
83 output = subprocess.check_output([args.fio] + test['args']);
84 if test['output'] in output:
85 print "PASSED '{0}' found with arguments {1}".format(test['output'], test['args'])
87 print "FAILED '{0}' NOT found with arguments {1}".format(test['output'], test['args'])
90 # test some read workloads
92 # if ss active and attained,
93 # check that runtime is less than job time
95 # how to check ramp time?
98 # check that runtime is what was specified
100 reads = [ [ {'s': True, 'timeout': 100, 'numjobs': 1, 'ss_dur': 5, 'ss_ramp': 3, 'iops': True, 'slope': True, 'ss_limit': 0.1, 'pct': True},
101 {'s': False, 'timeout': 20, 'numjobs': 2},
102 {'s': True, 'timeout': 100, 'numjobs': 3, 'ss_dur': 10, 'ss_ramp': 5, 'iops': False, 'slope': True, 'ss_limit': 0.1, 'pct': True},
103 {'s': True, 'timeout': 10, 'numjobs': 3, 'ss_dur': 10, 'ss_ramp': 500, 'iops': False, 'slope': True, 'ss_limit': 0.1, 'pct': True} ],
111 parameters = [ "--name=job{0}".format(jobnum),
113 "--filename={0}".format(args.read),
114 "--rw=randrw", "--rwmixread=100", "--stonewall",
115 "--group_reporting", "--numjobs={0}".format(job['numjobs']),
116 "--time_based", "--runtime={0}".format(job['timeout']) ]
124 ss += ":" + str(job['ss_limit'])
127 parameters.extend([ '--ss_dur={0}'.format(job['ss_dur']),
128 '--ss={0}'.format(ss),
129 '--ss_ramp={0}'.format(job['ss_ramp']) ])
130 accum.extend(parameters)
133 tf = tempfile.NamedTemporaryFile(delete=False)
135 output = subprocess.check_output([args.fio,
136 "--output-format=json",
137 "--output={0}".format(tf.name)] + accum)
138 with open(tf.name, 'r') as source:
139 jsondata = json.loads(source.read())
142 for job in jsondata['jobs']:
143 line = "suite {0}, {1}".format(suitenum, job['job options']['name'])
144 if suite[jobnum]['s']:
145 if job['steadystate']['attained'] == 1:
146 # check runtime >= ss_dur + ss_ramp, check criterion, check criterion < limit
147 mintime = (suite[jobnum]['ss_dur'] + suite[jobnum]['ss_ramp']) * 1000
148 actual = job['read']['runtime']
150 line = 'FAILED ' + line + ' ss attained, runtime {0} < ss_dur {1} + ss_ramp {2}'.format(actual, suite[jobnum]['ss_dur'], suite[jobnum]['ss_ramp'])
152 line = line + ' ss attained, runtime {0} > ss_dur {1} + ss_ramp {2},'.format(actual, suite[jobnum]['ss_dur'], suite[jobnum]['ss_ramp'])
153 objsame, met, mean, target = check(data=job['steadystate']['data'],
154 iops=suite[jobnum]['iops'],
155 slope=suite[jobnum]['slope'],
156 pct=suite[jobnum]['pct'],
157 limit=suite[jobnum]['ss_limit'],
158 dur=suite[jobnum]['ss_dur'],
159 criterion=job['steadystate']['criterion'])
161 line = 'FAILED ' + line + ' fio criterion {0} != calculated criterion {1}, data: {2} '.format(job['steadystate']['criterion'], target, job['steadystate']['data'])
164 line = 'PASSED ' + line + ' target {0} < limit {1}, data {2}'.format(target, suite[jobnum]['ss_limit'], job['steadystate']['data'])
166 line = 'FAILED ' + line + ' target {0} < limit {1} but fio reports ss not attained, data: {2}'.format(target, suite[jobnum]['ss_limit'], job['steadystate']['data'])
169 # check runtime, confirm criterion calculation, and confirm that criterion was not met
170 expected = suite[jobnum]['timeout'] * 1000
171 actual = job['read']['runtime']
172 if abs(expected - actual) > 10:
173 line = 'FAILED ' + line + ' ss not attained, expected runtime {0} != actual runtime {1}'.format(expected, actual)
175 line = line + ' ss not attained, runtime {0} != ss_dur {1} + ss_ramp {2},'.format(actual, suite[jobnum]['ss_dur'], suite[jobnum]['ss_ramp'])
176 objsame, met, mean, target = check(data=job['steadystate']['data'],
177 iops=suite[jobnum]['iops'],
178 slope=suite[jobnum]['slope'],
179 pct=suite[jobnum]['pct'],
180 limit=suite[jobnum]['ss_limit'],
181 dur=suite[jobnum]['ss_dur'],
182 criterion=job['steadystate']['criterion'])
184 if actual > (suite[jobnum]['ss_dur'] + suite[jobnum]['ss_ramp'])*1000:
185 line = 'FAILED ' + line + ' fio criterion {0} != calculated criterion {1}, data: {2} '.format(job['steadystate']['criterion'], target, job['steadystate']['data'])
187 line = 'PASSED ' + line + ' fio criterion {0} == 0.0 since ss_dur + ss_ramp has not elapsed, data: {1} '.format(job['steadystate']['criterion'], job['steadystate']['data'])
190 line = 'FAILED ' + line + ' target {0} < threshold {1} but fio reports ss not attained, data: {2}'.format(target, suite[jobnum]['ss_limit'], job['steadystate']['data'])
192 line = 'PASSED ' + line + ' criterion {0} > threshold {1}, data {2}'.format(target, suite[jobnum]['ss_limit'], job['steadystate']['data'])
194 expected = suite[jobnum]['timeout'] * 1000
195 actual = job['read']['runtime']
196 if abs(expected - actual) < 10:
200 line = result + line + ' no ss, expected runtime {0} ~= actual runtime {1}'.format(expected, actual)