Commit Graph

226 Commits

Author SHA1 Message Date
Peter Krempa
d154807d5b tests: utils: Introduce helper for dispatching libvirt errors
In cases when we call a libvirt helper which reports an error the error
would be hidden unless libvirt library debug is on. This produces a lot
of output and is hard to debug.

The helper provides a way to dispatch the libvirt error in specific
cases sice we do already dispatch it in case when virTestRun is used.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2019-11-20 12:57:50 +01:00
Pavel Hrdina
43b01ef2d6 replace use of gnulib snprintf by g_snprintf
Glib implementation follows the ISO C99 standard so it's safe to replace
the gnulib implementation.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2019-11-15 15:07:40 +01:00
Ján Tomko
5c89468ff2 remove unused regex.h includes
The code using regexes got moved, but the include stayed.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2019-11-14 17:45:40 +01:00
Michal Privoznik
4fa804c0c7 tests: Use g_strdup_printf() instead of virAsprintf()
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2019-11-12 16:15:59 +01:00
Peter Krempa
205d6a2af7 util: buffer: Remove virBufferError
The function now does not return an error so we can drop it fully.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-10-24 19:35:34 +02:00
Ján Tomko
29b1e859e3 tests: use g_strdup instead of VIR_STRDUP
Replace all occurrences of
  if (VIR_STRDUP(a, b) < 0)
     /* effectively dead code */
with:
  a = g_strdup(b);

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2019-10-21 12:51:59 +02:00
Ján Tomko
64023f6d21 Use g_strdup instead of ignoring VIR_STRDUP's value
Replace all the occurrences of
  ignore_value(VIR_STRDUP(a, b));
with
  a = g_strdup(b);

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2019-10-21 12:51:55 +02:00
Daniel P. Berrangé
5722e26ec5 util: drop logging filter/output flags
With the removal of support for log message stack traces, there is
nothing using the logging filter/output flags and they can be removed.

Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2019-10-18 16:25:17 +01:00
Daniel P. Berrangé
9b80e0c12a util: drop support for stack traces with logging
The log filters have supported the use of a "+" before the source match
string to request that a stack trace be emitted for every log message:

  commit 548563956e
  Author: Daniel P. Berrange <berrange@redhat.com>
  Date:   Wed May 9 15:18:56 2012 +0100

    Allow stack traces to be included with log messages

    Sometimes it is useful to see the callpath for log messages.
    This change enhances the log filter syntax so that stack traces
    can be show by setting '1:+NAME' instead of '1:NAME'.

With the huge & ever increasing number of logging statements per file,
this will be incredibly verbose and have a major performance penalty.
This makes the feature impractical to use widely and as such it is not
worth the code maint cost.

Removing this seldom used feature allows us to drop the 'execinfo'
module in gnulib which provides the backtrace() function which doesn't
exist on non-Linux.

Users who want to get stack traces of parts of libvirt can use GDB,
or systemtap for live tracing with minimal perf impact.

Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2019-10-18 16:25:17 +01:00
Ján Tomko
1e2ae2e311 Use g_autofree instead of VIR_AUTOFREE
Since commit 44e7f02915
    util: rewrite auto cleanup macros to use glib's equivalent

VIR_AUTOFREE is just an alias for g_autofree. Use the GLib macros
directly instead of our custom aliases.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2019-10-16 12:06:43 +02:00
Ján Tomko
67e72053c1 Use G_N_ELEMENTS instead of ARRAY_CARDINALITY
Prefer the GLib version of the macro.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2019-10-15 16:14:19 +02:00
Ján Tomko
0d94f02455 tests: use G_GNUC_UNUSED
Use G_GNUC_UNUSED from GLib instead of ATTRIBUTE_UNUSED.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2019-10-15 11:25:25 +02:00
Daniel P. Berrangé
c4d18e8b3e util: replace strerror/strerror_r with g_strerror
g_strerror is offers the safety/correctness benefits of strerror_r, with
the API design convenience of strerror.

Use of virStrerror should be eliminated through the codebase in favour
of g_strerror.

commandhelper.c is a special case as its a tiny single threaded test
program, not linked to glib, so it just uses traditional strerror().

Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2019-10-14 10:54:42 +01:00
Daniel P. Berrangé
2c535e50f5 util: remove some no-op thread functions
Neither virThreadInitialize or virThreadOnExit do anything since we
dropped the Win32 threads impl, in favour of win-pthreads with:

  commit 0240d94c36
  Author: Daniel P. Berrange <berrange@redhat.com>
  Date:   Wed Jan 22 16:17:10 2014 +0000

      Remove windows thread implementation in favour of pthreads

