2 # SPDX-License-Identifier: GPL-2.0-only
4 # Copyright (c) 2019 Western Digital Corporation or its affiliates.
9 # Automate running of fio tests
12 # python3 run-fio-tests.py [-r fio-root] [-f fio-path] [-a artifact-root]
13 # [--skip # # #...] [--run-only # # #...]
17 # # git clone git://git.kernel.dk/fio.git
20 # # python3 t/run-fio-tests.py
25 # - Linux (libaio ioengine, zbd tests, etc)
26 # - The artifact directory must be on a file system that accepts 512-byte IO
27 # (t0002, t0003, t0004).
28 # - The artifact directory needs to be on an SSD. Otherwise tests that carry
29 # out file-based IO will trigger a timeout (t0006).
31 # - SciPy (steadystate_tests.py)
32 # - libzbc (zbd tests)
33 # - root privileges (zbd test)
34 # - kernel 4.19 or later for zoned null block devices (zbd tests)
35 # - CUnit support (unittests)
40 # TODO run multiple tests simultaneously
41 # TODO Add sgunmap tests (requires SAS SSD)
42 # TODO automatically detect dependencies and skip tests accordingly
53 from pathlib import Path
56 class FioTest(object):
57 """Base for all fio tests."""
59 def __init__(self, exe_path, parameters, success):
60 self.exe_path = exe_path
61 self.parameters = parameters
62 self.success = success
64 self.artifact_root = None
68 self.failure_reason = ''
70 def setup(self, artifact_root, testnum):
71 self.artifact_root = artifact_root
72 self.testnum = testnum
73 self.test_dir = os.path.join(artifact_root, "{:04d}".format(testnum))
74 if not os.path.exists(self.test_dir):
75 os.mkdir(self.test_dir)
77 self.command_file = os.path.join(
79 "{0}.command".format(os.path.basename(self.exe_path)))
80 self.stdout_file = os.path.join(
82 "{0}.stdout".format(os.path.basename(self.exe_path)))
83 self.stderr_file = os.path.join(
85 "{0}.stderr".format(os.path.basename(self.exe_path)))
86 self.exticode_file = os.path.join(
88 "{0}.exitcode".format(os.path.basename(self.exe_path)))
91 raise NotImplementedError()
93 def check_result(self):
94 raise NotImplementedError()
97 class FioExeTest(FioTest):
98 """Test consists of an executable binary or script"""
100 def __init__(self, exe_path, parameters, success):
101 """Construct a FioExeTest which is a FioTest consisting of an
102 executable binary or script.
104 exe_path: location of executable binary or script
105 parameters: list of parameters for executable
106 success: Definition of test success
109 FioTest.__init__(self, exe_path, parameters, success)
111 def setup(self, artifact_root, testnum):
112 super(FioExeTest, self).setup(artifact_root, testnum)
116 command = [self.exe_path] + self.parameters
118 command = [self.exe_path]
119 command_file = open(self.command_file, "w+")
120 command_file.write("%s\n" % command)
123 stdout_file = open(self.stdout_file, "w+")
124 stderr_file = open(self.stderr_file, "w+")
125 exticode_file = open(self.exticode_file, "w+")
128 # Avoid using subprocess.run() here because when a timeout occurs,
129 # fio will be stopped with SIGKILL. This does not give fio a
130 # chance to clean up and means that child processes may continue
131 # running and submitting IO.
132 proc = subprocess.Popen(command,
136 universal_newlines=True)
137 proc.communicate(timeout=self.success['timeout'])
138 exticode_file.write('{0}\n'.format(proc.returncode))
139 logging.debug("return code: %d" % proc.returncode)
140 self.output['proc'] = proc
141 except subprocess.TimeoutExpired:
145 self.output['failure'] = 'timeout'
151 self.output['failure'] = 'exception'
152 self.output['exc_info'] = sys.exc_info()
156 exticode_file.close()
158 def check_result(self):
159 if 'proc' not in self.output:
160 if self.output['failure'] == 'timeout':
161 self.failure_reason = "{0} timeout,".format(self.failure_reason)
163 assert self.output['failure'] == 'exception'
164 self.failure_reason = '{0} exception: {1}, {2}'.format(
165 self.failure_reason, self.output['exc_info'][0],
166 self.output['exc_info'][1])
171 if 'zero_return' in self.success:
172 if self.success['zero_return']:
173 if self.output['proc'].returncode != 0:
175 self.failure_reason = "{0} non-zero return code,".format(self.failure_reason)
177 if self.output['proc'].returncode == 0:
178 self.failure_reason = "{0} zero return code,".format(self.failure_reason)
181 stderr_size = os.path.getsize(self.stderr_file)
182 if 'stderr_empty' in self.success:
183 if self.success['stderr_empty']:
185 self.failure_reason = "{0} stderr not empty,".format(self.failure_reason)
189 self.failure_reason = "{0} stderr empty,".format(self.failure_reason)
193 class FioJobTest(FioExeTest):
194 """Test consists of a fio job"""
196 def __init__(self, fio_path, fio_job, success, fio_pre_job=None,
197 fio_pre_success=None, output_format="normal"):
198 """Construct a FioJobTest which is a FioExeTest consisting of a
199 single fio job file with an optional setup step.
201 fio_path: location of fio executable
202 fio_job: location of fio job file
203 success: Definition of test success
204 fio_pre_job: fio job for preconditioning
205 fio_pre_success: Definition of test success for fio precon job
206 output_format: normal (default), json, jsonplus, or terse
209 self.fio_job = fio_job
210 self.fio_pre_job = fio_pre_job
211 self.fio_pre_success = fio_pre_success if fio_pre_success else success
212 self.output_format = output_format
213 self.precon_failed = False
214 self.json_data = None
215 self.fio_output = "{0}.output".format(os.path.basename(self.fio_job))
217 "--output-format={0}".format(self.output_format),
218 "--output={0}".format(self.fio_output),
221 FioExeTest.__init__(self, fio_path, self.fio_args, success)
223 def setup(self, artifact_root, testnum):
224 super(FioJobTest, self).setup(artifact_root, testnum)
226 self.command_file = os.path.join(
228 "{0}.command".format(os.path.basename(self.fio_job)))
229 self.stdout_file = os.path.join(
231 "{0}.stdout".format(os.path.basename(self.fio_job)))
232 self.stderr_file = os.path.join(
234 "{0}.stderr".format(os.path.basename(self.fio_job)))
235 self.exticode_file = os.path.join(
237 "{0}.exitcode".format(os.path.basename(self.fio_job)))
239 def run_pre_job(self):
240 precon = FioJobTest(self.exe_path, self.fio_pre_job,
241 self.fio_pre_success,
242 output_format=self.output_format)
243 precon.setup(self.artifact_root, self.testnum)
245 precon.check_result()
246 self.precon_failed = not precon.passed
247 self.failure_reason = precon.failure_reason
253 if not self.precon_failed:
254 super(FioJobTest, self).run()
256 logging.debug("precondition step failed")
258 def check_result(self):
259 if self.precon_failed:
261 self.failure_reason = "{0} precondition step failed,".format(self.failure_reason)
264 super(FioJobTest, self).check_result()
269 if 'json' in self.output_format:
271 with open(os.path.join(self.test_dir, self.fio_output), "r") as output_file:
272 file_data = output_file.read()
273 except EnvironmentError:
274 self.failure_reason = "{0} unable to open output file,".format(self.failure_reason)
278 self.json_data = json.loads(file_data)
279 except json.JSONDecodeError:
280 self.failure_reason = "{0} unable to decode JSON data,".format(self.failure_reason)
284 class FioJobTest_t0005(FioJobTest):
285 """Test consists of fio test job t0005
286 Confirm that read['io_kbytes'] == write['io_kbytes'] == 102400"""
288 def check_result(self):
289 super(FioJobTest_t0005, self).check_result()
294 if self.json_data['jobs'][0]['read']['io_kbytes'] != 102400:
295 self.failure_reason = "{0} bytes read mismatch,".format(self.failure_reason)
297 if self.json_data['jobs'][0]['write']['io_kbytes'] != 102400:
298 self.failure_reason = "{0} bytes written mismatch,".format(self.failure_reason)
302 class FioJobTest_t0006(FioJobTest):
303 """Test consists of fio test job t0006
304 Confirm that read['io_kbytes'] ~ 2*write['io_kbytes']"""
306 def check_result(self):
307 super(FioJobTest_t0006, self).check_result()
312 ratio = self.json_data['jobs'][0]['read']['io_kbytes'] \
313 / self.json_data['jobs'][0]['write']['io_kbytes']
314 logging.debug("ratio: %f" % ratio)
315 if ratio < 1.99 or ratio > 2.01:
316 self.failure_reason = "{0} read/write ratio mismatch,".format(self.failure_reason)
320 class FioJobTest_t0007(FioJobTest):
321 """Test consists of fio test job t0007
322 Confirm that read['io_kbytes'] = 87040"""
324 def check_result(self):
325 super(FioJobTest_t0007, self).check_result()
330 if self.json_data['jobs'][0]['read']['io_kbytes'] != 87040:
331 self.failure_reason = "{0} bytes read mismatch,".format(self.failure_reason)
335 class FioJobTest_t0008(FioJobTest):
336 """Test consists of fio test job t0008
337 Confirm that read['io_kbytes'] = 32768 and that
338 write['io_kbytes'] ~ 16568
340 I did runs with fio-ae2fafc8 and saw write['io_kbytes'] values of
341 16585, 16588. With two runs of fio-3.16 I obtained 16568"""
343 def check_result(self):
344 super(FioJobTest_t0008, self).check_result()
349 ratio = self.json_data['jobs'][0]['write']['io_kbytes'] / 16568
350 logging.debug("ratio: %f" % ratio)
352 if ratio < 0.99 or ratio > 1.01:
353 self.failure_reason = "{0} bytes written mismatch,".format(self.failure_reason)
355 if self.json_data['jobs'][0]['read']['io_kbytes'] != 32768:
356 self.failure_reason = "{0} bytes read mismatch,".format(self.failure_reason)
360 class FioJobTest_t0009(FioJobTest):
361 """Test consists of fio test job t0009
362 Confirm that runtime >= 60s"""
364 def check_result(self):
365 super(FioJobTest_t0009, self).check_result()
370 logging.debug('elapsed: %d' % self.json_data['jobs'][0]['elapsed'])
372 if self.json_data['jobs'][0]['elapsed'] < 60:
373 self.failure_reason = "{0} elapsed time mismatch,".format(self.failure_reason)
377 class FioJobTest_t0011(FioJobTest):
378 """Test consists of fio test job t0009
379 Confirm that job0 iops == 1000
380 and that job1_iops / job0_iops ~ 8
381 With two runs of fio-3.16 I observed a ratio of 8.3"""
383 def check_result(self):
384 super(FioJobTest_t0011, self).check_result()
389 iops1 = self.json_data['jobs'][0]['read']['iops']
390 iops2 = self.json_data['jobs'][1]['read']['iops']
391 ratio = iops2 / iops1
392 logging.debug("ratio: %f" % ratio)
394 if iops1 < 999 or iops1 > 1001:
395 self.failure_reason = "{0} iops value mismatch,".format(self.failure_reason)
398 if ratio < 7 or ratio > 9:
399 self.failure_reason = "{0} iops ratio mismatch,".format(self.failure_reason)
405 'stderr_empty': True,
409 'zero_return': False,
410 'stderr_empty': False,
415 'stderr_empty': False,
421 'test_class': FioJobTest,
422 'job': 't0001-52c58027.fio',
423 'success': SUCCESS_DEFAULT,
429 'test_class': FioJobTest,
430 'job': 't0002-13af05ae-post.fio',
431 'success': SUCCESS_DEFAULT,
432 'pre_job': 't0002-13af05ae-pre.fio',
437 'test_class': FioJobTest,
438 'job': 't0003-0ae2c6e1-post.fio',
439 'success': SUCCESS_NONZERO,
440 'pre_job': 't0003-0ae2c6e1-pre.fio',
441 'pre_success': SUCCESS_DEFAULT,
445 'test_class': FioJobTest,
446 'job': 't0004-8a99fdf6.fio',
447 'success': SUCCESS_DEFAULT,
453 'test_class': FioJobTest_t0005,
454 'job': 't0005-f7078f7b.fio',
455 'success': SUCCESS_DEFAULT,
458 'output_format': 'json',
462 'test_class': FioJobTest_t0006,
463 'job': 't0006-82af2a7c.fio',
464 'success': SUCCESS_DEFAULT,
467 'output_format': 'json',
471 'test_class': FioJobTest_t0007,
472 'job': 't0007-37cf9e3c.fio',
473 'success': SUCCESS_DEFAULT,
476 'output_format': 'json',
480 'test_class': FioJobTest_t0008,
481 'job': 't0008-ae2fafc8.fio',
482 'success': SUCCESS_DEFAULT,
485 'output_format': 'json',
489 'test_class': FioJobTest_t0009,
490 'job': 't0009-f8b0bd10.fio',
491 'success': SUCCESS_DEFAULT,
494 'output_format': 'json',
498 'test_class': FioJobTest,
499 'job': 't0010-b7aae4ba.fio',
500 'success': SUCCESS_DEFAULT,
506 'test_class': FioJobTest_t0011,
507 'job': 't0011-5d2788d5.fio',
508 'success': SUCCESS_DEFAULT,
511 'output_format': 'json',
515 'test_class': FioExeTest,
518 'success': SUCCESS_DEFAULT,
522 'test_class': FioExeTest,
525 'success': SUCCESS_DEFAULT,
529 'test_class': FioExeTest,
530 'exe': 't/lfsr-test',
531 'parameters': ['0xFFFFFF', '0', '0', 'verify'],
532 'success': SUCCESS_STDERR,
536 'test_class': FioExeTest,
537 'exe': 't/readonly.py',
538 'parameters': ['-f', '{fio_path}'],
539 'success': SUCCESS_DEFAULT,
543 'test_class': FioExeTest,
544 'exe': 't/steadystate_tests.py',
545 'parameters': ['{fio_path}'],
546 'success': SUCCESS_DEFAULT,
550 'test_class': FioExeTest,
553 'success': SUCCESS_STDERR,
557 'test_class': FioExeTest,
558 'exe': 't/strided.py',
559 'parameters': ['{fio_path}'],
560 'success': SUCCESS_DEFAULT,
564 'test_class': FioExeTest,
565 'exe': 't/zbd/run-tests-against-regular-nullb',
567 'success': SUCCESS_DEFAULT,
571 'test_class': FioExeTest,
572 'exe': 't/zbd/run-tests-against-zoned-nullb',
574 'success': SUCCESS_DEFAULT,
578 'test_class': FioExeTest,
579 'exe': 'unittests/unittest',
581 'success': SUCCESS_DEFAULT,
587 parser = argparse.ArgumentParser()
588 parser.add_argument('-r', '--fio-root',
589 help='fio root path')
590 parser.add_argument('-f', '--fio',
591 help='path to fio executable (e.g., ./fio)')
592 parser.add_argument('-a', '--artifact-root',
593 help='artifact root directory')
594 parser.add_argument('-s', '--skip', nargs='+', type=int,
595 help='list of test(s) to skip')
596 parser.add_argument('-o', '--run-only', nargs='+', type=int,
597 help='list of test(s) to run, skipping all others')
598 parser.add_argument('-d', '--debug', action='store_true',
599 help='provide debug output')
600 args = parser.parse_args()
608 logging.basicConfig(level=logging.DEBUG)
610 logging.basicConfig(level=logging.INFO)
613 fio_root = args.fio_root
615 fio_root = str(Path(__file__).absolute().parent.parent)
616 print("fio root is %s" % fio_root)
621 fio_path = os.path.join(fio_root, "fio")
622 print("fio path is %s" % fio_path)
623 if not shutil.which(fio_path):
624 print("Warning: fio executable not found")
626 artifact_root = args.artifact_root if args.artifact_root else \
627 "fio-test-{0}".format(time.strftime("%Y%m%d-%H%M%S"))
628 os.mkdir(artifact_root)
629 print("Artifact directory is %s" % artifact_root)
635 for config in TEST_LIST:
636 if (args.skip and config['test_id'] in args.skip) or \
637 (args.run_only and config['test_id'] not in args.run_only):
638 skipped = skipped + 1
639 print("Test {0} SKIPPED".format(config['test_id']))
642 if issubclass(config['test_class'], FioJobTest):
643 if config['pre_job']:
644 fio_pre_job = os.path.join(fio_root, 't', 'jobs',
648 if config['pre_success']:
649 fio_pre_success = config['pre_success']
651 fio_pre_success = None
652 if 'output_format' in config:
653 output_format = config['output_format']
655 output_format = 'normal'
656 test = config['test_class'](
658 os.path.join(fio_root, 't', 'jobs', config['job']),
660 fio_pre_job=fio_pre_job,
661 fio_pre_success=fio_pre_success,
662 output_format=output_format)
663 elif issubclass(config['test_class'], FioExeTest):
664 exe_path = os.path.join(fio_root, config['exe'])
665 if config['parameters']:
666 parameters = [p.format(fio_path=fio_path) for p in config['parameters']]
669 test = config['test_class'](exe_path, parameters,
672 print("Test {0} FAILED: unable to process test config".format(config['test_id']))
676 test.setup(artifact_root, config['test_id'])
683 result = "FAILED: {0}".format(test.failure_reason)
685 with open(test.stderr_file, "r") as stderr_file:
686 logging.debug("stderr:\n%s" % stderr_file.read())
687 with open(test.stdout_file, "r") as stdout_file:
688 logging.debug("stdout:\n%s" % stdout_file.read())
689 print("Test {0} {1}".format(config['test_id'], result))
691 print("{0} test(s) passed, {1} failed, {2} skipped".format(passed, failed, skipped))
696 if __name__ == '__main__':