t/jsonplus2csv_test: reduce file size
[fio.git] / t / jsonplus2csv_test.py
CommitLineData
8403eca6
VF
1#!/usr/bin/env python3
2# SPDX-License-Identifier: GPL-2.0-only
3#
4# Copyright (c) 2020 Western Digital Corporation or its affiliates.
5#
6"""
7jsonplus2csv-test.py
8
9Do one basic test of tools/fio_jsonplus2csv
10
11USAGE
12python jsonplus2csv-test.py [-f fio-executable] [-s script-location]
13
14EXAMPLES
15python t/jsonplus2csv-test.py
16python t/jsonplus2csv-test.py -f ./fio -s tools
17
18REQUIREMENTS
19Python 3.5+
20"""
21
22import os
23import sys
24import platform
25import argparse
26import subprocess
27
28
29def parse_args():
30 """Parse command-line arguments."""
31
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()
38
39
40def run_fio(fio):
41 """Run fio to generate json+ data.
42
43 Parameters:
44 fio path to fio executable.
45 """
46
ef918ab1 47# We need an async ioengine to get submission latencies
8403eca6
VF
48 if platform.system() == 'Linux':
49 aio = 'libaio'
50 elif platform.system() == 'Windows':
51 aio = 'windowsaio'
52 else:
53 aio = 'posixaio'
54
55 fio_args = [
56 "--output=fio-output.json",
57 "--output-format=json+",
58 "--filename=fio_jsonplus_clat2csv.test",
59 "--ioengine=" + aio,
60 "--time_based",
61 "--runtime=3s",
ef918ab1 62 "--size=1M",
8403eca6
VF
63 "--slat_percentiles=1",
64 "--clat_percentiles=1",
65 "--lat_percentiles=1",
66 "--thread=1",
67 "--name=test1",
68 "--rw=randrw",
69 "--name=test2",
70 "--rw=read",
71 "--name=test3",
72 "--rw=write",
73 ]
74
75 output = subprocess.run([fio] + fio_args, stdout=subprocess.PIPE,
76 stderr=subprocess.PIPE)
77
78 return output
79
80
81def 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.
84
85 Parameters:
86 fio_output subprocess.run object describing fio run.
87 script_path path to fio_jsonplus_clat2csv script.
88 """
89
90 if fio_output.returncode != 0:
91 return False
92
93 if platform.system() == 'Windows':
94 script = ['python.exe', script_path]
95 else:
96 script = [script_path]
97
98 script_args = ["fio-output.json", "fio-output.csv"]
99 script_args_validate = script_args + ["--validate"]
100
101 script_output = subprocess.run(script + script_args)
102 if script_output.returncode != 0:
103 return False
104
105 script_output = subprocess.run(script + script_args_validate)
106 if script_output.returncode != 0:
107 return False
108
109 return True
110
111
112def main():
113 """Entry point for this script."""
114
115 args = parse_args()
116
117 index = 1
118 passed = 0
119 failed = 0
120
121 if args.fio:
122 fio_path = args.fio
123 else:
124 fio_path = os.path.join(os.path.dirname(__file__), '../fio')
125 if not os.path.exists(fio_path):
126 fio_path = 'fio'
127 print("fio path is", fio_path)
128
129 if args.script:
130 script_path = args.script
131 else:
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)
136
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")))
140 if status:
141 passed = passed + 1
142 else:
143 failed = failed + 1
144 index = index + 1
145
146 print("{0} tests passed, {1} failed".format(passed, failed))
147
148 sys.exit(failed)
149
150if __name__ == '__main__':
151 main()