Skip to content

Commit

Permalink
build: Use a single tests option to control if we build any tests
Browse files Browse the repository at this point in the history
  • Loading branch information
swick committed Jan 7, 2025
1 parent fa81f01 commit 01d4cb7
Show file tree
Hide file tree
Showing 4 changed files with 146 additions and 143 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
run: |
meson setup _build \
-Dinstalled-tests=true \
-Dpytest=enabled \
-Dtests=enabled \
-Db_sanitize=${{ matrix.sanitizer }} \
-Db_lundef=false
meson compile -C _build
Expand Down
32 changes: 27 additions & 5 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ geoclue_dep = dependency(
pipewire_dep = dependency('libpipewire-0.3', version: '>= 0.2.90')
libsystemd_dep = dependency('libsystemd', required: get_option('systemd'))
gudev_dep = dependency('gudev-1.0', required: get_option('gudev'))
umockdev_dep = dependency('umockdev-1.0', required: get_option('pytest'))
umockdev_dep = dependency('umockdev-1.0', required: get_option('tests'))

gst_inspect = find_program('gst-inspect-1.0', required: false)
if gst_inspect.found()
Expand All @@ -133,6 +133,13 @@ else
have_wav_parse = false
endif

pytest = find_program('pytest-3', 'pytest', required: get_option('tests'))
python = pymod.find_installation(
'python3',
modules: ['dbus', 'dbusmock', 'gi'],
required: get_option('tests'),
)

bwrap = find_program('bwrap', required: get_option('sandboxed-image-validation').allowed() or get_option('sandboxed-sound-validation').allowed())

if not bwrap.found()
Expand Down Expand Up @@ -178,8 +185,6 @@ endif

rst2man = find_program('rst2man', 'rst2man.py', required: get_option('man-pages'))

enable_installed_tests = get_option('installed-tests')

###### systemd units, dbus service files, pkgconfig

base_config = configuration_data()
Expand All @@ -203,13 +208,30 @@ pkgconfig.generate(
},
)

###### subdirs

subdir('data')
subdir('src')
subdir('document-portal')
subdir('tests')
subdir('po')
subdir('doc')

enable_tests = get_option('tests') \
.require(pytest.found()) \
.require(python.found()) \
.require(python.language_version().version_compare('>=3.9'),
error_message: 'Python version >=3.9 is required') \
.require(umockdev_dep.found()) \
.require(have_wav_parse,
error_message: 'gst-inspect and the wavparse plugins are required') \
.allowed()

enable_installed_tests = get_option('installed-tests')

if enable_tests
subdir('tests')
endif

###### generate config.h
configure_file(output: 'config.h', configuration: config_h)

