backup: Wire up qemu full pull backup commands over QMP
[libvirt/ericb.git] / tests / testutils.h
blob8c12fd7c12bf9ad6ad7343dbec02982aa74de935
1 /*
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/>.
21 #pragma once
23 #include "viralloc.h"
24 #include "virfile.h"
25 #include "virstring.h"
26 #include "virjson.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 */
34 #ifndef NO_LIBVIRT
35 # undef fprintf
36 # define fprintf virFilePrintf
37 #endif
39 extern char *progname;
41 /* Makefile.am provides these two definitions */
42 #if !defined(abs_srcdir) || !defined(abs_builddir)
43 # error Fix Makefile.am
44 #endif
46 bool virTestOOMActive(void);
48 int virTestRun(const char *title,
49 int (*body)(const void *data),
50 const void *data);
51 int virTestLoadFile(const char *file, char **buf);
52 char *virTestLoadFilePath(const char *p, ...)
53 ATTRIBUTE_SENTINEL;
54 virJSONValuePtr virTestLoadFileJSON(const char *p, ...)
55 ATTRIBUTE_SENTINEL;
57 int virTestCaptureProgramOutput(const char *const argv[], char **buf, int maxlen);
59 void virTestClearCommandPath(char *cmdset);
61 int virTestDifference(FILE *stream,
62 const char *expect,
63 const char *actual);
64 int virTestDifferenceFull(FILE *stream,
65 const char *expect,
66 const char *expectName,
67 const char *actual,
68 const char *actualName);
69 int virTestDifferenceFullNoRegenerate(FILE *stream,
70 const char *expect,
71 const char *expectName,
72 const char *actual,
73 const char *actualName);
74 int virTestDifferenceBin(FILE *stream,
75 const char *expect,
76 const char *actual,
77 size_t length);
78 int virTestCompareToFile(const char *actual,
79 const char *filename);
80 int virTestCompareToString(const char *expect,
81 const char *actual);
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(...) \
91 do { \
92 if (virTestGetDebug()) \
93 fprintf(stderr, __VA_ARGS__); \
94 } while (0)
96 #define VIR_TEST_VERBOSE(...) \
97 do { \
98 if (virTestGetVerbose()) \
99 fprintf(stderr, __VA_ARGS__); \
100 } while (0)
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,
110 char **argv,
111 int (*func)(void),
112 ...);
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) \
121 do { \
122 const char *preload = getenv("LD_PRELOAD"); \
123 if (preload == NULL || strstr(preload, lib) == NULL) { \
124 char *newenv; \
125 if (!virFileIsExecutable(lib)) { \
126 perror(lib); \
127 return EXIT_FAILURE; \
129 if (!preload) { \
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); \
138 } while (0)
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,
147 int seq);
148 virDomainXMLOptionPtr virTestGenericDomainXMLConfInit(void);
150 typedef enum {
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,
160 const char *inxml,
161 const char *outfile,
162 bool live,
163 unsigned int parseFlags,
164 testCompareDomXML2XMLResult expectResult);