File: readonly.py

package info (click to toggle)
fio 3.41-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,012 kB
  • sloc: ansic: 82,290; python: 9,862; sh: 6,067; makefile: 813; yacc: 204; lex: 184
file content (161 lines) | stat: -rwxr-xr-x 4,546 bytes parent folder | download | duplicates (2)
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
154
155
156
157
158
159
160
161
#!/usr/bin/env python3
# SPDX-License-Identifier: GPL-2.0-only
#
# Copyright (c) 2019 Western Digital Corporation or its affiliates.

"""
# readonly.py
#
# Do some basic tests of the --readonly parameter
#
# USAGE
# python readonly.py [-f fio-executable]
#
# EXAMPLES
# python t/readonly.py
# python t/readonly.py -f ./fio
#
# REQUIREMENTS
# Python 3.5+
#
"""

import os
import sys
import time
import argparse
from pathlib import Path
from fiotestlib import FioJobCmdTest, run_fio_tests
from fiotestcommon import SUCCESS_DEFAULT, SUCCESS_NONZERO


class FioReadOnlyTest(FioJobCmdTest):
    """fio read only test."""

    def setup(self, parameters):
        """Setup the test."""

        fio_args = [
                    "--name=readonly",
                    "--ioengine=null",
                    "--time_based",
                    "--runtime=1s",
                    "--size=1M",
                    f"--rw={self.fio_opts['rw']}",
                   ]
        if 'readonly-pre' in parameters:
            fio_args.insert(0, "--readonly")
        if 'readonly-post' in parameters:
            fio_args.append("--readonly")

        super().setup(fio_args)


TEST_LIST = [
            {
                "test_id": 1,
                "fio_opts": { "rw": "randread", },
                "readonly-pre": 1,
                "success": SUCCESS_DEFAULT,
                "test_class": FioReadOnlyTest,
            },
            {
                "test_id": 2,
                "fio_opts": { "rw": "randwrite", },
                "readonly-pre": 1,
                "success": SUCCESS_NONZERO,
                "test_class": FioReadOnlyTest,
            },
            {
                "test_id": 3,
                "fio_opts": { "rw": "randtrim", },
                "readonly-pre": 1,
                "success": SUCCESS_NONZERO,
                "test_class": FioReadOnlyTest,
            },
            {
                "test_id": 4,
                "fio_opts": { "rw": "randread", },
                "readonly-post": 1,
                "success": SUCCESS_DEFAULT,
                "test_class": FioReadOnlyTest,
            },
            {
                "test_id": 5,
                "fio_opts": { "rw": "randwrite", },
                "readonly-post": 1,
                "success": SUCCESS_NONZERO,
                "test_class": FioReadOnlyTest,
            },
            {
                "test_id": 6,
                "fio_opts": { "rw": "randtrim", },
                "readonly-post": 1,
                "success": SUCCESS_NONZERO,
                "test_class": FioReadOnlyTest,
            },
            {
                "test_id": 7,
                "fio_opts": { "rw": "randread", },
                "success": SUCCESS_DEFAULT,
                "test_class": FioReadOnlyTest,
            },
            {
                "test_id": 8,
                "fio_opts": { "rw": "randwrite", },
                "success": SUCCESS_DEFAULT,
                "test_class": FioReadOnlyTest,
            },
            {
                "test_id": 9,
                "fio_opts": { "rw": "randtrim", },
                "success": SUCCESS_DEFAULT,
                "test_class": FioReadOnlyTest,
            },
        ]


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('-a', '--artifact-root', help='artifact root directory')
    parser.add_argument('-s', '--skip', nargs='+', type=int,
                        help='list of test(s) to skip')
    parser.add_argument('-o', '--run-only', nargs='+', type=int,
                        help='list of test(s) to run, skipping all others')
    args = parser.parse_args()

    return args


def main():
    """Run readonly tests."""

    args = parse_args()

    if args.fio:
        fio_path = str(Path(args.fio).absolute())
    else:
        fio_path = 'fio'
    print(f"fio path is {fio_path}")

    artifact_root = args.artifact_root if args.artifact_root else \
        f"readonly-test-{time.strftime('%Y%m%d-%H%M%S')}"
    os.mkdir(artifact_root)
    print(f"Artifact directory is {artifact_root}")

    test_env = {
              'fio_path': fio_path,
              'fio_root': str(Path(__file__).absolute().parent.parent),
              'artifact_root': artifact_root,
              'basename': 'readonly',
              }

    _, failed, _ = run_fio_tests(TEST_LIST, test_env, args)
    sys.exit(failed)


if __name__ == '__main__':
    main()