t/nvmept_trim: increase transfer size for some tests
[fio.git] / t / readonly.py
1 #!/usr/bin/env python3
2 # SPDX-License-Identifier: GPL-2.0-only
3 #
4 # Copyright (c) 2019 Western Digital Corporation or its affiliates.
5 #
6 #
7 # readonly.py
8 #
9 # Do some basic tests of the --readonly paramter
10 #
11 # USAGE
12 # python readonly.py [-f fio-executable]
13 #
14 # EXAMPLES
15 # python t/readonly.py
16 # python t/readonly.py -f ./fio
17 #
18 # REQUIREMENTS
19 # Python 3.5+
20 #
21 #
22
23 import sys
24 import argparse
25 import subprocess
26
27
28 def parse_args():
29     parser = argparse.ArgumentParser()
30     parser.add_argument('-f', '--fio',
31                         help='path to fio executable (e.g., ./fio)')
32     args = parser.parse_args()
33
34     return args
35
36
37 def run_fio(fio, test, index):
38     fio_args = [
39                 "--max-jobs=16",
40                 "--name=readonly",
41                 "--ioengine=null",
42                 "--time_based",
43                 "--runtime=1s",
44                 "--size=1M",
45                 "--rw={rw}".format(**test),
46                ]
47     if 'readonly-pre' in test:
48         fio_args.insert(0, "--readonly")
49     if 'readonly-post' in test:
50         fio_args.append("--readonly")
51
52     output = subprocess.run([fio] + fio_args, stdout=subprocess.PIPE,
53                             stderr=subprocess.PIPE)
54
55     return output
56
57
58 def check_output(output, test):
59     expect_error = False
60     if 'readonly-pre' in test or 'readonly-post' in test:
61         if 'write' in test['rw'] or 'trim' in test['rw']:
62             expect_error = True
63
64 #    print(output.stdout)
65 #    print(output.stderr)
66
67     if output.returncode == 0:
68         if expect_error:
69             return False
70         else:
71             return True
72     else:
73         if expect_error:
74             return True
75         else:
76             return False
77
78
79 if __name__ == '__main__':
80     args = parse_args()
81
82     tests = [
83                 {
84                     "rw": "randread",
85                     "readonly-pre": 1,
86                 },
87                 {
88                     "rw": "randwrite",
89                     "readonly-pre": 1,
90                 },
91                 {
92                     "rw": "randtrim",
93                     "readonly-pre": 1,
94                 },
95                 {
96                     "rw": "randread",
97                     "readonly-post": 1,
98                 },
99                 {
100                     "rw": "randwrite",
101                     "readonly-post": 1,
102                 },
103                 {
104                     "rw": "randtrim",
105                     "readonly-post": 1,
106                 },
107                 {
108                     "rw": "randread",
109                 },
110                 {
111                     "rw": "randwrite",
112                 },
113                 {
114                     "rw": "randtrim",
115                 },
116             ]
117
118     index = 1
119     passed = 0
120     failed = 0
121
122     if args.fio:
123         fio_path = args.fio
124     else:
125         fio_path = 'fio'
126
127     for test in tests:
128         output = run_fio(fio_path, test, index)
129         status = check_output(output, test)
130         print("Test {0} {1}".format(index, ("PASSED" if status else "FAILED")))
131         if status:
132             passed = passed + 1
133         else:
134             failed = failed + 1
135         index = index + 1
136
137     print("{0} tests passed, {1} failed".format(passed, failed))
138
139     sys.exit(failed)