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.
This commit is contained in:
Marco Trevisan (Treviño) 2019-12-13 20:34:08 +01:00
parent 09576e5209
commit 43a8c909bf
2 changed files with 52 additions and 1 deletions

View file

@ -57,6 +57,35 @@ enum {
}; };
static guint signals[LAST_SIGNAL] = { 0 }; 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 static void
async_device_init_done_cb (GObject *source_object, GAsyncResult *res, gpointer user_data) 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; g_autoptr(GError) error = NULL;
FpContextPrivate *priv = fp_context_get_instance_private (self); FpContextPrivate *priv = fp_context_get_instance_private (self);
guint i;
priv->drivers = fpi_get_driver_types (); 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->devices = g_ptr_array_new_with_free_func (g_object_unref);
priv->cancellable = g_cancellable_new (); priv->cancellable = g_cancellable_new ();

View file

@ -11,6 +11,9 @@ envs.prepend('LD_LIBRARY_PATH', join_paths(meson.build_root(), 'libfprint'))
# random numbers rather than proper ones) # random numbers rather than proper ones)
envs.set('FP_DEVICE_EMULATION', '1') 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') envs.set('NO_AT_BRIDGE', '1')
if get_option('introspection') if get_option('introspection')
@ -31,10 +34,13 @@ if get_option('introspection')
] ]
foreach driver_test: drivers_tests foreach driver_test: drivers_tests
driver_envs = envs
driver_envs.set('FP_DRIVERS_WHITELIST', driver_test)
test(driver_test, test(driver_test,
find_program('umockdev-test.py'), find_program('umockdev-test.py'),
args: join_paths(meson.current_source_dir(), driver_test), args: join_paths(meson.current_source_dir(), driver_test),
env: envs, env: driver_envs,
suite: ['drivers'], suite: ['drivers'],
timeout: 10, timeout: 10,
depends: libfprint_typelib, depends: libfprint_typelib,