From 125817aff0fd86d500b5add8e4cd6622724d32f9 Mon Sep 17 00:00:00 2001 From: "Chi Song (from Dev Box)" Date: Wed, 2 Oct 2024 16:32:17 -0700 Subject: [PATCH] check platforms to prevent mismached feature types. --- lisa/runners/lisa_runner.py | 17 +++++++--------- lisa/testsuite.py | 39 +++++++++++++++++++++++++++++++++++-- 2 files changed, 44 insertions(+), 12 deletions(-) diff --git a/lisa/runners/lisa_runner.py b/lisa/runners/lisa_runner.py index 6de9e38c3..c9fa1abbc 100644 --- a/lisa/runners/lisa_runner.py +++ b/lisa/runners/lisa_runner.py @@ -655,7 +655,9 @@ class LisaRunner(BaseRunner): tested_environment = environment.get_guest_environment() try: if result.check_environment( - environment=tested_environment, save_reason=True + environment=tested_environment, + environment_platform_type=self.platform.type_name(), + save_reason=True, ) and ( not result.runtime_data.use_new_environment or environment.is_new @@ -784,9 +786,6 @@ class LisaRunner(BaseRunner): platform_type: str, ) -> None: assert platform_type - platform_type_set = search_space.SetSpace[str]( - is_allow_set=True, items=[platform_type] - ) cases_ignored_features: Dict[str, Set[str]] = {} # if platform defined requirement, replace the requirement from @@ -797,12 +796,10 @@ class LisaRunner(BaseRunner): platform_requirement = self._create_platform_requirement() test_req: TestCaseRequirement = test_result.runtime_data.requirement - # check if there is platform requirement on test case - if test_req.platform_type and len(test_req.platform_type) > 0: - check_result = platform_type_set.check(test_req.platform_type) - if not check_result.result: - test_result.set_status(TestStatus.SKIPPED, check_result.reasons) - continue + check_result = test_result.check_platform(platform_type) + if not check_result.result: + test_result.set_status(TestStatus.SKIPPED, check_result.reasons) + continue if test_result.can_run: assert test_req.environment diff --git a/lisa/testsuite.py b/lisa/testsuite.py index ffe2dfe25..1e6dbedab 100644 --- a/lisa/testsuite.py +++ b/lisa/testsuite.py @@ -187,11 +187,23 @@ class TestResult: self._send_result_message(self.stacktrace) def check_environment( - self, environment: Environment, save_reason: bool = False + self, + environment: Environment, + # The environment platform may not be associated to the environment at + # early stage, so pass it in to validate. + environment_platform_type: str = "", + save_reason: bool = False, ) -> bool: requirement = self.runtime_data.metadata.requirement assert requirement.environment - check_result = requirement.environment.check(environment.capability) + + check_result = search_space.ResultReason() + if environment_platform_type: + check_result = self.check_platform(environment_platform_type) + + if check_result.result: + check_result = requirement.environment.check(environment.capability) + if ( check_result.result and requirement.os_type @@ -230,6 +242,29 @@ class TestResult: return self._timer.elapsed(False) + def check_platform( + self, environment_platform_type: str + ) -> search_space.ResultReason: + result = search_space.ResultReason() + + assert environment_platform_type, "platform type is not defined" + environment_platform_type_set = search_space.SetSpace[str]( + is_allow_set=True, items=[environment_platform_type] + ) + # only check platform, when it's defined. + if ( + not self.runtime_data.requirement + or not self.runtime_data.requirement.platform_type + or len(self.runtime_data.requirement.platform_type.items) == 0 + ): + return result + + test_supported_platforms = self.runtime_data.requirement.platform_type + + result = environment_platform_type_set.check(test_supported_platforms) + + return result + def _send_result_message(self, stacktrace: Optional[str] = None) -> None: self.elapsed = self.get_elapsed()