Reviewed-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2019-09-19 12:50:21 +01:00
Daniel P. Berrangé
2c52ecd960 util: purge all code for testing OOM handling
The OOM handling requires special build time options which we never
enable in our CI. Even once enabled the tests are incredibly slow and
typically require manual inspection of the results to weed out false
positives.

Since there was previous agreement to switch to abort on OOM in libvirt
code, there's no point continuing to keep the unused OOM testing code.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2019-09-13 10:05:17 +01:00
Daniel P. Berrangé
b1b878c512 util: activate directory override when used from library
The Perl bindings for libvirt use the test driver for unit tests. This
tries to load the cpu_map/index.xml file, and when run from an
uninstalled build will fail.

The problem is that virFileActivateDirOverride is called by our various
binaries like libvirtd, virsh, but is not called when a 3rd party app
uses libvirt.so

To deal with this we allow the LIBVIRT_DIR_OVERRIDE=1 env variable to be
set and make virInitialize look for this. The 'run' script will set it,
so now build using this script to run against an uninstalled tree we
will correctly resolve files to the source tree.

Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2019-09-10 11:03:35 +01:00
Michal Privoznik
d07ce21610 tests: Always put a '\n' after each debug print
There is an inconsistency with VIR_TEST_DEBUG() calls. One half
(roughly) of calls does have the newline character the other one
doesn't. Well, it doesn't have it because it assumed blindly that
new line will be printed, which is not the case.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-08-27 15:49:48 +02:00
Roman Bolshakov
fde361083d tests: Add lib- prefix to all mocks
In preparation libtool "-module" flag removal, add lib prefix to all
mock shared objects.

While at it, introduce VIR_TEST_MOCK macros that makes path out of mock
name to be used with VIR_TEST_PRELOAD or VIR_TEST_MAIN_PRELOAD.  That,
hopefully, improves readability, reduces line length and allows to
tailor VIR_TEST_MOCK for specific platform if it has shared library
suffix different from ".so".

Signed-off-by: Roman Bolshakov <r.bolshakov@yadro.com>
2019-08-23 11:26:26 +01:00
Andrea Bolognani
3e8c2f30b1 tests: Don't use TEST_DRIVER_DIR in virTestCaptureProgramExecChild()
TEST_DRIVER_DIR is defined as "$(top_builddir)/src/.libs"; however,
as of commit bc6e206322, virDriverLoadModule() will search (the
absolute version of) that directory automatically, which means
passing it through the environment is no longer necessary.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
2019-03-14 10:05:21 +01:00
Andrea Bolognani
094f29df07 Use virStringHasSuffix() where possible
When dealing with internal paths we don't need to worry about
whether or not suffixes are lowercase since we have full control
over them, which means we can avoid performing case-insensitive
string comparisons.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
ACKed-by: Peter Krempa <pkrempa@redhat.com>
2019-03-07 10:10:49 +01:00
Andrea Bolognani
2de7dcba7e util: Rename virFileHasSuffix() to virStringHasCaseSuffix()
Despite its name, this is really just a general-purpose string
manipulation function, so it should be moved to the virstring
module and renamed accordingly.

In addition to the obvious s/File/String/, also tweak the name
to make it clear that the presence of the suffix is verified
using case-insensitive comparison.

