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 if platform.system() == 'Linux':
49 elif platform.system() == 'Windows':
55 "--output=fio-output.json",
56 "--output-format=json+",
57 "--filename=fio_jsonplus_clat2csv.test",
62 "--slat_percentiles=1",
63 "--clat_percentiles=1",
64 "--lat_percentiles=1",
74 output = subprocess.run([fio] + fio_args, stdout=subprocess.PIPE,
75 stderr=subprocess.PIPE)
80 def check_output(fio_output, script_path):
81 """Run t/fio_jsonplus_clat2csv and validate the generated CSV files
82 against the original json+ fio output.
85 fio_output subprocess.run object describing fio run.
86 script_path path to fio_jsonplus_clat2csv script.
89 if fio_output.returncode != 0:
92 if platform.system() == 'Windows':
93 script = ['python.exe', script_path]
95 script = [script_path]
97 script_args = ["fio-output.json", "fio-output.csv"]
98 script_args_validate = script_args + ["--validate"]
100 script_output = subprocess.run(script + script_args)
101 if script_output.returncode != 0:
104 script_output = subprocess.run(script + script_args_validate)
105 if script_output.returncode != 0:
112 """Entry point for this script."""
123 fio_path = os.path.join(os.path.dirname(__file__), '../fio')
124 if not os.path.exists(fio_path):
126 print("fio path is", fio_path)
129 script_path = args.script
131 script_path = os.path.join(os.path.dirname(__file__), '../tools/fio_jsonplus_clat2csv')
132 if not os.path.exists(script_path):
133 script_path = 'fio_jsonplus_clat2csv'
134 print("script path is", script_path)
136 fio_output = run_fio(fio_path)
137 status = check_output(fio_output, script_path)
138 print("Test {0} {1}".format(index, ("PASSED" if status else "FAILED")))
145 print("{0} tests passed, {1} failed".format(passed, failed))
149 if __name__ == '__main__':