summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2022-06-10 00:22:44 +0300
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2022-06-29 21:16:22 +0300
commit4d15a071e3ee73f769087859c04e0b7de5ac36dd (patch)
tree9657fae2c8e2e5f21196415c6d71ed14a93d51a6
parent11404d7162f0e164fa4a3dcd68337cd3a23dcf6b (diff)
kmstest: Support specifying property values in percents
If the property is a string that ends with a '%' character, treat it as a percentage of the range reported by the property and convert it to the corresponding numerical value. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
-rwxr-xr-xtests/kmstest.py31
1 files changed, 24 insertions, 7 deletions
diff --git a/tests/kmstest.py b/tests/kmstest.py
index cecaaaf..ac95456 100755
--- a/tests/kmstest.py
+++ b/tests/kmstest.py
@@ -258,10 +258,27 @@ 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 __format_props(self, obj, props):
+ out = {}
+ for k, v in props.items():
+ if isinstance(v, str):
+ if v.endswith('%'):
+ prop = obj.get_prop(k)
+ if prop.type not in (pykms.PropertyType.Range, pykms.PropertyType.SignedRange):
+ raise RuntimeError(f'Unsupported property type {prop.type} for value {v}')
+
+ min, max = prop.values
+ v = min + int((max - min) * int(v[:-1]) / 100)
+ else:
+ v = int(v)
+
+ if not isinstance(v, int):
+ raise RuntimeError(f'Unsupported value type {type(v)} for property {k}')
+
+ # Convert negative values to a 64-bit unsigned integer as required
+ # by the bindings for AtomicRequest::add().
+ out[k] = v & ((1 << 64) - 1)
+ return out
def add(self, obj, *kwargs):
if obj.id not in self.__props:
@@ -269,13 +286,13 @@ class AtomicRequest(pykms.AtomicReq):
obj_props = self.__props[obj.id]
if len(kwargs) == 1 and isinstance(kwargs[0], collections.abc.Mapping):
- props = self.__format_props(kwargs[0])
+ props = self.__format_props(obj, kwargs[0])
elif len(kwargs) == 2:
- props = self.__format_props({ kwargs[0]: = kwargs[1] })
+ props = self.__format_props(obj, { kwargs[0]: kwargs[1] })
obj_props.update(props)
- super().add(obj, *kwargs)
+ super().add(obj, props)
def commit(self, data=0, allow_modeset=False):
ret = super().commit(data, allow_modeset)