meson.build: change the test builds to be a feature

This way we get to use 'auto' feature which will enable the tests
as dependencies are available. Right now, the basic tests don't have any
dependencies beyond what libei needs, only the pytests have extra
requirements that are handled in the 'auto' processing.
This commit is contained in:
Peter Hutterer 2023-05-10 08:50:06 +10:00
parent 95a5cebabb
commit fafc30d4cc
2 changed files with 70 additions and 51 deletions

View file

@ -1,3 +1,3 @@
option('documentation', type: 'array', value: [], choices: ['api', 'protocol'], description: 'Enable documentation builds')
option('tests', type: 'boolean', value: 'true', description: 'Enable/disable tests')
option('tests', type: 'feature', value: 'auto', description: 'Enable/disable tests')
option('liboeffis', type: 'feature', value: 'auto', description: 'Build liboeffis.so')

View file

@ -1,4 +1,5 @@
if not get_option('tests')
if get_option('tests').disabled()
summary({'Test suite enabled': false}, section: 'Test options')
subdir_done()
endif
@ -41,25 +42,6 @@ test('unit-tests-eis',
c_args: ['-D_enable_tests_'],
dependencies: [dep_unittest, dep_libutil]))
pymod = import('python')
required_python_modules = ['pytest', 'attr', 'structlog']
if build_oeffis
required_python_modules += ['dbusmock']
endif
python = pymod.find_installation('python3', modules: required_python_modules)
if python.language_version().version_compare('< 3.11')
pymod.find_installation('python3', modules: ['strenum'])
endif
pytest = find_program('pytest-3', 'pytest')
pytest_args = ['--verbose', '--log-level=DEBUG']
optional_python_modules = ['xdist']
if pymod.find_installation('python3', modules: optional_python_modules, required: false).found()
pytest_args += ['-n', 'auto']
configure_file(input: 'conftest.py', output: '@PLAINNAME@', copy: true)
endif
if build_oeffis
test('unit-tests-oeffis',
executable('unit-tests-oeffis',
@ -68,15 +50,6 @@ if build_oeffis
include_directories: [inc_src, inc_builddir],
c_args: ['-D_enable_tests_'],
dependencies: deps_liboeffis + [dep_unittest]))
env = environment()
env.set('LD_LIBRARY_PATH', fs.parent(lib_liboeffis.full_path()))
test('oeffis-pytest', pytest,
args: pytest_args,
suite: 'python',
workdir: meson.current_source_dir(),
env: env,
)
endif
lib_eierpecken = static_library('eierpecken',
@ -133,31 +106,77 @@ if add_languages('cpp', required: false)
install: false)
endif
eiproto_python_template = files('eiproto.py.tmpl')
eiproto_python = custom_target('eiproto.py',
input: protocol_xml,
output: 'eiproto.py',
command: [scanner, '--component=ei', '--output=@OUTPUT@', '@INPUT@', eiproto_python_template],
build_by_default: true)
# Python-based tests
protocol_test_config = configuration_data()
protocol_test_config.set('LIBEI_TEST_SERVER', eis_demo_server.full_path())
configure_file(input: 'test_protocol.py',
output: '@PLAINNAME@',
configuration: protocol_test_config)
pymod = import('python')
required_python_modules = ['pytest', 'attr', 'structlog']
python = pymod.find_installation('python3', required: get_option('tests'))
if python.found() and python.language_version().version_compare('< 3.11')
required_python_modules += ['strenum']
endif
if build_oeffis
required_python_modules += ['dbusmock']
endif
test('protocol-test', pytest,
args: pytest_args,
suite: 'python',
workdir: meson.project_build_root(),
)
if valgrind.found()
env = environment()
env.set('LIBEI_USE_VALGRIND', '1')
test('protocol-test-valgrind', pytest,
python = pymod.find_installation('python3',
modules: required_python_modules,
required: get_option('tests'))
pytest = find_program('pytest-3', 'pytest', required: get_option('tests'))
pytest_args = ['--verbose', '--log-level=DEBUG']
enable_pytest = python.found() and pytest.found()
if enable_pytest
# pytest xdist is nice because it significantly speeds up our
# test process, but it's not required
optional_python_modules = ['xdist']
if pymod.find_installation('python3', modules: optional_python_modules, required: false).found()
pytest_args += ['-n', 'auto']
configure_file(input: 'conftest.py', output: '@PLAINNAME@', copy: true)
endif
eiproto_python_template = files('eiproto.py.tmpl')
eiproto_python = custom_target('eiproto.py',
input: protocol_xml,
output: 'eiproto.py',
command: [scanner, '--component=ei', '--output=@OUTPUT@', '@INPUT@', eiproto_python_template],
build_by_default: true)
protocol_test_config = configuration_data()
protocol_test_config.set('LIBEI_TEST_SERVER', eis_demo_server.full_path())
configure_file(input: 'test_protocol.py',
output: '@PLAINNAME@',
configuration: protocol_test_config)
test('protocol-test', pytest,
args: pytest_args,
suite: 'python',
workdir: meson.project_build_root(),
env: env
)
if valgrind.found()
env = environment()
env.set('LIBEI_USE_VALGRIND', '1')
test('protocol-test-valgrind', pytest,
args: pytest_args,
suite: 'python',
workdir: meson.project_build_root(),
env: env
)
endif
if build_oeffis
env = environment()
env.set('LD_LIBRARY_PATH', fs.parent(lib_liboeffis.full_path()))
test('oeffis-pytest', pytest,
args: pytest_args,
suite: 'python',
workdir: meson.current_source_dir(),
env: env,
)
endif
endif
summary({'valgrind available': valgrind.found(),
'unit tests enabled': true,
'pytest tests enabled': enable_pytest,
}, section: 'Test options')