2006-05-09 15:35:46 +00:00
|
|
|
/*
|
2014-03-07 14:38:51 +01:00
|
|
|
* testutils.h: test utils
|
2006-05-09 15:35:46 +00:00
|
|
|
*
|
2013-02-22 15:42:39 -07:00
|
|
|
* Copyright (C) 2005, 2008-2013 Red Hat, Inc.
|
2006-05-09 15:35:46 +00:00
|
|
|
*
|
2012-07-27 17:39:53 +08: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 16:30:55 -06:00
|
|
|
* License along with this library. If not, see
|
2012-07-27 17:39:53 +08:00
|
|
|
* <http://www.gnu.org/licenses/>.
|
2006-05-09 15:35:46 +00:00
|
|
|
*
|
|
|
|
|
* Karel Zak <kzak@redhat.com>
|
|
|
|
|
*/
|
|
|
|
|
|
2016-03-25 10:51:34 +01:00
|
|
|
#ifndef __VIR_TEST_UTILS_H__
|
|
|
|
|
# define __VIR_TEST_UTILS_H__
|
2006-05-09 15:35:46 +00:00
|
|
|
|
2010-03-09 19:22:22 +01:00
|
|
|
# include <stdio.h>
|
2012-12-12 18:06:53 +00:00
|
|
|
# include "viralloc.h"
|
2013-07-18 10:54:21 +01: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 19:22:22 +01:00
|
|
|
# define EXIT_AM_SKIP 77 /* tell Automake we're skipping a test */
|
2011-04-29 10:21:20 -06:00
|
|
|
# define EXIT_AM_HARDFAIL 99 /* tell Automake that the framework is broken */
|
|
|
|
|
|
2013-07-29 12:01:19 -06:00
|
|
|
/* Work around lack of gnulib support for fprintf %z */
|
2013-07-29 13:06:27 -06:00
|
|
|
# ifndef NO_LIBVIRT
|
|
|
|
|
# undef fprintf
|
|
|
|
|
# define fprintf virFilePrintf
|
|
|
|
|
# endif
|
2013-07-29 12:01:19 -06:00
|
|
|
|
2011-04-29 10:21:20 -06:00
|
|
|
extern char *progname;
|
2013-11-27 14:31:53 -07:00
|
|
|
|
|
|
|
|
/* Makefile.am provides these two definitions */
|
|
|
|
|
# if !defined(abs_srcdir) || !defined(abs_builddir)
|
|
|
|
|
# error Fix Makefile.am
|
|
|
|
|
# endif
|
2009-12-15 09:43:29 +01:00
|
|
|
|
2016-05-26 17:01:56 +02:00
|
|
|
bool virTestOOMActive(void);
|
2013-09-23 14:21:52 +01:00
|
|
|
|
2016-05-26 17:01:50 +02:00
|
|
|
int virTestRun(const char *title,
|
|
|
|
|
int (*body)(const void *data),
|
|
|
|
|
const void *data);
|
2016-05-26 17:01:52 +02:00
|
|
|
int virTestLoadFile(const char *file, char **buf);
|
2016-05-26 17:02:05 +02:00
|
|
|
int virTestCaptureProgramOutput(const char *const argv[], char **buf, int maxlen);
|
2008-02-05 19:27:37 +00:00
|
|
|
|
2016-05-26 17:01:55 +02:00
|
|
|
void virTestClearCommandPath(char *cmdset);
|
2014-03-20 10:30:44 +00:00
|
|
|
|
2016-05-26 17:01:51 +02:00
|
|
|
int virTestDifference(FILE *stream,
|
|
|
|
|
const char *expect,
|
|
|
|
|
const char *actual);
|
2016-05-26 17:01:54 +02:00
|
|
|
int virTestDifferenceFull(FILE *stream,
|
|
|
|
|
const char *expect,
|
|
|
|
|
const char *expectName,
|
|
|
|
|
const char *actual,
|
|
|
|
|
const char *actualName);
|
2016-05-26 17:02:01 +02:00
|
|
|
int virTestDifferenceFullNoRegenerate(FILE *stream,
|
|
|
|
|
const char *expect,
|
|
|
|
|
const char *expectName,
|
|
|
|
|
const char *actual,
|
|
|
|
|
const char *actualName);
|
2016-05-26 17:02:04 +02:00
|
|
|
int virTestDifferenceBin(FILE *stream,
|
|
|
|
|
const char *expect,
|
|
|
|
|
const char *actual,
|
|
|
|
|
size_t length);
|
2016-05-26 17:01:53 +02:00
|
|
|
int virTestCompareToFile(const char *strcontent,
|
|
|
|
|
const char *filename);
|
2016-04-20 15:14:34 -06:00
|
|
|
int virTestCompareToString(const char *strcontent,
|
|
|
|
|
const char *strsrc);
|
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 15:43:07 -06:00
|
|
|
unsigned int virTestGetExpensive(void);
|
2015-12-10 13:30:37 +01:00
|
|
|
unsigned int virTestGetRegenerate(void);
|
2009-10-16 11:37:36 -04:00
|
|
|
|
2015-04-23 13:38:00 -04: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)
|
|
|
|
|
|
2016-05-26 17:01:58 +02:00
|
|
|
char *virTestLogContentAndReset(void);
|
2010-09-10 10:25:49 -06:00
|
|
|
|
2016-05-26 17:02:00 +02:00
|
|
|
void virTestQuiesceLibvirtErrors(bool always);
|
2013-09-17 15:20:24 +02:00
|
|
|
|
2016-05-26 17:01:57 +02:00
|
|
|
void virTestCounterReset(const char *prefix);
|
2016-05-26 17:02:06 +02:00
|
|
|
const char *virTestCounterNext(void);
|
2015-01-15 11:44:58 +01:00
|
|
|
|
2016-05-26 17:02:08 +02:00
|
|
|
int virTestMain(int argc,
|
|
|
|
|
char **argv,
|
|
|
|
|
int (*func)(void),
|
|
|
|
|
...);
|
2008-05-29 15:21:45 +00:00
|
|
|
|
2011-04-29 10:21:20 -06:00
|
|
|
/* Setup, then call func() */
|
2016-04-18 14:10:33 +02:00
|
|
|
# define VIRT_TEST_MAIN(func) \
|
|
|
|
|
int main(int argc, char **argv) { \
|
2016-05-26 17:02:08 +02:00
|
|
|
return virTestMain(argc, argv, func, NULL); \
|
2008-05-29 15:21:45 +00:00
|
|
|
}
|
|
|
|
|
|
2016-04-26 15:00:24 +02:00
|
|
|
# define VIRT_TEST_PRELOAD(lib) \
|
|
|
|
|
do { \
|
2012-08-10 14:31:14 +01:00
|
|
|
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 10:41:50 +02:00
|
|
|
if (!preload) { \
|
|
|
|
|
newenv = (char *) lib; \
|
|
|
|
|
} else if (virAsprintf(&newenv, "%s:%s", lib, preload) < 0) { \
|
2012-08-10 14:31:14 +01:00
|
|
|
perror("virAsprintf"); \
|
2013-02-22 15:42:39 -07:00
|
|
|
return EXIT_FAILURE; \
|
2012-08-10 14:31:14 +01:00
|
|
|
} \
|
|
|
|
|
setenv("LD_PRELOAD", newenv, 1); \
|
|
|
|
|
execv(argv[0], argv); \
|
|
|
|
|
} \
|
2016-04-26 15:00:24 +02:00
|
|
|
} while (0)
|
|
|
|
|
|
2016-05-20 16:27:00 +02:00
|
|
|
# define VIRT_TEST_MAIN_PRELOAD(func, ...) \
|
2016-04-26 15:00:24 +02:00
|
|
|
int main(int argc, char **argv) { \
|
2016-05-26 17:02:08 +02:00
|
|
|
return virTestMain(argc, argv, func, __VA_ARGS__, NULL); \
|
2012-08-10 14:31:14 +01:00
|
|
|
}
|
|
|
|
|
|
2013-11-12 11:57:56 +00:00
|
|
|
virCapsPtr virTestGenericCapsInit(void);
|
|
|
|
|
virDomainXMLOptionPtr virTestGenericDomainXMLConfInit(void);
|
|
|
|
|
|
2016-04-08 12:04:10 -04: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 15:55:01 -05:00
|
|
|
typedef int (*testCompareDomXML2XMLPreFormatCallback)(virDomainDefPtr def,
|
|
|
|
|
const void *opaque);
|
2016-01-08 15:55:44 -05:00
|
|
|
int testCompareDomXML2XMLFiles(virCapsPtr caps,
|
|
|
|
|
virDomainXMLOptionPtr xmlopt,
|
|
|
|
|
const char *inxml,
|
|
|
|
|
const char *outfile,
|
2016-01-27 15:55:01 -05:00
|
|
|
bool live,
|
|
|
|
|
testCompareDomXML2XMLPreFormatCallback cb,
|
2016-02-25 15:17:14 +01:00
|
|
|
const void *opaque,
|
2016-04-08 12:04:10 -04:00
|
|
|
unsigned int parseFlags,
|
|
|
|
|
testCompareDomXML2XMLResult expectResult);
|
2016-01-08 15:55:44 -05:00
|
|
|
|
2016-03-25 10:51:34 +01:00
|
|
|
#endif /* __VIR_TEST_UTILS_H__ */
|