mirror of
https://gitlab.freedesktop.org/libfprint/libfprint.git
synced 2026-06-11 02:28:05 +00:00
Merge tag 'v1.90.1' into tod
Tag 1.90.1
This commit is contained in:
+30
-7
@@ -26,12 +26,35 @@ if get_option('introspection')
|
||||
envs.prepend('GI_TYPELIB_PATH', join_paths(meson.build_root(), 'libfprint'))
|
||||
|
||||
if 'virtual_image' in drivers
|
||||
test('virtual-image',
|
||||
find_program('virtual-image.py'),
|
||||
args: '--verbose',
|
||||
env: envs,
|
||||
depends: libfprint_typelib,
|
||||
)
|
||||
python3 = find_program('python3')
|
||||
unittest_inspector = find_program('unittest_inspector.py')
|
||||
base_args = files('virtual-image.py')
|
||||
suite = []
|
||||
|
||||
r = run_command(unittest_inspector, files('virtual-image.py'))
|
||||
unit_tests = r.stdout().strip().split('\n')
|
||||
|
||||
if r.returncode() == 0 and unit_tests.length() > 0
|
||||
suite += 'virtual-image'
|
||||
else
|
||||
unit_tests = ['virtual-image']
|
||||
endif
|
||||
|
||||
foreach ut: unit_tests
|
||||
ut_suite = suite
|
||||
ut_args = base_args
|
||||
if unit_tests.length() > 1
|
||||
ut_args += ut
|
||||
ut_suite += ut.split('.')[0]
|
||||
endif
|
||||
test(ut,
|
||||
python3,
|
||||
args: ut_args,
|
||||
suite: ut_suite,
|
||||
depends: libfprint_typelib,
|
||||
env: envs,
|
||||
)
|
||||
endforeach
|
||||
else
|
||||
test('virtual-image',
|
||||
find_program('sh'),
|
||||
@@ -43,7 +66,7 @@ if get_option('introspection')
|
||||
driver_envs = envs
|
||||
driver_envs.set('FP_DRIVERS_WHITELIST', driver_test)
|
||||
|
||||
if driver_test in drivers
|
||||
if driver_test in drivers and gusb_dep.version().version_compare('>= 0.3.0')
|
||||
test(driver_test,
|
||||
find_program('umockdev-test.py'),
|
||||
args: join_paths(meson.current_source_dir(), driver_test),
|
||||
|
||||
+89
-19
@@ -35,9 +35,15 @@ fpi_device_fake_probe (FpDevice *device)
|
||||
FpDeviceClass *dev_class = FP_DEVICE_GET_CLASS (device);
|
||||
FpiDeviceFake *fake_dev = FPI_DEVICE_FAKE (device);
|
||||
|
||||
fake_dev->last_called_function = fpi_device_fake_probe;
|
||||
g_assert_cmpuint (fpi_device_get_current_action (device), ==, FPI_DEVICE_ACTION_PROBE);
|
||||
|
||||
fake_dev->last_called_function = fpi_device_fake_probe;
|
||||
if (fake_dev->return_action_error)
|
||||
{
|
||||
fpi_device_action_error (device, fake_dev->ret_error);
|
||||
return;
|
||||
}
|
||||
|
||||
fpi_device_probe_complete (device, dev_class->id, dev_class->full_name,
|
||||
fake_dev->ret_error);
|
||||
}
|
||||
@@ -47,9 +53,15 @@ fpi_device_fake_open (FpDevice *device)
|
||||
{
|
||||
FpiDeviceFake *fake_dev = FPI_DEVICE_FAKE (device);
|
||||
|
||||
fake_dev->last_called_function = fpi_device_fake_open;
|
||||
g_assert_cmpuint (fpi_device_get_current_action (device), ==, FPI_DEVICE_ACTION_OPEN);
|
||||
|
||||
fake_dev->last_called_function = fpi_device_fake_open;
|
||||
if (fake_dev->return_action_error)
|
||||
{
|
||||
fpi_device_action_error (device, fake_dev->ret_error);
|
||||
return;
|
||||
}
|
||||
|
||||
fpi_device_open_complete (device, fake_dev->ret_error);
|
||||
}
|
||||
|
||||
@@ -58,9 +70,15 @@ fpi_device_fake_close (FpDevice *device)
|
||||
{
|
||||
FpiDeviceFake *fake_dev = FPI_DEVICE_FAKE (device);
|
||||
|
||||
fake_dev->last_called_function = fpi_device_fake_close;
|
||||
g_assert_cmpuint (fpi_device_get_current_action (device), ==, FPI_DEVICE_ACTION_CLOSE);
|
||||
|
||||
fake_dev->last_called_function = fpi_device_fake_close;
|
||||
if (fake_dev->return_action_error)
|
||||
{
|
||||
fpi_device_action_error (device, fake_dev->ret_error);
|
||||
return;
|
||||
}
|
||||
|
||||
fpi_device_close_complete (device, fake_dev->ret_error);
|
||||
}
|
||||
|
||||
@@ -70,13 +88,20 @@ fpi_device_fake_enroll (FpDevice *device)
|
||||
FpiDeviceFake *fake_dev = FPI_DEVICE_FAKE (device);
|
||||
FpPrint *print = fake_dev->ret_print;
|
||||
|
||||
fake_dev->last_called_function = fpi_device_fake_enroll;
|
||||
g_assert_cmpuint (fpi_device_get_current_action (device), ==, FPI_DEVICE_ACTION_ENROLL);
|
||||
|
||||
if (fake_dev->return_action_error)
|
||||
{
|
||||
fpi_device_action_error (device, fake_dev->ret_error);
|
||||
return;
|
||||
}
|
||||
|
||||
fpi_device_get_enroll_data (device, (FpPrint **) &fake_dev->action_data);
|
||||
|
||||
if (!print && !fake_dev->ret_error)
|
||||
fpi_device_get_enroll_data (device, &print);
|
||||
|
||||
fake_dev->last_called_function = fpi_device_fake_enroll;
|
||||
fpi_device_enroll_complete (device,
|
||||
print ? g_object_ref (print) : NULL,
|
||||
fake_dev->ret_error);
|
||||
@@ -88,15 +113,29 @@ fpi_device_fake_verify (FpDevice *device)
|
||||
FpiDeviceFake *fake_dev = FPI_DEVICE_FAKE (device);
|
||||
FpPrint *print = fake_dev->ret_print;
|
||||
|
||||
fake_dev->last_called_function = fpi_device_fake_verify;
|
||||
g_assert_cmpuint (fpi_device_get_current_action (device), ==, FPI_DEVICE_ACTION_VERIFY);
|
||||
|
||||
if (fake_dev->return_action_error)
|
||||
{
|
||||
fpi_device_action_error (device, fake_dev->ret_error);
|
||||
return;
|
||||
}
|
||||
|
||||
fpi_device_get_verify_data (device, (FpPrint **) &fake_dev->action_data);
|
||||
|
||||
if (!print && !fake_dev->ret_error)
|
||||
fpi_device_get_verify_data (device, &print);
|
||||
|
||||
fake_dev->last_called_function = fpi_device_fake_verify;
|
||||
fpi_device_verify_complete (device, fake_dev->ret_result, print,
|
||||
fake_dev->ret_error);
|
||||
if (!fake_dev->ret_error || fake_dev->ret_error->domain == FP_DEVICE_RETRY)
|
||||
{
|
||||
fpi_device_verify_report (device, fake_dev->ret_result, print, fake_dev->ret_error);
|
||||
fpi_device_verify_complete (device, NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
fpi_device_verify_complete (device, fake_dev->ret_error);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -105,7 +144,15 @@ fpi_device_fake_identify (FpDevice *device)
|
||||
FpiDeviceFake *fake_dev = FPI_DEVICE_FAKE (device);
|
||||
FpPrint *match = fake_dev->ret_match;
|
||||
|
||||
fake_dev->last_called_function = fpi_device_fake_identify;
|
||||
g_assert_cmpuint (fpi_device_get_current_action (device), ==, FPI_DEVICE_ACTION_IDENTIFY);
|
||||
|
||||
if (fake_dev->return_action_error)
|
||||
{
|
||||
fpi_device_action_error (device, fake_dev->ret_error);
|
||||
return;
|
||||
}
|
||||
|
||||
fpi_device_get_identify_data (device, (GPtrArray **) &fake_dev->action_data);
|
||||
|
||||
if (!match && !fake_dev->ret_error)
|
||||
@@ -127,9 +174,15 @@ fpi_device_fake_identify (FpDevice *device)
|
||||
}
|
||||
}
|
||||
|
||||
fake_dev->last_called_function = fpi_device_fake_identify;
|
||||
fpi_device_identify_complete (device, match, fake_dev->ret_print,
|
||||
fake_dev->ret_error);
|
||||
if (!fake_dev->ret_error || fake_dev->ret_error->domain == FP_DEVICE_RETRY)
|
||||
{
|
||||
fpi_device_identify_report (device, match, fake_dev->ret_print, fake_dev->ret_error);
|
||||
fpi_device_identify_complete (device, NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
fpi_device_identify_complete (device, fake_dev->ret_error);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -137,10 +190,16 @@ fpi_device_fake_capture (FpDevice *device)
|
||||
{
|
||||
FpiDeviceFake *fake_dev = FPI_DEVICE_FAKE (device);
|
||||
|
||||
g_assert_cmpuint (fpi_device_get_current_action (device), ==, FPI_DEVICE_ACTION_CAPTURE);
|
||||
fpi_device_get_capture_data (device, (gboolean *) &fake_dev->action_data);
|
||||
|
||||
fake_dev->last_called_function = fpi_device_fake_capture;
|
||||
g_assert_cmpuint (fpi_device_get_current_action (device), ==, FPI_DEVICE_ACTION_CAPTURE);
|
||||
|
||||
if (fake_dev->return_action_error)
|
||||
{
|
||||
fpi_device_action_error (device, fake_dev->ret_error);
|
||||
return;
|
||||
}
|
||||
|
||||
fpi_device_get_capture_data (device, (gboolean *) &fake_dev->action_data);
|
||||
fpi_device_capture_complete (device, fake_dev->ret_image, fake_dev->ret_error);
|
||||
}
|
||||
|
||||
@@ -149,9 +208,15 @@ fpi_device_fake_list (FpDevice *device)
|
||||
{
|
||||
FpiDeviceFake *fake_dev = FPI_DEVICE_FAKE (device);
|
||||
|
||||
fake_dev->last_called_function = fpi_device_fake_list;
|
||||
g_assert_cmpuint (fpi_device_get_current_action (device), ==, FPI_DEVICE_ACTION_LIST);
|
||||
|
||||
fake_dev->last_called_function = fpi_device_fake_list;
|
||||
if (fake_dev->return_action_error)
|
||||
{
|
||||
fpi_device_action_error (device, fake_dev->ret_error);
|
||||
return;
|
||||
}
|
||||
|
||||
fpi_device_list_complete (device, fake_dev->ret_list, fake_dev->ret_error);
|
||||
}
|
||||
|
||||
@@ -160,10 +225,16 @@ fpi_device_fake_delete (FpDevice *device)
|
||||
{
|
||||
FpiDeviceFake *fake_dev = FPI_DEVICE_FAKE (device);
|
||||
|
||||
g_assert_cmpuint (fpi_device_get_current_action (device), ==, FPI_DEVICE_ACTION_DELETE);
|
||||
fpi_device_get_delete_data (device, (gpointer) & fake_dev->action_data);
|
||||
|
||||
fake_dev->last_called_function = fpi_device_fake_delete;
|
||||
g_assert_cmpuint (fpi_device_get_current_action (device), ==, FPI_DEVICE_ACTION_DELETE);
|
||||
|
||||
if (fake_dev->return_action_error)
|
||||
{
|
||||
fpi_device_action_error (device, fake_dev->ret_error);
|
||||
return;
|
||||
}
|
||||
|
||||
fpi_device_get_delete_data (device, (gpointer) (&fake_dev->action_data));
|
||||
fpi_device_delete_complete (device, fake_dev->ret_error);
|
||||
}
|
||||
|
||||
@@ -172,9 +243,8 @@ fpi_device_fake_cancel (FpDevice *device)
|
||||
{
|
||||
FpiDeviceFake *fake_dev = FPI_DEVICE_FAKE (device);
|
||||
|
||||
g_assert_cmpuint (fpi_device_get_current_action (device), !=, FPI_DEVICE_ACTION_NONE);
|
||||
|
||||
fake_dev->last_called_function = fpi_device_fake_cancel;
|
||||
g_assert_cmpuint (fpi_device_get_current_action (device), !=, FPI_DEVICE_ACTION_NONE);
|
||||
}
|
||||
|
||||
static void
|
||||
|
||||
@@ -30,6 +30,7 @@ struct _FpiDeviceFake
|
||||
FpDevice parent;
|
||||
|
||||
gpointer last_called_function;
|
||||
gboolean return_action_error;
|
||||
|
||||
GError *ret_error;
|
||||
FpPrint *ret_print;
|
||||
|
||||
+905
-62
File diff suppressed because it is too large
Load Diff
Executable
+46
@@ -0,0 +1,46 @@
|
||||
#! /usr/bin/env python3
|
||||
# Copyright © 2020, Canonical Ltd
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2.1 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public
|
||||
# License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
# Authors:
|
||||
# Marco Trevisan <marco.trevisan@canonical.com>
|
||||
|
||||
import argparse
|
||||
import importlib.util
|
||||
import inspect
|
||||
import os
|
||||
import unittest
|
||||
|
||||
def list_tests(module):
|
||||
tests = []
|
||||
for name, obj in inspect.getmembers(module):
|
||||
if inspect.isclass(obj) and issubclass(obj, unittest.TestCase):
|
||||
cases = unittest.defaultTestLoader.getTestCaseNames(obj)
|
||||
tests += [ (obj, '{}.{}'.format(name, t)) for t in cases ]
|
||||
return tests
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('unittest_source', type=argparse.FileType('r'))
|
||||
|
||||
args = parser.parse_args()
|
||||
source_path = args.unittest_source.name
|
||||
spec = importlib.util.spec_from_file_location(
|
||||
os.path.basename(source_path), source_path)
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(module)
|
||||
|
||||
for machine, human in list_tests(module):
|
||||
print(human)
|
||||
+79
-38
@@ -1,20 +1,24 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
|
||||
import gi
|
||||
gi.require_version('FPrint', '2.0')
|
||||
from gi.repository import FPrint, GLib, Gio
|
||||
|
||||
import os
|
||||
import sys
|
||||
import unittest
|
||||
import socket
|
||||
import struct
|
||||
import subprocess
|
||||
import shutil
|
||||
import glob
|
||||
import cairo
|
||||
import tempfile
|
||||
try:
|
||||
import gi
|
||||
gi.require_version('FPrint', '2.0')
|
||||
from gi.repository import FPrint, GLib, Gio
|
||||
|
||||
import os
|
||||
import sys
|
||||
import unittest
|
||||
import socket
|
||||
import struct
|
||||
import subprocess
|
||||
import shutil
|
||||
import glob
|
||||
import cairo
|
||||
import tempfile
|
||||
except Exception as e:
|
||||
print("Missing dependencies: %s" % str(e))
|
||||
sys.exit(77)
|
||||
|
||||
# Re-run the test with the passed wrapper if set
|
||||
wrapper = os.getenv('LIBFPRINT_TEST_WRAPPER')
|
||||
@@ -97,15 +101,13 @@ class VirtualImage(unittest.TestCase):
|
||||
del self.con
|
||||
self.dev.close_sync()
|
||||
|
||||
def send_retry(self, retry_error=1, iterate=True):
|
||||
# The default (1) is too-short
|
||||
self.sendall(struct.pack('ii', -1, retry_error))
|
||||
def send_retry(self, retry_error=FPrint.DeviceRetry.TOO_SHORT, iterate=True):
|
||||
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))
|
||||
def send_error(self, device_error=FPrint.DeviceError.GENERAL, iterate=True):
|
||||
self.con.sendall(struct.pack('ii', -2, device_error))
|
||||
while iterate and ctx.pending():
|
||||
ctx.iteration(False)
|
||||
|
||||
@@ -212,15 +214,16 @@ 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')
|
||||
|
||||
self._verify_match = None
|
||||
self._verify_fp = None
|
||||
self.dev.verify(fp_whorl, None, verify_cb)
|
||||
self.dev.verify(fp_whorl, callback=verify_cb)
|
||||
self.send_image('whorl')
|
||||
while self._verify_match is None:
|
||||
ctx.iteration(True)
|
||||
@@ -228,41 +231,79 @@ class VirtualImage(unittest.TestCase):
|
||||
|
||||
self._verify_match = None
|
||||
self._verify_fp = None
|
||||
self.dev.verify(fp_whorl, None, verify_cb)
|
||||
self.dev.verify(fp_whorl, callback=verify_cb)
|
||||
self.send_image('tented_arch')
|
||||
while self._verify_match is None:
|
||||
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)
|
||||
self.dev.identify([fp_whorl, fp_tented_arch], callback=identify_cb)
|
||||
self.send_image('tented_arch')
|
||||
while self._identify_fp is None:
|
||||
ctx.iteration(True)
|
||||
assert(self._identify_match is fp_tented_arch)
|
||||
|
||||
self._identify_fp = None
|
||||
self.dev.identify([fp_whorl, fp_tented_arch], None, identify_cb)
|
||||
self.dev.identify([fp_whorl, fp_tented_arch], callback=identify_cb)
|
||||
self.send_image('whorl')
|
||||
while self._identify_fp is None:
|
||||
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
|
||||
|
||||
@@ -290,7 +331,7 @@ class VirtualImage(unittest.TestCase):
|
||||
|
||||
self._verify_match = None
|
||||
self._verify_fp = None
|
||||
self.dev.verify(fp_whorl_new, None, verify_cb)
|
||||
self.dev.verify(fp_whorl_new, callback=verify_cb)
|
||||
self.send_image('whorl')
|
||||
while self._verify_match is None:
|
||||
ctx.iteration(True)
|
||||
@@ -298,12 +339,12 @@ class VirtualImage(unittest.TestCase):
|
||||
|
||||
self._verify_match = None
|
||||
self._verify_fp = None
|
||||
self.dev.verify(fp_whorl_new, None, verify_cb)
|
||||
self.dev.verify(fp_whorl_new, callback=verify_cb)
|
||||
self.send_image('tented_arch')
|
||||
while self._verify_match is None:
|
||||
ctx.iteration(True)
|
||||
assert(not self._verify_match)
|
||||
|
||||
# avoid writing to stderr
|
||||
unittest.main(testRunner=unittest.TextTestRunner(stream=sys.stdout, verbosity=2))
|
||||
|
||||
if __name__ == '__main__':
|
||||
# avoid writing to stderr
|
||||
unittest.main(testRunner=unittest.TextTestRunner(stream=sys.stdout, verbosity=2))
|
||||
|
||||
Reference in New Issue
Block a user