[Piglit] [PATCH 1/2] framework/dmesg.py: add a filtering mechanism

Ilia Mirkin imirkin at alum.mit.edu
Wed Apr 30 09:20:31 PDT 2014


On Wed, Apr 30, 2014 at 12:12 PM, Thomas Wood <thomas.wood at intel.com> wrote:
> Only update the test status if at least one of the lines in the dmesg
> output matches the given regular expression.

Would be nice to provide a mechanism to set this on the cmdline too,
but not required as part of this change. Just a thought.

>
> Signed-off-by: Thomas Wood <thomas.wood at intel.com>
> ---
>  framework/dmesg.py | 11 +++++++++++
>  1 file changed, 11 insertions(+)
>
> diff --git a/framework/dmesg.py b/framework/dmesg.py
> index 3af8496..78b8d46 100644
> --- a/framework/dmesg.py
> +++ b/framework/dmesg.py
> @@ -53,6 +53,7 @@ class LinuxDmesg(object):
>          """ Create a dmesg instance """
>          self._last_message = None
>          self._new_messages = []
> +        self.regex = None;
>
>          # Populate self.dmesg initially, otherwise the first test will always
>          # be full of dmesg crud.
> @@ -101,6 +102,16 @@ class LinuxDmesg(object):
>          # if update_dmesg() found new entries replace the results of the test
>          # and subtests
>          if self._new_messages:
> +
> +            if (self.regex is not None):

No need for parens. Also, you can just do

if self.regex:

Since RE objects will implicitly evaluate to true

> +                found = False
> +                for line in self._new_messages:
> +                    if self.regex.search(line) is not None:

Same deal here -- no need for "is not None" -- match objects are
implicitly true. (Which is what .search() returns IIRC.)

> +                        found = True
> +                        break
> +                if not found:
> +                    return result

If you're a fan of "fancy" python, you can use the for/else construct
and write this as:

for line in self._new_messages:
  if self.regex.search(line):
    break
else:
  return result

> +
>              result['result'] = replace(result['result'])
>
>              # Replace any subtests
> --
> 1.9.0
>
> _______________________________________________
> Piglit mailing list
> Piglit at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/piglit


More information about the Piglit mailing list