A few trivial whitespace changes are squashed in.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
ACKed-by: Peter Krempa <pkrempa@redhat.com>
2019-03-07 10:08:47 +01:00
Michal Privoznik
740aeb349f testutils: Explicitly name virTestCompare*() arguments
Currently, some arguments are called strcontent and strsrc, or
content and src or some other combination. This makes it
impossible to see at the first glance what argument is supposed
to represent 'expected' value and which one represents 'actual'
value. Rename the arguments to make it obvious.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-02-20 15:54:41 +01:00
Michal Privoznik
9de317d0d1 virTestCompareToULL: Rename local variables
The current naming makes it hard for me to see which holds the
expected value and which holds the actual value. Rename them to
make it obvious.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-02-20 15:54:31 +01:00
Michal Privoznik
86d1f08669 virTestCompareToULL: Use VIR_AUTOFREE()
In order to save a few lines of code, and also since it's hype
let's use VIR_AUTOFREE() for the two strings we allocate there.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-02-20 15:53:32 +01:00
Michal Privoznik
c99e954973 Remove even more Author(s): lines from source files
In 600462834f we've tried to remove Author(s): lines
from comments at the beginning of our source files. Well, in some
files while we removed the "Author" line we did not remove the
actual list of authors.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
2019-01-03 13:24:18 +01:00
Erik Skultety
5165ff0971 src: More cleanup of some system headers already contained in internal.h
All of the ones being removed are pulled in by internal.h. The only
exception is sanlock which expects the application to include <stdint.h>
before sanlock's headers, because sanlock prototypes use fixed width
int, but they don't include stdint.h themselves, so we have to leave
that one in place.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
Acked-by: Michal Privoznik <mprivozn@redhat.com>
2018-09-20 10:16:39 +02:00
Erik Skultety
9403b63102 internal: Move <stdio.h> include to internal.h
It doesn't really make sense for us to have stdlib.h and string.h but
not stdio.h in the internal.h header.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
Acked-by: Michal Privoznik <mprivozn@redhat.com>
2018-09-20 10:16:38 +02:00
Cole Robinson
b251d6ad24 conf: Drop unnecessary caps parsing logic
The comment says:

    /* If the logic here seems fairly arbitrary, that's because it is :)
     * This is duplicating how the code worked before
     * CapabilitiesDomainDataLookup was added. We can simplify this,
     * but it would take a bit of work because the test suite fails
     * in numerous minor ways. */

Nowadays the test suite changes appear quite simple, just extending
test capabilities data a bit so that we aren't trying to define
invalid arch/os/virtType/machine combos

Acked-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
2018-07-26 10:13:00 -04:00
ramyelkest
2b6667abbf all: Replace virGetLastError with virGetLastErrorCode where we can
Replace instances where we previously called virGetLastError just to
either get the code or to check if an error exists with
virGetLastErrorCode to avoid a validity pre-check.

Signed-off-by: Ramy Elkest <ramyelkest@gmail.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
2018-06-05 18:44:05 +02:00
Andrea Bolognani
4fe4ffdbdf tests: Create full host NUMA topology in more cases
vircapstest has code to add a full host NUMA topology, that
is, one that includes all information about nodes and CPUs
including IDs; testQemuCapsInit(), which is used to create a
mock virCapsPtr for QEMU tests, however, just fakes it by
setting nnumaCell_max to some number.

While the latter approach has served us well so far, we're
going to need all the information to be filled in soon. In
order to do that, we can just move the existing code from
vircapstest to testutils and, with some renaming and
trivial tweaking, use it as-is.

Interestingly, the NUMA topology generated by the function
is rigged up so that the NUMA nodes aren't (necessarily)
numbered starting from 0, which is a nice way to spot
mistaken assumptions in our codebase.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2018-04-19 17:57:52 +02:00
Peter Krempa
9c75425aa2 tests: utils: Fix out-of-bounds access to memory in virTestCompareToFile
Similarly to 3506f1ecfd, the contents of 'cmpcontent' may be an empty
string so the following code would access memory out of the array.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2018-04-04 12:04:21 +02:00
Peter Krempa
dff110d232 tests: utils: Tolerate NULL actual data in virTestCompareToFile
The function docs state that 'strcontent' may be NULL. This was added in
8b3a0b28ba but that commit neglected to fix rest of the function.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2018-04-03 15:48:37 +02:00
Peter Krempa
1b28038300 tests: util: Remove callback from testCompareDomXML2XMLFiles
The testCompareDomXML2XMLPreFormatCallback is no longer used and thus
can be removed.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2018-03-13 13:54:11 +01:00
Martin Kletzander
b8bbc23fea Only output initialized capabilities with VIR_TEST_DEBUG > 1
Currenty virTestInit() outputs all capabilities that it created when running
with VIR_TEST_DEBUG=1.  Since this is quite a lot of output for every call of
this function (and it is not needed until debugging a really deep-down issue)
let's just output the info when VIR_TEST_DEBUG is strictly greater than 1.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2017-11-18 10:45:10 +01:00
Pino Toscano
ef5c8a91aa tests: fix TTY check in virTestUseTerminalColors()
Since colors would be used when writing to stdout, then check that
stdout is a TTY, instead of stdin.

