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

Dylan Baker dylan at pnwbakers.com
Wed Jun 1 23:34:49 UTC 2016


Quoting Brian Paul (2016-06-01 16:21:07)
> On 05/31/2016 02:45 PM, Dylan Baker wrote:
> > 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?
> 
> Unfortunately, I don't have a build environment set up in Windows to 
> build Piglit ATM.  We normally build it on a Jenkins/Hudson system and I 
> grab it from there.
> 
> Maybe we could revert the original patch until I can get set up here?
> 
> -Brian
> 

I have a branch with appveyor support, and I'm basically ready to send
that out for review. I've used to get a patch that I think should get
things working and I'll send that out in a few minutes.

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/20160601/60272f6c/attachment-0001.sig>


More information about the Piglit mailing list