|
|
73b847 |
From 61e3951e442b6ff8b6ab7ba651e028e61df3aa41 Mon Sep 17 00:00:00 2001
|
|
|
73b847 |
From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= <mail@3v1n0.net>
|
|
|
73b847 |
Date: Fri, 13 Dec 2019 20:34:08 +0100
|
|
|
73b847 |
Subject: [PATCH 113/181] fp-context: Use an env to define a whitelist of
|
|
|
73b847 |
drivers to enable
|
|
|
73b847 |
|
|
|
73b847 |
This avoids that we pick unwanted drivers when running the tests in a
|
|
|
73b847 |
machine that has some supported device attached.
|
|
|
73b847 |
---
|
|
|
73b847 |
libfprint/fp-context.c | 45 ++++++++++++++++++++++++++++++++++++++++++
|
|
|
73b847 |
tests/meson.build | 8 +++++++-
|
|
|
73b847 |
2 files changed, 52 insertions(+), 1 deletion(-)
|
|
|
73b847 |
|
|
|
73b847 |
diff --git a/libfprint/fp-context.c b/libfprint/fp-context.c
|
|
|
73b847 |
index 3e47f03..6764241 100644
|
|
|
73b847 |
--- a/libfprint/fp-context.c
|
|
|
73b847 |
+++ b/libfprint/fp-context.c
|
|
|
73b847 |
@@ -57,6 +57,35 @@ enum {
|
|
|
73b847 |
};
|
|
|
73b847 |
static guint signals[LAST_SIGNAL] = { 0 };
|
|
|
73b847 |
|
|
|
73b847 |
+static const char *
|
|
|
73b847 |
+get_drivers_whitelist_env (void)
|
|
|
73b847 |
+{
|
|
|
73b847 |
+ return g_getenv ("FP_DRIVERS_WHITELIST");
|
|
|
73b847 |
+}
|
|
|
73b847 |
+
|
|
|
73b847 |
+static gboolean
|
|
|
73b847 |
+is_driver_allowed (const gchar *driver)
|
|
|
73b847 |
+{
|
|
|
73b847 |
+ g_auto(GStrv) whitelisted_drivers = NULL;
|
|
|
73b847 |
+ const char *fp_drivers_whitelist_env;
|
|
|
73b847 |
+ int i;
|
|
|
73b847 |
+
|
|
|
73b847 |
+ g_return_val_if_fail (driver, TRUE);
|
|
|
73b847 |
+
|
|
|
73b847 |
+ fp_drivers_whitelist_env = get_drivers_whitelist_env ();
|
|
|
73b847 |
+
|
|
|
73b847 |
+ if (!fp_drivers_whitelist_env)
|
|
|
73b847 |
+ return TRUE;
|
|
|
73b847 |
+
|
|
|
73b847 |
+ whitelisted_drivers = g_strsplit (fp_drivers_whitelist_env, ":", -1);
|
|
|
73b847 |
+
|
|
|
73b847 |
+ for (i = 0; whitelisted_drivers[i]; ++i)
|
|
|
73b847 |
+ if (g_strcmp0 (driver, whitelisted_drivers[i]) == 0)
|
|
|
73b847 |
+ return TRUE;
|
|
|
73b847 |
+
|
|
|
73b847 |
+ return FALSE;
|
|
|
73b847 |
+}
|
|
|
73b847 |
+
|
|
|
73b847 |
static void
|
|
|
73b847 |
async_device_init_done_cb (GObject *source_object, GAsyncResult *res, gpointer user_data)
|
|
|
73b847 |
{
|
|
|
73b847 |
@@ -242,9 +271,25 @@ fp_context_init (FpContext *self)
|
|
|
73b847 |
{
|
|
|
73b847 |
g_autoptr(GError) error = NULL;
|
|
|
73b847 |
FpContextPrivate *priv = fp_context_get_instance_private (self);
|
|
|
73b847 |
+ guint i;
|
|
|
73b847 |
|
|
|
73b847 |
priv->drivers = fpi_get_driver_types ();
|
|
|
73b847 |
|
|
|
73b847 |
+ if (get_drivers_whitelist_env ())
|
|
|
73b847 |
+ {
|
|
|
73b847 |
+ for (i = 0; i < priv->drivers->len;)
|
|
|
73b847 |
+ {
|
|
|
73b847 |
+ GType driver = g_array_index (priv->drivers, GType, i);
|
|
|
73b847 |
+ g_autoptr(GTypeClass) type_class = g_type_class_ref (driver);
|
|
|
73b847 |
+ FpDeviceClass *cls = FP_DEVICE_CLASS (type_class);
|
|
|
73b847 |
+
|
|
|
73b847 |
+ if (!is_driver_allowed (cls->id))
|
|
|
73b847 |
+ g_array_remove_index (priv->drivers, i);
|
|
|
73b847 |
+ else
|
|
|
73b847 |
+ ++i;
|
|
|
73b847 |
+ }
|
|
|
73b847 |
+ }
|
|
|
73b847 |
+
|
|
|
73b847 |
priv->devices = g_ptr_array_new_with_free_func (g_object_unref);
|
|
|
73b847 |
|
|
|
73b847 |
priv->cancellable = g_cancellable_new ();
|
|
|
73b847 |
diff --git a/tests/meson.build b/tests/meson.build
|
|
|
73b847 |
index 6e56cb3..082ce86 100644
|
|
|
73b847 |
--- a/tests/meson.build
|
|
|
73b847 |
+++ b/tests/meson.build
|
|
|
73b847 |
@@ -11,6 +11,9 @@ envs.prepend('LD_LIBRARY_PATH', join_paths(meson.build_root(), 'libfprint'))
|
|
|
73b847 |
# random numbers rather than proper ones)
|
|
|
73b847 |
envs.set('FP_DEVICE_EMULATION', '1')
|
|
|
73b847 |
|
|
|
73b847 |
+# Set a colon-separated list of native drivers we enable in tests
|
|
|
73b847 |
+envs.set('FP_DRIVERS_WHITELIST', 'virtual_image')
|
|
|
73b847 |
+
|
|
|
73b847 |
envs.set('NO_AT_BRIDGE', '1')
|
|
|
73b847 |
|
|
|
73b847 |
if get_option('introspection')
|
|
|
73b847 |
@@ -31,10 +34,13 @@ if get_option('introspection')
|
|
|
73b847 |
]
|
|
|
73b847 |
|
|
|
73b847 |
foreach driver_test: drivers_tests
|
|
|
73b847 |
+ driver_envs = envs
|
|
|
73b847 |
+ driver_envs.set('FP_DRIVERS_WHITELIST', driver_test)
|
|
|
73b847 |
+
|
|
|
73b847 |
test(driver_test,
|
|
|
73b847 |
find_program('umockdev-test.py'),
|
|
|
73b847 |
args: join_paths(meson.current_source_dir(), driver_test),
|
|
|
73b847 |
- env: envs,
|
|
|
73b847 |
+ env: driver_envs,
|
|
|
73b847 |
suite: ['drivers'],
|
|
|
73b847 |
timeout: 10,
|
|
|
73b847 |
depends: libfprint_typelib,
|
|
|
73b847 |
--
|
|
|
73b847 |
2.24.1
|
|
|
73b847 |
|