Fix the fnctl import on Windows

Submitted by Olivier Berthier on May 30, 2016, 10:21 a.m.

Details

Message ID 1464603674-30833-1-git-send-email-olivierx.berthier@linux.intel.com
State New
Headers show
Series "Fix the fnctl import on Windows" ( rev: 1 ) in Piglit

Not browsing as part of any series.

Commit Message

Olivier Berthier May 30, 2016, 10:21 a.m.
This patch disables the fnctl import on Windows.
---
 framework/monitoring.py | 97 ++++++++++++++++++++++++++-----------------------
 1 file changed, 52 insertions(+), 45 deletions(-)

Patch hide | download patch | download mbox

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):

Comments

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@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
On Tue, May 31, 2016 at 1:45 PM, Dylan Baker <dylan@pnwbakers.com> 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@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
>
> _______________________________________________
> Piglit mailing list
> Piglit@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/piglit
>

This patch disables fnctl import on all non-Linux instead of just Windows.
Quoting Olivier Berthier (2016-05-30 03:21:14)
[snip]
> +        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)

I'm very confused here. What exactly is a locked file? Since on Linux at
least you can read a locked file as long as you have the proper
permissions I can't figure out what locking has to do with this code.
With the test you provided if I replace the whole of 'lines = []'
through 'f.close()' with 'lines = f.readlines()' the test passes, so
either the code here is bogus, the test is bogus, or both.

I think if we need to rely on POSIX-only modules then we need to guard
is_locked behind os.name == 'posix' or similar.

Dylan

> +
> +                    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
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@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
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@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
On Wednesday 01 Jun 2016 à 15:22:12 (-0700), Dylan Baker wrote:
> Quoting Olivier Berthier (2016-05-30 03:21:14)
> [snip]
> > +        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)
> 
> I'm very confused here. What exactly is a locked file? Since on Linux at
> least you can read a locked file as long as you have the proper
> permissions I can't figure out what locking has to do with this code.
> With the test you provided if I replace the whole of 'lines = []'
> through 'f.close()' with 'lines = f.readlines()' the test passes, so
> either the code here is bogus, the test is bogus, or both.
> 
> I think if we need to rely on POSIX-only modules then we need to guard
> is_locked behind os.name == 'posix' or similar.
> 
> Dylan
> 

I used this methode instead of readlines() because it works with standard files
and with the files like /dev/kmsg. I think it increase the field of view for
monitoring.

However, if there is another way I can change it. Or if reading these files
don't provides any relevant information we can't find in dmesg or in another
log, we can juste change to readlines() and remove fnctl.

Olivier

> > +
> > +                    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