5 # Test option parsing and functionality for fio's steady state detection feature.
7 # steadystate_tests.py --read file-for-read-testing --write file-for-write-testing ./fio
14 # only option parsing and read tests are carried out
15 # On Windows this script works under Cygwin but not from cmd.exe
16 # On Windows I encounter frequent fio problems generating JSON output (nothing to decode)
18 # if ss attained: min runtime = ss_dur + ss_ramp
19 # if not attained: runtime = timeout
21 from __future__ import absolute_import
22 from __future__ import print_function
29 from scipy import stats
32 parser = argparse.ArgumentParser()
33 parser.add_argument('fio', help='path to fio executable')
34 args = parser.parse_args()
39 def check(data, iops, slope, pct, limit, dur, criterion):
40 measurement = 'iops' if iops else 'bw'
41 data = data[measurement]
42 mean = sum(data) / len(data)
44 x = list(range(len(data)))
45 m, intercept, r_value, p_value, std_err = stats.linregress(x,data)
48 target = (m / mean * 100) if mean != 0 else 0
49 criterion = criterion[:-1]
55 maxdev = max(abs(mean-x), maxdev)
57 target = maxdev / mean * 100
58 criterion = criterion[:-1]
62 criterion = float(criterion)
66 objsame = abs(target - criterion) / criterion < 0.005
67 return (objsame, target < limit, mean, target)
70 if __name__ == '__main__':
73 pp = pprint.PrettyPrinter(indent=4)
81 parsing = [ { 'args': ["--parse-only", "--debug=parse", "--ss_dur=10s", "--ss=iops:10", "--ss_ramp=5"],
82 'output': "set steady state IOPS threshold to 10.000000" },
83 { 'args': ["--parse-only", "--debug=parse", "--ss_dur=10s", "--ss=iops:10%", "--ss_ramp=5"],
84 'output': "set steady state threshold to 10.000000%" },
85 { 'args': ["--parse-only", "--debug=parse", "--ss_dur=10s", "--ss=iops:.1%", "--ss_ramp=5"],
86 'output': "set steady state threshold to 0.100000%" },
87 { 'args': ["--parse-only", "--debug=parse", "--ss_dur=10s", "--ss=bw:10%", "--ss_ramp=5"],
88 'output': "set steady state threshold to 10.000000%" },
89 { 'args': ["--parse-only", "--debug=parse", "--ss_dur=10s", "--ss=bw:.1%", "--ss_ramp=5"],
90 'output': "set steady state threshold to 0.100000%" },
91 { 'args': ["--parse-only", "--debug=parse", "--ss_dur=10s", "--ss=bw:12", "--ss_ramp=5"],
92 'output': "set steady state BW threshold to 12" },
95 output = subprocess.check_output([args.fio] + test['args'])
96 if test['output'] in output.decode():
97 print("PASSED '{0}' found with arguments {1}".format(test['output'], test['args']))
100 print("FAILED '{0}' NOT found with arguments {1}".format(test['output'], test['args']))
104 # test some read workloads
106 # if ss active and attained,
107 # check that runtime is less than job time
109 # how to check ramp time?
112 # check that runtime is what was specified
114 reads = [ {'s': True, 'timeout': 100, 'numjobs': 1, 'ss_dur': 5, 'ss_ramp': 3, 'iops': True, 'slope': True, 'ss_limit': 0.1, 'pct': True},
115 {'s': False, 'timeout': 20, 'numjobs': 2},
116 {'s': True, 'timeout': 100, 'numjobs': 3, 'ss_dur': 10, 'ss_ramp': 5, 'iops': False, 'slope': True, 'ss_limit': 0.1, 'pct': True},
117 {'s': True, 'timeout': 10, 'numjobs': 3, 'ss_dur': 10, 'ss_ramp': 500, 'iops': False, 'slope': True, 'ss_limit': 0.1, 'pct': True},
118 {'s': True, 'timeout': 10, 'numjobs': 3, 'ss_dur': 10, 'ss_ramp': 500, 'iops': False, 'slope': True, 'ss_limit': 0.1, 'pct': True, 'ss_interval': 5},
124 tf = "steadystate_job{0}.json".format(jobnum)
125 parameters = [ "--max-jobs=16", "--name=job{0}".format(jobnum) ]
126 parameters.extend([ "--thread",
127 "--output-format=json",
128 "--output={0}".format(tf),
135 "--numjobs={0}".format(job['numjobs']),
137 "--runtime={0}".format(job['timeout']) ])
145 ss += ":" + str(job['ss_limit'])
148 parameters.extend([ '--ss_dur={0}'.format(job['ss_dur']),
149 '--ss={0}'.format(ss),
150 '--ss_ramp={0}'.format(job['ss_ramp']) ])
152 output = subprocess.call([args.fio] + parameters)
153 with open(tf, 'r') as source:
154 jsondata = json.loads(source.read())
157 for jsonjob in jsondata['jobs']:
158 line = "{0}".format(jsonjob['job options']['name'])
160 if jsonjob['steadystate']['attained'] == 1:
161 # check runtime >= ss_dur + ss_ramp, check criterion, check criterion < limit
162 mintime = (job['ss_dur'] + job['ss_ramp']) * 1000
163 actual = jsonjob['read']['runtime']
165 line = 'FAILED ' + line + ' ss attained, runtime {0} < ss_dur {1} + ss_ramp {2}'.format(actual, job['ss_dur'], job['ss_ramp'])
168 line = line + ' ss attained, runtime {0} > ss_dur {1} + ss_ramp {2},'.format(actual, job['ss_dur'], job['ss_ramp'])
169 objsame, met, mean, target = check(data=jsonjob['steadystate']['data'],
173 limit=job['ss_limit'],
175 criterion=jsonjob['steadystate']['criterion'])
177 line = 'FAILED ' + line + ' fio criterion {0} != calculated criterion {1} '.format(jsonjob['steadystate']['criterion'], target)
181 line = 'PASSED ' + line + ' target {0} < limit {1}'.format(target, job['ss_limit'])
184 line = 'FAILED ' + line + ' target {0} < limit {1} but fio reports ss not attained '.format(target, job['ss_limit'])
187 # check runtime, confirm criterion calculation, and confirm that criterion was not met
188 expected = job['timeout'] * 1000
189 actual = jsonjob['read']['runtime']
190 if abs(expected - actual) > 50:
191 line = 'FAILED ' + line + ' ss not attained, expected runtime {0} != actual runtime {1}'.format(expected, actual)
193 line = line + ' ss not attained, runtime {0} != ss_dur {1} + ss_ramp {2},'.format(actual, job['ss_dur'], job['ss_ramp'])
194 objsame, met, mean, target = check(data=jsonjob['steadystate']['data'],
198 limit=job['ss_limit'],
200 criterion=jsonjob['steadystate']['criterion'])
202 if actual > (job['ss_dur'] + job['ss_ramp'])*1000:
203 line = 'FAILED ' + line + ' fio criterion {0} != calculated criterion {1} '.format(jsonjob['steadystate']['criterion'], target)
206 line = 'PASSED ' + line + ' fio criterion {0} == 0.0 since ss_dur + ss_ramp has not elapsed '.format(jsonjob['steadystate']['criterion'])
210 line = 'FAILED ' + line + ' target {0} < threshold {1} but fio reports ss not attained '.format(target, job['ss_limit'])
213 line = 'PASSED ' + line + ' criterion {0} > threshold {1}'.format(target, job['ss_limit'])
216 expected = job['timeout'] * 1000
217 actual = jsonjob['read']['runtime']
218 if abs(expected - actual) > 50:
224 line = result + line + ' no ss, expected runtime {0} ~= actual runtime {1}'.format(expected, actual)
226 if 'steadystate' in jsonjob:
227 pp.pprint(jsonjob['steadystate'])
230 print("{0} test(s) PASSED, {1} test(s) FAILED".format(passed,failed))