| 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 parameter |
| 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 os |
| 24 | import sys |
| 25 | import time |
| 26 | import argparse |
| 27 | from pathlib import Path |
| 28 | from fiotestlib import FioJobCmdTest, run_fio_tests |
| 29 | from fiotestcommon import SUCCESS_DEFAULT, SUCCESS_NONZERO |
| 30 | |
| 31 | |
| 32 | class FioReadOnlyTest(FioJobCmdTest): |
| 33 | """fio read only test.""" |
| 34 | |
| 35 | def setup(self, parameters): |
| 36 | """Setup the test.""" |
| 37 | |
| 38 | fio_args = [ |
| 39 | "--name=readonly", |
| 40 | "--ioengine=null", |
| 41 | "--time_based", |
| 42 | "--runtime=1s", |
| 43 | "--size=1M", |
| 44 | f"--rw={self.fio_opts['rw']}", |
| 45 | ] |
| 46 | if 'readonly-pre' in parameters: |
| 47 | fio_args.insert(0, "--readonly") |
| 48 | if 'readonly-post' in parameters: |
| 49 | fio_args.append("--readonly") |
| 50 | |
| 51 | super().setup(fio_args) |
| 52 | |
| 53 | |
| 54 | TEST_LIST = [ |
| 55 | { |
| 56 | "test_id": 1, |
| 57 | "fio_opts": { "rw": "randread", }, |
| 58 | "readonly-pre": 1, |
| 59 | "success": SUCCESS_DEFAULT, |
| 60 | "test_class": FioReadOnlyTest, |
| 61 | }, |
| 62 | { |
| 63 | "test_id": 2, |
| 64 | "fio_opts": { "rw": "randwrite", }, |
| 65 | "readonly-pre": 1, |
| 66 | "success": SUCCESS_NONZERO, |
| 67 | "test_class": FioReadOnlyTest, |
| 68 | }, |
| 69 | { |
| 70 | "test_id": 3, |
| 71 | "fio_opts": { "rw": "randtrim", }, |
| 72 | "readonly-pre": 1, |
| 73 | "success": SUCCESS_NONZERO, |
| 74 | "test_class": FioReadOnlyTest, |
| 75 | }, |
| 76 | { |
| 77 | "test_id": 4, |
| 78 | "fio_opts": { "rw": "randread", }, |
| 79 | "readonly-post": 1, |
| 80 | "success": SUCCESS_DEFAULT, |
| 81 | "test_class": FioReadOnlyTest, |
| 82 | }, |
| 83 | { |
| 84 | "test_id": 5, |
| 85 | "fio_opts": { "rw": "randwrite", }, |
| 86 | "readonly-post": 1, |
| 87 | "success": SUCCESS_NONZERO, |
| 88 | "test_class": FioReadOnlyTest, |
| 89 | }, |
| 90 | { |
| 91 | "test_id": 6, |
| 92 | "fio_opts": { "rw": "randtrim", }, |
| 93 | "readonly-post": 1, |
| 94 | "success": SUCCESS_NONZERO, |
| 95 | "test_class": FioReadOnlyTest, |
| 96 | }, |
| 97 | { |
| 98 | "test_id": 7, |
| 99 | "fio_opts": { "rw": "randread", }, |
| 100 | "success": SUCCESS_DEFAULT, |
| 101 | "test_class": FioReadOnlyTest, |
| 102 | }, |
| 103 | { |
| 104 | "test_id": 8, |
| 105 | "fio_opts": { "rw": "randwrite", }, |
| 106 | "success": SUCCESS_DEFAULT, |
| 107 | "test_class": FioReadOnlyTest, |
| 108 | }, |
| 109 | { |
| 110 | "test_id": 9, |
| 111 | "fio_opts": { "rw": "randtrim", }, |
| 112 | "success": SUCCESS_DEFAULT, |
| 113 | "test_class": FioReadOnlyTest, |
| 114 | }, |
| 115 | ] |
| 116 | |
| 117 | |
| 118 | def parse_args(): |
| 119 | """Parse command-line arguments.""" |
| 120 | |
| 121 | parser = argparse.ArgumentParser() |
| 122 | parser.add_argument('-f', '--fio', help='path to fio executable (e.g., ./fio)') |
| 123 | parser.add_argument('-a', '--artifact-root', help='artifact root directory') |
| 124 | parser.add_argument('-s', '--skip', nargs='+', type=int, |
| 125 | help='list of test(s) to skip') |
| 126 | parser.add_argument('-o', '--run-only', nargs='+', type=int, |
| 127 | help='list of test(s) to run, skipping all others') |
| 128 | args = parser.parse_args() |
| 129 | |
| 130 | return args |
| 131 | |
| 132 | |
| 133 | def main(): |
| 134 | """Run readonly tests.""" |
| 135 | |
| 136 | args = parse_args() |
| 137 | |
| 138 | if args.fio: |
| 139 | fio_path = str(Path(args.fio).absolute()) |
| 140 | else: |
| 141 | fio_path = 'fio' |
| 142 | print(f"fio path is {fio_path}") |
| 143 | |
| 144 | artifact_root = args.artifact_root if args.artifact_root else \ |
| 145 | f"readonly-test-{time.strftime('%Y%m%d-%H%M%S')}" |
| 146 | os.mkdir(artifact_root) |
| 147 | print(f"Artifact directory is {artifact_root}") |
| 148 | |
| 149 | test_env = { |
| 150 | 'fio_path': fio_path, |
| 151 | 'fio_root': str(Path(__file__).absolute().parent.parent), |
| 152 | 'artifact_root': artifact_root, |
| 153 | 'basename': 'readonly', |
| 154 | } |
| 155 | |
| 156 | _, failed, _ = run_fio_tests(TEST_LIST, test_env, args) |
| 157 | sys.exit(failed) |
| 158 | |
| 159 | |
| 160 | if __name__ == '__main__': |
| 161 | main() |