From 11404d7162f0e164fa4a3dcd68337cd3a23dcf6b Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Thu, 9 Jun 2022 23:55:01 +0300 Subject: kmstest: Move props value formatting to AtomicRequest Centralize props value formatting in the AtomicRequest.add() function to avoid having to call it manually through the code base. Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- tests/kmstest.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/tests/kmstest.py b/tests/kmstest.py index 14e28cd..cecaaaf 100755 --- a/tests/kmstest.py +++ b/tests/kmstest.py @@ -258,15 +258,22 @@ class AtomicRequest(pykms.AtomicReq): self.__test = test self.__props = {} + def __format_props(self, props): + # Convert negative values to a 64-bit unsigned integer as required + # by the bindings for AtomicRequest::add(). + return {k: v & ((1 << 64) - 1) for k, v in props.items()} + def add(self, obj, *kwargs): if obj.id not in self.__props: self.__props[obj.id] = {} - props = self.__props[obj.id] + obj_props = self.__props[obj.id] if len(kwargs) == 1 and isinstance(kwargs[0], collections.abc.Mapping): - props.update(kwargs[0]) + props = self.__format_props(kwargs[0]) elif len(kwargs) == 2: - props[kwargs[0]] = kwargs[1] + props = self.__format_props({ kwargs[0]: = kwargs[1] }) + + obj_props.update(props) super().add(obj, *kwargs) @@ -309,9 +316,6 @@ class KMSTest(object): def __del__(self): self.logger.close() - def __format_props(self, props): - return {k: v & ((1 << 64) - 1) for k, v in props.items()} - def atomic_crtc_disable(self, crtc, sync=True): req = AtomicRequest(self) req.add(crtc, {'ACTIVE': 0, 'MODE_ID': 0}) @@ -368,7 +372,7 @@ class KMSTest(object): def atomic_plane_set(self, plane, crtc, source, destination, fb, sync=False): req = AtomicRequest(self) - req.add(plane, self.__format_props({ + req.add(plane, { 'FB_ID': fb.id, 'CRTC_ID': crtc.id, 'SRC_X': int(source.left * 65536), @@ -379,7 +383,7 @@ class KMSTest(object): 'CRTC_Y': destination.top, 'CRTC_W': destination.width, 'CRTC_H': destination.height, - })) + }) if sync: return req.commit_sync() else: -- cgit v1.2.3