Compare commits

...

13 Commits

Author SHA1 Message Date
Daniel P. Berrangé a47e73d6e7 src/node_device: don't overwrite error messages
The nodedev code unhelpfully reports

  couldn't convert node device def to mdevctl JSON

which hides the actual error message

  No JSON parser implementation is available

Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2024-05-08 16:01:34 +01:00
Daniel P. Berrangé 479333af2c tests: don't run mdevctl test if lacking YAJL
The mdev code requires YAJL in order to convert from node dev XML to
mdev's config format.

Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2024-05-08 16:01:34 +01:00
Daniel P. Berrangé 7817c3f89c test: drop bogus check for YAJL from libxl test/mock
The libxlmock.c conditionalizes on WITH_YAJL, but this mock is
used from other tests which only conditionalize on WITH_LIBXL.
The libxl code does not have any dependancy on YAJL, so the
bogus condition can be removed from the mock and also from
libxlxml2domconfigtest.c

Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2024-05-08 16:01:34 +01:00
Daniel P. Berrangé 971305e86f tests: always build securityselinuxhelper if libselinux is present
The securityselinuxhelper build is conditionalized on the SELinux
security driver feature. It is also needed, however, by viridentitytest
whenever libselinux is present.

Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2024-05-08 16:01:34 +01:00
Daniel P. Berrangé c8c5170b74 test: conditionalize 'virsh-auth' on test driver
The 'virsh-auth' test is mistakenly conditionalized on the libvirtd
daemon build, however, it just uses the 'test:///default' driver
URI, so does not require a daemon.

Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2024-05-08 16:01:34 +01:00
Daniel P. Berrangé 08bfb18736 tests: build driver modules before virdrivermoduletest
The virdrivermoduletest will attempt to dlopen() each driver module,
so they must be build before the test can run.

Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2024-05-08 16:01:34 +01:00
Daniel P. Berrangé a76ffee365 tests: build 'virsh' before running virsh-auth test
The 'virsh-auth' test needs to be able to invoke the 'virsh' binary

Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2024-05-08 16:00:19 +01:00
Daniel P. Berrangé 0dc278dd02 src: ensure augeas test file is generated before running test
We fail to express an ordering between the custom target that
generates the combined augeas test input file, and the meson
test command.

Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2024-05-08 15:57:46 +01:00
Daniel P. Berrangé bdfe46ed6e meson: record which other options are a pre-requisite
Several meson options cannot be enabled, without first enabling another
option. This adds a small comment prior to an option to record its
mandatory dependencies.

Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2024-05-08 15:57:34 +01:00
Daniel P. Berrangé 67ac2cd590 tests: fix tests when test driver is disabled
Various tests try to open a connection to 'test:///default' and
must be skipped when the test driver is disabled.

Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2024-05-08 15:57:31 +01:00
Daniel P. Berrangé 20acd5b1be scripts/rpcgen: skip tests if tirpc is not present
This skips building tests which rely on tirpc when it is not
present.

Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2024-05-08 15:57:13 +01:00
Daniel P. Berrangé ae6a89884a tests: fix two off-by-1 errors in read-big-pipe test
When testPipeFeeder copies the XML document into the padded buffer, it
tells virStrcpy that 'xmlsize' bytes are available. This is under
reporting size by 1 byte, and as a result it fails to copy the trailing
'\n' replacing it with '\0'. The return value of virStrcpy wasn't
checked, but was reporting this truncation.

When testPipeFeeder then sends the padded buffer down the pipe, it asks
to send 'emptyspace + xmlsize + 1' bytes, which means it sends the data,
as well as the trailing '\0' terminator.

Both bugs combined mean it is sending '\0\0' as the last bytes, instead
of '\n' which was intended. When virFileReadAll reads data from the
pipe, it ends up adding another '\0' resulting in a very NUL terminated
string ('\0\0\0'). This is all harmless, but should be fixed regardless.

Reviewed-by: Andrea Bolognani <abologna@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2024-05-08 14:33:42 +01:00
Daniel P. Berrangé e1c32120ce tests: fix hang in virshtest 'read-big-pipe' case
The virshtest program testPipeFeeder method is doing this:

  mkfifo("test.fifo", 0600) ;

  int fd = open("test.fifo", O_RDWR);

  char buf[...];
  memset(buf, 'a', sizeof(buf));
  write(fd, buf, sizeof(buf)) == sizeof(buf));
  close(fd);

while the the 'virsh' child process then ends up doing:

  fd = open("test.fifo", O_RDONLY);
  read(fd, buf, sizeof(buf)) == sizeof(buf));
  close(fd);

