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':
56 "--output=fio-output.json",
57 "--output-format=json+",
58 "--filename=fio_jsonplus_clat2csv.test",
63 "--slat_percentiles=1",
64 "--clat_percentiles=1",
65 "--lat_percentiles=1",
75 output = subprocess.run([fio] + fio_args, stdout=subprocess.PIPE,
76 stderr=subprocess.PIPE)
81 def check_output(fio_output, script_path):
82 """Run t/fio_jsonplus_clat2csv and validate the generated CSV files
83 against the original json+ fio output.
86 fio_output subprocess.run object describing fio run.
87 script_path path to fio_jsonplus_clat2csv script.
90 if fio_output.returncode != 0:
93 if platform.system() == 'Windows':
94 script = ['python.exe', script_path]
96 script = [script_path]
98 script_args = ["fio-output.json", "fio-output.csv"]
99 script_args_validate = script_args + ["--validate"]
101 script_output = subprocess.run(script + script_args)
102 if script_output.returncode != 0:
105 script_output = subprocess.run(script + script_args_validate)
106 if script_output.returncode != 0:
113 """Entry point for this script."""
124 fio_path = os.path.join(os.path.dirname(__file__), '../fio')
125 if not os.path.exists(fio_path):
127 print("fio path is", fio_path)
130 script_path = args.script
132 script_path = os.path.join(os.path.dirname(__file__), '../tools/fio_jsonplus_clat2csv')
133 if not os.path.exists(script_path):
134 script_path = 'fio_jsonplus_clat2csv'
135 print("script path is", script_path)
137 fio_output = run_fio(fio_path)
138 status = check_output(fio_output, script_path)
139 print("Test {0} {1}".format(index, ("PASSED" if status else "FAILED")))
146 print("{0} tests passed, {1} failed".format(passed, failed))
150 if __name__ == '__main__':