2 # Note: this script is python2 and python3 compatible.
6 # Test option parsing and functonality for fio's steady state detection feature.
8 # steadystate_tests.py --read file-for-read-testing --write file-for-write-testing ./fio
15 # only option parsing and read tests are carried out
16 # On Windows this script works under Cygwin but not from cmd.exe
17 # On Windows I encounter frequent fio problems generating JSON output (nothing to decode)
19 # if ss attained: min runtime = ss_dur + ss_ramp
20 # if not attained: runtime = timeout
22 from __future__ import absolute_import
23 from __future__ import print_function
30 from scipy import stats
33 parser = argparse.ArgumentParser()
34 parser.add_argument('fio',
35 help='path to fio executable')
36 parser.add_argument('--read',
37 help='target for read testing')
38 parser.add_argument('--write',
39 help='target for write testing')
40 args = parser.parse_args()
45 def check(data, iops, slope, pct, limit, dur, criterion):
46 measurement = 'iops' if iops else 'bw'
47 data = data[measurement]
48 mean = sum(data) / len(data)
50 x = list(range(len(data)))
51 m, intercept, r_value, p_value, std_err = stats.linregress(x,data)
54 target = (m / mean * 100) if mean != 0 else 0
55 criterion = criterion[:-1]
61 maxdev = max(abs(mean-x), maxdev)
63 target = maxdev / mean * 100
64 criterion = criterion[:-1]
68 criterion = float(criterion)
72 objsame = abs(target - criterion) / criterion < 0.005
73 return (objsame, target < limit, mean, target)
76 if __name__ == '__main__':
79 pp = pprint.PrettyPrinter(indent=4)
87 parsing = [ { 'args': ["--parse-only", "--debug=parse", "--ss_dur=10s", "--ss=iops:10", "--ss_ramp=5"],
88 'output': "set steady state IOPS threshold to 10.000000" },
89 { 'args': ["--parse-only", "--debug=parse", "--ss_dur=10s", "--ss=iops:10%", "--ss_ramp=5"],
90 'output': "set steady state threshold to 10.000000%" },
91 { 'args': ["--parse-only", "--debug=parse", "--ss_dur=10s", "--ss=iops:.1%", "--ss_ramp=5"],
92 'output': "set steady state threshold to 0.100000%" },
93 { 'args': ["--parse-only", "--debug=parse", "--ss_dur=10s", "--ss=bw:10%", "--ss_ramp=5"],
94 'output': "set steady state threshold to 10.000000%" },
95 { 'args': ["--parse-only", "--debug=parse", "--ss_dur=10s", "--ss=bw:.1%", "--ss_ramp=5"],
96 'output': "set steady state threshold to 0.100000%" },
97 { 'args': ["--parse-only", "--debug=parse", "--ss_dur=10s", "--ss=bw:12", "--ss_ramp=5"],
98 'output': "set steady state BW threshold to 12" },
101 output = subprocess.check_output([args.fio] + test['args'])
102 if test['output'] in output.decode():
103 print("PASSED '{0}' found with arguments {1}".format(test['output'], test['args']))
106 print("FAILED '{0}' NOT found with arguments {1}".format(test['output'], test['args']))
110 # test some read workloads
112 # if ss active and attained,
113 # check that runtime is less than job time
115 # how to check ramp time?
118 # check that runtime is what was specified
120 reads = [ {'s': True, 'timeout': 100, 'numjobs': 1, 'ss_dur': 5, 'ss_ramp': 3, 'iops': True, 'slope': True, 'ss_limit': 0.1, 'pct': True},
121 {'s': False, 'timeout': 20, 'numjobs': 2},
122 {'s': True, 'timeout': 100, 'numjobs': 3, 'ss_dur': 10, 'ss_ramp': 5, 'iops': False, 'slope': True, 'ss_limit': 0.1, 'pct': True},
123 {'s': True, 'timeout': 10, 'numjobs': 3, 'ss_dur': 10, 'ss_ramp': 500, 'iops': False, 'slope': True, 'ss_limit': 0.1, 'pct': True},
126 if args.read == None:
127 if os.name == 'posix':
128 args.read = '/dev/zero'
129 extra = [ "--size=128M" ]
131 print("ERROR: file for read testing must be specified on non-posix systems")
139 tf = "steadystate_job{0}.json".format(jobnum)
140 parameters = [ "--name=job{0}".format(jobnum) ]
141 parameters.extend(extra)
142 parameters.extend([ "--thread",
143 "--output-format=json",
144 "--output={0}".format(tf),
145 "--filename={0}".format(args.read),
150 "--numjobs={0}".format(job['numjobs']),
152 "--runtime={0}".format(job['timeout']) ])
160 ss += ":" + str(job['ss_limit'])
163 parameters.extend([ '--ss_dur={0}'.format(job['ss_dur']),
164 '--ss={0}'.format(ss),
165 '--ss_ramp={0}'.format(job['ss_ramp']) ])
167 output = subprocess.call([args.fio] + parameters)
168 with open(tf, 'r') as source:
169 jsondata = json.loads(source.read())
172 for jsonjob in jsondata['jobs']:
173 line = "{0}".format(jsonjob['job options']['name'])
175 if jsonjob['steadystate']['attained'] == 1:
176 # check runtime >= ss_dur + ss_ramp, check criterion, check criterion < limit
177 mintime = (job['ss_dur'] + job['ss_ramp']) * 1000
178 actual = jsonjob['read']['runtime']
180 line = 'FAILED ' + line + ' ss attained, runtime {0} < ss_dur {1} + ss_ramp {2}'.format(actual, job['ss_dur'], job['ss_ramp'])
183 line = line + ' ss attained, runtime {0} > ss_dur {1} + ss_ramp {2},'.format(actual, job['ss_dur'], job['ss_ramp'])
184 objsame, met, mean, target = check(data=jsonjob['steadystate']['data'],
188 limit=job['ss_limit'],
190 criterion=jsonjob['steadystate']['criterion'])
192 line = 'FAILED ' + line + ' fio criterion {0} != calculated criterion {1} '.format(jsonjob['steadystate']['criterion'], target)
196 line = 'PASSED ' + line + ' target {0} < limit {1}'.format(target, job['ss_limit'])
199 line = 'FAILED ' + line + ' target {0} < limit {1} but fio reports ss not attained '.format(target, job['ss_limit'])
202 # check runtime, confirm criterion calculation, and confirm that criterion was not met
203 expected = job['timeout'] * 1000
204 actual = jsonjob['read']['runtime']
205 if abs(expected - actual) > 10:
206 line = 'FAILED ' + line + ' ss not attained, expected runtime {0} != actual runtime {1}'.format(expected, actual)
208 line = line + ' ss not attained, runtime {0} != ss_dur {1} + ss_ramp {2},'.format(actual, job['ss_dur'], job['ss_ramp'])
209 objsame, met, mean, target = check(data=jsonjob['steadystate']['data'],
213 limit=job['ss_limit'],
215 criterion=jsonjob['steadystate']['criterion'])
217 if actual > (job['ss_dur'] + job['ss_ramp'])*1000:
218 line = 'FAILED ' + line + ' fio criterion {0} != calculated criterion {1} '.format(jsonjob['steadystate']['criterion'], target)
221 line = 'PASSED ' + line + ' fio criterion {0} == 0.0 since ss_dur + ss_ramp has not elapsed '.format(jsonjob['steadystate']['criterion'])
225 line = 'FAILED ' + line + ' target {0} < threshold {1} but fio reports ss not attained '.format(target, job['ss_limit'])
228 line = 'PASSED ' + line + ' criterion {0} > threshold {1}'.format(target, job['ss_limit'])
231 expected = job['timeout'] * 1000
232 actual = jsonjob['read']['runtime']
233 if abs(expected - actual) < 10:
239 line = result + line + ' no ss, expected runtime {0} ~= actual runtime {1}'.format(expected, actual)
241 if 'steadystate' in jsonjob:
242 pp.pprint(jsonjob['steadystate'])
245 print("{0} test(s) PASSED, {1} test(s) FAILED".format(passed,failed))