Commit Graph

285 Commits

Author SHA1 Message Date
Martin Kletzander
4cbc15d037 tests: don't fail with newer gnutls
gnutls-3.3.0 and newer leaves 2 FDs open in order to be backwards
compatible when it comes to chrooted binaries [1].  Linking
commandhelper with gnutls then leaves these two FDs open and
commandtest fails thanks to that.  This patch does not link
commandhelper with libvirt.la, but rather only the utilities making
the test pass.

Based on suggestion from Daniel [2].

[1] http://lists.gnutls.org/pipermail/gnutls-help/2014-April/003429.html
[2] https://www.redhat.com/archives/libvir-list/2014-April/msg01119.html

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2014-05-02 09:56:33 +02:00
Dwight Engen
2a1ea9067f build: add nwfilterxml2firewalldata to dist
Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
2014-04-25 17:49:02 +01:00
Daniel P. Berrange
3ba789ccd5 Add a test suite for nwfilter ebiptables tech driver
Create a nwfilterxml2firewalltest to exercise the
ebiptables_driver.applyNewRules method with a variety of
different XML input files. The XML input files are taken
from the libvirt-tck nwfilter tests. While the nwfilter
tests verify the final state of the iptables chains, this
test verifies the set of commands invoked to create the
chains.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2014-04-25 15:44:10 +01:00
Daniel P. Berrange
8d55986427 Convert nwfilter ebiptablesAllTeardown to virFirewall
Convert the nwfilter ebiptablesAllTeardown method to use the
virFirewall object APIs instead of creating shell scripts
using virBuffer APIs. This provides a performance improvement
through allowing direct use of firewalld dbus APIs and will
facilitate automated testing.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2014-04-25 15:44:09 +01:00
Daniel P. Berrange
20512b8436 Add test for converting network XML to iptables rules
Using the virCommand dry run capability, capture iptables rules
created by various network XML documents.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2014-04-25 15:44:09 +01:00
Daniel P. Berrange
3a0ca7de51 Introduce an object for managing firewall rulesets
The network and nwfilter drivers both have a need to update
firewall rules. The currently share no code for interacting
with iptables / firewalld. The nwfilter driver is fairly
tied to the concept of creating shell scripts to execute
which makes it very hard to port to talk to firewalld via
DBus APIs.

This patch introduces a virFirewallPtr object which is able
to represent a complete sequence of rule changes, with the
ability to have multiple transactional checkpoints with
rollbacks. By formally separating the definition of the rules
to be applied from the mechanism used to apply them, it is
also possible to write a firewall engine that uses firewalld
DBus APIs natively instead of via the slow firewalld-cmd.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2014-04-25 15:44:09 +01:00
Daniel P. Berrange
18dc77d3b5 Add test suite for viralloc APIs
In debugging a crash on OOM, I thought that the virInsert APIs
might be at fault, but couldn't isolate them as a cause. While
the viralloc APIs are used in many test suites, this is as a
side-effect, they are not directly tested :-)

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2014-04-25 11:29:55 +01:00
Jiri Denemark
844a5c1eed tests: Fix systemd test with --without-driver-modules
Every test that makes use of virmock.h (only virsystemdtest as of now)
needs to be linked with -export-dynamic to make sure the LD_PRELOADed
mock library can access its wrap_* symbols. Normally,
DRIVER_MODULE_LDFLAGS variable contains -export-dynamic but when
--without-driver-modules configure option is used, DRIVER_MODULE_LDFLAGS
is empty.

This patch turns on -export-dynamic for all tests unconditionally
regardless on --without-driver-modules. This fixes virsystemdtest and
all future users of virmock.h.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2014-04-10 20:30:41 +02:00
Roman Bogorodskiy
6d7a287c5a tests: add bhyve xml2xml test
The only implemented test for now is domain metadata test.
2014-04-08 20:50:36 +04:00
Daniel P. Berrange
4607168e77 Switch systemd test to use generic dbus mock
Remove the virsystemdmock.la library and instead make use
of the shared virmockdbus.la library

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2014-04-08 11:04:09 +01:00
Daniel P. Berrange
2c3ce1de94 Create a re-usable DBus LD_PRELOAD mock library
A number of test suites want to mock the DBus APIs. To avoid
re-inventing the wheel create a re-usable virmockdbus.la
library for LD_PRELOAD usage.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2014-04-08 11:03:59 +01:00
Daniel P. Berrange
442ba49351 Introduce a new set of helper macros for mocking symbols
Introduce virmock.h which provides some macros to assist in
creation of LD_PRELOAD overrides. When these are used, the
LD_PRELOAD code simply has some stubs which forward to a
wrapper function inside the main test case. This means that
logic for the test no longer has to be split between the
virXXXtest.c and virXXXmock.c files. It will also make it
possible to provide some common reusable modules for mocking
code like DBus.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2014-04-08 11:03:54 +01:00
Guido Günther
ed1b5d8e8d tests: link against libxml2
to avoid