Expand All @@ -218,8 +240,8 @@ summary({
'Enable libsystemd support': have_libsystemd,
'Enable geoclue support': have_geoclue,
'Enable gudev support': have_gudev,
'Enable test suite': enable_tests,
'Enable installed tests:': enable_installed_tests,
'Enable python test suite': enable_pytest,
'Build man pages': rst2man.found(),
'Build flatpak interfaces': flatpak_intf_dir != '',
'Sandboxed image validation': bwrap.found(),
Expand Down
8 changes: 4 additions & 4 deletions meson_options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ option('datarootdir',
type: 'string',
value: '',
description: 'Define the datarootdir for the pkgconf file')
option('tests',
type: 'feature',
value: 'enabled',
description: 'Enable the test suite')
option('installed-tests',
type: 'boolean',
value: false,
description: 'Enable installation of some test cases')
option('pytest',
type: 'feature',
value: 'enabled',
description: 'Enable the pytest-based test suite')
option('man-pages',
type: 'feature',
value: 'auto',
Expand Down
247 changes: 114 additions & 133 deletions tests/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -62,143 +62,124 @@ test(
protocol: test_protocol,
)

pytest = find_program('pytest-3', 'pytest', required: get_option('pytest'))
python = pymod.find_installation(
'python3',
modules: ['dbus', 'dbusmock', 'gi'],
required: get_option('pytest'),
)
pytest_args = ['--verbose', '--log-level=DEBUG']

pytest_env = environment()
pytest_env.set('XDG_DESKTOP_PORTAL_PATH', xdg_desktop_portal.full_path())
pytest_env.set('XDG_PERMISSION_STORE_PATH', xdg_permission_store.full_path())
pytest_env.set('XDG_DOCUMENT_PORTAL_PATH', xdg_document_portal.full_path())
pytest_env.set('XDP_VALIDATE_ICON', xdp_validate_icon.full_path())
pytest_env.set('XDP_VALIDATE_SOUND', xdp_validate_sound.full_path())

# pytest xdist is nice because it significantly speeds up our
# test process, but it's not required
if pymod.find_installation('python3', modules: ['xdist'], required: false).found()
# using auto can easily start too many tests which will block each other
# a value of around 5 seems to work well
pytest_args += ['-n', '5']
endif

enable_pytest = get_option('pytest') \
.require(pytest.found()) \
.require(python.found()) \
.require(python.language_version().version_compare('>=3.9'),
error_message: 'Python version >=3.9 is required') \
.require(umockdev_dep.found()) \
.require(have_wav_parse,
error_message: 'gst-inspect and the wavparse plugins are required') \
.allowed()

if enable_pytest
pytest_args = ['--verbose', '--log-level=DEBUG']

pytest_env = environment()
pytest_env.set('XDG_DESKTOP_PORTAL_PATH', xdg_desktop_portal.full_path())
pytest_env.set('XDG_PERMISSION_STORE_PATH', xdg_permission_store.full_path())
pytest_env.set('XDG_DOCUMENT_PORTAL_PATH', xdg_document_portal.full_path())
pytest_env.set('XDP_VALIDATE_ICON', xdp_validate_icon.full_path())
pytest_env.set('XDP_VALIDATE_SOUND', xdp_validate_sound.full_path())

# pytest xdist is nice because it significantly speeds up our
# test process, but it's not required
if pymod.find_installation('python3', modules: ['xdist'], required: false).found()
# using auto can easily start too many tests which will block each other
# a value of around 5 seems to work well
pytest_args += ['-n', '5']
endif

pytest_files = [
'test_account.py',
'test_background.py',
'test_camera.py',
'test_clipboard.py',
'test_document_fuse.py',
'test_email.py',
'test_filechooser.py',
'test_globalshortcuts.py',
'test_inhibit.py',
'test_inputcapture.py',
'test_location.py',
'test_notification.py',
'test_openuri.py',
'test_permission_store.py',
'test_print.py',
'test_remotedesktop.py',
'test_settings.py',
'test_screenshot.py',
'test_trash.py',
'test_usb.py',
'test_wallpaper.py',
]

template_files = [
'templates/access.py',
'templates/account.py',
'templates/appchooser.py',
'templates/background.py',
'templates/clipboard.py',
'templates/email.py',
'templates/filechooser.py',
'templates/geoclue2.py',
'templates/globalshortcuts.py',
'templates/inhibit.py',
'templates/__init__.py',
'templates/inputcapture.py',
'templates/lockdown.py',
'templates/notification.py',
'templates/print.py',
'templates/remotedesktop.py',
'templates/screenshot.py',
'templates/settings.py',
'templates/usb.py',
'templates/wallpaper.py',
]
pytest_files = [
'test_account.py',
'test_background.py',
'test_camera.py',
'test_clipboard.py',
'test_document_fuse.py',
'test_email.py',
'test_filechooser.py',
'test_globalshortcuts.py',
'test_inhibit.py',
'test_inputcapture.py',
'test_location.py',
'test_notification.py',
'test_openuri.py',
'test_permission_store.py',
'test_print.py',
'test_remotedesktop.py',
'test_settings.py',
'test_screenshot.py',
'test_trash.py',
'test_usb.py',
'test_wallpaper.py',
]

template_files = [
'templates/access.py',
'templates/account.py',
'templates/appchooser.py',
'templates/background.py',
'templates/clipboard.py',
'templates/email.py',
'templates/filechooser.py',
'templates/geoclue2.py',
'templates/globalshortcuts.py',
'templates/inhibit.py',
'templates/__init__.py',
'templates/inputcapture.py',
'templates/lockdown.py',
'templates/notification.py',
'templates/print.py',
'templates/remotedesktop.py',
'templates/screenshot.py',
'templates/settings.py',
'templates/usb.py',
'templates/wallpaper.py',
]

foreach pytest_file : pytest_files
testname = pytest_file.replace('.py', '')
test(
'pytest/@0@'.format(testname),
pytest,
args: [meson.current_source_dir()] + pytest_args + ['-k', testname],
env: pytest_env,
suite: ['pytest'],
timeout: 120,
)
endforeach

if enable_installed_tests
install_data(
pytest_files,
'__init__.py',
'conftest.py',
'asan.suppression',
install_dir: installed_tests_dir / 'tests',
)
install_data(
template_files,
install_dir: installed_tests_dir / 'tests' / 'templates',
)

installed_env = {
'XDG_DESKTOP_PORTAL_PATH': libexecdir / 'xdg-desktop-portal',
'XDG_PERMISSION_STORE_PATH': libexecdir / 'xdg-permission-store',
'XDG_DOCUMENT_PORTAL_PATH': libexecdir / 'xdg-document-portal',
'XDP_VALIDATE_ICON': libexecdir / 'xdg-desktop-portal-validate-icon',
'XDP_VALIDATE_SOUND': libexecdir / 'xdg-desktop-portal-validate-sound',
}
env = ''
foreach key, value : installed_env
env += f'@key@=@value@ '
endforeach

foreach pytest_file : pytest_files
testname = pytest_file.replace('.py', '')
test(
'pytest/@0@'.format(testname),
pytest,
args: [meson.current_source_dir()] + pytest_args + ['-k', testname],
env: pytest_env,
suite: ['pytest'],
timeout: 120,
)
endforeach

if enable_installed_tests
install_data(
pytest_files,
'__init__.py',
'conftest.py',
'asan.suppression',
install_dir: installed_tests_dir / 'tests',
)
install_data(
template_files,
install_dir: installed_tests_dir / 'tests' / 'templates',
)
exec = [pytest.full_path(), installed_tests_dir / 'tests'] + pytest_args + ['-k', testname]
exec = ' '.join(exec)

data = configuration_data()
data.set('exec', exec)
data.set('env', env)
data.set('libdir', libdir)

installed_env = {
'XDG_DESKTOP_PORTAL_PATH': libexecdir / 'xdg-desktop-portal',
'XDG_PERMISSION_STORE_PATH': libexecdir / 'xdg-permission-store',
'XDG_DOCUMENT_PORTAL_PATH': libexecdir / 'xdg-document-portal',
'XDP_VALIDATE_ICON': libexecdir / 'xdg-desktop-portal-validate-icon',
'XDP_VALIDATE_SOUND': libexecdir / 'xdg-desktop-portal-validate-sound',
}
env = ''
foreach key, value : installed_env
env += f'@key@=@value@ '
endforeach

foreach pytest_file : pytest_files
testname = pytest_file.replace('.py', '')

exec = [pytest.full_path(), installed_tests_dir / 'tests'] + pytest_args + ['-k', testname]
exec = ' '.join(exec)

data = configuration_data()
data.set('exec', exec)
data.set('env', env)
data.set('libdir', libdir)

configure_file(
input: 'template.test.in',
output: '@[email protected]'.format(testname),
configuration: data,
install: true,
install_dir: installed_tests_data_dir,
)
endforeach
endif
configure_file(
input: 'template.test.in',
output: '@[email protected]'.format(testname),
configuration: data,
install: true,
install_dir: installed_tests_data_dir,
)
endforeach
endif

0 comments on commit 01d4cb7

Please sign in to comment.