From dd6a670eef2a3175a22831b503f71d5afcea063e Mon Sep 17 00:00:00 2001 From: duerpei Date: Wed, 19 Apr 2023 13:52:06 +0800 Subject: tests: add precheck func for test suites under LTP Add precheck func for test suites under LTP. Ensure that the test suites could be skipped if the test conditions are not met. Bug-AGL: SPEC-4755 Signed-off-by: duerpei Change-Id: Ib605a2109d04dd4f8544ef9a10f63c172489e827 --- tests/LTP/agl_test_ltp_base.py | 3 +++ tests/LTP/cve/run_tests.py | 2 ++ tests/LTP/math/run_tests.py | 2 ++ tests/LTP/posix_conformance_tests/run_tests.py | 9 ++++++--- tests/LTP/syscalls/run_tests.py | 2 ++ 5 files changed, 15 insertions(+), 3 deletions(-) diff --git a/tests/LTP/agl_test_ltp_base.py b/tests/LTP/agl_test_ltp_base.py index 982e60d..06f3642 100644 --- a/tests/LTP/agl_test_ltp_base.py +++ b/tests/LTP/agl_test_ltp_base.py @@ -37,6 +37,9 @@ class LTPBase(AGLBaseTest): reObj = re.compile('^([\\w\\-]+)(\\s+)(\\w+)', re.MULTILINE) test_file = self.LTPTEST + self.test_name + path_obj = pathlib.Path(test_file) + if not path_obj.is_file(): + return case_list test_cases = open(test_file, 'r') line = test_cases.readline() while line: diff --git a/tests/LTP/cve/run_tests.py b/tests/LTP/cve/run_tests.py index f8e864f..8ed99e5 100644 --- a/tests/LTP/cve/run_tests.py +++ b/tests/LTP/cve/run_tests.py @@ -21,6 +21,8 @@ class CveBase(LTPBase): os.environ['KCONFIG_SKIP_CHECK'] = "True" instance = CveBase() +skip_msg = "The current environment does not match the test requirements." +pytestmark = pytest.mark.skipif(instance.precheck() == False, reason = skip_msg) test_case_list = instance.get_test_case_list() @pytest.fixture(scope='module') diff --git a/tests/LTP/math/run_tests.py b/tests/LTP/math/run_tests.py index 9f82915..e288534 100644 --- a/tests/LTP/math/run_tests.py +++ b/tests/LTP/math/run_tests.py @@ -7,6 +7,8 @@ class MathBase(LTPBase): super().__init__(test_name="math") instance = MathBase() +skip_msg = "The current environment does not match the test requirements." +pytestmark = pytest.mark.skipif(instance.precheck() == False, reason = skip_msg) test_case_list = instance.get_test_case_list() @pytest.fixture(scope='module') diff --git a/tests/LTP/posix_conformance_tests/run_tests.py b/tests/LTP/posix_conformance_tests/run_tests.py index 9d8405d..a081743 100644 --- a/tests/LTP/posix_conformance_tests/run_tests.py +++ b/tests/LTP/posix_conformance_tests/run_tests.py @@ -24,6 +24,8 @@ class Conformance_Base(LTPBase): case_name_list = [] # root path root_dir = pathlib.Path(self.LTPDIR + "./conformance/interfaces/") + if not root_dir.is_dir(): + return case_name_list # search case name by .run-test/.sh files without run.sh for child in root_dir.iterdir(): if child.is_file(): @@ -103,11 +105,12 @@ def local_precheck(): #write test suite info to file instance.write_skip_info() return output + +instance = Conformance_Base() skip_msg = "The current environment does not match the test requirements." -pytestmark = pytest.mark.skipif(local_precheck() == False, reason = skip_msg) +pytestmark = pytest.mark.skipif(local_precheck() == False or instance.precheck() == False, reason = skip_msg) -instance_paramtrize = Conformance_Base() -@pytest.mark.parametrize('case_name', instance_paramtrize.init_param_list()) +@pytest.mark.parametrize('case_name', instance.init_param_list()) def test_posix_conformance(testbase: Conformance_Base, case_name): testbase.run_case(case_name) diff --git a/tests/LTP/syscalls/run_tests.py b/tests/LTP/syscalls/run_tests.py index 37bd365..5421f28 100644 --- a/tests/LTP/syscalls/run_tests.py +++ b/tests/LTP/syscalls/run_tests.py @@ -40,6 +40,8 @@ class SyscallsBase(LTPBase): cwd=cwd_buf, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) instance = SyscallsBase() +skip_msg = "The current environment does not match the test requirements." +pytestmark = pytest.mark.skipif(instance.precheck() == False, reason = skip_msg) case_list = instance.get_test_case_list() @pytest.fixture(scope='module') -- cgit 1.2.3-korg