2 * testutils.h: test utils
4 * Copyright (C) 2005, 2008-2013 Red Hat, Inc.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library. If not, see
18 * <http://www.gnu.org/licenses/>.
25 #include "virstring.h"
27 #include "capabilities.h"
28 #include "domain_conf.h"
30 #define EXIT_AM_SKIP 77 /* tell Automake we're skipping a test */
31 #define EXIT_AM_HARDFAIL 99 /* tell Automake that the framework is broken */
33 /* Work around lack of gnulib support for fprintf %z */
36 # define fprintf virFilePrintf
39 extern char *progname
;
41 /* Makefile.am provides these two definitions */
42 #if !defined(abs_srcdir) || !defined(abs_builddir)
43 # error Fix Makefile.am
46 bool virTestOOMActive(void);
48 int virTestRun(const char *title
,
49 int (*body
)(const void *data
),
51 int virTestLoadFile(const char *file
, char **buf
);
52 char *virTestLoadFilePath(const char *p
, ...)
54 virJSONValuePtr
virTestLoadFileJSON(const char *p
, ...)
57 int virTestCaptureProgramOutput(const char *const argv
[], char **buf
, int maxlen
);
59 void virTestClearCommandPath(char *cmdset
);
61 int virTestDifference(FILE *stream
,
64 int virTestDifferenceFull(FILE *stream
,
66 const char *expectName
,
68 const char *actualName
);
69 int virTestDifferenceFullNoRegenerate(FILE *stream
,
71 const char *expectName
,
73 const char *actualName
);
74 int virTestDifferenceBin(FILE *stream
,
78 int virTestCompareToFile(const char *actual
,
79 const char *filename
);
80 int virTestCompareToString(const char *expect
,
82 int virTestCompareToULL(unsigned long long expect
,
83 unsigned long long actual
);
85 unsigned int virTestGetDebug(void);
86 unsigned int virTestGetVerbose(void);
87 unsigned int virTestGetExpensive(void);
88 unsigned int virTestGetRegenerate(void);
90 #define VIR_TEST_DEBUG(...) \
92 if (virTestGetDebug()) \
93 fprintf(stderr, __VA_ARGS__); \
96 #define VIR_TEST_VERBOSE(...) \
98 if (virTestGetVerbose()) \
99 fprintf(stderr, __VA_ARGS__); \
102 char *virTestLogContentAndReset(void);
104 void virTestQuiesceLibvirtErrors(bool always
);
106 void virTestCounterReset(const char *prefix
);
107 const char *virTestCounterNext(void);
109 int virTestMain(int argc
,
114 /* Setup, then call func() */
115 #define VIR_TEST_MAIN(func) \
116 int main(int argc, char **argv) { \
117 return virTestMain(argc, argv, func, NULL); \
120 #define VIR_TEST_PRELOAD(lib) \
122 const char *preload = getenv("LD_PRELOAD"); \
123 if (preload == NULL || strstr(preload, lib) == NULL) { \
125 if (!virFileIsExecutable(lib)) { \
127 return EXIT_FAILURE; \
130 newenv = (char *) lib; \
131 } else if (virAsprintf(&newenv, "%s:%s", lib, preload) < 0) { \
132 perror("virAsprintf"); \
133 return EXIT_FAILURE; \
135 setenv("LD_PRELOAD", newenv, 1); \
136 execv(argv[0], argv); \
140 #define VIR_TEST_MAIN_PRELOAD(func, ...) \
141 int main(int argc, char **argv) { \
142 return virTestMain(argc, argv, func, __VA_ARGS__, NULL); \
145 virCapsPtr
virTestGenericCapsInit(void);
146 int virTestCapsBuildNUMATopology(virCapsPtr caps
,
148 virDomainXMLOptionPtr
virTestGenericDomainXMLConfInit(void);
151 TEST_COMPARE_DOM_XML2XML_RESULT_SUCCESS
,
152 TEST_COMPARE_DOM_XML2XML_RESULT_FAIL_PARSE
,
153 TEST_COMPARE_DOM_XML2XML_RESULT_FAIL_STABILITY
,
154 TEST_COMPARE_DOM_XML2XML_RESULT_FAIL_FORMAT
,
155 TEST_COMPARE_DOM_XML2XML_RESULT_FAIL_COMPARE
,
156 } testCompareDomXML2XMLResult
;
158 int testCompareDomXML2XMLFiles(virCapsPtr caps
,
159 virDomainXMLOptionPtr xmlopt
,
163 unsigned int parseFlags
,
164 testCompareDomXML2XMLResult expectResult
);