This avoids the usage of terminal color codes when the output is
directed to file.
2017-11-10 16:12:43 +01:00
Michal Privoznik
3506f1ecfd virTestCompareToFile: Don't access memory we don't own
After reading the contents of a file some cleanup is performed.
However, the check for it might access a byte outside of the
string - if the file is empty in the first place. Then strlen()
is zero.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2017-08-07 10:44:06 +02:00
Peter Krempa
8b3a0b28ba tests: utils: Allow NULL strings to be equal to empty file in virTestCompareToFile
Treat an NULL string equivalent to an empty string in
virTestCompareToFile so that callers don't need to add additional logic
in case when a test produces no output.
2017-07-28 17:59:06 +02:00
Peter Krempa
5aec02dc37 make: Drop building without driver modules
Driver modules proved to be reliable for a long time. Since support for
not building modules complicates the code and makefiles drop it.

Reviewed-by: Daniel P. Berrange <berrange@redhat.com>
2017-07-27 12:00:35 +02:00
Peter Krempa
e5d03a2c1a tests: utils: Add virTestLoadFileJSON helper
This new helper loads, parses and returns a JSON file from 'abs_srcdir'
By using variable arguments for the function, it's not necessary to
format the path separately in the test cases.

Reviewed-by: Eric Blake <eblake@redhat.com>
2017-07-27 09:38:39 +02:00
Peter Krempa
d492b19259 tests: utils: Add virTestLoadFilePath helper
This new helper loads and returns a file from 'abs_srcdir'. By using
variable arguments for the function, it's not necessary to format the
path separately in the test cases.

Reviewed-by: Eric Blake <eblake@redhat.com>
2017-07-27 09:34:49 +02:00
Peter Krempa
55e8314efd tests: utils: Don't calculate file size in virTestLoadFile
The callers don't use it so don't waste a strlen(). Also fix the comment
for the function.

Reviewed-by: Eric Blake <eblake@redhat.com>
2017-07-27 09:29:57 +02:00
Martin Kletzander
64bebb2ba4 testutils: Remove unneeded variable
virDomainXMLOptionNew() gladly accepts NULL and it is used in some
drivers.  There is no need for additional variable with no members set

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2017-07-24 15:49:54 +02:00
Jiri Denemark
25af7e950a conf: Add save cookie callbacks to xmlopt
virDomainXMLOption gains driver specific callbacks for parsing and
formatting save cookies.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2017-06-07 13:36:01 +02:00
Martin Kletzander
f4c09b913e Reset the whole stack in testutils
The memset() was resetting only 30 bytes in the array (size of the
array), but it is array of pointers.  Since it is a static array,
let's just reset it by its size.

Found by gcc-7.1:

  testutils.c: In function 'virTestRun':
  testutils.c:243:13: error: 'memset' used with length equal to number
  of elements without multiplication by element size [-Werror=memset-elt-size]
    memset(testAllocStack, 0, ARRAY_CARDINALITY(testAllocStack));
    ^~~~~~

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2017-06-05 09:50:51 +02:00
Michal Privoznik
4f0aeed871 virDomainXMLOption: Introduce virDomainABIStabilityDomain
While checking for ABI stability, drivers might pose additional
checks that are not valid for general case. For instance, qemu
driver might check some memory backing attributes because of how
qemu works. But those attributes may work well in other drivers.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2017-06-05 09:08:52 +02:00
Andrea Bolognani
4ceac4bf29 tests: Rename VIRT_TEST_* macros to VIR_TEST_*
We use the "vir" prefix pretty consistently in our
APIs, both external and internal, which made these
macros stood out.
2017-04-04 17:30:03 +02:00
Andrea Bolognani
94918e2035 tests: Introduce virTestCompareToULL()
This will be used later on in the test suite.
2017-03-28 10:54:50 +02:00
John Ferlan
9f66e09bc5 util: Change return argument for virBitmapParseUnlimited
Rather than returning an int and a *bitmap pointer, just return and
check a NULL bitmap pointer
2017-03-22 13:49:59 -04:00
Erik Skultety
c9279169a1 daemon: Split output parsing and output defining
Since virLogParseAndDefineOutputs is going to be stripped from 'output defining'
logic, replace all relevant occurrences with virLogSetOutputs call to make the
change transparent to all original callers (daemons mostly).

Signed-off-by: Erik Skultety <eskultet@redhat.com>
2016-10-10 08:27:25 +02:00
Michal Privoznik
c41b989112 virDomainDefParse{File,String}: Introduce @parseOpaque argument
We want to pass the proper opaque pointer instead of NULL to
virDomainDefParse and subsequently virDomainDefParseNode too.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-09-26 16:50:12 +02:00