123 lines
4.6 KiB
Diff
123 lines
4.6 KiB
Diff
|
From 2ce87cc7a8c662b12900acb9697d74bee0f143f4 Mon Sep 17 00:00:00 2001
|
||
|
From: Benjamin Berg <bberg@redhat.com>
|
||
|
Date: Mon, 13 Jan 2020 17:57:31 +0100
|
||
|
Subject: [PATCH 176/181] tests: Add error reporting tests based on virtual
|
||
|
driver
|
||
|
|
||
|
We were not testing the image device error reporting functions yet
|
||
|
inside libfprint (fprintd already had such tests). Add tests to make
|
||
|
sure we catch errors earlier.
|
||
|
---
|
||
|
tests/virtual-image.py | 61 ++++++++++++++++++++++++++++++++++--------
|
||
|
1 file changed, 50 insertions(+), 11 deletions(-)
|
||
|
|
||
|
diff --git a/tests/virtual-image.py b/tests/virtual-image.py
|
||
|
index 11ec8ae..a6bf6d2 100755
|
||
|
--- a/tests/virtual-image.py
|
||
|
+++ b/tests/virtual-image.py
|
||
|
@@ -99,13 +99,13 @@ class VirtualImage(unittest.TestCase):
|
||
|
|
||
|
def send_retry(self, retry_error=1, iterate=True):
|
||
|
# The default (1) is too-short
|
||
|
- self.sendall(struct.pack('ii', -1, retry_error))
|
||
|
+ self.con.sendall(struct.pack('ii', -1, retry_error))
|
||
|
while iterate and ctx.pending():
|
||
|
ctx.iteration(False)
|
||
|
|
||
|
def send_error(self, device_error=0, iterate=True):
|
||
|
# The default (0) is a generic error
|
||
|
- self.sendall(struct.pack('ii', -1, retry_error))
|
||
|
+ self.con.sendall(struct.pack('ii', -2, device_error))
|
||
|
while iterate and ctx.pending():
|
||
|
ctx.iteration(False)
|
||
|
|
||
|
@@ -212,9 +212,10 @@ class VirtualImage(unittest.TestCase):
|
||
|
done = False
|
||
|
|
||
|
def verify_cb(dev, res):
|
||
|
- match, fp = dev.verify_finish(res)
|
||
|
- self._verify_match = match
|
||
|
- self._verify_fp = fp
|
||
|
+ try:
|
||
|
+ self._verify_match, self._verify_fp = dev.verify_finish(res)
|
||
|
+ except gi.repository.GLib.Error as e:
|
||
|
+ self._verify_error = e
|
||
|
|
||
|
fp_whorl = self.enroll_print('whorl')
|
||
|
|
||
|
@@ -234,20 +235,39 @@ class VirtualImage(unittest.TestCase):
|
||
|
ctx.iteration(True)
|
||
|
assert(not self._verify_match)
|
||
|
|
||
|
+ # Test verify error cases
|
||
|
+ self._verify_fp = None
|
||
|
+ self._verify_error = None
|
||
|
+ self.dev.verify(fp_whorl, callback=verify_cb)
|
||
|
+ self.send_retry()
|
||
|
+ while self._verify_fp is None and self._verify_error is None:
|
||
|
+ ctx.iteration(True)
|
||
|
+ assert(self._verify_error is not None)
|
||
|
+ assert(self._verify_error.matches(FPrint.device_retry_quark(), FPrint.DeviceRetry.TOO_SHORT))
|
||
|
+
|
||
|
+ self._verify_fp = None
|
||
|
+ self._verify_error = None
|
||
|
+ self.dev.verify(fp_whorl, callback=verify_cb)
|
||
|
+ self.send_error()
|
||
|
+ while self._verify_fp is None and self._verify_error is None:
|
||
|
+ ctx.iteration(True)
|
||
|
+ assert(self._verify_error is not None)
|
||
|
+ print(self._verify_error)
|
||
|
+ assert(self._verify_error.matches(FPrint.device_error_quark(), FPrint.DeviceError.GENERAL))
|
||
|
+
|
||
|
def test_identify(self):
|
||
|
done = False
|
||
|
|
||
|
- def verify_cb(dev, res):
|
||
|
- r, fp = dev.verify_finish(res)
|
||
|
- self._verify_match = r
|
||
|
- self._verify_fp = fp
|
||
|
-
|
||
|
fp_whorl = self.enroll_print('whorl')
|
||
|
fp_tented_arch = self.enroll_print('tented_arch')
|
||
|
|
||
|
def identify_cb(dev, res):
|
||
|
print('Identify finished')
|
||
|
- self._identify_match, self._identify_fp = self.dev.identify_finish(res)
|
||
|
+ try:
|
||
|
+ self._identify_match, self._identify_fp = self.dev.identify_finish(res)
|
||
|
+ except gi.repository.GLib.Error as e:
|
||
|
+ print(e)
|
||
|
+ self._identify_error = e
|
||
|
|
||
|
self._identify_fp = None
|
||
|
self.dev.identify([fp_whorl, fp_tented_arch], None, identify_cb)
|
||
|
@@ -263,6 +283,25 @@ class VirtualImage(unittest.TestCase):
|
||
|
ctx.iteration(True)
|
||
|
assert(self._identify_match is fp_whorl)
|
||
|
|
||
|
+ # Test error cases
|
||
|
+ self._identify_fp = None
|
||
|
+ self._identify_error = None
|
||
|
+ self.dev.identify([fp_whorl, fp_tented_arch], callback=identify_cb)
|
||
|
+ self.send_retry()
|
||
|
+ while self._identify_fp is None and self._identify_error is None:
|
||
|
+ ctx.iteration(True)
|
||
|
+ assert(self._identify_error is not None)
|
||
|
+ assert(self._identify_error.matches(FPrint.device_retry_quark(), FPrint.DeviceRetry.TOO_SHORT))
|
||
|
+
|
||
|
+ self._identify_fp = None
|
||
|
+ self._identify_error = None
|
||
|
+ self.dev.identify([fp_whorl, fp_tented_arch], callback=identify_cb)
|
||
|
+ self.send_error()
|
||
|
+ while self._identify_fp is None and self._identify_error is None:
|
||
|
+ ctx.iteration(True)
|
||
|
+ assert(self._identify_error is not None)
|
||
|
+ assert(self._identify_error.matches(FPrint.device_error_quark(), FPrint.DeviceError.GENERAL))
|
||
|
+
|
||
|
def test_verify_serialized(self):
|
||
|
done = False
|
||
|
|
||
|
--
|
||
|
2.24.1
|
||
|
|