mirror of
https://gitlab.freedesktop.org/libfprint/fprintd.git
synced 2026-01-31 08:40:29 +01:00
tests: Pull more OutputChecker fixes
While debugging the g-s-d testsuite a few more issues in the OutputChecker code came up. Pull in these fixes ensuring that EOF and the read side FD are handled correctly.
This commit is contained in:
parent
f4995dcabe
commit
9ae3c16f2d
1 changed files with 24 additions and 5 deletions
|
|
@ -58,12 +58,19 @@ class OutputChecker(object):
|
|||
|
||||
r = os.read(self._pipe_fd_r, 1024)
|
||||
if not r:
|
||||
os.close(self._pipe_fd_r)
|
||||
self._pipe_fd_r = -1
|
||||
self._lines_sem.release()
|
||||
return
|
||||
except OSError as e:
|
||||
if e.errno == errno.EWOULDBLOCK:
|
||||
continue
|
||||
|
||||
# We get a bad file descriptor error when the outside closes the FD
|
||||
if self._pipe_fd_r >= 0:
|
||||
os.close(self._pipe_fd_r)
|
||||
self._pipe_fd_r = -1
|
||||
self._lines_sem.release()
|
||||
return
|
||||
|
||||
l = r.split(b'\n')
|
||||
|
|
@ -88,6 +95,13 @@ class OutputChecker(object):
|
|||
try:
|
||||
l = self._lines.pop(0)
|
||||
except IndexError:
|
||||
# EOF, throw error
|
||||
if self._pipe_fd_r == -1:
|
||||
if failmsg:
|
||||
raise AssertionError("No further messages: " % failmsg)
|
||||
else:
|
||||
raise AssertionError('No client waiting for needle %s' % (str(needle_re)))
|
||||
|
||||
# Check if should wake up
|
||||
if not self._lines_sem.acquire(timeout = deadline - time.time()):
|
||||
if failmsg:
|
||||
|
|
@ -121,6 +135,10 @@ class OutputChecker(object):
|
|||
try:
|
||||
l = self._lines.pop(0)
|
||||
except IndexError:
|
||||
# EOF, so everything good
|
||||
if self._pipe_fd_r == -1:
|
||||
break
|
||||
|
||||
# Check if should wake up
|
||||
if not self._lines_sem.acquire(timeout = deadline - time.time()):
|
||||
# Timed out, so everything is good
|
||||
|
|
@ -159,7 +177,8 @@ class OutputChecker(object):
|
|||
|
||||
fd = self._pipe_fd_r
|
||||
self._pipe_fd_r = -1
|
||||
os.close(fd)
|
||||
if fd >= 0:
|
||||
os.close(fd)
|
||||
|
||||
self._thread.join()
|
||||
|
||||
|
|
@ -172,9 +191,9 @@ class OutputChecker(object):
|
|||
self._pipe_fd_w = -1
|
||||
|
||||
def __del__(self):
|
||||
if self._pipe_fd_r > 0:
|
||||
if self._pipe_fd_r >= 0:
|
||||
os.close(self._pipe_fd_r)
|
||||
if self._pipe_fd_w > 0:
|
||||
self._pipe_fd_r = -1
|
||||
if self._pipe_fd_w >= 0:
|
||||
os.close(self._pipe_fd_w)
|
||||
|
||||
assert not self._thread.is_alive()
|
||||
self._pipe_fd_w = -1
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue