doc: update fio doc for xnvme engine
[fio.git] / t / run-fio-tests.py
CommitLineData
df1eaa36
VF
1#!/usr/bin/env python3
2# SPDX-License-Identifier: GPL-2.0-only
3#
4# Copyright (c) 2019 Western Digital Corporation or its affiliates.
5#
6"""
7# run-fio-tests.py
8#
9# Automate running of fio tests
10#
11# USAGE
12# python3 run-fio-tests.py [-r fio-root] [-f fio-path] [-a artifact-root]
13# [--skip # # #...] [--run-only # # #...]
14#
15#
16# EXAMPLE
b048455f 17# # git clone git://git.kernel.dk/fio.git
df1eaa36
VF
18# # cd fio
19# # make -j
20# # python3 t/run-fio-tests.py
21#
22#
23# REQUIREMENTS
b1bc705e 24# - Python 3.5 (subprocess.run)
df1eaa36
VF
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).
30# - 4 CPUs (t0009)
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)
36#
37"""
38
39#
40# TODO run multiple tests simultaneously
41# TODO Add sgunmap tests (requires SAS SSD)
df1eaa36
VF
42#
43
44import os
45import sys
46import json
47import time
6d5470c3 48import shutil
df1eaa36
VF
49import logging
50import argparse
b1bc705e 51import platform
aa9f2627 52import traceback
df1eaa36 53import subprocess
b1bc705e 54import multiprocessing
df1eaa36
VF
55from pathlib import Path
56
57
58class FioTest(object):
59 """Base for all fio tests."""
60
61 def __init__(self, exe_path, parameters, success):
62 self.exe_path = exe_path
63 self.parameters = parameters
64 self.success = success
65 self.output = {}
66 self.artifact_root = None
67 self.testnum = None
68 self.test_dir = None
69 self.passed = True
70 self.failure_reason = ''
704cc4df
VF
71 self.command_file = None
72 self.stdout_file = None
73 self.stderr_file = None
74 self.exitcode_file = None
df1eaa36
VF
75
76 def setup(self, artifact_root, testnum):
704cc4df
VF
77 """Setup instance variables for test."""
78
df1eaa36
VF
79 self.artifact_root = artifact_root
80 self.testnum = testnum
81 self.test_dir = os.path.join(artifact_root, "{:04d}".format(testnum))
82 if not os.path.exists(self.test_dir):
83 os.mkdir(self.test_dir)
84
85 self.command_file = os.path.join(
704cc4df
VF
86 self.test_dir,
87 "{0}.command".format(os.path.basename(self.exe_path)))
df1eaa36 88 self.stdout_file = os.path.join(
704cc4df
VF
89 self.test_dir,
90 "{0}.stdout".format(os.path.basename(self.exe_path)))
df1eaa36 91 self.stderr_file = os.path.join(
704cc4df
VF
92 self.test_dir,
93 "{0}.stderr".format(os.path.basename(self.exe_path)))
94 self.exitcode_file = os.path.join(
95 self.test_dir,
96 "{0}.exitcode".format(os.path.basename(self.exe_path)))
df1eaa36
VF
97
98 def run(self):
704cc4df
VF
99 """Run the test."""
100
df1eaa36
VF
101 raise NotImplementedError()
102
103 def check_result(self):
704cc4df
VF
104 """Check test results."""
105
df1eaa36
VF
106 raise NotImplementedError()
107
108
109class FioExeTest(FioTest):
110 """Test consists of an executable binary or script"""
111
112 def __init__(self, exe_path, parameters, success):
113 """Construct a FioExeTest which is a FioTest consisting of an
114 executable binary or script.
115
116 exe_path: location of executable binary or script
117 parameters: list of parameters for executable
118 success: Definition of test success
119 """
120
121 FioTest.__init__(self, exe_path, parameters, success)
122
df1eaa36 123 def run(self):
704cc4df
VF
124 """Execute the binary or script described by this instance."""
125
58a77d2a 126 command = [self.exe_path] + self.parameters
df1eaa36
VF
127 command_file = open(self.command_file, "w+")
128 command_file.write("%s\n" % command)
129 command_file.close()
130
131 stdout_file = open(self.stdout_file, "w+")
132 stderr_file = open(self.stderr_file, "w+")
704cc4df 133 exitcode_file = open(self.exitcode_file, "w+")
df1eaa36 134 try:
b048455f 135 proc = None
df1eaa36
VF
136 # Avoid using subprocess.run() here because when a timeout occurs,
137 # fio will be stopped with SIGKILL. This does not give fio a
138 # chance to clean up and means that child processes may continue
139 # running and submitting IO.
140 proc = subprocess.Popen(command,
141 stdout=stdout_file,
142 stderr=stderr_file,
143 cwd=self.test_dir,
144 universal_newlines=True)
145 proc.communicate(timeout=self.success['timeout'])
704cc4df
VF
146 exitcode_file.write('{0}\n'.format(proc.returncode))
147 logging.debug("Test %d: return code: %d", self.testnum, proc.returncode)
df1eaa36
VF
148 self.output['proc'] = proc
149 except subprocess.TimeoutExpired:
150 proc.terminate()
151 proc.communicate()
152 assert proc.poll()
153 self.output['failure'] = 'timeout'
154 except Exception:
b048455f
VF
155 if proc:
156 if not proc.poll():
157 proc.terminate()
158 proc.communicate()
df1eaa36
VF
159 self.output['failure'] = 'exception'
160 self.output['exc_info'] = sys.exc_info()
161 finally:
162 stdout_file.close()
163 stderr_file.close()
704cc4df 164 exitcode_file.close()
df1eaa36
VF
165
166 def check_result(self):
704cc4df
VF
167 """Check results of test run."""
168
df1eaa36
VF
169 if 'proc' not in self.output:
170 if self.output['failure'] == 'timeout':
171 self.failure_reason = "{0} timeout,".format(self.failure_reason)
172 else:
173 assert self.output['failure'] == 'exception'
174 self.failure_reason = '{0} exception: {1}, {2}'.format(
704cc4df
VF
175 self.failure_reason, self.output['exc_info'][0],
176 self.output['exc_info'][1])
df1eaa36
VF
177
178 self.passed = False
179 return
180
181 if 'zero_return' in self.success:
182 if self.success['zero_return']:
183 if self.output['proc'].returncode != 0:
184 self.passed = False
185 self.failure_reason = "{0} non-zero return code,".format(self.failure_reason)
186 else:
187 if self.output['proc'].returncode == 0:
188 self.failure_reason = "{0} zero return code,".format(self.failure_reason)
189 self.passed = False
190
6d5470c3 191 stderr_size = os.path.getsize(self.stderr_file)
df1eaa36 192 if 'stderr_empty' in self.success:
df1eaa36
VF
193 if self.success['stderr_empty']:
194 if stderr_size != 0:
195 self.failure_reason = "{0} stderr not empty,".format(self.failure_reason)
196 self.passed = False
197 else:
198 if stderr_size == 0:
199 self.failure_reason = "{0} stderr empty,".format(self.failure_reason)
200 self.passed = False
201
202
203class FioJobTest(FioExeTest):
204 """Test consists of a fio job"""
205
206 def __init__(self, fio_path, fio_job, success, fio_pre_job=None,
207 fio_pre_success=None, output_format="normal"):
208 """Construct a FioJobTest which is a FioExeTest consisting of a
209 single fio job file with an optional setup step.
210
211 fio_path: location of fio executable
212 fio_job: location of fio job file
213 success: Definition of test success
214 fio_pre_job: fio job for preconditioning
215 fio_pre_success: Definition of test success for fio precon job
216 output_format: normal (default), json, jsonplus, or terse
217 """
218
219 self.fio_job = fio_job
220 self.fio_pre_job = fio_pre_job
221 self.fio_pre_success = fio_pre_success if fio_pre_success else success
222 self.output_format = output_format
223 self.precon_failed = False
224 self.json_data = None
225 self.fio_output = "{0}.output".format(os.path.basename(self.fio_job))
226 self.fio_args = [
771dbb52 227 "--max-jobs=16",
df1eaa36
VF
228 "--output-format={0}".format(self.output_format),
229 "--output={0}".format(self.fio_output),
230 self.fio_job,
231 ]
232 FioExeTest.__init__(self, fio_path, self.fio_args, success)
233
234 def setup(self, artifact_root, testnum):
704cc4df
VF
235 """Setup instance variables for fio job test."""
236
df1eaa36
VF
237 super(FioJobTest, self).setup(artifact_root, testnum)
238
239 self.command_file = os.path.join(
704cc4df
VF
240 self.test_dir,
241 "{0}.command".format(os.path.basename(self.fio_job)))
df1eaa36 242 self.stdout_file = os.path.join(
704cc4df
VF
243 self.test_dir,
244 "{0}.stdout".format(os.path.basename(self.fio_job)))
df1eaa36 245 self.stderr_file = os.path.join(
704cc4df
VF
246 self.test_dir,
247 "{0}.stderr".format(os.path.basename(self.fio_job)))
248 self.exitcode_file = os.path.join(
249 self.test_dir,
250 "{0}.exitcode".format(os.path.basename(self.fio_job)))
df1eaa36
VF
251
252 def run_pre_job(self):
704cc4df
VF
253 """Run fio job precondition step."""
254
df1eaa36
VF
255 precon = FioJobTest(self.exe_path, self.fio_pre_job,
256 self.fio_pre_success,
257 output_format=self.output_format)
258 precon.setup(self.artifact_root, self.testnum)
259 precon.run()
260 precon.check_result()
261 self.precon_failed = not precon.passed
262 self.failure_reason = precon.failure_reason
263
264 def run(self):
704cc4df
VF
265 """Run fio job test."""
266
df1eaa36
VF
267 if self.fio_pre_job:
268 self.run_pre_job()
269
270 if not self.precon_failed:
271 super(FioJobTest, self).run()
272 else:
704cc4df 273 logging.debug("Test %d: precondition step failed", self.testnum)
df1eaa36 274
15a73987
VF
275 @classmethod
276 def get_file(cls, filename):
277 """Safely read a file."""
278 file_data = ''
279 success = True
280
281 try:
282 with open(filename, "r") as output_file:
283 file_data = output_file.read()
284 except OSError:
285 success = False
286
287 return file_data, success
288
df1eaa36 289 def check_result(self):
704cc4df
VF
290 """Check fio job results."""
291
df1eaa36
VF
292 if self.precon_failed:
293 self.passed = False
294 self.failure_reason = "{0} precondition step failed,".format(self.failure_reason)
295 return
296
297 super(FioJobTest, self).check_result()
298
6d5470c3
VF
299 if not self.passed:
300 return
301
704cc4df 302 if 'json' not in self.output_format:
742b8799
VF
303 return
304
15a73987
VF
305 file_data, success = self.get_file(os.path.join(self.test_dir, self.fio_output))
306 if not success:
742b8799
VF
307 self.failure_reason = "{0} unable to open output file,".format(self.failure_reason)
308 self.passed = False
309 return
310
311 #
312 # Sometimes fio informational messages are included at the top of the
313 # JSON output, especially under Windows. Try to decode output as JSON
db2637ec 314 # data, skipping everything until the first {
742b8799
VF
315 #
316 lines = file_data.splitlines()
db2637ec
VF
317 file_data = '\n'.join(lines[lines.index("{"):])
318 try:
319 self.json_data = json.loads(file_data)
320 except json.JSONDecodeError:
321 self.failure_reason = "{0} unable to decode JSON data,".format(self.failure_reason)
322 self.passed = False
df1eaa36
VF
323
324
325class FioJobTest_t0005(FioJobTest):
326 """Test consists of fio test job t0005
327 Confirm that read['io_kbytes'] == write['io_kbytes'] == 102400"""
328
329 def check_result(self):
330 super(FioJobTest_t0005, self).check_result()
331
332 if not self.passed:
333 return
334
335 if self.json_data['jobs'][0]['read']['io_kbytes'] != 102400:
336 self.failure_reason = "{0} bytes read mismatch,".format(self.failure_reason)
337 self.passed = False
338 if self.json_data['jobs'][0]['write']['io_kbytes'] != 102400:
339 self.failure_reason = "{0} bytes written mismatch,".format(self.failure_reason)
340 self.passed = False
341
342
343class FioJobTest_t0006(FioJobTest):
344 """Test consists of fio test job t0006
345 Confirm that read['io_kbytes'] ~ 2*write['io_kbytes']"""
346
347 def check_result(self):
348 super(FioJobTest_t0006, self).check_result()
349
350 if not self.passed:
351 return
352
353 ratio = self.json_data['jobs'][0]['read']['io_kbytes'] \
354 / self.json_data['jobs'][0]['write']['io_kbytes']
704cc4df 355 logging.debug("Test %d: ratio: %f", self.testnum, ratio)
df1eaa36
VF
356 if ratio < 1.99 or ratio > 2.01:
357 self.failure_reason = "{0} read/write ratio mismatch,".format(self.failure_reason)
358 self.passed = False
359
360
361class FioJobTest_t0007(FioJobTest):
362 """Test consists of fio test job t0007
363 Confirm that read['io_kbytes'] = 87040"""
364
365 def check_result(self):
366 super(FioJobTest_t0007, self).check_result()
367
368 if not self.passed:
369 return
370
371 if self.json_data['jobs'][0]['read']['io_kbytes'] != 87040:
372 self.failure_reason = "{0} bytes read mismatch,".format(self.failure_reason)
373 self.passed = False
374
375
376class FioJobTest_t0008(FioJobTest):
377 """Test consists of fio test job t0008
378 Confirm that read['io_kbytes'] = 32768 and that
379 write['io_kbytes'] ~ 16568
380
381 I did runs with fio-ae2fafc8 and saw write['io_kbytes'] values of
382 16585, 16588. With two runs of fio-3.16 I obtained 16568"""
383
384 def check_result(self):
385 super(FioJobTest_t0008, self).check_result()
386
387 if not self.passed:
388 return
389
390 ratio = self.json_data['jobs'][0]['write']['io_kbytes'] / 16568
704cc4df 391 logging.debug("Test %d: ratio: %f", self.testnum, ratio)
df1eaa36
VF
392
393 if ratio < 0.99 or ratio > 1.01:
394 self.failure_reason = "{0} bytes written mismatch,".format(self.failure_reason)
395 self.passed = False
396 if self.json_data['jobs'][0]['read']['io_kbytes'] != 32768:
397 self.failure_reason = "{0} bytes read mismatch,".format(self.failure_reason)
398 self.passed = False
399
400
401class FioJobTest_t0009(FioJobTest):
402 """Test consists of fio test job t0009
403 Confirm that runtime >= 60s"""
404
405 def check_result(self):
406 super(FioJobTest_t0009, self).check_result()
407
408 if not self.passed:
409 return
410
704cc4df 411 logging.debug('Test %d: elapsed: %d', self.testnum, self.json_data['jobs'][0]['elapsed'])
df1eaa36
VF
412
413 if self.json_data['jobs'][0]['elapsed'] < 60:
414 self.failure_reason = "{0} elapsed time mismatch,".format(self.failure_reason)
415 self.passed = False
416
417
d4e74fda
DB
418class FioJobTest_t0012(FioJobTest):
419 """Test consists of fio test job t0012
420 Confirm ratios of job iops are 1:5:10
421 job1,job2,job3 respectively"""
422
423 def check_result(self):
424 super(FioJobTest_t0012, self).check_result()
425
426 if not self.passed:
427 return
428
429 iops_files = []
430 for i in range(1,4):
431 file_data, success = self.get_file(os.path.join(self.test_dir, "{0}_iops.{1}.log".format(os.path.basename(self.fio_job), i)))
432
433 if not success:
434 self.failure_reason = "{0} unable to open output file,".format(self.failure_reason)
435 self.passed = False
436 return
437
438 iops_files.append(file_data.splitlines())
439
440 # there are 9 samples for job1 and job2, 4 samples for job3
441 iops1 = 0.0
442 iops2 = 0.0
443 iops3 = 0.0
444 for i in range(9):
445 iops1 = iops1 + float(iops_files[0][i].split(',')[1])
446 iops2 = iops2 + float(iops_files[1][i].split(',')[1])
447 iops3 = iops3 + float(iops_files[2][i].split(',')[1])
448
449 ratio1 = iops3/iops2
450 ratio2 = iops3/iops1
451 logging.debug(
452 "sample {0}: job1 iops={1} job2 iops={2} job3 iops={3} job3/job2={4:.3f} job3/job1={5:.3f}".format(
453 i, iops1, iops2, iops3, ratio1, ratio2
454 )
455 )
456
457 # test job1 and job2 succeeded to recalibrate
458 if ratio1 < 1 or ratio1 > 3 or ratio2 < 7 or ratio2 > 13:
459 self.failure_reason = "{0} iops ratio mismatch iops1={1} iops2={2} iops3={3} expected r1~2 r2~10 got r1={4:.3f} r2={5:.3f},".format(
460 self.failure_reason, iops1, iops2, iops3, ratio1, ratio2
461 )
462 self.passed = False
463 return
464
465
466class FioJobTest_t0014(FioJobTest):
467 """Test consists of fio test job t0014
468 Confirm that job1_iops / job2_iops ~ 1:2 for entire duration
469 and that job1_iops / job3_iops ~ 1:3 for first half of duration.
470
471 The test is about making sure the flow feature can
472 re-calibrate the activity dynamically"""
473
474 def check_result(self):
475 super(FioJobTest_t0014, self).check_result()
476
477 if not self.passed:
478 return
479
480 iops_files = []
481 for i in range(1,4):
482 file_data, success = self.get_file(os.path.join(self.test_dir, "{0}_iops.{1}.log".format(os.path.basename(self.fio_job), i)))
483
484 if not success:
485 self.failure_reason = "{0} unable to open output file,".format(self.failure_reason)
486 self.passed = False
487 return
488
489 iops_files.append(file_data.splitlines())
490
491 # there are 9 samples for job1 and job2, 4 samples for job3
492 iops1 = 0.0
493 iops2 = 0.0
494 iops3 = 0.0
495 for i in range(9):
496 if i < 4:
497 iops3 = iops3 + float(iops_files[2][i].split(',')[1])
498 elif i == 4:
499 ratio1 = iops1 / iops2
500 ratio2 = iops1 / iops3
501
502
503 if ratio1 < 0.43 or ratio1 > 0.57 or ratio2 < 0.21 or ratio2 > 0.45:
504 self.failure_reason = "{0} iops ratio mismatch iops1={1} iops2={2} iops3={3}\
505 expected r1~0.5 r2~0.33 got r1={4:.3f} r2={5:.3f},".format(
506 self.failure_reason, iops1, iops2, iops3, ratio1, ratio2
507 )
508 self.passed = False
509
510 iops1 = iops1 + float(iops_files[0][i].split(',')[1])
511 iops2 = iops2 + float(iops_files[1][i].split(',')[1])
512
513 ratio1 = iops1/iops2
514 ratio2 = iops1/iops3
515 logging.debug(
516 "sample {0}: job1 iops={1} job2 iops={2} job3 iops={3} job1/job2={4:.3f} job1/job3={5:.3f}".format(
517 i, iops1, iops2, iops3, ratio1, ratio2
518 )
519 )
520
521 # test job1 and job2 succeeded to recalibrate
522 if ratio1 < 0.43 or ratio1 > 0.57:
523 self.failure_reason = "{0} iops ratio mismatch iops1={1} iops2={2} expected ratio~0.5 got ratio={3:.3f},".format(
524 self.failure_reason, iops1, iops2, ratio1
525 )
526 self.passed = False
527 return
528
529
60ebb939 530class FioJobTest_t0015(FioJobTest):
de31fe9a 531 """Test consists of fio test jobs t0015 and t0016
60ebb939
VF
532 Confirm that mean(slat) + mean(clat) = mean(tlat)"""
533
534 def check_result(self):
535 super(FioJobTest_t0015, self).check_result()
536
537 if not self.passed:
538 return
539
540 slat = self.json_data['jobs'][0]['read']['slat_ns']['mean']
541 clat = self.json_data['jobs'][0]['read']['clat_ns']['mean']
542 tlat = self.json_data['jobs'][0]['read']['lat_ns']['mean']
543 logging.debug('Test %d: slat %f, clat %f, tlat %f', self.testnum, slat, clat, tlat)
544
545 if abs(slat + clat - tlat) > 1:
546 self.failure_reason = "{0} slat {1} + clat {2} = {3} != tlat {4},".format(
547 self.failure_reason, slat, clat, slat+clat, tlat)
548 self.passed = False
549
550
0a602473 551class FioJobTest_iops_rate(FioJobTest):
df1eaa36
VF
552 """Test consists of fio test job t0009
553 Confirm that job0 iops == 1000
554 and that job1_iops / job0_iops ~ 8
555 With two runs of fio-3.16 I observed a ratio of 8.3"""
556
557 def check_result(self):
0a602473 558 super(FioJobTest_iops_rate, self).check_result()
df1eaa36
VF
559
560 if not self.passed:
561 return
562
563 iops1 = self.json_data['jobs'][0]['read']['iops']
7ddc4ed1 564 logging.debug("Test %d: iops1: %f", self.testnum, iops1)
df1eaa36 565 iops2 = self.json_data['jobs'][1]['read']['iops']
7ddc4ed1 566 logging.debug("Test %d: iops2: %f", self.testnum, iops2)
df1eaa36 567 ratio = iops2 / iops1
704cc4df 568 logging.debug("Test %d: ratio: %f", self.testnum, ratio)
df1eaa36 569
0a9b8988 570 if iops1 < 950 or iops1 > 1050:
df1eaa36
VF
571 self.failure_reason = "{0} iops value mismatch,".format(self.failure_reason)
572 self.passed = False
573
d4e74fda 574 if ratio < 6 or ratio > 10:
df1eaa36
VF
575 self.failure_reason = "{0} iops ratio mismatch,".format(self.failure_reason)
576 self.passed = False
577
578
b1bc705e
VF
579class Requirements(object):
580 """Requirements consists of multiple run environment characteristics.
581 These are to determine if a particular test can be run"""
582
583 _linux = False
584 _libaio = False
585 _zbd = False
586 _root = False
587 _zoned_nullb = False
588 _not_macos = False
c58b33b4 589 _not_windows = False
b1bc705e
VF
590 _unittests = False
591 _cpucount4 = False
592
593 def __init__(self, fio_root):
594 Requirements._not_macos = platform.system() != "Darwin"
c58b33b4 595 Requirements._not_windows = platform.system() != "Windows"
b1bc705e
VF
596 Requirements._linux = platform.system() == "Linux"
597
598 if Requirements._linux:
15a73987
VF
599 config_file = os.path.join(fio_root, "config-host.h")
600 contents, success = FioJobTest.get_file(config_file)
601 if not success:
b1bc705e
VF
602 print("Unable to open {0} to check requirements".format(config_file))
603 Requirements._zbd = True
604 else:
b7694961 605 Requirements._zbd = "CONFIG_HAS_BLKZONED" in contents
b1bc705e
VF
606 Requirements._libaio = "CONFIG_LIBAIO" in contents
607
608 Requirements._root = (os.geteuid() == 0)
609 if Requirements._zbd and Requirements._root:
8854e368
VF
610 try:
611 subprocess.run(["modprobe", "null_blk"],
612 stdout=subprocess.PIPE,
613 stderr=subprocess.PIPE)
614 if os.path.exists("/sys/module/null_blk/parameters/zoned"):
615 Requirements._zoned_nullb = True
616 except Exception:
617 pass
b1bc705e 618
742b8799
VF
619 if platform.system() == "Windows":
620 utest_exe = "unittest.exe"
621 else:
622 utest_exe = "unittest"
623 unittest_path = os.path.join(fio_root, "unittests", utest_exe)
b1bc705e
VF
624 Requirements._unittests = os.path.exists(unittest_path)
625
626 Requirements._cpucount4 = multiprocessing.cpu_count() >= 4
627
628 req_list = [Requirements.linux,
629 Requirements.libaio,
630 Requirements.zbd,
631 Requirements.root,
632 Requirements.zoned_nullb,
633 Requirements.not_macos,
c58b33b4 634 Requirements.not_windows,
b1bc705e
VF
635 Requirements.unittests,
636 Requirements.cpucount4]
637 for req in req_list:
638 value, desc = req()
704cc4df 639 logging.debug("Requirements: Requirement '%s' met? %s", desc, value)
b1bc705e 640
704cc4df
VF
641 @classmethod
642 def linux(cls):
643 """Are we running on Linux?"""
b1bc705e
VF
644 return Requirements._linux, "Linux required"
645
704cc4df
VF
646 @classmethod
647 def libaio(cls):
648 """Is libaio available?"""
b1bc705e
VF
649 return Requirements._libaio, "libaio required"
650
704cc4df
VF
651 @classmethod
652 def zbd(cls):
653 """Is ZBD support available?"""
b1bc705e
VF
654 return Requirements._zbd, "Zoned block device support required"
655
704cc4df
VF
656 @classmethod
657 def root(cls):
658 """Are we running as root?"""
b1bc705e
VF
659 return Requirements._root, "root required"
660
704cc4df
VF
661 @classmethod
662 def zoned_nullb(cls):
663 """Are zoned null block devices available?"""
b1bc705e
VF
664 return Requirements._zoned_nullb, "Zoned null block device support required"
665
704cc4df
VF
666 @classmethod
667 def not_macos(cls):
668 """Are we running on a platform other than macOS?"""
b1bc705e
VF
669 return Requirements._not_macos, "platform other than macOS required"
670
704cc4df
VF
671 @classmethod
672 def not_windows(cls):
673 """Are we running on a platform other than Windws?"""
c58b33b4
VF
674 return Requirements._not_windows, "platform other than Windows required"
675
704cc4df
VF
676 @classmethod
677 def unittests(cls):
678 """Were unittests built?"""
b1bc705e
VF
679 return Requirements._unittests, "Unittests support required"
680
704cc4df
VF
681 @classmethod
682 def cpucount4(cls):
683 """Do we have at least 4 CPUs?"""
b1bc705e
VF
684 return Requirements._cpucount4, "4+ CPUs required"
685
686
df1eaa36 687SUCCESS_DEFAULT = {
704cc4df
VF
688 'zero_return': True,
689 'stderr_empty': True,
690 'timeout': 600,
691 }
df1eaa36 692SUCCESS_NONZERO = {
704cc4df
VF
693 'zero_return': False,
694 'stderr_empty': False,
695 'timeout': 600,
696 }
df1eaa36 697SUCCESS_STDERR = {
704cc4df
VF
698 'zero_return': True,
699 'stderr_empty': False,
700 'timeout': 600,
701 }
df1eaa36 702TEST_LIST = [
704cc4df
VF
703 {
704 'test_id': 1,
705 'test_class': FioJobTest,
706 'job': 't0001-52c58027.fio',
707 'success': SUCCESS_DEFAULT,
708 'pre_job': None,
709 'pre_success': None,
710 'requirements': [],
711 },
712 {
713 'test_id': 2,
714 'test_class': FioJobTest,
715 'job': 't0002-13af05ae-post.fio',
716 'success': SUCCESS_DEFAULT,
717 'pre_job': 't0002-13af05ae-pre.fio',
718 'pre_success': None,
719 'requirements': [Requirements.linux, Requirements.libaio],
720 },
721 {
722 'test_id': 3,
723 'test_class': FioJobTest,
724 'job': 't0003-0ae2c6e1-post.fio',
725 'success': SUCCESS_NONZERO,
726 'pre_job': 't0003-0ae2c6e1-pre.fio',
727 'pre_success': SUCCESS_DEFAULT,
728 'requirements': [Requirements.linux, Requirements.libaio],
729 },
730 {
731 'test_id': 4,
732 'test_class': FioJobTest,
733 'job': 't0004-8a99fdf6.fio',
734 'success': SUCCESS_DEFAULT,
735 'pre_job': None,
736 'pre_success': None,
737 'requirements': [Requirements.linux, Requirements.libaio],
738 },
739 {
740 'test_id': 5,
741 'test_class': FioJobTest_t0005,
742 'job': 't0005-f7078f7b.fio',
743 'success': SUCCESS_DEFAULT,
744 'pre_job': None,
745 'pre_success': None,
746 'output_format': 'json',
747 'requirements': [Requirements.not_windows],
748 },
749 {
750 'test_id': 6,
751 'test_class': FioJobTest_t0006,
752 'job': 't0006-82af2a7c.fio',
753 'success': SUCCESS_DEFAULT,
754 'pre_job': None,
755 'pre_success': None,
756 'output_format': 'json',
757 'requirements': [Requirements.linux, Requirements.libaio],
758 },
759 {
760 'test_id': 7,
761 'test_class': FioJobTest_t0007,
762 'job': 't0007-37cf9e3c.fio',
763 'success': SUCCESS_DEFAULT,
764 'pre_job': None,
765 'pre_success': None,
766 'output_format': 'json',
767 'requirements': [],
768 },
769 {
770 'test_id': 8,
771 'test_class': FioJobTest_t0008,
772 'job': 't0008-ae2fafc8.fio',
773 'success': SUCCESS_DEFAULT,
774 'pre_job': None,
775 'pre_success': None,
776 'output_format': 'json',
777 'requirements': [],
778 },
779 {
780 'test_id': 9,
781 'test_class': FioJobTest_t0009,
782 'job': 't0009-f8b0bd10.fio',
783 'success': SUCCESS_DEFAULT,
784 'pre_job': None,
785 'pre_success': None,
786 'output_format': 'json',
787 'requirements': [Requirements.not_macos,
788 Requirements.cpucount4],
789 # mac os does not support CPU affinity
790 },
791 {
792 'test_id': 10,
793 'test_class': FioJobTest,
794 'job': 't0010-b7aae4ba.fio',
795 'success': SUCCESS_DEFAULT,
796 'pre_job': None,
797 'pre_success': None,
798 'requirements': [],
799 },
800 {
801 'test_id': 11,
0a602473 802 'test_class': FioJobTest_iops_rate,
704cc4df
VF
803 'job': 't0011-5d2788d5.fio',
804 'success': SUCCESS_DEFAULT,
805 'pre_job': None,
806 'pre_success': None,
807 'output_format': 'json',
808 'requirements': [],
809 },
0a602473
BVA
810 {
811 'test_id': 12,
d4e74fda 812 'test_class': FioJobTest_t0012,
0a602473
BVA
813 'job': 't0012.fio',
814 'success': SUCCESS_DEFAULT,
815 'pre_job': None,
816 'pre_success': None,
817 'output_format': 'json',
d4e74fda 818 'requirements': [],
0a602473 819 },
f0c7ae7a
BVA
820 {
821 'test_id': 13,
061a0773 822 'test_class': FioJobTest,
f0c7ae7a
BVA
823 'job': 't0013.fio',
824 'success': SUCCESS_DEFAULT,
825 'pre_job': None,
826 'pre_success': None,
827 'output_format': 'json',
828 'requirements': [],
829 },
d4e74fda
DB
830 {
831 'test_id': 14,
832 'test_class': FioJobTest_t0014,
833 'job': 't0014.fio',
834 'success': SUCCESS_DEFAULT,
835 'pre_job': None,
836 'pre_success': None,
837 'output_format': 'json',
838 'requirements': [],
839 },
60ebb939
VF
840 {
841 'test_id': 15,
842 'test_class': FioJobTest_t0015,
843 'job': 't0015-e78980ff.fio',
844 'success': SUCCESS_DEFAULT,
845 'pre_job': None,
846 'pre_success': None,
847 'output_format': 'json',
848 'requirements': [Requirements.linux, Requirements.libaio],
849 },
de31fe9a
VF
850 {
851 'test_id': 16,
852 'test_class': FioJobTest_t0015,
853 'job': 't0016-259ebc00.fio',
854 'success': SUCCESS_DEFAULT,
855 'pre_job': None,
856 'pre_success': None,
857 'output_format': 'json',
858 'requirements': [],
859 },
704cc4df
VF
860 {
861 'test_id': 1000,
862 'test_class': FioExeTest,
863 'exe': 't/axmap',
864 'parameters': None,
865 'success': SUCCESS_DEFAULT,
866 'requirements': [],
867 },
868 {
869 'test_id': 1001,
870 'test_class': FioExeTest,
871 'exe': 't/ieee754',
872 'parameters': None,
873 'success': SUCCESS_DEFAULT,
874 'requirements': [],
875 },
876 {
877 'test_id': 1002,
878 'test_class': FioExeTest,
879 'exe': 't/lfsr-test',
880 'parameters': ['0xFFFFFF', '0', '0', 'verify'],
881 'success': SUCCESS_STDERR,
882 'requirements': [],
883 },
884 {
885 'test_id': 1003,
886 'test_class': FioExeTest,
887 'exe': 't/readonly.py',
888 'parameters': ['-f', '{fio_path}'],
889 'success': SUCCESS_DEFAULT,
890 'requirements': [],
891 },
892 {
893 'test_id': 1004,
894 'test_class': FioExeTest,
895 'exe': 't/steadystate_tests.py',
896 'parameters': ['{fio_path}'],
897 'success': SUCCESS_DEFAULT,
898 'requirements': [],
899 },
900 {
901 'test_id': 1005,
902 'test_class': FioExeTest,
903 'exe': 't/stest',
904 'parameters': None,
905 'success': SUCCESS_STDERR,
906 'requirements': [],
907 },
908 {
909 'test_id': 1006,
910 'test_class': FioExeTest,
911 'exe': 't/strided.py',
912 'parameters': ['{fio_path}'],
913 'success': SUCCESS_DEFAULT,
914 'requirements': [],
915 },
916 {
917 'test_id': 1007,
918 'test_class': FioExeTest,
037b2b50
DF
919 'exe': 't/zbd/run-tests-against-nullb',
920 'parameters': ['-s', '1'],
704cc4df
VF
921 'success': SUCCESS_DEFAULT,
922 'requirements': [Requirements.linux, Requirements.zbd,
923 Requirements.root],
924 },
925 {
926 'test_id': 1008,
927 'test_class': FioExeTest,
037b2b50
DF
928 'exe': 't/zbd/run-tests-against-nullb',
929 'parameters': ['-s', '2'],
704cc4df
VF
930 'success': SUCCESS_DEFAULT,
931 'requirements': [Requirements.linux, Requirements.zbd,
932 Requirements.root, Requirements.zoned_nullb],
933 },
934 {
935 'test_id': 1009,
936 'test_class': FioExeTest,
937 'exe': 'unittests/unittest',
938 'parameters': None,
939 'success': SUCCESS_DEFAULT,
940 'requirements': [Requirements.unittests],
941 },
942 {
943 'test_id': 1010,
944 'test_class': FioExeTest,
945 'exe': 't/latency_percentiles.py',
946 'parameters': ['-f', '{fio_path}'],
947 'success': SUCCESS_DEFAULT,
948 'requirements': [],
949 },
8403eca6
VF
950 {
951 'test_id': 1011,
952 'test_class': FioExeTest,
953 'exe': 't/jsonplus2csv_test.py',
954 'parameters': ['-f', '{fio_path}'],
955 'success': SUCCESS_DEFAULT,
956 'requirements': [],
957 },
df1eaa36
VF
958]
959
960
961def parse_args():
704cc4df
VF
962 """Parse command-line arguments."""
963
df1eaa36
VF
964 parser = argparse.ArgumentParser()
965 parser.add_argument('-r', '--fio-root',
966 help='fio root path')
967 parser.add_argument('-f', '--fio',
968 help='path to fio executable (e.g., ./fio)')
969 parser.add_argument('-a', '--artifact-root',
970 help='artifact root directory')
971 parser.add_argument('-s', '--skip', nargs='+', type=int,
972 help='list of test(s) to skip')
973 parser.add_argument('-o', '--run-only', nargs='+', type=int,
974 help='list of test(s) to run, skipping all others')
6d5470c3
VF
975 parser.add_argument('-d', '--debug', action='store_true',
976 help='provide debug output')
b1bc705e
VF
977 parser.add_argument('-k', '--skip-req', action='store_true',
978 help='skip requirements checking')
58a77d2a
VF
979 parser.add_argument('-p', '--pass-through', action='append',
980 help='pass-through an argument to an executable test')
df1eaa36
VF
981 args = parser.parse_args()
982
983 return args
984
985
986def main():
704cc4df
VF
987 """Entry point."""
988
df1eaa36 989 args = parse_args()
6d5470c3
VF
990 if args.debug:
991 logging.basicConfig(level=logging.DEBUG)
992 else:
993 logging.basicConfig(level=logging.INFO)
994
58a77d2a
VF
995 pass_through = {}
996 if args.pass_through:
997 for arg in args.pass_through:
998 if not ':' in arg:
999 print("Invalid --pass-through argument '%s'" % arg)
1000 print("Syntax for --pass-through is TESTNUMBER:ARGUMENT")
1001 return
061a0773 1002 split = arg.split(":", 1)
58a77d2a 1003 pass_through[int(split[0])] = split[1]
061a0773 1004 logging.debug("Pass-through arguments: %s", pass_through)
58a77d2a 1005
df1eaa36
VF
1006 if args.fio_root:
1007 fio_root = args.fio_root
1008 else:
6d5470c3
VF
1009 fio_root = str(Path(__file__).absolute().parent.parent)
1010 print("fio root is %s" % fio_root)
df1eaa36
VF
1011
1012 if args.fio:
1013 fio_path = args.fio
1014 else:
742b8799
VF
1015 if platform.system() == "Windows":
1016 fio_exe = "fio.exe"
1017 else:
1018 fio_exe = "fio"
1019 fio_path = os.path.join(fio_root, fio_exe)
6d5470c3
VF
1020 print("fio path is %s" % fio_path)
1021 if not shutil.which(fio_path):
1022 print("Warning: fio executable not found")
df1eaa36
VF
1023
1024 artifact_root = args.artifact_root if args.artifact_root else \
1025 "fio-test-{0}".format(time.strftime("%Y%m%d-%H%M%S"))
1026 os.mkdir(artifact_root)
1027 print("Artifact directory is %s" % artifact_root)
1028
b1bc705e
VF
1029 if not args.skip_req:
1030 req = Requirements(fio_root)
1031
df1eaa36
VF
1032 passed = 0
1033 failed = 0
1034 skipped = 0
1035
1036 for config in TEST_LIST:
1037 if (args.skip and config['test_id'] in args.skip) or \
1038 (args.run_only and config['test_id'] not in args.run_only):
1039 skipped = skipped + 1
b1bc705e 1040 print("Test {0} SKIPPED (User request)".format(config['test_id']))
df1eaa36
VF
1041 continue
1042
1043 if issubclass(config['test_class'], FioJobTest):
1044 if config['pre_job']:
1045 fio_pre_job = os.path.join(fio_root, 't', 'jobs',
1046 config['pre_job'])
1047 else:
1048 fio_pre_job = None
1049 if config['pre_success']:
1050 fio_pre_success = config['pre_success']
1051 else:
1052 fio_pre_success = None
1053 if 'output_format' in config:
1054 output_format = config['output_format']
1055 else:
1056 output_format = 'normal'
1057 test = config['test_class'](
1058 fio_path,
1059 os.path.join(fio_root, 't', 'jobs', config['job']),
1060 config['success'],
1061 fio_pre_job=fio_pre_job,
1062 fio_pre_success=fio_pre_success,
1063 output_format=output_format)
9393cdaa 1064 desc = config['job']
df1eaa36
VF
1065 elif issubclass(config['test_class'], FioExeTest):
1066 exe_path = os.path.join(fio_root, config['exe'])
1067 if config['parameters']:
1068 parameters = [p.format(fio_path=fio_path) for p in config['parameters']]
1069 else:
58a77d2a 1070 parameters = []
742b8799 1071 if Path(exe_path).suffix == '.py' and platform.system() == "Windows":
58a77d2a 1072 parameters.insert(0, exe_path)
742b8799 1073 exe_path = "python.exe"
58a77d2a
VF
1074 if config['test_id'] in pass_through:
1075 parameters += pass_through[config['test_id']].split()
df1eaa36
VF
1076 test = config['test_class'](exe_path, parameters,
1077 config['success'])
9393cdaa 1078 desc = config['exe']
df1eaa36
VF
1079 else:
1080 print("Test {0} FAILED: unable to process test config".format(config['test_id']))
1081 failed = failed + 1
1082 continue
1083
b1bc705e 1084 if not args.skip_req:
704cc4df 1085 reqs_met = True
b1bc705e 1086 for req in config['requirements']:
704cc4df
VF
1087 reqs_met, reason = req()
1088 logging.debug("Test %d: Requirement '%s' met? %s", config['test_id'], reason,
1089 reqs_met)
1090 if not reqs_met:
b1bc705e 1091 break
704cc4df 1092 if not reqs_met:
9393cdaa 1093 print("Test {0} SKIPPED ({1}) {2}".format(config['test_id'], reason, desc))
b1bc705e
VF
1094 skipped = skipped + 1
1095 continue
1096
aa9f2627
VF
1097 try:
1098 test.setup(artifact_root, config['test_id'])
1099 test.run()
1100 test.check_result()
1101 except KeyboardInterrupt:
1102 break
1103 except Exception as e:
1104 test.passed = False
1105 test.failure_reason += str(e)
1106 logging.debug("Test %d exception:\n%s\n", config['test_id'], traceback.format_exc())
df1eaa36
VF
1107 if test.passed:
1108 result = "PASSED"
1109 passed = passed + 1
1110 else:
1111 result = "FAILED: {0}".format(test.failure_reason)
1112 failed = failed + 1
15a73987
VF
1113 contents, _ = FioJobTest.get_file(test.stderr_file)
1114 logging.debug("Test %d: stderr:\n%s", config['test_id'], contents)
1115 contents, _ = FioJobTest.get_file(test.stdout_file)
1116 logging.debug("Test %d: stdout:\n%s", config['test_id'], contents)
9393cdaa 1117 print("Test {0} {1} {2}".format(config['test_id'], result, desc))
df1eaa36
VF
1118
1119 print("{0} test(s) passed, {1} failed, {2} skipped".format(passed, failed, skipped))
1120
1121 sys.exit(failed)
1122
1123
1124if __name__ == '__main__':
1125 main()