From 84f6799444868410893693bbb3e08e5e2bb761dc Mon Sep 17 00:00:00 2001 From: Jake Turner Date: Thu, 7 Nov 2024 14:55:51 +0000 Subject: [PATCH] Improve testcase _find_action Search for the action with the closest EID to the request Previously it would return the first action that was larger than the EID --- util/test/rdtest/testcase.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/util/test/rdtest/testcase.py b/util/test/rdtest/testcase.py index 3ba1d1171..3d38611c6 100644 --- a/util/test/rdtest/testcase.py +++ b/util/test/rdtest/testcase.py @@ -263,22 +263,28 @@ class TestCase: def _find_action(self, name: str, start_event: int, action_list): action: rd.ActionDescription + bestMatch = None + distance = 1000000 for action in action_list: # If this action matches, return it if action.eventId >= start_event and (name == '' or name in self.action_name(action)): - return action + if action.eventId - start_event < distance: + bestMatch = action + distance = action.eventId - start_event # Recurse to children - depth-first search ret: rd.ActionDescription = self._find_action(name, start_event, action.children) # If we found our action, return if ret is not None: - return ret + if ret.eventId - start_event < distance: + bestMatch = ret + distance = ret.eventId - start_event # Otherwise continue to next in the list # If we didn't find anything, return None - return None + return bestMatch def find_action(self, name: str, start_event: int = 0): """