The 'virsh' code hangs on open() on at least ppc64 and some other
arches. It can be provoked to hang even on x86 by reducing the size of
the buffer. It can be prevented from hanging on ppc64 by increasing the
size of the buffer.

What is happening is a result of differing page sizes, altering the
overall pipe capacity size, since pipes on linux default to 16 pages
in size and thus have architecture specific capacity when measured
in bytes.

 * On x86, testPipeFeeder opens R+W, tries to write 140kb and
   write() blocks because the pipe is full. This gives time for
   virsh to start up, and it can open the pipe for O_RDONLY
   since testPipeFeeder still has it open for write. Everything
   works as intended.

 * On ppc64,  testPipeFeeder opens R+W, tries to write 140kb
   and write() succeeds because the larger 64kb page size
   resulted in greater buffer capacity for the pipe. It thus
   quickly closes the pipe, removing the writer, and triggering
   discard of all the unread data. Now virsh starts up, tries
   to open the pipe for O_RDONLY and blocks waiting for a new
   writer to open it, which will never happen. Meson kills
   the test after 30 seconds.

   NB, every now & then, it will not block because virsh starts
   up quickly enough that testPipeFeeder has not yet closed the
   write end of the pipe, giving the illusion of correctness.

The key flaw here is that it should not have been using O_RDWR
in testPipeFeeder. Synchronization is required such that both
virsh and testPipeFeeder have their respective ends of the pipe
open before any data is sent. This is trivially arranged by
using O_WRONLY in testPipeFeeder.

Reviewed-by: Andrea Bolognani <abologna@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2024-05-08 14:33:34 +01:00
9 changed files with 83 additions and 37 deletions

View File

