[Piglit] [PATCH] Fix the fnctl import on Windows

Dylan Baker dylan at pnwbakers.com
Tue May 31 20:45:15 UTC 2016


Quoting Olivier Berthier (2016-05-30 03:21:14)
> This patch disables the fnctl import on Windows.
> ---
>  framework/monitoring.py | 97 ++++++++++++++++++++++++++-----------------------
>  1 file changed, 52 insertions(+), 45 deletions(-)
> 
> diff --git a/framework/monitoring.py b/framework/monitoring.py
> index f178bd6..9f7a0d1 100644
> --- a/framework/monitoring.py
> +++ b/framework/monitoring.py
> @@ -36,12 +36,17 @@ from __future__ import (
>  )
>  import abc
>  import errno
> -import fcntl
>  import os
>  import re
> +import sys
>  
>  import six
>  
> +try:
> +    import fcntl
> +except:
> +    pass
> +
>  from framework.core import PIGLIT_CONFIG
>  from framework.dmesg import LinuxDmesg
>  from framework import exceptions
> @@ -245,50 +250,52 @@ class MonitoringFile(BaseMonitoring):
>          This implements also a specific method for reading locked files.
>  
>          """
> -
> -        try:
> -            with open(self._monitoring_source, 'r') as f:
> -                lines = []
> -                if self._is_locked:
> -                    # Create a duplicated file descriptor, this avoid lock
> -                    fd = os.dup(f.fileno())
> -                    # use I/O control for reading the lines
> -                    fcntl.fcntl(fd, fcntl.F_SETFL, os.O_NONBLOCK)
> -
> -                    while True:
> -                        try:
> -                            line = os.read(fd, 1024)
> -                            if not line:
> -                                break;
> -                        except OSError as e:
> -                            if e.errno == errno.EAGAIN:
> -                                break
> -                            else:
> -                                raise e
> -                        lines.append(line.decode("utf-8", "strict"))
> -                    os.close(fd)
> -
> -                else:
> -                    lines = f.read().splitlines()
> -
> -                f.close()
> -
> -                # Find all new entries, do this by slicing the list of the lines to only
> -                # returns elements after the last element stored. If there are not
> -                # matches a value error is raised, that means all of the lines are new
> -                l = 0
> -                for index, item in enumerate(reversed(lines)):
> -                    if item == self._last_message:
> -                        l = len(lines) - index  # don't include the matched element
> -                        break
> -                self._new_messages = lines[l:]
> -                # Attempt to store the last element of lines,
> -                # unless there was no line
> -                self._last_message = lines[-1] if lines else None
> -        except Exception:
> -            # if an error occured, we consider there are no new messages
> -            self._new_messages = []
> -            pass
> +        if sys.platform.startswith('linux'):
> +            try:
> +                with open(self._monitoring_source, 'r') as f:
> +                    lines = []
> +                    if self._is_locked:
> +                        # Create a duplicated file descriptor, this avoid lock
> +                        fd = os.dup(f.fileno())
> +                        # use I/O control for reading the lines
> +                        fcntl.fcntl(fd, fcntl.F_SETFL, os.O_NONBLOCK)
> +
> +                        while True:
> +                            try:
> +                                line = os.read(fd, 1024)
> +                                if not line:
> +                                    break;
> +                            except OSError as e:
> +                                if e.errno == errno.EAGAIN:
> +                                    break
> +                                else:
> +                                    raise e
> +                            lines.append(line.decode("utf-8", "strict"))
> +                        os.close(fd)
> +
> +                    else:
> +                        lines = f.read().splitlines()
> +
> +                    f.close()
> +
> +                    # Find all new entries, do this by slicing the list of
> +                    # the lines to only returns elements after the last element
> +                    # stored. If there are not matches a value error is raised,
> +                    # that means all of the lines are new
> +                    l = 0
> +                    for index, item in enumerate(reversed(lines)):
> +                        if item == self._last_message:
> +                            # don't include the matched element
> +                            l = len(lines) - index
> +                            break
> +                    self._new_messages = lines[l:]
> +                    # Attempt to store the last element of lines,
> +                    # unless there was no line
> +                    self._last_message = lines[-1] if lines else None
> +            except Exception:
> +                # if an error occured, we consider there are no new messages
> +                self._new_messages = []
> +                pass
>  
>  
>  class MonitoringLinuxDmesg(BaseMonitoring, LinuxDmesg):
> -- 
> 2.8.1
> 
> _______________________________________________
> Piglit mailing list
> Piglit at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/piglit

Brian, can you have someone test this and see if it works for you?

Dylan
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: signature
URL: <https://lists.freedesktop.org/archives/piglit/attachments/20160531/d701cefc/attachment.sig>


More information about the Piglit mailing list