2 # SPDX-License-Identifier: GPL-2.0-only
4 # Copyright (c) 2020 Western Digital Corporation or its affiliates.
9 Do one basic test of tools/fio_jsonplus2csv
12 python jsonplus2csv-test.py [-f fio-executable] [-s script-location]
15 python t/jsonplus2csv-test.py
16 python t/jsonplus2csv-test.py -f ./fio -s tools
30 """Parse command-line arguments."""
32 parser = argparse.ArgumentParser()
33 parser.add_argument('-f', '--fio',
34 help='path to fio executable (e.g., ./fio)')
35 parser.add_argument('-s', '--script',
36 help='directory containing fio_jsonplus2csv script')
37 return parser.parse_args()
41 """Run fio to generate json+ data.
44 fio path to fio executable.
47 # We need an async ioengine to get submission latencies
48 if platform.system() == 'Linux':
50 elif platform.system() == 'Windows':
57 "--output=fio-output.json",
58 "--output-format=json+",
59 "--filename=fio_jsonplus_clat2csv.test",
64 "--slat_percentiles=1",
65 "--clat_percentiles=1",
66 "--lat_percentiles=1",
76 output = subprocess.run([fio] + fio_args, stdout=subprocess.PIPE,
77 stderr=subprocess.PIPE)
82 def check_output(fio_output, script_path):
83 """Run t/fio_jsonplus_clat2csv and validate the generated CSV files
84 against the original json+ fio output.
87 fio_output subprocess.run object describing fio run.
88 script_path path to fio_jsonplus_clat2csv script.
91 if fio_output.returncode != 0:
92 print("ERROR: fio run failed")
95 if platform.system() == 'Windows':
96 script = ['python.exe', script_path]
98 script = [script_path]
100 script_args = ["fio-output.json", "fio-output.csv"]
101 script_args_validate = script_args + ["--validate"]
103 script_output = subprocess.run(script + script_args)
104 if script_output.returncode != 0:
107 script_output = subprocess.run(script + script_args_validate)
108 if script_output.returncode != 0:
115 """Entry point for this script."""
126 fio_path = os.path.join(os.path.dirname(__file__), '../fio')
127 if not os.path.exists(fio_path):
129 print("fio path is", fio_path)
132 script_path = args.script
134 script_path = os.path.join(os.path.dirname(__file__), '../tools/fio_jsonplus_clat2csv')
135 if not os.path.exists(script_path):
136 script_path = 'fio_jsonplus_clat2csv'
137 print("script path is", script_path)
139 fio_output = run_fio(fio_path)
140 status = check_output(fio_output, script_path)
141 print("Test {0} {1}".format(index, ("PASSED" if status else "FAILED")))
148 print("{0} tests passed, {1} failed".format(passed, failed))
152 if __name__ == '__main__':