mirror of
https://gitlab.freedesktop.org/libfprint/libfprint.git
synced 2026-09-09 04:40:06 +00:00
fpi-device: Only use emulation mode by pre-loading a library
Rather than just do it in production if set, make it more difficult to potentially inject the test mode. So rely on a weak definition of fpi_device_emulation_mode_enabled() that can be only set externally
This commit is contained in:
+22
-2
@@ -74,6 +74,18 @@ if get_option('introspection')
|
||||
output: 'create-driver-test.py')
|
||||
endif
|
||||
|
||||
test_emulation_lib = shared_library('fprint-test-emulation',
|
||||
'test-emulation.c',
|
||||
dependencies: libfprint_private_dep,
|
||||
install: installed_tests,
|
||||
install_dir: installed_tests_execdir,
|
||||
)
|
||||
test_emulation_lib_name = fs.name(test_emulation_lib.full_path())
|
||||
|
||||
# Preload the test-emulation library so that the weak NULL implementation
|
||||
# in libfprint is overridden with one that honours FP_DEVICE_EMULATION.
|
||||
envs.prepend('LD_PRELOAD', test_emulation_lib.full_path())
|
||||
|
||||
env_parser_cmd = '''
|
||||
import os;
|
||||
print(" ".join([f"{k}={v}" for k, v in os.environ.items()
|
||||
@@ -86,6 +98,7 @@ envs_str = run_command(python3, '-c', env_parser_cmd,
|
||||
|
||||
envs_str = ' '.join([
|
||||
envs_str,
|
||||
'LD_PRELOAD=' + (installed_tests_execdir / test_emulation_lib_name),
|
||||
'G_TEST_SRCDIR=' + installed_tests_testdir,
|
||||
'G_TEST_BUILDDIR=' + installed_tests_execdir,
|
||||
])
|
||||
@@ -133,7 +146,10 @@ if get_option('introspection')
|
||||
python3,
|
||||
args: ut_args,
|
||||
suite: ut_suite,
|
||||
depends: libfprint_typelib,
|
||||
depends: [
|
||||
libfprint_typelib,
|
||||
test_emulation_lib,
|
||||
],
|
||||
env: envs,
|
||||
)
|
||||
endforeach
|
||||
@@ -187,7 +203,10 @@ if get_option('introspection')
|
||||
env: driver_envs,
|
||||
suite: ['drivers'],
|
||||
timeout: args.get('timeout', 15),
|
||||
depends: libfprint_typelib,
|
||||
depends: [
|
||||
libfprint_typelib,
|
||||
test_emulation_lib,
|
||||
],
|
||||
)
|
||||
|
||||
if installed_tests
|
||||
@@ -206,6 +225,7 @@ if get_option('introspection')
|
||||
'driver_test': driver_test,
|
||||
'driver_env': ' '.join([
|
||||
driver_envs_str,
|
||||
'LD_PRELOAD=' + (installed_tests_execdir / test_emulation_lib_name),
|
||||
'LD_LIBRARY_PATH=' + installed_tests_libdir,
|
||||
# FIXME: Adding this requires gnome-desktop-testing!12
|
||||
# 'GI_TYPELIB_PATH=' + installed_tests_libdir / 'girepository-1.0',
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (C) 2026 Canonical, Ltd.
|
||||
*
|
||||
* This library 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 library 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, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "fpi-device.h"
|
||||
|
||||
gboolean
|
||||
(fpi_device_emulation_mode_enabled) (FpDevice *device)
|
||||
{
|
||||
static gsize emulation_mode = 0;
|
||||
|
||||
if (g_once_init_enter (&emulation_mode))
|
||||
g_once_init_leave (&emulation_mode,
|
||||
g_strcmp0 (g_getenv ("FP_DEVICE_EMULATION"), "1") == 0 ?
|
||||
TRUE : G_MAXSIZE);
|
||||
|
||||
return emulation_mode == TRUE;
|
||||
}
|
||||
Reference in New Issue
Block a user