# 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 paramter
+# Do some basic tests of the --readonly parameter
#
# USAGE
# python readonly.py [-f fio-executable]
# REQUIREMENTS
# Python 3.5+
#
-#
+"""
+import os
import sys
+import time
import argparse
-import subprocess
+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('-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 run_fio(fio, test, index):
- fio_args = [
- "--name=readonly",
- "--ioengine=null",
- "--time_based",
- "--runtime=1s",
- "--size=1M",
- "--rw={rw}".format(**test),
- ]
- if 'readonly-pre' in test:
- fio_args.insert(0, "--readonly")
- if 'readonly-post' in test:
- fio_args.append("--readonly")
-
- output = subprocess.run([fio] + fio_args, stdout=subprocess.PIPE,
- stderr=subprocess.PIPE)
-
- return output
-
-
-def check_output(output, test):
- expect_error = False
- if 'readonly-pre' in test or 'readonly-post' in test:
- if 'write' in test['rw'] or 'trim' in test['rw']:
- expect_error = True
-
-# print(output.stdout)
-# print(output.stderr)
-
- if output.returncode == 0:
- if expect_error:
- return False
- else:
- return True
- else:
- if expect_error:
- return True
- else:
- return False
-
+def main():
+ """Run readonly tests."""
-if __name__ == '__main__':
args = parse_args()
- tests = [
- {
- "rw": "randread",
- "readonly-pre": 1,
- },
- {
- "rw": "randwrite",
- "readonly-pre": 1,
- },
- {
- "rw": "randtrim",
- "readonly-pre": 1,
- },
- {
- "rw": "randread",
- "readonly-post": 1,
- },
- {
- "rw": "randwrite",
- "readonly-post": 1,
- },
- {
- "rw": "randtrim",
- "readonly-post": 1,
- },
- {
- "rw": "randread",
- },
- {
- "rw": "randwrite",
- },
- {
- "rw": "randtrim",
- },
- ]
-
- index = 1
- passed = 0
- failed = 0
-
if args.fio:
- fio_path = args.fio
+ fio_path = str(Path(args.fio).absolute())
else:
fio_path = 'fio'
+ print(f"fio path is {fio_path}")
- for test in tests:
- output = run_fio(fio_path, test, index)
- status = check_output(output, test)
- print("Test {0} {1}".format(index, ("PASSED" if status else "FAILED")))
- if status:
- passed = passed + 1
- else:
- failed = failed + 1
- index = index + 1
+ 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}")
- print("{0} tests passed, {1} failed".format(passed, failed))
+ 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()