File: testutils.h

package info (click to toggle)
libvirt 3.0.0-4%2Bdeb9u4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 221,536 kB
  • sloc: ansic: 536,027; xml: 118,597; sh: 9,608; makefile: 5,399; perl: 3,888; python: 3,838; ml: 468; sed: 16
file content (165 lines) | stat: -rw-r--r-- 6,575 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/*
 * testutils.h: test utils
 *
 * Copyright (C) 2005, 2008-2013 Red Hat, Inc.
 *
 * 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
 * License along with this library.  If not, see
 * <http://www.gnu.org/licenses/>.
 *
 * Karel Zak <kzak@redhat.com>
 */

#ifndef __VIR_TEST_UTILS_H__
# define __VIR_TEST_UTILS_H__

# include <stdio.h>
# include "viralloc.h"
# include "virfile.h"
# include "virstring.h"
# include "capabilities.h"
# include "domain_conf.h"

# define EXIT_AM_SKIP 77 /* tell Automake we're skipping a test */
# define EXIT_AM_HARDFAIL 99 /* tell Automake that the framework is broken */

/* Work around lack of gnulib support for fprintf %z */
# ifndef NO_LIBVIRT
#  undef fprintf
#  define fprintf virFilePrintf
# endif

extern char *progname;

/* Makefile.am provides these two definitions */
# if !defined(abs_srcdir) || !defined(abs_builddir)
#  error Fix Makefile.am
# endif

bool virTestOOMActive(void);

int virTestRun(const char *title,
               int (*body)(const void *data),
               const void *data);
int virTestLoadFile(const char *file, char **buf);
int virTestCaptureProgramOutput(const char *const argv[], char **buf, int maxlen);

void virTestClearCommandPath(char *cmdset);

int virTestDifference(FILE *stream,
                      const char *expect,
                      const char *actual);
int virTestDifferenceFull(FILE *stream,
                          const char *expect,
                          const char *expectName,
                          const char *actual,
                          const char *actualName);
int virTestDifferenceFullNoRegenerate(FILE *stream,
                                      const char *expect,
                                      const char *expectName,
                                      const char *actual,
                                      const char *actualName);
int virTestDifferenceBin(FILE *stream,
                         const char *expect,
                         const char *actual,
                         size_t length);
int virTestCompareToFile(const char *strcontent,
                         const char *filename);
int virTestCompareToString(const char *strcontent,
                           const char *strsrc);

unsigned int virTestGetDebug(void);
unsigned int virTestGetVerbose(void);
unsigned int virTestGetExpensive(void);
unsigned int virTestGetRegenerate(void);

# 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)

char *virTestLogContentAndReset(void);

void virTestQuiesceLibvirtErrors(bool always);

void virTestCounterReset(const char *prefix);
const char *virTestCounterNext(void);

int virTestMain(int argc,
                char **argv,
                int (*func)(void),
                ...);

/* Setup, then call func() */
# define VIRT_TEST_MAIN(func)                           \
    int main(int argc, char **argv) {                   \
        return virTestMain(argc, argv, func, NULL);     \
    }

# define VIRT_TEST_PRELOAD(lib)                                         \
    do {                                                                \
        const char *preload = getenv("LD_PRELOAD");                     \
        if (preload == NULL || strstr(preload, lib) == NULL) {          \
            char *newenv;                                               \
            if (!virFileIsExecutable(lib)) {                            \
                perror(lib);                                            \
                return EXIT_FAILURE;                                    \
            }                                                           \
            if (!preload) {                                             \
                newenv = (char *) lib;                                  \
            } else if (virAsprintf(&newenv, "%s:%s", lib, preload) < 0) {   \
                perror("virAsprintf");                                  \
                return EXIT_FAILURE;                                    \
            }                                                           \
            setenv("LD_PRELOAD", newenv, 1);                            \
            execv(argv[0], argv);                                       \
        }                                                               \
    } while (0)

# define VIRT_TEST_MAIN_PRELOAD(func, ...)                              \
    int main(int argc, char **argv) {                                   \
        return virTestMain(argc, argv, func, __VA_ARGS__, NULL);        \
    }

virCapsPtr virTestGenericCapsInit(void);
virDomainXMLOptionPtr virTestGenericDomainXMLConfInit(void);

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;

typedef int (*testCompareDomXML2XMLPreFormatCallback)(virDomainDefPtr def,
                                                      const void *opaque);
int testCompareDomXML2XMLFiles(virCapsPtr caps,
                               virDomainXMLOptionPtr xmlopt,
                               const char *inxml,
                               const char *outfile,
                               bool live,
                               testCompareDomXML2XMLPreFormatCallback cb,
                               const void *opaque,
                               unsigned int parseFlags,
                               testCompareDomXML2XMLResult expectResult);

#endif /* __VIR_TEST_UTILS_H__ */