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