summaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
Diffstat (limited to 't')
-rw-r--r--t/jobs/readonly-r.fio5
-rw-r--r--t/jobs/readonly-t.fio5
-rw-r--r--t/jobs/readonly-w.fio5
-rwxr-xr-xt/readonly.py138
-rwxr-xr-xt/readonly.sh84
5 files changed, 138 insertions, 99 deletions
diff --git a/t/jobs/readonly-r.fio b/t/jobs/readonly-r.fio
deleted file mode 100644
index 34ba9b5e..00000000
--- a/t/jobs/readonly-r.fio
+++ /dev/null
@@ -1,5 +0,0 @@
-[test]
-filename=${DUT}
-rw=randread
-time_based
-runtime=1s
diff --git a/t/jobs/readonly-t.fio b/t/jobs/readonly-t.fio
deleted file mode 100644
index f3e093c1..00000000
--- a/t/jobs/readonly-t.fio
+++ /dev/null
@@ -1,5 +0,0 @@
-[test]
-filename=${DUT}
-rw=randtrim
-time_based
-runtime=1s
diff --git a/t/jobs/readonly-w.fio b/t/jobs/readonly-w.fio
deleted file mode 100644
index 26029ef2..00000000
--- a/t/jobs/readonly-w.fio
+++ /dev/null
@@ -1,5 +0,0 @@
-[test]
-filename=${DUT}
-rw=randwrite
-time_based
-runtime=1s
diff --git a/t/readonly.py b/t/readonly.py
new file mode 100755
index 00000000..43686c9c
--- /dev/null
+++ b/t/readonly.py
@@ -0,0 +1,138 @@
+#!/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 paramter
+#
+# USAGE
+# python readonly.py [-f fio-executable]
+#
+# EXAMPLES
+# python t/readonly.py
+# python t/readonly.py -f ./fio
+#
+# REQUIREMENTS
+# Python 3.5+
+#
+#
+
+import sys
+import argparse
+import subprocess
+
+
+def parse_args():
+ parser = argparse.ArgumentParser()
+ parser.add_argument('-f', '--fio',
+ help='path to fio executable (e.g., ./fio)')
+ 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
+
+
+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
+ else:
+ fio_path = 'fio'
+
+ 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
+
+ print("{0} tests passed, {1} failed".format(passed, failed))
+
+ sys.exit(failed)
diff --git a/t/readonly.sh b/t/readonly.sh
deleted file mode 100755
index d7094146..00000000
--- a/t/readonly.sh
+++ /dev/null
@@ -1,84 +0,0 @@
-#!/bin/bash
-#
-# Do some basic test of the --readonly parameter
-#
-# DUT should be a device that accepts read, write, and trim operations
-#
-# Example usage:
-#
-# DUT=/dev/fioa t/readonly.sh
-#
-TESTNUM=1
-
-#
-# The first parameter is the return code
-# The second parameter is 0 if the return code should be 0
-# positive if the return code should be positive
-#
-check () {
- echo "********************"
-
- if [ $2 -gt 0 ]; then
- if [ $1 -eq 0 ]; then
- echo "Test $TESTNUM failed"
- echo "********************"
- exit 1
- else
- echo "Test $TESTNUM passed"
- fi
- else
- if [ $1 -gt 0 ]; then
- echo "Test $TESTNUM failed"
- echo "********************"
- exit 1
- else
- echo "Test $TESTNUM passed"
- fi
- fi
-
- echo "********************"
- echo
- TESTNUM=$((TESTNUM+1))
-}
-
-./fio --name=test --filename=$DUT --rw=randread --readonly --time_based --runtime=1s &> /dev/null
-check $? 0
-./fio --name=test --filename=$DUT --rw=randwrite --readonly --time_based --runtime=1s &> /dev/null
-check $? 1
-./fio --name=test --filename=$DUT --rw=randtrim --readonly --time_based --runtime=1s &> /dev/null
-check $? 1
-
-./fio --name=test --filename=$DUT --readonly --rw=randread --time_based --runtime=1s &> /dev/null
-check $? 0
-./fio --name=test --filename=$DUT --readonly --rw=randwrite --time_based --runtime=1s &> /dev/null
-check $? 1
-./fio --name=test --filename=$DUT --readonly --rw=randtrim --time_based --runtime=1s &> /dev/null
-check $? 1
-
-./fio --name=test --filename=$DUT --rw=randread --time_based --runtime=1s &> /dev/null
-check $? 0
-./fio --name=test --filename=$DUT --rw=randwrite --time_based --runtime=1s &> /dev/null
-check $? 0
-./fio --name=test --filename=$DUT --rw=randtrim --time_based --runtime=1s &> /dev/null
-check $? 0
-
-./fio t/jobs/readonly-r.fio --readonly &> /dev/null
-check $? 0
-./fio t/jobs/readonly-w.fio --readonly &> /dev/null
-check $? 1
-./fio t/jobs/readonly-t.fio --readonly &> /dev/null
-check $? 1
-
-./fio --readonly t/jobs/readonly-r.fio &> /dev/null
-check $? 0
-./fio --readonly t/jobs/readonly-w.fio &> /dev/null
-check $? 1
-./fio --readonly t/jobs/readonly-t.fio &> /dev/null
-check $? 1
-
-./fio t/jobs/readonly-r.fio &> /dev/null
-check $? 0
-./fio t/jobs/readonly-w.fio &> /dev/null
-check $? 0
-./fio t/jobs/readonly-t.fio &> /dev/null
-check $? 0