t/run-fio-tests: move get_file outside of FioJobFileTest
authorVincent Fu <vincent.fu@samsung.com>
Fri, 2 Jun 2023 19:04:31 +0000 (19:04 +0000)
committerVincent Fu <vincent.fu@samsung.com>
Thu, 8 Jun 2023 18:38:56 +0000 (14:38 -0400)
There's no reason for this helper function to be part of a class. Just
make it an independent helper.

Signed-off-by: Vincent Fu <vincent.fu@samsung.com>
t/fiotestcommon.py
t/fiotestlib.py

index 8250bf523f8054328774573da063eec103555169..f5012c82c4af6c62c3533bf5431e0dd21dc5a7b7 100644 (file)
@@ -7,11 +7,11 @@ be used to help with running fio tests.
 """
 
 import os
+import locale
 import logging
 import platform
 import subprocess
 import multiprocessing
-from fiotestlib import FioJobFileTest
 
 
 SUCCESS_DEFAULT = {
@@ -30,6 +30,21 @@ SUCCESS_STDERR = {
     'timeout': 600,
     }
 
+
+def get_file(filename):
+    """Safely read a file."""
+    file_data = ''
+    success = True
+
+    try:
+        with open(filename, "r", encoding=locale.getpreferredencoding()) as output_file:
+            file_data = output_file.read()
+    except OSError:
+        success = False
+
+    return file_data, success
+
+
 class Requirements():
     """Requirements consists of multiple run environment characteristics.
     These are to determine if a particular test can be run"""
@@ -53,7 +68,7 @@ class Requirements():
 
         if Requirements._linux:
             config_file = os.path.join(fio_root, "config-host.h")
-            contents, success = FioJobFileTest.get_file(config_file)
+            contents, success = get_file(config_file)
             if not success:
                 print(f"Unable to open {config_file} to check requirements")
                 Requirements._zbd = True
@@ -61,7 +76,7 @@ class Requirements():
                 Requirements._zbd = "CONFIG_HAS_BLKZONED" in contents
                 Requirements._libaio = "CONFIG_LIBAIO" in contents
 
-            contents, success = FioJobFileTest.get_file("/proc/kallsyms")
+            contents, success = get_file("/proc/kallsyms")
             if not success:
                 print("Unable to open '/proc/kallsyms' to probe for io_uring support")
             else:
index 8b48470e6c978b55a7f321e195c529d705edcc86..6aa46e29424adf6bb96180ff1158025469b89ae1 100755 (executable)
@@ -18,6 +18,7 @@ import platform
 import traceback
 import subprocess
 from pathlib import Path
+from fiotestcommon import get_file
 
 
 class FioTest():
@@ -233,20 +234,6 @@ class FioJobFileTest(FioExeTest):
         else:
             logging.debug("Test %d: precondition step failed", self.testnum)
 
-    @classmethod
-    def get_file(cls, filename):
-        """Safely read a file."""
-        file_data = ''
-        success = True
-
-        try:
-            with open(filename, "r", encoding=locale.getpreferredencoding()) as output_file:
-                file_data = output_file.read()
-        except OSError:
-            success = False
-
-        return file_data, success
-
     def get_file_fail(self, filename):
         """Safely read a file and fail the test upon error."""
         file_data = None
@@ -381,9 +368,9 @@ def run_fio_tests(test_list, test_env, args):
         else:
             result = f"FAILED: {test.failure_reason}"
             failed = failed + 1
-            contents, _ = FioJobFileTest.get_file(test.stderr_file)
+            contents, _ = get_file(test.stderr_file)
             logging.debug("Test %d: stderr:\n%s", config['test_id'], contents)
-            contents, _ = FioJobFileTest.get_file(test.stdout_file)
+            contents, _ = get_file(test.stdout_file)
             logging.debug("Test %d: stdout:\n%s", config['test_id'], contents)
         print(f"Test {config['test_id']} {result} {desc}")