2020-05-21 17:41:32 +03:00
tests_dep = declare_dependency (
compile_args : [
'-Dabs_builddir="@0@"' . format ( meson . current_build_dir ( ) ) ,
'-Dabs_top_builddir="@0@"' . format ( meson . build_root ( ) ) ,
'-Dabs_srcdir="@0@"' . format ( meson . current_source_dir ( ) ) ,
'-Dabs_top_srcdir="@0@"' . format ( meson . source_root ( ) ) ,
] + coverage_flags + cc_flags_relaxed_frame_limit ,
dependencies : [
apparmor_dep ,
dlopen_dep ,
glib_dep ,
gnutls_dep ,
libnl_dep ,
libxml_dep ,
rpc_dep ,
sasl_dep ,
selinux_dep ,
xdr_dep ,
yajl_dep ,
] ,
include_directories : [
conf_inc_dir ,
hypervisor_inc_dir ,
libvirt_inc ,
src_inc_dir ,
top_inc_dir ,
util_inc_dir ,
] ,
link_args : libvirt_export_dynamic ,
)
2020-07-27 12:12:56 +03:00
2020-07-10 12:14:56 +03:00
tests_env = [
'abs_builddir=@0@' . format ( meson . current_build_dir ( ) ) ,
'abs_srcdir=@0@' . format ( meson . current_source_dir ( ) ) ,
'abs_top_builddir=@0@' . format ( meson . build_root ( ) ) ,
'abs_top_srcdir=@0@' . format ( meson . source_root ( ) ) ,
'LC_ALL=C' ,
'LIBVIRT_AUTOSTART=0' ,
]
if use_expensive_tests
tests_env + = 'VIR_TEST_EXPENSIVE=1'
else
tests_env + = 'VIR_TEST_EXPENSIVE=0'
endif
2020-07-27 12:12:56 +03:00
# mock_libs:
# each entry is a dictionary with following items:
# * name - mock library name which is also used as default source file name (required)
# * sources - override default sources based on name (optional, default [])
# * deps - additional dependencies (optional, default [])
mock_libs = [
{ 'name' : 'domaincapsmock' } ,
{ 'name' : 'shunload' , 'sources' : [ 'shunloadhelper.c' ] } ,
{ 'name' : 'vircgroupmock' } ,
{ 'name' : 'virdeterministichashmock' } ,
{ 'name' : 'virfilecachemock' } ,
{ 'name' : 'virhostcpumock' } ,
{ 'name' : 'virhostdevmock' } ,
{ 'name' : 'virnetdaemonmock' } ,
{ 'name' : 'virnetdevmock' } ,
{ 'name' : 'virnetserverclientmock' } ,
{ 'name' : 'virpcimock' } ,
{ 'name' : 'virportallocatormock' } ,
{ 'name' : 'virprocessmock' } ,
{ 'name' : 'virrandommock' } ,
]
if host_machine . system ( ) == 'linux'
mock_libs + = [
{ 'name' : 'virfilemock' } ,
{ 'name' : 'virnetdevbandwidthmock' } ,
{ 'name' : 'virnumamock' } ,
{ 'name' : 'virtestmock' } ,
{ 'name' : 'virusbmock' } ,
]
endif
if conf . has ( 'WITH_BHYVE' )
mock_libs + = [
{ 'name' : 'bhyveargv2xmlmock' } ,
{ 'name' : 'bhyvexml2argvmock' } ,
]
endif
if conf . has ( 'WITH_DBUS' )
mock_libs + = [
{ 'name' : 'virdbusmock' , 'deps' : [ dbus_dep ] } ,
]
endif
if conf . has ( 'WITH_LIBXL' )
mock_libs + = [
{ 'name' : 'xlmock' , 'sources' : [ 'libxlmock.c' ] , 'deps' : [ libxl_dep ] } ,
]
endif
if conf . has ( 'WITH_NSS' )
mock_libs + = [
{ 'name' : 'nssmock' } ,
]
endif
if conf . has ( 'WITH_QEMU' )
mock_libs + = [
{ 'name' : 'qemucaps2xmlmock' } ,
{ 'name' : 'qemucapsprobemock' } ,
{ 'name' : 'qemucpumock' } ,
{ 'name' : 'qemuhotplugmock' } ,
{ 'name' : 'qemuxml2argvmock' } ,
]
endif
if conf . has ( 'WITH_SECDRIVER_SELINUX' )
mock_libs + = [
{ 'name' : 'securityselinuxhelper' } ,
]
endif
foreach mock : mock_libs
shared_module (
mock [ 'name' ] ,
mock . get ( 'sources' , [ '@0@.c' . format ( mock [ 'name' ] ) ] ) ,
dependencies : [
tests_dep ,
mock . get ( 'deps' , [ ] ) ,
] ,
link_with : [
libvirt_lib ,
] ,
)
endforeach
2020-06-18 03:01:49 +03:00
# build libraries used by tests
test_utils_lib = static_library (
'test_utils' ,
[ 'testutils.c' ] ,
dependencies : [ tests_dep ] ,
)
if conf . has ( 'WITH_LIBXL' )
test_utils_xen_lib = static_library (
'test_utils_xen' ,
[ 'testutilsxen.c' ] ,
dependencies : [ tests_dep ] ,
)
2020-07-27 12:16:34 +03:00
test_xen_driver_lib = shared_library (
'test_xen_driver' ,
link_whole : [ libxl_driver_imp ] ,
link_with : [ libvirt_lib ] ,
)
2020-06-18 03:01:49 +03:00
else
test_utils_xen_lib = [ ]
2020-07-27 12:16:34 +03:00
test_xen_driver_lib = [ ]
2020-06-18 03:01:49 +03:00
endif
if conf . has ( 'WITH_LXC' )
test_utils_lxc_lib = static_library (
'test_utils_lxc' ,
[ 'testutilslxc.c' ] ,
dependencies : [ tests_dep ] ,
)
else
test_utils_lxc_lib = [ ]
endif
if conf . has ( 'WITH_QEMU' )
test_utils_qemu_lib = static_library (
'test_utils_qemu' ,
[ 'testutilsqemu.c' ] ,
dependencies : [ tests_dep ] ,
)
test_utils_qemu_monitor_lib = static_library (
'test_utils_qemu_monitor' ,
[ 'qemumonitortestutils.c' , 'testutilsqemuschema.c' ] ,
dependencies : [ tests_dep ] ,
)
2020-07-27 12:16:34 +03:00
test_qemu_driver_lib = shared_library (
'test_qemu_driver' ,
[ qemu_dtrace_gen_objects ] ,
link_whole : [ qemu_driver_impl ] ,
link_with : [ libvirt_lib ] ,
)
2020-06-18 03:01:49 +03:00
else
2020-07-27 12:16:34 +03:00
test_qemu_driver_lib = [ ]
2020-06-18 03:01:49 +03:00
test_utils_qemu_lib = [ ]
test_utils_qemu_monitor_lib = [ ]
endif
test_file_wrapper_lib = static_library (
'test_file_wrapper' ,
[ 'virfilewrapper.c' ] ,
dependencies : [ tests_dep ] ,
)
2020-06-18 03:02:30 +03:00
# build helpers used by tests
# Must not link to any libvirt modules - libc only otherwise external
# libraries might unexpectedly leak file descriptors into commandhelper
# invalidating the test logic assumptions.
executable (
'commandhelper' ,
[ 'commandhelper.c' ] ,
dependencies : [
tests_dep ,
] ,
link_args : [
libvirt_no_indirect ,
] ,
)
2020-06-18 03:02:58 +03:00
# This is a fake SSH we use from virnetsockettest
executable (
'ssh' ,
[ 'ssh.c' ] ,
dependencies : [
tests_dep ,
] ,
link_args : [
coverage_flags ,
] ,
)
2020-06-25 14:05:51 +03:00
# build and define libvirt tests
# tests:
# each entry is a dictionary with following items:
# * name - name of the test which is also used as default source file name (required)
# * sources - override default sources based on name (optional, default [ '$name.c' ])
# * c_args - args used by test (optional, default [])
# * deps - additional dependencies (optional, default [])
# * include - include_directories (optional, default [])
# * link_with - compiled libraries to link with (optional, default [])
# * link_whole - compiled libraries to link whole (optional, default [])
tests = [ ]
foreach data : tests
test_sources = '@0@.c' . format ( data [ 'name' ] )
test_bin = executable (
data [ 'name' ] ,
[
data . get ( 'sources' , test_sources ) ,
dtrace_gen_objects ,
] ,
c_args : [
data . get ( 'c_args' , [ ] ) ,
] ,
dependencies : [
tests_dep ,
data . get ( 'deps' , [ ] ) ,
] ,
include_directories : [
data . get ( 'include' , [ ] ) ,
] ,
link_args : [
libvirt_no_indirect ,
] ,
link_with : [
libvirt_lib ,
data . get ( 'link_with' , [ ] ) ,
] ,
link_whole : [
test_utils_lib ,
data . get ( 'link_whole' , [ ] ) ,
] ,
export_dynamic : true ,
)
test ( data [ 'name' ] , test_bin , env : tests_env )
endforeach