2006-05-09 15:35:46 +00:00
|
|
|
/*
|
2014-03-07 13:38:51 +00:00
|
|
|
* testutils.h: test utils
|
2006-05-09 15:35:46 +00:00
|
|
|
*
|
2013-02-22 22:42:39 +00:00
|
|
|
* Copyright (C) 2005, 2008-2013 Red Hat, Inc.
|
2006-05-09 15:35:46 +00:00
|
|
|
*
|
2012-07-27 09:39:53 +00:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2012-09-20 22:30:55 +00:00
|
|
|
* License along with this library. If not, see
|
2012-07-27 09:39:53 +00:00
|
|
|
* <http://www.gnu.org/licenses/>.
|
2006-05-09 15:35:46 +00:00
|
|
|
*
|
|
|
|
* Karel Zak <kzak@redhat.com>
|
|
|
|
*/
|
|
|
|
|
2016-03-25 09:51:34 +00:00
|
|
|
#ifndef __VIR_TEST_UTILS_H__
|
|
|
|
# define __VIR_TEST_UTILS_H__
|
2006-05-09 15:35:46 +00:00
|
|
|
|
2010-03-09 18:22:22 +00:00
|
|
|
# include <stdio.h>
|
2012-12-12 18:06:53 +00:00
|
|
|
# include "viralloc.h"
|
2013-07-18 09:54:21 +00:00
|
|
|
# include "virfile.h"
|
|
|
|
# include "virstring.h"
|
2013-11-12 11:57:56 +00:00
|
|
|
# include "capabilities.h"
|
|
|
|
# include "domain_conf.h"
|
2009-05-12 16:45:14 +00:00
|
|
|
|
2010-03-09 18:22:22 +00:00
|
|
|
# define EXIT_AM_SKIP 77 /* tell Automake we're skipping a test */
|
2011-04-29 16:21:20 +00:00
|
|
|
# define EXIT_AM_HARDFAIL 99 /* tell Automake that the framework is broken */
|
|
|
|
|
2013-07-29 18:01:19 +00:00
|
|
|
/* Work around lack of gnulib support for fprintf %z */
|
2013-07-29 19:06:27 +00:00
|
|
|
# ifndef NO_LIBVIRT
|
|
|
|
# undef fprintf
|
|
|
|
# define fprintf virFilePrintf
|
|
|
|
# endif
|
2013-07-29 18:01:19 +00:00
|
|
|
|
2011-04-29 16:21:20 +00:00
|
|
|
extern char *progname;
|
2013-11-27 21:31:53 +00:00
|
|
|
|
|
|
|
/* Makefile.am provides these two definitions */
|
|
|
|
# if !defined(abs_srcdir) || !defined(abs_builddir)
|
|
|
|
# error Fix Makefile.am
|
|
|
|
# endif
|
2009-12-15 08:43:29 +00:00
|
|
|
|
Introduce new OOM testing support
The previous OOM testing support would re-run the entire "main"
method each iteration, failing a different malloc each time.
When a test suite has 'n' allocations, the number of repeats
requires is (n * (n + 1) ) / 2. This gets very large, very
quickly.
This new OOM testing support instead integrates at the
virtTestRun level, so each individual test case gets repeated,
instead of the entire test suite. This means the values of
'n' are orders of magnitude smaller.
The simple usage is
$ VIR_TEST_OOM=1 ./qemuxml2argvtest
...
29) QEMU XML-2-ARGV clock-utc ... OK
Test OOM for nalloc=36 .................................... OK
30) QEMU XML-2-ARGV clock-localtime ... OK
Test OOM for nalloc=36 .................................... OK
31) QEMU XML-2-ARGV clock-france ... OK
Test OOM for nalloc=38 ...................................... OK
...
the second lines reports how many mallocs have to be failed, and thus
how many repeats of the test will be run.
If it crashes, then running under valgrind will often show the problem
$ VIR_TEST_OOM=1 ../run valgrind ./qemuxml2argvtest
When debugging problems it is also helpful to select an individual
test case
$ VIR_TEST_RANGE=30 VIR_TEST_OOM=1 ../run valgrind ./qemuxml2argvtest
When things get really tricky, it is possible to request that just
specific allocs are failed. eg to fail allocs 5 -> 12, use
$ VIR_TEST_RANGE=30 VIR_TEST_OOM=1:5-12 ../run valgrind ./qemuxml2argvtest
In the worse case, you might want to know the stack trace of the
alloc which was failed then VIR_TEST_OOM_TRACE can be set. If it
is set to 1 then it will only print if it thinks a mistake happened.
This is often not reliable, so setting it to 2 will make it print
the stack trace for every alloc that is failed.
$ VIR_TEST_OOM_TRACE=2 VIR_TEST_RANGE=30 VIR_TEST_OOM=1:5-5 ../run valgrind ./qemuxml2argvtest
30) QEMU XML-2-ARGV clock-localtime ... OK
Test OOM for nalloc=36 !virAllocN
/home/berrange/src/virt/libvirt/src/util/viralloc.c:180
virHashCreateFull
/home/berrange/src/virt/libvirt/src/util/virhash.c:144
virDomainDefParseXML
/home/berrange/src/virt/libvirt/src/conf/domain_conf.c:11745
virDomainDefParseNode
/home/berrange/src/virt/libvirt/src/conf/domain_conf.c:12646
virDomainDefParse
/home/berrange/src/virt/libvirt/src/conf/domain_conf.c:12590
testCompareXMLToArgvFiles
/home/berrange/src/virt/libvirt/tests/qemuxml2argvtest.c:106
virtTestRun
/home/berrange/src/virt/libvirt/tests/testutils.c:250
mymain
/home/berrange/src/virt/libvirt/tests/qemuxml2argvtest.c:418 (discriminator 2)
virtTestMain
/home/berrange/src/virt/libvirt/tests/testutils.c:750
??
??:0
_start
??:?
FAILED
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-09-23 13:21:52 +00:00
|
|
|
bool virtTestOOMActive(void);
|
|
|
|
|
2008-08-20 20:48:35 +00:00
|
|
|
int virtTestRun(const char *title,
|
|
|
|
int (*body)(const void *data),
|
|
|
|
const void *data);
|
2011-04-24 22:25:10 +00:00
|
|
|
int virtTestLoadFile(const char *file, char **buf);
|
|
|
|
int virtTestCaptureProgramOutput(const char *const argv[], char **buf, int maxlen);
|
2008-02-05 19:27:37 +00:00
|
|
|
|
2014-03-20 10:30:44 +00:00
|
|
|
void virtTestClearCommandPath(char *cmdset);
|
|
|
|
|
2008-08-20 20:48:35 +00:00
|
|
|
int virtTestDifference(FILE *stream,
|
|
|
|
const char *expect,
|
|
|
|
const char *actual);
|
2014-10-29 14:53:36 +00:00
|
|
|
int virtTestDifferenceFull(FILE *stream,
|
|
|
|
const char *expect,
|
|
|
|
const char *expectName,
|
|
|
|
const char *actual,
|
|
|
|
const char *actualName);
|
2015-12-10 12:40:54 +00:00
|
|
|
int virtTestDifferenceFullNoRegenerate(FILE *stream,
|
|
|
|
const char *expect,
|
|
|
|
const char *expectName,
|
|
|
|
const char *actual,
|
|
|
|
const char *actualName);
|
2010-12-06 17:03:22 +00:00
|
|
|
int virtTestDifferenceBin(FILE *stream,
|
|
|
|
const char *expect,
|
|
|
|
const char *actual,
|
|
|
|
size_t length);
|
2015-04-23 15:14:26 +00:00
|
|
|
int virtTestCompareToFile(const char *strcontent,
|
|
|
|
const char *filename);
|
2006-05-09 15:35:46 +00:00
|
|
|
|
2009-11-30 19:01:31 +00:00
|
|
|
unsigned int virTestGetDebug(void);
|
|
|
|
unsigned int virTestGetVerbose(void);
|
2013-08-02 21:43:07 +00:00
|
|
|
unsigned int virTestGetExpensive(void);
|
2015-12-10 12:30:37 +00:00
|
|
|
unsigned int virTestGetRegenerate(void);
|
2009-10-16 15:37:36 +00:00
|
|
|
|
2015-04-23 17:38:00 +00:00
|
|
|
# define VIR_TEST_DEBUG(...) \
|
|
|
|
do { \
|
|
|
|
if (virTestGetDebug()) \
|
|
|
|
fprintf(stderr, __VA_ARGS__); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
# define VIR_TEST_VERBOSE(...) \
|
|
|
|
do { \
|
|
|
|
if (virTestGetVerbose()) \
|
|
|
|
fprintf(stderr, __VA_ARGS__); \
|
|
|
|
} while (0)
|
|
|
|
|
tests: silence qemuargv2xmltest noise
Before this patch, the testsuite was noisy:
TEST: qemuargv2xmltest
........................................ 40
................20:41:28.046: warning : qemuParseCommandLine:6565 : unknown QEMU argument '-unknown', adding to the qemu namespace
20:41:28.046: warning : qemuParseCommandLine:6565 : unknown QEMU argument 'parameter', adding to the qemu namespace
. 57 OK
PASS: qemuargv2xmltest
It's not a real failure (which is why the test was completing
successfully), so much as an intentional warning to the user that use
of the qemu namespace has the potential for undefined effects that
leaked through the default logging behavior. After this patch series,
all tests can access any logged data, and this particular test can
explicitly check for the presence or absence of the warning, such that
the test output becomes:
TEST: qemuargv2xmltest
........................................ 40
................. 57 OK
PASS: qemuargv2xmltest
* tests/testutils.h (virtTestLogContentAndReset): New prototype.
* tests/testutils.c (struct virtTestLogData): New struct.
(virtTestLogOutput, virtTestLogClose, virtTestLogContentAndReset):
New functions.
(virtTestMain): Always capture log data emitted during tests.
* tests/qemuargv2xmltest.c (testCompareXMLToArgvHelper, mymain):
Use flag to mark which tests expect noisy stderr.
(testCompareXMLToArgvFiles): Add parameter to test whether stderr
was appropriately silent.
2010-09-10 16:25:49 +00:00
|
|
|
char *virtTestLogContentAndReset(void);
|
|
|
|
|
2013-09-17 13:20:24 +00:00
|
|
|
void virtTestQuiesceLibvirtErrors(bool always);
|
|
|
|
|
2015-01-15 10:44:58 +00:00
|
|
|
void virtTestCounterReset(const char *prefix);
|
|
|
|
const char *virtTestCounterNext(void);
|
|
|
|
|
2008-08-20 20:48:35 +00:00
|
|
|
int virtTestMain(int argc,
|
|
|
|
char **argv,
|
2011-04-29 16:21:20 +00:00
|
|
|
int (*func)(void));
|
2008-05-29 15:21:45 +00:00
|
|
|
|
2011-04-29 16:21:20 +00:00
|
|
|
/* Setup, then call func() */
|
|
|
|
# define VIRT_TEST_MAIN(func) \
|
|
|
|
int main(int argc, char **argv) { \
|
|
|
|
return virtTestMain(argc, argv, func); \
|
2008-05-29 15:21:45 +00:00
|
|
|
}
|
|
|
|
|
2012-08-10 13:31:14 +00:00
|
|
|
# define VIRT_TEST_MAIN_PRELOAD(func, lib) \
|
|
|
|
int main(int argc, char **argv) { \
|
|
|
|
const char *preload = getenv("LD_PRELOAD"); \
|
|
|
|
if (preload == NULL || strstr(preload, lib) == NULL) { \
|
|
|
|
char *newenv; \
|
2013-03-28 18:01:21 +00:00
|
|
|
if (!virFileIsExecutable(lib)) { \
|
|
|
|
perror(lib); \
|
|
|
|
return EXIT_FAILURE; \
|
|
|
|
} \
|
2013-07-30 08:41:50 +00:00
|
|
|
if (!preload) { \
|
|
|
|
newenv = (char *) lib; \
|
|
|
|
} else if (virAsprintf(&newenv, "%s:%s", lib, preload) < 0) { \
|
2012-08-10 13:31:14 +00:00
|
|
|
perror("virAsprintf"); \
|
2013-02-22 22:42:39 +00:00
|
|
|
return EXIT_FAILURE; \
|
2012-08-10 13:31:14 +00:00
|
|
|
} \
|
|
|
|
setenv("LD_PRELOAD", newenv, 1); \
|
|
|
|
execv(argv[0], argv); \
|
|
|
|
} \
|
|
|
|
return virtTestMain(argc, argv, func); \
|
|
|
|
}
|
|
|
|
|
2013-11-12 11:57:56 +00:00
|
|
|
virCapsPtr virTestGenericCapsInit(void);
|
|
|
|
virDomainXMLOptionPtr virTestGenericDomainXMLConfInit(void);
|
|
|
|
|
2016-04-08 16:04:10 +00:00
|
|
|
typedef enum {
|
|
|
|
TEST_COMPARE_DOM_XML2XML_RESULT_SUCCESS,
|
|
|
|
TEST_COMPARE_DOM_XML2XML_RESULT_FAIL_PARSE,
|
|
|
|
TEST_COMPARE_DOM_XML2XML_RESULT_FAIL_STABILITY,
|
|
|
|
TEST_COMPARE_DOM_XML2XML_RESULT_FAIL_CB,
|
|
|
|
TEST_COMPARE_DOM_XML2XML_RESULT_FAIL_FORMAT,
|
|
|
|
TEST_COMPARE_DOM_XML2XML_RESULT_FAIL_COMPARE,
|
|
|
|
} testCompareDomXML2XMLResult;
|
|
|
|
|
2016-01-27 20:55:01 +00:00
|
|
|
typedef int (*testCompareDomXML2XMLPreFormatCallback)(virDomainDefPtr def,
|
|
|
|
const void *opaque);
|
2016-01-08 20:55:44 +00:00
|
|
|
int testCompareDomXML2XMLFiles(virCapsPtr caps,
|
|
|
|
virDomainXMLOptionPtr xmlopt,
|
|
|
|
const char *inxml,
|
|
|
|
const char *outfile,
|
2016-01-27 20:55:01 +00:00
|
|
|
bool live,
|
|
|
|
testCompareDomXML2XMLPreFormatCallback cb,
|
2016-02-25 14:17:14 +00:00
|
|
|
const void *opaque,
|
2016-04-08 16:04:10 +00:00
|
|
|
unsigned int parseFlags,
|
|
|
|
testCompareDomXML2XMLResult expectResult);
|
2016-01-08 20:55:44 +00:00
|
|
|
|
2016-03-25 09:51:34 +00:00
|
|
|
#endif /* __VIR_TEST_UTILS_H__ */
|