tests: Add support for installed tests

They allow distrubtions to check whether libfprint continues working as
expected, in different contexts.
This commit is contained in:
Marco Trevisan (Treviño)
2023-06-23 13:44:59 -04:00
parent 3d4cf44f9b
commit ba3cc04e84
6 changed files with 126 additions and 4 deletions

View File

@@ -21,3 +21,8 @@ executable('cpp-test',
'cpp-test.cpp', 'cpp-test.cpp',
dependencies: libfprint_dep, dependencies: libfprint_dep,
) )
if installed_tests
install_subdir('prints',
install_dir: installed_tests_testdir)
endif

View File

@@ -13,6 +13,11 @@ gnome = import('gnome')
libfprint_conf = configuration_data() libfprint_conf = configuration_data()
libfprint_conf.set_quoted('LIBFPRINT_VERSION', meson.project_version()) libfprint_conf.set_quoted('LIBFPRINT_VERSION', meson.project_version())
prefix = get_option('prefix')
libdir = prefix / get_option('libdir')
libexecdir = prefix / get_option('libexecdir')
datadir = prefix / get_option('datadir')
cc = meson.get_compiler('c') cc = meson.get_compiler('c')
cpp = meson.get_compiler('cpp') cpp = meson.get_compiler('cpp')
host_system = host_machine.system() host_system = host_machine.system()
@@ -297,7 +302,6 @@ subdir('libfprint')
configure_file(output: 'config.h', configuration: libfprint_conf) configure_file(output: 'config.h', configuration: libfprint_conf)
subdir('examples')
if get_option('doc') if get_option('doc')
subdir('doc') subdir('doc')
endif endif
@@ -308,6 +312,8 @@ endif
subdir('data') subdir('data')
subdir('tests') subdir('tests')
subdir('examples')
pkgconfig = import('pkgconfig') pkgconfig = import('pkgconfig')
pkgconfig.generate( pkgconfig.generate(
name: versioned_libname, name: versioned_libname,

View File

@@ -30,3 +30,7 @@ option('doc',
description: 'Whether to build the API documentation', description: 'Whether to build the API documentation',
type: 'boolean', type: 'boolean',
value: true) value: true)
option('installed-tests',
description: 'Whether to install the installed tests',
type: 'boolean',
value: true)

5
tests/driver.test.in Normal file
View File

@@ -0,0 +1,5 @@
[Test]
Type=session
# We can't use TestEnvironment as per
# https://gitlab.gnome.org/GNOME/gnome-desktop-testing/-/issues/1
Exec=env @driver_env@ @installed_tests_execdir@/@umockdev_test_name@ @installed_tests_testdir@/@driver_test@

View File

@@ -23,6 +23,13 @@ envs.set('FP_PRINTS_PATH', meson.project_source_root() / 'examples' / 'prints')
envs.set('NO_AT_BRIDGE', '1') envs.set('NO_AT_BRIDGE', '1')
python3 = find_program('python3')
installed_tests = get_option('installed-tests')
installed_tests_execdir = libexecdir / 'installed-tests' / versioned_libname
installed_tests_testdir = datadir / 'installed-tests' / versioned_libname
installed_tests_libdir = libdir
drivers_tests = [ drivers_tests = [
'aes2501', 'aes2501',
'aes3500', 'aes3500',
@@ -54,6 +61,16 @@ if get_option('introspection')
output: 'create-driver-test.py') output: 'create-driver-test.py')
endif endif
env_parser_cmd = '''
import os;
print(" ".join([f"{k}={v}" for k, v in os.environ.items()
if k.startswith("FP_") or k.startswith("G_")]))
'''
envs_str = run_command(python3, '-c', env_parser_cmd,
env: envs,
check: installed_tests).stdout().strip()
if get_option('introspection') if get_option('introspection')
envs.prepend('GI_TYPELIB_PATH', meson.project_build_root() / 'libfprint') envs.prepend('GI_TYPELIB_PATH', meson.project_build_root() / 'libfprint')
virtual_devices_tests = [ virtual_devices_tests = [
@@ -61,9 +78,9 @@ if get_option('introspection')
'virtual-device', 'virtual-device',
] ]
python3 = find_program('python3')
unittest_inspector = find_program('unittest_inspector.py') unittest_inspector = find_program('unittest_inspector.py')
umockdev_test = find_program('umockdev-test.py') umockdev_test_name = 'umockdev-test.py'
umockdev_test = find_program(umockdev_test_name)
foreach vdtest: virtual_devices_tests foreach vdtest: virtual_devices_tests
driver_name = '_'.join(vdtest.split('-')) driver_name = '_'.join(vdtest.split('-'))
@@ -95,6 +112,31 @@ if get_option('introspection')
env: envs, env: envs,
) )
endforeach endforeach
if installed_tests
install_data(base_args,
install_dir: installed_tests_execdir,
install_mode: 'rwxr-xr-x',
)
configure_file(
input: 'test.in',
output: vdtest + '.test',
install_dir: installed_tests_testdir,
configuration: {
# FIXME: use fs.name() on meson 0.58
'exec': installed_tests_execdir / '@0@'.format(base_args[0]).split('/')[-1],
'env': ' '.join([
envs_str,
'LD_LIBRARY_PATH=' + installed_tests_libdir,
'FP_PRINTS_PATH=' + installed_tests_testdir / 'prints',
# FIXME: Adding this requires gnome-desktop-testing!12
# 'GI_TYPELIB_PATH=' + installed_tests_libdir / 'girepository-1.0',
]),
'extra_content': '',
},
)
endif
else else
test(vdtest, test(vdtest,
find_program('sh'), find_program('sh'),
@@ -103,6 +145,7 @@ if get_option('introspection')
endif endif
endforeach endforeach
driver_tests_enabled = false
foreach driver_test: drivers_tests foreach driver_test: drivers_tests
driver_name = driver_test.split('-')[0] driver_name = driver_test.split('-')[0]
driver_envs = envs driver_envs = envs
@@ -110,6 +153,7 @@ if get_option('introspection')
if (driver_name in supported_drivers and if (driver_name in supported_drivers and
gusb_dep.version().version_compare('>= 0.3.0')) gusb_dep.version().version_compare('>= 0.3.0'))
driver_tests_enabled = true
test(driver_test, test(driver_test,
python3, python3,
args: [ args: [
@@ -121,6 +165,32 @@ if get_option('introspection')
timeout: 15, timeout: 15,
depends: libfprint_typelib, depends: libfprint_typelib,
) )
if installed_tests
driver_envs_str = run_command(python3, '-c', env_parser_cmd,
env: driver_envs,
check: true).stdout().strip()
configure_file(
input: 'driver.test.in',
output: 'driver-' + driver_test + '.test',
install_dir: installed_tests_testdir,
configuration: {
'installed_tests_execdir': installed_tests_execdir,
'installed_tests_testdir': installed_tests_testdir,
'umockdev_test_name': umockdev_test_name,
'driver_test': driver_test,
'driver_env': ' '.join([
driver_envs_str,
'LD_LIBRARY_PATH=' + installed_tests_libdir,
# FIXME: Adding this requires gnome-desktop-testing!12
# 'GI_TYPELIB_PATH=' + installed_tests_libdir / 'girepository-1.0',
]),
},
)
install_subdir(driver_test, install_dir: installed_tests_testdir)
endif
else else
test(driver_test, test(driver_test,
find_program('sh'), find_program('sh'),
@@ -128,6 +198,17 @@ if get_option('introspection')
) )
endif endif
endforeach endforeach
if installed_tests and driver_tests_enabled
install_data(umockdev_test.full_path(),
install_dir: installed_tests_execdir,
install_mode: 'rwxr-xr-x',
)
install_data('capture.py',
install_dir: installed_tests_execdir,
install_mode: 'rwxr-xr-x',
)
endif
else else
warning('Skipping all driver tests as introspection bindings are missing') warning('Skipping all driver tests as introspection bindings are missing')
test('virtual-image', test('virtual-image',
@@ -200,13 +281,28 @@ foreach test_name: unit_tests
sources: [basename + '.c', test_config_h], sources: [basename + '.c', test_config_h],
dependencies: [ libfprint_private_dep ] + extra_deps, dependencies: [ libfprint_private_dep ] + extra_deps,
c_args: common_cflags, c_args: common_cflags,
link_with: test_utils, link_whole: test_utils,
install: installed_tests,
install_dir: installed_tests_execdir,
) )
test(test_name, test(test_name,
test_exe, test_exe,
suite: ['unit-tests'], suite: ['unit-tests'],
env: envs, env: envs,
) )
configure_file(
input: 'test.in',
output: test_name + '.test',
install: installed_tests,
install_dir: installed_tests_testdir,
configuration: {
'exec': installed_tests_execdir / basename,
'env': envs_str,
'extra_content': 'TestEnvironment=LD_LIBRARY_PATH=' +
installed_tests_libdir,
},
)
endforeach endforeach
# Run udev rule generator with fatal warnings # Run udev rule generator with fatal warnings

6
tests/test.in Normal file
View File

@@ -0,0 +1,6 @@
[Test]
Type=session
# We can't use TestEnvironment as per
# https://gitlab.gnome.org/GNOME/gnome-desktop-testing/-/issues/1
Exec=env @env@ @exec@
@extra_content@