summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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)