@ -4,6 +4,7 @@ option('packager_version', type: 'string', value: '', description: 'Extra packag
option('system', type: 'boolean', value: false, description: 'Set install paths to system ones')
option('runstatedir', type: 'string', value: '', description: 'State directory for temporary sockets, pid files, etc')
option('initconfdir', type: 'string', value: '', description: 'directory for init script configuration files')
# dep:tests
option('expensive_tests', type: 'feature', value: 'auto', description: 'set the default for enabling expensive tests (long timeouts)')
option('test_coverage', type: 'boolean', value: false, description: 'turn on code coverage instrumentation')
option('git_werror', type: 'feature', value: 'auto', description: 'use -Werror if building from GIT')
@ -17,6 +18,7 @@ option('tests', type: 'feature', value: 'auto', description: 'whether to build a
option('apparmor', type: 'feature', value: 'auto', description: 'apparmor support')
option('attr', type: 'feature', value: 'auto', description: 'attr support')
option('audit', type: 'feature', value: 'auto', description: 'audit support')
# dep:readline
option('bash_completion', type: 'feature', value: 'auto', description: 'bash-completion support')
option('bash_completion_dir', type: 'string', value: '', description: 'directory containing bash completion scripts')
option('blkid', type: 'feature', value: 'auto', description: 'blkid support')
@ -40,7 +42,9 @@ option('sanlock', type: 'feature', value: 'auto', description: 'sanlock support'
option('sasl', type: 'feature', value: 'auto', description: 'sasl support')
option('selinux', type: 'feature', value: 'auto', description: 'selinux support')
option('selinux_mount', type: 'string', value: '', description: 'set SELinux mount point')
# dep:pciaccess
option('udev', type: 'feature', value: 'auto', description: 'udev support')
# dep:driver_remote
option('wireshark_dissector', type: 'feature', value: 'auto', description: 'wireshark support')
option('wireshark_plugindir', type: 'string', value: '', description: 'wireshark plugins directory for use when installing wireshark plugin')
option('yajl', type: 'feature', value: 'auto', description: 'yajl support')
@ -48,17 +52,26 @@ option('yajl', type: 'feature', value: 'auto', description: 'yajl support')
# build driver options
option('driver_bhyve', type: 'feature', value: 'auto', description: 'bhyve driver')
# dep:curl
option('driver_esx', type: 'feature', value: 'auto', description: 'esx driver')
# dep:openwsman
option('driver_hyperv', type: 'feature', value: 'auto', description: 'Hyper-V driver')
# dep:pciaccess dep:udev dep:driver_remote dep:driver_libvirtd
option('driver_interface', type: 'feature', value: 'auto', description: 'host interface driver')
# dep:driver_remote
option('driver_libvirtd', type: 'feature', value: 'auto', description: 'libvirtd driver')
# dep:driver_remote dep:driver_libvirtd
option('driver_libxl', type: 'feature', value: 'auto', description: 'libxenlight driver')
# dep:driver_remote dep:driver_libvirtd
option('driver_lxc', type: 'feature', value: 'auto', description: 'Linux Container driver')
# dep:curl dep:yajl dep:driver_remote dep:driver_libvirtd
option('driver_ch', type: 'feature', value: 'auto', description: 'Cloud-Hypervisor driver')
option('ch_user', type: 'string', value: '', description: 'username to run Cloud-Hypervisor system instance as')
option('ch_group', type: 'string', value: '', description: 'groupname to run Cloud-Hypervisor system instance as')
# dep:driver_remote dep:driver_libvirtd
option('driver_network', type: 'feature', value: 'auto', description: 'virtual network driver')
option('driver_openvz', type: 'feature', value: 'auto', description: 'OpenVZ driver')
# dep:yajl dep:driver_remote dep:driver_libvirtd
option('driver_qemu', type: 'feature', value: 'auto', description: 'QEMU/KVM driver')
option('qemu_user', type: 'string', value: '', description: 'username to run QEMU system instance as')
option('qemu_group', type: 'string', value: '', description: 'groupname to run QEMU system instance as')
@ -74,7 +87,9 @@ option('driver_vmware', type: 'feature', value: 'auto', description: 'VMware dri
option('driver_vz', type: 'feature', value: 'auto', description: 'Virtuozzo driver')
option('secdriver_apparmor', type: 'feature', value: 'auto', description: 'use AppArmor security driver')
# dep:secdriver_apparmor
option('apparmor_profiles', type: 'feature', value: 'auto', description: 'install apparmor profiles')
# dep:selinux
option('secdriver_selinux', type: 'feature', value: 'auto', description: 'use SELinux security driver')
@ -97,16 +112,21 @@ option('storage_zfs', type: 'feature', value: 'auto', description: 'ZFS backend
option('chrdev_lock_files', type: 'string', value: '', description: 'location for UUCP style lock files for character devices (leave empty for default paths on some platforms)')
option('dtrace', type: 'feature', value: 'auto', description: 'use dtrace for static probing')
option('firewalld', type: 'feature', value: 'auto', description: 'firewalld support')
# dep:firewalld
option('firewalld_zone', type: 'feature', value: 'auto', description: 'whether to install firewalld libvirt zone')
option('host_validate', type: 'feature', value: 'auto', description: 'build virt-host-validate')
option('init_script', type: 'combo', choices: ['systemd', 'openrc', 'check', 'none'], value: 'check', description: 'Style of init script to install')
option('loader_nvram', type: 'string', value: '', description: 'Pass list of pairs of <loader>:<nvram> paths. Both pairs and list items are separated by a colon.')
option('login_shell', type: 'feature', value: 'auto', description: 'build virt-login-shell')
# dep:yajl dep:driver_network dep:libvirtd
option('nss', type: 'feature', value: 'auto', description: 'enable Name Service Switch plugin for resolving guest IP addresses')
# dep:numactl
option('numad', type: 'feature', value: 'auto', description: 'use numad to manage CPU placement dynamically')
option('nbdkit', type: 'feature', value: 'auto', description: 'Build nbdkit storage backend')
# dep:nbdkit
option('nbdkit_config_default', type: 'feature', value: 'auto', description: 'Whether to use nbdkit storage backend for network disks by default (configurable)')
option('pm_utils', type: 'feature', value: 'auto', description: 'use pm-utils for power management')
option('sysctl_config', type: 'feature', value: 'auto', description: 'Whether to install sysctl configs')
# dep:sysctl_config
option('userfaultfd_sysctl', type: 'feature', value: 'auto', description: 'Whether to install sysctl config for enabling unprivileged userfaultfd')
option('tls_priority', type: 'string', value: 'NORMAL', description: 'set the default TLS session priority string')

View File

@ -1,6 +1,6 @@
subdir('rpcgen')
if tests_enabled[0]
if tests_enabled[0] and xdr_dep.found()
subdir('tests')
if pytest_prog.found() and host_machine.system() != 'darwin'

View File

@ -578,6 +578,8 @@ endif
# build libvirt shared modules
virt_module_deps = []
foreach module : virt_modules
mod = shared_module(
module['name'],
@ -607,6 +609,7 @@ foreach module : virt_modules
install_rpath: libvirt_rpath,
)
set_variable('@0@_module'.format(module['name'].underscorify()), mod)
virt_module_deps += mod
endforeach
@ -1048,7 +1051,8 @@ if tests_enabled[0]
'-I', data['builddir'],
data['file'].full_path(),
],
suite: 'script'
suite: 'script',
depends: [data['file']]
)
endforeach
endif

View File

@ -774,8 +774,6 @@ nodeDeviceGetMdevctlCommand(virNodeDeviceDef *def,
}
if (nodeDeviceDefToMdevctlConfig(def, &inbuf, true) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("couldn't convert node device def to mdevctl JSON"));
return NULL;
}

View File

@ -33,6 +33,7 @@ static char *fchost_prefix;
#define TEST_FC_HOST_NUM 5
#define TEST_FC_HOST_NUM_NO_FAB 6
#ifdef WITH_TEST
/* virNodeDeviceCreateXML using "<parent>" to find the vport capable HBA */
static const char test7_xml[] =
"<device>"
@ -85,7 +86,7 @@ static const char test11_xml[] =
" <path>/dev/disk/by-path</path>"
" </target>"
"</pool>";
#endif /* WITH_TEST */
/* Test virIsVHBACapable */
static int
@ -222,7 +223,7 @@ test6(const void *data G_GNUC_UNUSED)
}
#ifdef WITH_TEST
/* Test manageVHBAByNodeDevice
* - Test both virNodeDeviceCreateXML and virNodeDeviceDestroy
* - Create a node device vHBA allowing usage of various different
@ -313,7 +314,7 @@ manageVHBAByStoragePool(const void *data)
virConnectClose(conn);
return ret;
}
#endif
static int
mymain(void)
@ -334,6 +335,7 @@ mymain(void)
ret = -1;
if (virTestRun("virVHBAGetConfig-empty-fabric_wwn", test6, NULL) < 0)
ret = -1;
#ifdef WITH_TEST
if (virTestRun("manageVHBAByNodeDevice-by-parent", manageVHBAByNodeDevice,
test7_xml) < 0)
ret = -1;
@ -349,6 +351,7 @@ mymain(void)
if (virTestRun("manageVHBAByStoragePool-by-parent", manageVHBAByStoragePool,
test11_xml) < 0)
ret = -1;
#endif
VIR_FREE(fchost_prefix);
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;

View File

@ -20,7 +20,7 @@
#include <config.h>
#if defined(WITH_LIBXL) && defined(WITH_YAJL)
#if defined(WITH_LIBXL)
# include "virmock.h"
# include <sys/stat.h>
# include <unistd.h>
@ -168,4 +168,4 @@ libxlDomainGetEmulatorType(const virDomainDef *def G_GNUC_UNUSED)
return LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN;
}
#endif /* WITH_LIBXL && WITH_YAJL */
#endif /* WITH_LIBXL */

View File

@ -28,7 +28,7 @@
#include "testutils.h"
#if defined(WITH_LIBXL) && defined(WITH_YAJL)
#if defined(WITH_LIBXL)
# include "internal.h"
# include "libxl/libxl_conf.h"
@ -224,4 +224,4 @@ int main(void)
return EXIT_AM_SKIP;
}
#endif /* WITH_LIBXL && WITH_YAJL */
#endif /* WITH_LIBXL */

