From: Vincent Fu Date: Fri, 2 Jun 2023 19:04:31 +0000 (+0000) Subject: t/run-fio-tests: move get_file outside of FioJobFileTest X-Git-Tag: fio-3.36~101 X-Git-Url: https://git.kernel.dk/?a=commitdiff_plain;h=ecd6d30fcea14e42d933f1895b2f910cbe84506b;p=fio.git t/run-fio-tests: move get_file outside of FioJobFileTest 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 --- diff --git a/t/fiotestcommon.py b/t/fiotestcommon.py index 8250bf52..f5012c82 100644 --- a/t/fiotestcommon.py +++ b/t/fiotestcommon.py @@ -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: diff --git a/t/fiotestlib.py b/t/fiotestlib.py index 8b48470e..6aa46e29 100755 --- a/t/fiotestlib.py +++ b/t/fiotestlib.py @@ -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}")