CCLD     storagevolxml2argvtest
/usr/bin/ld: ../src/.libs/libvirt_driver_storage_impl.a(libvirt_driver_storage_impl_la-storage_backend.o): undefined reference to symbol 'xmlFreeDoc@@LIBXML2_2.4.30'
//usr/lib/x86_64-linux-gnu/libxml2.so.2: error adding symbols: DSO missing from command line
2014-04-08 08:42:16 +02:00
Jincheng Miao
cdc5f3f1a3 tests: build viridentitytest only WITH_ATTR.
Commit d7c4e0036 assumed all SELinux tests depended upon
securityselinuxhelper need xattr support, but forgot to
move viridentitytest under WITH_ATTR.

Reported-by: Nehal J Wani <nehaljw.kkd1@gmail.com>
Signed-off-by: Jincheng Miao <jmiao@redhat.com>
2014-04-07 13:49:24 +02:00
Roman Bogorodskiy
1994d2dddb bhyve: add xml2args unittest
At this point unittest covers 4 basic cases:

 - minimal working XML for bhyve
 - same as above, but with virtio disk
 - ACPI and APIC args test
 - MAC address test
2014-03-27 08:33:41 +04:00
Francesco Romani
231b63e3ca qemu: add unit tests for the capabilities xml
The test is loosely inspired from qemucapabilitiestest
and qemuxml2xmltest.

Added a new test instead of extending an existing one because
the feature being tested don't really fits nicely in any
existing place.
2014-03-26 13:41:25 +01:00
Jiri Denemark
11cb128f21 tests: Set abs_*dir in a consistent way
Use $(shell cd $(...) && pwd) to set abs_*dir variables similarly to
what src/Makefile.am does.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2014-03-20 22:25:46 +01:00
Ján Tomko
c22e989df6 Add test for virISCSIGetSession
Parse iscsiadm output with and without the recently introduced
flashnode info. [1]

This should check that commits like 57e17a7 (fixing [2]) do
not break iscsiadm output parsing.

[1] https://github.com/mikechristie/open-iscsi/commit/181af9a
[2] https://bugzilla.redhat.com/show_bug.cgi?id=1067173
2014-03-20 18:10:34 +01:00
Martin Kletzander
eeb1e80e7f build: Fix make distcheck
I forgot to delete the underscore in object_locking_SOURCES when
changing the name in one of previous cleanups.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2014-03-19 14:43:08 +01:00
Martin Kletzander
db272ebf9d tests: cleanup object-locking test
When ran, cil is throwing out some errors and warnings for obsolete
'or' unused variables and wrong module name (it should not contain a
hyphen; hence the rename).

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2014-03-18 10:20:49 +01:00
Chunyan Liu
cd618e0212 add unit test for new virhostdev common library
Add unit test for hostdev common library. Current tests are based on virpcimock.
2014-03-12 17:03:16 +00:00
Jiri Denemark
7176221a9e tests: Distribute securityselinuxhelperdata
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2014-03-11 11:07:52 +01:00
Daniel P. Berrange
3a7fe8d508 Add helper APIs for generating cryptographic hashes
GNULIB provides APIs for calculating md5 and sha256 hashes,
but these APIs only return you raw byte arrays. Most users
in libvirt want the hash in printable string format. Add
some helper APIs in util/vircrypto.{c,h} for doing this.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2014-03-10 16:39:18 +00:00
Michael Chapman
8914b875ea tests: Test virIdentityGetSystem
Test it once with SELinux enabled and once with it disabled.

