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