2 # Note: this script is python2 and python 3 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
31 from scipy import stats
32 from six.moves import range
35 parser = argparse.ArgumentParser()
36 parser.add_argument('fio',
37 help='path to fio executable')
38 parser.add_argument('--read',
39 help='target for read testing')
40 parser.add_argument('--write',
41 help='target for write testing')
42 args = parser.parse_args()
47 def check(data, iops, slope, pct, limit, dur, criterion):
48 measurement = 'iops' if iops else 'bw'
49 data = data[measurement]
50 mean = sum(data) / len(data)
52 x = list(range(len(data)))
53 m, intercept, r_value, p_value, std_err = stats.linregress(x,data)
56 target = m / mean * 100
57 criterion = criterion[:-1]
63 maxdev = max(abs(mean-x), maxdev)
65 target = maxdev / mean * 100
66 criterion = criterion[:-1]
70 criterion = float(criterion)
71 return (abs(target - criterion) / criterion < 0.005), target < limit, mean, target
74 if __name__ == '__main__':
77 pp = pprint.PrettyPrinter(indent=4)
82 parsing = [ { 'args': ["--parse-only", "--debug=parse", "--ss_dur=10s", "--ss=iops:10", "--ss_ramp=5"],
83 'output': "set steady state IOPS threshold to 10.000000" },
84 { 'args': ["--parse-only", "--debug=parse", "--ss_dur=10s", "--ss=iops:10%", "--ss_ramp=5"],
85 'output': "set steady state threshold to 10.000000%" },
86 { 'args': ["--parse-only", "--debug=parse", "--ss_dur=10s", "--ss=iops:.1%", "--ss_ramp=5"],
87 'output': "set steady state threshold to 0.100000%" },
88 { 'args': ["--parse-only", "--debug=parse", "--ss_dur=10s", "--ss=bw:10%", "--ss_ramp=5"],
89 'output': "set steady state threshold to 10.000000%" },
90 { 'args': ["--parse-only", "--debug=parse", "--ss_dur=10s", "--ss=bw:.1%", "--ss_ramp=5"],
91 'output': "set steady state threshold to 0.100000%" },
92 { 'args': ["--parse-only", "--debug=parse", "--ss_dur=10s", "--ss=bw:12", "--ss_ramp=5"],
93 'output': "set steady state BW threshold to 12" },
96 output = subprocess.check_output([args.fio] + test['args'])
97 if test['output'] in output.decode():
98 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']))
103 # test some read workloads
105 # if ss active and attained,
106 # check that runtime is less than job time
108 # how to check ramp time?
111 # check that runtime is what was specified
113 reads = [ {'s': True, 'timeout': 100, 'numjobs': 1, 'ss_dur': 5, 'ss_ramp': 3, 'iops': True, 'slope': True, 'ss_limit': 0.1, 'pct': True},
114 {'s': False, 'timeout': 20, 'numjobs': 2},
115 {'s': True, 'timeout': 100, 'numjobs': 3, 'ss_dur': 10, 'ss_ramp': 5, 'iops': False, 'slope': True, 'ss_limit': 0.1, 'pct': True},
116 {'s': True, 'timeout': 10, 'numjobs': 3, 'ss_dur': 10, 'ss_ramp': 500, 'iops': False, 'slope': True, 'ss_limit': 0.1, 'pct': True},
119 if args.read == None:
120 if os.name == 'posix':
121 args.read = '/dev/zero'
122 extra = [ "--size=134217728" ] # 128 MiB
124 print("ERROR: file for read testing must be specified on non-posix systems")
132 tf = uuid.uuid4().hex
133 parameters = [ "--name=job{0}".format(jobnum) ]
134 parameters.extend(extra)
135 parameters.extend([ "--thread",
136 "--output-format=json",
137 "--output={0}".format(tf),
138 "--filename={0}".format(args.read),
143 "--numjobs={0}".format(job['numjobs']),
145 "--runtime={0}".format(job['timeout']) ])
153 ss += ":" + str(job['ss_limit'])
156 parameters.extend([ '--ss_dur={0}'.format(job['ss_dur']),
157 '--ss={0}'.format(ss),
158 '--ss_ramp={0}'.format(job['ss_ramp']) ])
160 output = subprocess.call([args.fio] + parameters)
161 with open(tf, 'r') as source:
162 jsondata = json.loads(source.read())
165 for jsonjob in jsondata['jobs']:
166 line = "job {0}".format(jsonjob['job options']['name'])
168 if jsonjob['steadystate']['attained'] == 1:
169 # check runtime >= ss_dur + ss_ramp, check criterion, check criterion < limit
170 mintime = (job['ss_dur'] + job['ss_ramp']) * 1000
171 actual = jsonjob['read']['runtime']
173 line = 'FAILED ' + line + ' ss attained, runtime {0} < ss_dur {1} + ss_ramp {2}'.format(actual, job['ss_dur'], job['ss_ramp'])
175 line = line + ' ss attained, runtime {0} > ss_dur {1} + ss_ramp {2},'.format(actual, job['ss_dur'], job['ss_ramp'])
176 objsame, met, mean, target = check(data=jsonjob['steadystate']['data'],
180 limit=job['ss_limit'],
182 criterion=jsonjob['steadystate']['criterion'])
184 line = 'FAILED ' + line + ' fio criterion {0} != calculated criterion {1} '.format(jsonjob['steadystate']['criterion'], target)
187 line = 'PASSED ' + line + ' target {0} < limit {1}'.format(target, job['ss_limit'])
189 line = 'FAILED ' + line + ' target {0} < limit {1} but fio reports ss not attained '.format(target, job['ss_limit'])
191 # check runtime, confirm criterion calculation, and confirm that criterion was not met
192 expected = job['timeout'] * 1000
193 actual = jsonjob['read']['runtime']
194 if abs(expected - actual) > 10:
195 line = 'FAILED ' + line + ' ss not attained, expected runtime {0} != actual runtime {1}'.format(expected, actual)
197 line = line + ' ss not attained, runtime {0} != ss_dur {1} + ss_ramp {2},'.format(actual, job['ss_dur'], job['ss_ramp'])
198 objsame, met, mean, target = check(data=jsonjob['steadystate']['data'],
202 limit=job['ss_limit'],
204 criterion=jsonjob['steadystate']['criterion'])
206 if actual > (job['ss_dur'] + job['ss_ramp'])*1000:
207 line = 'FAILED ' + line + ' fio criterion {0} != calculated criterion {1} '.format(jsonjob['steadystate']['criterion'], target)
209 line = 'PASSED ' + line + ' fio criterion {0} == 0.0 since ss_dur + ss_ramp has not elapsed '.format(jsonjob['steadystate']['criterion'])
212 line = 'FAILED ' + line + ' target {0} < threshold {1} but fio reports ss not attained '.format(target, job['ss_limit'])
214 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) < 10:
222 line = result + line + ' no ss, expected runtime {0} ~= actual runtime {1}'.format(expected, actual)
224 if 'steadystate' in jsonjob:
225 pp.pprint(jsonjob['steadystate'])