Signed-off-by: Michael Chapman <mike@very.puzzling.org>
2014-03-07 15:27:00 +01:00
Ján Tomko
a093628857 Replace space with a tab in the Makefile
All the other test_programs in the section use tabs
and virportallocatortest sticks out with tab width
other than 8.
2014-03-03 14:35:22 +01:00
Ján Tomko
855e9faa19 Add tests for virUSBDeviceFind functions
Mock the /sys/bus/usb directory and test the finding
(and not finding) of some USB devices.
2014-03-03 14:35:22 +01:00
Eric Blake
f2dc1f6704 build: avoid ld_preload tests on mingw
Running ./autobuild.sh complained during the mingw cross-compile:

  CC       libvirportallocatormock_la-virportallocatortest.lo
../../tests/virportallocatortest.c:32:20: fatal error: dlfcn.h: No such file or directory
 # include <dlfcn.h>
                    ^
compilation terminated.  With that fixed, the next failure was:

  CCLD     qemuxml2argvmock.la
libtool: link: libtool library `qemuxml2argvmock.la' must begin with `lib'
libtool: link: Try `libtool --help --mode=link' for more information.

While we don't need to limit all LD_PRELOAD tests to just Linux, we
do need to limit them to platforms that actually support loading;
we also need to avoid building qemu tests when qemu is not enabled.

* tests/virportallocatortest.c: Make conditional on <dlfcn.h>.
* tests/Makefile.am (test_libraries): Only build qemu mock library
when building qemu tests.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-02-25 18:51:11 -07:00
Daniel P. Berrange
432a3fee3b Rename virDomainGetRootFilesystem to virDomainGetFilesystemForTarget
The virDomainGetRootFilesystem method can be generalized to allow
any filesystem path to be obtained.

While doing this, start a new test case for purpose of testing various
helper methods in the domain_conf.{c,h} files, such as this one.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2014-02-20 15:50:46 +00:00
Ján Tomko
665344da01 Add tests for secret XML parsing
also validate it against the RNG schema.
2014-02-14 16:47:14 +01:00
Cédric Bosdonnat
18fb3df463 Forgot to add lxcconf2xmldata to dist. 2014-02-14 16:13:54 +01:00
Peter Krempa
e32268184b storage: Add file storage APIs in the default storage driver
Add APIs that will allow to use the storage driver to assist in
operations on files even for remote filesystems without native
representation as files in the host.
2014-02-14 10:47:56 +01:00
Cédric Bosdonnat
7195c807b2 LXC driver: started implementing connectDomainXMLFromNative
This function aims at converting LXC configuration into a libvirt
domain XML description to help users migrate from LXC to libvirt.

Here is an example of how the lxc configuration works:
virsh -c lxc:/// domxml-from-native lxc-tools /var/lib/lxc/migrate_test/config

It is possible that some parts couldn't be properly mapped into a
domain XML fragment, so users should carefully review the result
before creating the domain.

fstab files in lxc.mount lines will need to be merged into the
configuration file as lxc.mount.entry.

As we can't know the amount of memory of the host, we have to set a
default value for max_balloon that users will probably want to adjust.
2014-02-12 17:52:46 +00:00
Pradipta Kr. Banerjee
eb64e8752b vircapstest: Introduce virCapabilitiesGetCpusForNodemask test
This test creates a Fake NUMA topology with non-sequential cell ids
to check if libvirt properly handles the same

Signed-off-by: Shivaprasad G Bhat <sbhat@linux.vnet.ibm.com>
Signed-off-by: Pradipta Kr. Banerjee <bpradip@in.ibm.com>
2014-02-11 14:44:20 +00:00
Michal Privoznik
e505db0f6c qemuxml2argvtest: Test localtime clock basis
When trying to introduce a test for previous patch, I've
noticed that the command line is constructed using current
time. This won't work in our test suite (unless you guys
wants to set a specific time prior to each test run :) ).
Therefore we need to mock calls to time(2) to return the
same value every time it's called.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2014-02-06 08:22:22 +01:00
John Ferlan
02bf6568f4 tests: Add test for new virkmod functions
Adding tests for new virKMod{Config|Load|Unload}() API's.

A test for virKModIsBlacklisted() would require some setup which cannot
be assumed.
2014-02-04 08:59:37 -05:00
Michal Privoznik
defec0de5f virnetdevbandwidthtest: Link with libxml2
I've received a notice over IRC that on some systems, the
virnetdevbandwidthtest is not linked with libxml:

  /usr/bin/ld: virnetdevbandwidthtest.o: undefined reference to symbol 'xmlStrEqual@@LIBXML2_2.4.30'
  /usr/lib/x86_64-linux-gnu/libxml2.so.2: error adding symbols: DSO missing from command line

Trivial way avoiding this is to add LIBXML_LIBS to
virnetdevbandwidthtest_LDADD.
2014-02-03 17:50:32 +01:00
Osier Yang
6fdece9a33 tests: Add tests for scsi utils
This creates the basic unit tests for the scsi utils.

Signed-off-by: Osier Yang <jyang@redhat.com>
2014-01-30 15:50:37 +08:00
Michal Privoznik
2636dc8c4d tests: Introduce virnetdevbandwidthtest
The only API tested so far would be virNetDevBandwidthMinimal.
But there's more to come!

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2014-01-27 12:11:34 +01:00
Cédric Bosdonnat
b775b48e94 Added domain start/stop/define/undefine event unit tests
These unit tests are aiming at providing some help during the domain
events refactoring.
2013-12-10 11:23:20 +00:00
Daniel P. Berrange
d45b833d14 Pull lxcContainerGetSubtree out into shared virfile module
Move the code for lxcContainerGetSubtree into the virfile
module creating 2 new functions

  int virFileGetMountSubtree(const char *mtabpath,
                             const char *prefix,
                             char ***mountsret,
                             size_t *nmountsret);
  int virFileGetMountReverseSubtree(const char *mtabpath,
                                    const char *prefix,
                                    char ***mountsret,
                                    size_t *nmountsret);

Add a new virfiletest.c test case to validate the new code.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-11-28 11:49:01 +00:00
Eric Blake
0aa873d741 tests: guarantee abs_srcdir in all C tests
While trying to debug a failure of virpcitest during 'make distcheck',
I noticed that with a VPATH build, 'cd tests; ./virpcitest' fails for
an entirely different reason.  To reproduce the distcheck failure, I
had to run 'cd tests; abs_srcdir=/path/to/src ./virpcitest'.  But we
document in HACKING that all of our tests are supposed to be runnable
without requiring extra environment variables.

The solution: hardcode the location of srcdir into the just-built
binaries, rather than requiring make to prepopulate environment
variables.  With this, './virpcitest' passes even in a VPATH build
(provided that $(srcdir) is writable; a followup patch will fix the
conditions required by 'make distcheck').  [Note: the makefile must
still pass on directory variables to the test environment of shell
scripts, since those aren't compiled.  So while this solves the case
of a compiled test, it still requires environment variables to pass
a VPATH build of any shell script test case that relies on srcdir.]

* tests/Makefile.am (AM_CFLAGS): Define abs_srcdir in all compiled
tests.
* tests/testutils.h (abs_srcdir): Quit declaring.
* tests/testutils.c (virtTestMain): Rely on define rather than
environment variable.
* tests/virpcimock.c (pci_device_new_from_stub): Rely on define.
* tests/cputest.c (mymain): Adjust abs_top_srcdir default.
* tests/qemuxml2argvtest.c (mymain): Likewise.
* tests/qemuxmlnstest.c (mymain): Likewise.

Signed-off-by: Eric Blake <eblake@redhat.com>
2013-11-27 14:39:56 -07:00
Jiri Denemark
3afde0756f qemu: Add monitor APIs to fetch CPUID data from QEMU
The qemu monitor supports retrieval of actual CPUID bits presented to
the guest using QMP monitor. Add APIs to extract these information and
tests for them.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2013-11-08 09:44:36 +01:00
Michal Privoznik
5ac7f07860 tests: Distribute virpcitestdata
Since 21685c955e we have tests/virpcitestdata dir containing the PCI
config files for some dummy PCI devices that are used int virpcitest.
However, the directory containing the config files is not distributed
making 'make rpm' fail.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2013-11-07 11:59:14 +01:00
Michal Privoznik
25527ae25c virpcitest: Test virPCIDeviceDetach
This commit introduces yet another test under virpcitest:
virPCIDeviceDetach. However, in order to be able to do this, the
virpcimock needs to be extended to model the kernel behavior on PCI
device binding and unbinding (create 'driver' symlinks under the device
tree, check for device ID in driver's ID table, etc.)

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2013-11-04 17:28:48 +01:00
Michal Privoznik
d770618842 tests: Introduce virpcitest
Among with this test introduce virpcimock as we need to mock some
syscalls, e.g. redirect open() of a file under /sys/bus/pci to a
stub sysfs tree.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2013-11-04 14:56:56 +01:00
Michal Privoznik
9eb68903f5 tests: Use lv_abs_top_builddir instead of bare abs_top_builddir
As stated in the comment above introduction of the lv_abs_top_builddir
variable, older automake doesn't provide abs_top_builddir variable.
Hence, we are creating our own one with lv_ prefix. However, when
exporting env variables to the tests, the variables are not evaluated
but only substituted. Hence:

  LIBVIRT_DRIVER_DIR="$(abs_top_builddir)/src/.libs"

is set to "/src/.libs" with old automake (even though we *think* we've
set the $abs_top_builddir variable just a few line above).

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2013-10-22 15:42:15 +01:00
Daniel Hansel
6285c17f79 build: Add lxc testcase to dist list
Introduced by commit 3f029fb531 the RPM build
was broken due to a missing LXC textcase.

Signed-off-by: Daniel Hansel <daniel.hansel@linux.vnet.ibm.com>
2013-10-15 14:31:21 +02:00
Daniel P. Berrange
5787f0b95e Fix flaw in detecting log format
The log message regex has been

[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}\.[0-9]{3}\+[0-9]{4}: [0-9]+: debug|info|warning|error :

The precedence of '|' is high though, so this is equivalent to matching

   [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}\.[0-9]{3}\+[0-9]{4}: [0-9]+: debug

Or

   info

Or

   warning

Or

   error :

Which is clearly not what it should have done. This caused the code to
skip over things which are not log messages. The solution is to simply
add brackets.

A test case is also added to validate correctness.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-10-14 10:31:01 +01:00
Eric Blake
bdc55cc7d2 build: fix build --without-remote
I tried to test ./configure --without-lxc --without-remote.
First, the build failed with some odd errors, such as an
inability to build xen, or link failures for virNetTLSInit.
But when you think about it, once there is no remote code,
all of libvirtd is useless, any stateful driver that depends
on libvirtd is also not worth compiling, and any libraries
used only by RPC code are not needed.  So I patched
configure.ac to make for some saner defaults when an
explicit disable is attempted.  Similarly, since we have
migrated virnetdevbridge into generic code, the workaround
for Linux kernel stupidity must not depend on stateful
drivers being in use.

Then there's 'make check' that needs segregation.

Wow - quite a bit of cleanup to make --without-remote useful :)

* configure.ac: Let --without-remote toggle defaults on stateful
drivers and other libraries.  Pick up Linux kernel workarounds
even when qemu and lxc are not being compiled.
* tests/Makefile.am (test_programs): Factor out programs that
require remote.
* src/libvirt_private.syms (rpc/virnet*.h): Move...
* src/libvirt_remote.syms: ...into new file.
* src/Makefile.am (SYM_FILES): Ship new syms file.

Signed-off-by: Eric Blake <eblake@redhat.com>
2013-10-04 17:01:47 -06:00
Michal Privoznik
63857eb4a0 tests: Introduce qemucapabilitiestest
This test is there to ensure that our capabilities detection code isn't
broken somehow.

How to gather test data:

Firstly, the data is split into two separate files. The former (with
suffix .replies) contains all the qemu replies. This is very fragile as
introducing a new device can mean yet another monitor command and hence
edit of this file in the future. But there's no better way of doing
this. To get this data simply turn on debug logs and copy all the
QEMU_MONITOR_IO_PROCESS lines. But be careful to not copy incomplete
ones (yeah, we report some incomplete lines too). Long story short, at
the libvirtd startup, a dummy qemu is spawn to get all the capabilities.

The latter (with suffix .caps) contains capabilities XML. Just start a
domain and copy the corresponding part from its state XML file.
Including <qemuCaps> tag.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2013-10-01 11:13:36 +02:00