View File

@ -74,7 +74,6 @@ endif
mock_libs = [
{ 'name': 'domaincapsmock' },
{ 'name': 'shunload', 'sources': [ 'shunloadhelper.c' ] },
{ 'name': 'vircgroupmock' },
{ 'name': 'virdnsmasqmock' },
{ 'name': 'virfilecachemock' },
@ -106,6 +105,11 @@ if host_machine.system() != 'windows'
]
endif
if conf.has('WITH_TEST')
mock_libs += [
{ 'name': 'shunload', 'sources': [ 'shunloadhelper.c' ] },
]
endif
# build libraries used by tests
@ -258,15 +262,11 @@ tests += [
{ 'name': 'domainconftest' },
{ 'name': 'genericxml2xmltest' },
{ 'name': 'interfacexml2xmltest' },
{ 'name': 'metadatatest' },
{ 'name': 'networkmetadatatest' },
{ 'name': 'networkxml2xmlupdatetest' },
{ 'name': 'nodedevxml2xmltest' },
{ 'name': 'nwfilterxml2xmltest' },
{ 'name': 'objecteventtest' },
{ 'name': 'seclabeltest' },
{ 'name': 'secretxml2xmltest' },
{ 'name': 'shunloadtest', 'deps': [ thread_dep ] },
{ 'name': 'sockettest' },
{ 'name': 'storagevolxml2xmltest' },
{ 'name': 'sysinfotest' },
@ -298,7 +298,6 @@ tests += [
{ 'name': 'virportallocatortest' },
{ 'name': 'virrotatingfiletest' },
{ 'name': 'virschematest' },
{ 'name': 'virshtest', 'depends': [ virsh_prog ] },
{ 'name': 'virstringtest' },
{ 'name': 'virsystemdtest' },
{ 'name': 'virtimetest' },
@ -333,6 +332,17 @@ if host_machine.system() == 'linux'
endif
endif
if conf.has('WITH_TEST')
tests += [
{ 'name': 'fdstreamtest' },
{ 'name': 'metadatatest' },
{ 'name': 'networkmetadatatest' },
{ 'name': 'objecteventtest' },
{ 'name': 'shunloadtest', 'deps': [ thread_dep ] },
{ 'name': 'virshtest', 'depends': [ virsh_prog ] },
]
endif
if conf.has('WITH_BHYVE')
tests += [
{ 'name': 'bhyveargv2xmltest', 'link_with': [ bhyve_driver_impl ] },
@ -364,9 +374,8 @@ endif
if conf.has('WITH_LIBVIRTD')
tests += [
{ 'name': 'eventtest', 'deps': [ thread_dep ] },
{ 'name': 'fdstreamtest' },
{ 'name': 'virdriverconnvalidatetest' },
{ 'name': 'virdrivermoduletest' },
{ 'name': 'virdrivermoduletest', 'depends': virt_module_deps },
]
endif
@ -393,7 +402,7 @@ if conf.has('WITH_NETWORK')
]
endif
if conf.has('WITH_NODE_DEVICES')
if conf.has('WITH_NODE_DEVICES') and conf.has('WITH_YAJL')
tests += [
{ 'name': 'nodedevmdevctltest', 'link_with': [ node_device_driver_impl ] },
]
@ -499,7 +508,9 @@ if conf.has('WITH_SECDRIVER_SELINUX')
]
endif
endif
endif
if conf.has('WITH_SELINUX')
mock_libs += [
{ 'name': 'securityselinuxhelper' },
]
@ -619,12 +630,14 @@ test(
suite: 'script',
)
# vsh based client self-test, which can be run directly from meson
test('virsh self-test',
virsh_prog,
args: [ '-q', '-c', 'test:///default', 'self-test' ],
suite: 'bin',
)
if conf.has('WITH_TEST')
# vsh based client self-test, which can be run directly from meson
test('virsh self-test',
virsh_prog,
args: [ '-q', '-c', 'test:///default', 'self-test' ],
suite: 'bin',
)
endif
if conf.has('WITH_REMOTE')
test('virt-admin self-test',
@ -700,6 +713,12 @@ endforeach
# list of test scripts to run
test_scripts = []
if conf.has('WITH_TEST')
test_scripts += [
{ 'name': 'virsh-auth', 'depends': [ virsh_prog ] }
]
endif
if conf.has('WITH_LIBVIRTD')
test('libvirtd fail with missing config',
libvirtd_prog,
@ -708,18 +727,20 @@ if conf.has('WITH_LIBVIRTD')
suite: 'bin',
)
test_scripts += [
'virsh-auth',
]
if conf.has('WITH_SECDRIVER_APPARMOR')
test_scripts += 'virt-aa-helper-test'
test_scripts += { 'name': 'virt-aa-helper-test' }
endif
endif
foreach name : test_scripts
script = find_program(name)
test(name, script, env: tests_env, suite: 'script')
foreach data : test_scripts
script = find_program(data['name'])
test(data['name'],
script,
env: tests_env,
depends: [
data.get('depends', []),
],
suite: 'script')
endforeach
testenv = runutf8

View File

@ -145,15 +145,15 @@ testPipeFeeder(void *opaque)
g_autofree char *doc = g_new0(char, emptyspace + xmlsize + 1);
VIR_AUTOCLOSE fd = -1;
if ((fd = open(pipepath, O_RDWR)) < 0) {
if ((fd = open(pipepath, O_WRONLY)) < 0) {
fprintf(stderr, "\nfailed to open pipe '%s': %s\n", pipepath, g_strerror(errno));
return;
}
memset(doc, ' ', emptyspace);
virStrcpy(doc + emptyspace, xml, xmlsize);
g_assert(virStrcpy(doc + emptyspace, xml, xmlsize + 1) == 0);
if (safewrite(fd, doc, emptyspace + xmlsize + 1) < 0) {
if (safewrite(fd, doc, emptyspace + xmlsize) < 0) {
fprintf(stderr, "\nfailed to write to pipe '%s': %s\n", pipepath, g_strerror(errno));
return;
}