summaryrefslogtreecommitdiff
path: root/test/meson.build
diff options
context:
space:
mode:
Diffstat (limited to 'test/meson.build')
-rw-r--r--test/meson.build191
1 files changed, 191 insertions, 0 deletions
diff --git a/test/meson.build b/test/meson.build
new file mode 100644
index 0000000..3539f8d
--- /dev/null
+++ b/test/meson.build
@@ -0,0 +1,191 @@
+# Copyright 2022 Collabora Ltd.
+# SPDX-License-Identifier: MIT
+
+installed_testdir = get_option('libexecdir') / 'installed-tests' / meson.project_name()
+installed_test_testdir = installed_testdir / 'test'
+installed_test_metadir = get_option('datadir') / 'installed-tests' / meson.project_name()
+test_env = environment()
+test_env.set('DBUS_TOP_SRCDIR', meson.project_source_root())
+test_env.set('DBUS_TOP_BUILDDIR', meson.project_build_root())
+test_env.set('DBUS_TEST_TMPDIR', meson.project_build_root() / 'test')
+test_env.set('DBUS_TEST_UNINSTALLED', '1')
+test_env.set('DBUS_PYTHON_VERSION', meson.project_version())
+test_env.set('PYTHON', py.full_path())
+test_env.set('DBUS_FATAL_WARNINGS', '1')
+test_env.set(
+ 'PYTHONPATH',
+ ':'.join([
+ meson.project_source_root(),
+ meson.project_source_root() / 'test',
+ meson.project_build_root(),
+ meson.project_build_root() / 'test',
+ ])
+)
+
+dbus_py_test = py.extension_module(
+ 'dbus_py_test',
+ sources: [
+ 'dbus_py_test.c',
+ ],
+ dependencies: [
+ dbus_dep,
+ py.dependency(),
+ ],
+ include_directories: project_include_directories,
+ install: get_option('installed_tests'),
+ install_dir: installed_test_testdir,
+)
+
+build_time_test_config = {
+ 'PYTHON': py.full_path(),
+ 'G_TEST_SRCDIR': meson.project_source_root(),
+ 'G_TEST_BUILDDIR': meson.project_build_root(),
+ 'configure_input': 'Generated by build system, do not edit',
+}
+
+configure_file(
+ input: 'TestSuitePythonService.service.in',
+ output: 'TestSuitePythonService.service',
+ configuration: build_time_test_config,
+)
+
+tmp_session_bus_conf = configure_file(
+ input: 'tmp-session-bus.conf.in',
+ output: 'tmp-session-bus.conf',
+ configuration: build_time_test_config,
+)
+
+if get_option('installed_tests')
+ subdir('installable')
+
+ install_data(
+ 'cross-test-client.py',
+ 'cross-test-server.py',
+ 'crosstest.py',
+ 'dbus_test_utils.py',
+ 'test-service.py',
+ 'wait-for-name.py',
+ install_dir: installed_test_testdir,
+ )
+endif
+
+dbus_run_session = find_program('dbus-run-session', required: true)
+
+build_time_dbus_run_session_args = [
+ '--config-file=@0@'.format(tmp_session_bus_conf),
+ '--',
+]
+
+installed_wrapper = [
+ dbus_run_session.full_path(),
+ '--config-file=@0@'.format(
+ get_option('prefix') / installed_test_testdir / 'tmp-session-bus.conf'
+ ),
+ '--',
+ 'env',
+ 'PYTHON=' + py.full_path(),
+ 'DBUS_TOP_SRCDIR=' + (get_option('prefix') / installed_testdir),
+ 'DBUS_TOP_BUILDDIR=' + (get_option('prefix') / installed_testdir),
+]
+
+compiled_test_cases = ['import-repeatedly']
+
+foreach test_case : compiled_test_cases
+ exe = executable(
+ 'test-' + test_case,
+ test_case + '.c',
+ dependencies: [
+ py.dependency(embed: true),
+ ],
+ install: get_option('installed_tests'),
+ install_dir: installed_test_testdir,
+ )
+ test(
+ test_case,
+ dbus_run_session,
+ args: build_time_dbus_run_session_args + [exe],
+ env: test_env,
+ )
+
+ if get_option('installed_tests')
+ configure_file(
+ input: 'compiled.test.in',
+ output: 'test-' + test_case + '.test',
+ configuration: {
+ 'wrapper': ' '.join(installed_wrapper),
+ 'program': get_option('prefix') / installed_test_testdir / 'test-' + test_case,
+ },
+ install: true,
+ install_dir: installed_test_metadir,
+ )
+ endif
+endforeach
+
+py_test_cases = [
+ 'client',
+ 'exception-py3',
+ 'p2p',
+ 'signals',
+ 'standalone',
+ 'unusable-main-loop',
+]
+install_test_sources = []
+
+foreach test_case : py_test_cases
+ install_test_sources += ['test-@0@.py'.format(test_case)]
+ test(
+ test_case,
+ dbus_run_session,
+ args: build_time_dbus_run_session_args + [
+ py.full_path(),
+ files('test-' + test_case + '.py'),
+ ],
+ env: test_env,
+ )
+
+ if get_option('installed_tests')
+ configure_file(
+ input: 'py.test.in',
+ output: 'test-' + test_case + '.py.test',
+ configuration: {
+ 'wrapper': ' '.join(installed_wrapper),
+ 'python': py.full_path(),
+ 'program': get_option('prefix') / installed_test_testdir / 'test-' + test_case + '.py',
+ },
+ install: true,
+ install_dir: installed_test_metadir,
+ )
+ endif
+endforeach
+
+sh_test_cases = ['run-test']
+
+foreach test_case : sh_test_cases
+ install_test_sources += ['@0@.sh'.format(test_case)]
+ test(
+ test_case + '.sh',
+ dbus_run_session,
+ args: build_time_dbus_run_session_args + [files(test_case + '.sh')],
+ env: test_env,
+ )
+
+ if get_option('installed_tests')
+ configure_file(
+ input: 'sh.test.in',
+ output: test_case + '.sh.test',
+ configuration: {
+ 'wrapper': ' '.join(installed_wrapper),
+ 'program': get_option('prefix') / installed_test_testdir / test_case + '.sh',
+ },
+ install: true,
+ install_dir: installed_test_metadir,
+ )
+ endif
+endforeach
+
+if get_option('installed_tests')
+ install_data(
+ install_test_sources,
+ install_dir: installed_test_testdir,
+ )
+endif