Re: [kms-test] [PATCH 05/10] kmstest: Support specifying property values in percents

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Quoting Laurent Pinchart (2022-06-10 00:40:26)
> 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.
> 

This seems neat, I'm guessing that following patches are about to show
me the use case, so I'll just throw this in now:


Reviewed-by: Kieran Bingham <kieran.bingham@xxxxxxxxxxxxxxxx>

> Signed-off-by: Laurent Pinchart <laurent.pinchart@xxxxxxxxxxxxxxxx>
> ---
>  tests/kmstest.py | 27 ++++++++++++++++++++++-----
>  1 file changed, 22 insertions(+), 5 deletions(-)
> 
> diff --git a/tests/kmstest.py b/tests/kmstest.py
> index 2afaa513aa4d..a99bf3b89d34 100755
> --- a/tests/kmstest.py
> +++ b/tests/kmstest.py
> @@ -258,8 +258,25 @@ class AtomicRequest(pykms.AtomicReq):
>          self.__test = test
>          self.__props = {}
>  
> -    def __format_props(self, props):
> -        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}')
> +
> +            out[k] = v & ((1 << 64) - 1)
> +        return out
>  
>      def add(self, obj, *kwargs):
>          if obj.id not in self.__props:
> @@ -267,13 +284,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)
> -- 
> Regards,
> 
> Laurent Pinchart
>




[Index of Archives]     [Linux Samsung SOC]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Device Mapper]

  Powered by Linux