diff --git a/scripts/pylib/twister/twisterlib/quarantine.py b/scripts/pylib/twister/twisterlib/quarantine.py index cb05a920ca6..e4baa52781e 100644 --- a/scripts/pylib/twister/twisterlib/quarantine.py +++ b/scripts/pylib/twister/twisterlib/quarantine.py @@ -41,6 +41,10 @@ class QuarantineElement: architectures: list[str] = field(default_factory=list) simulations: list[str] = field(default_factory=list) comment: str = 'NA' + re_scenarios: list = field(default_factory=list) + re_platforms: list = field(default_factory=list) + re_architectures: list = field(default_factory=list) + re_simulations: list = field(default_factory=list) def __post_init__(self): # If there is no entry in filters then take all possible values. @@ -53,6 +57,12 @@ class QuarantineElement: self.architectures = [] if 'all' in self.simulations: self.simulations = [] + # keep precompiled regexp entiries to speed-up matching + self.re_scenarios = [re.compile(pat) for pat in self.scenarios] + self.re_platforms = [re.compile(pat) for pat in self.platforms] + self.re_architectures = [re.compile(pat) for pat in self.architectures] + self.re_simulations = [re.compile(pat) for pat in self.simulations] + # However, at least one of the filters ('scenarios', platforms' ...) # must be given (there is no sense to put all possible configuration # into quarantine) @@ -101,16 +111,16 @@ class QuarantineData: for qelem in self.qlist: matched: bool = False if (qelem.scenarios - and (matched := _is_element_matched(scenario, qelem.scenarios)) is False): + and (matched := _is_element_matched(scenario, qelem.re_scenarios)) is False): continue if (qelem.platforms - and (matched := _is_element_matched(platform, qelem.platforms)) is False): + and (matched := _is_element_matched(platform, qelem.re_platforms)) is False): continue if (qelem.architectures - and (matched := _is_element_matched(architecture, qelem.architectures)) is False): + and (matched := _is_element_matched(architecture, qelem.re_architectures)) is False): continue if (qelem.simulations - and (matched := _is_element_matched(simulation, qelem.simulations)) is False): + and (matched := _is_element_matched(simulation, qelem.re_simulations)) is False): continue if matched: @@ -118,9 +128,9 @@ class QuarantineData: return None -def _is_element_matched(element: str, list_of_elements: list) -> bool: +def _is_element_matched(element: str, list_of_elements: list[re.Pattern]) -> bool: """Return True if given element is matching to any of elements from the list""" for pattern in list_of_elements: - if re.fullmatch(pattern, element): + if pattern.fullmatch(element): return True return False diff --git a/scripts/tests/twister/test_quarantine.py b/scripts/tests/twister/test_quarantine.py index 8988d7978ca..1e4b7d2f405 100644 --- a/scripts/tests/twister/test_quarantine.py +++ b/scripts/tests/twister/test_quarantine.py @@ -104,10 +104,9 @@ def test_quarantinedata_post_init(): quarantine_element = QuarantineElement( platforms=['dummy platform'], - architectures=[] + architectures=[], + simulations=['dummy simulation', 'another simulation'] ) - quarantine_element.scenarios = [] - quarantine_element.simulations = ['dummy simulation', 'another simulation'] quarantine_data_qlist = [quarantine_element, quarantine_element_dict]