remote: add sysusers file to create 'libvirt' group
[libvirt.git] / tests / testutilsqemu.h
blob74e307d65346d4bea023997860f78e357be98cec
1 /*
2 * This library is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU Lesser General Public
4 * License as published by the Free Software Foundation; either
5 * version 2.1 of the License, or (at your option) any later version.
7 * This library is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 * Lesser General Public License for more details.
12 * You should have received a copy of the GNU Lesser General Public
13 * License along with this library. If not, see
14 * <http://www.gnu.org/licenses/>.
17 #pragma once
19 #ifdef WITH_QEMU
21 # include "capabilities.h"
22 # include "virfilecache.h"
23 # include "domain_conf.h"
24 # include "qemu/qemu_capabilities.h"
25 # include "qemu/qemu_conf.h"
27 # define TEST_QEMU_CAPS_PATH abs_srcdir "/qemucapabilitiesdata"
28 # define TEST_TPM_ENV_VAR "VIR_TEST_MOCK_FAKE_TPM_VERSION"
29 # define TPM_VER_1_2 "1.2"
30 # define TPM_VER_2_0 "2.0"
31 # define TEST_NBDKIT_PATH "/fakebindir/nbdkit"
33 enum {
34 GIC_NONE = 0,
35 GIC_V2,
36 GIC_V3,
37 GIC_BOTH,
40 typedef enum {
41 ARG_QEMU_CAPS = QEMU_CAPS_LAST + 1,
42 ARG_QEMU_CAPS_DEL,
43 ARG_GIC,
44 ARG_MIGRATE_FROM,
45 ARG_MIGRATE_FD,
46 ARG_FLAGS,
47 ARG_PARSEFLAGS,
48 ARG_CAPS_ARCH,
49 ARG_CAPS_VER,
50 ARG_CAPS_VARIANT,
51 ARG_CAPS_HOST_CPU_MODEL,
52 ARG_FD_GROUP, /* name, nfds, fd[0], ... fd[n-1] */
53 ARG_VDPA_FD, /* vdpadev, fd */
54 ARG_NBDKIT_CAPS,
55 ARG_END,
56 } testQemuInfoArgName;
58 typedef enum {
59 FLAG_EXPECT_FAILURE = 1 << 0,
60 FLAG_EXPECT_PARSE_ERROR = 1 << 1,
61 FLAG_REAL_CAPS = 1 << 2,
62 FLAG_SLIRP_HELPER = 1 << 3,
63 FLAG_ALLOW_DUPLICATE_OUTPUT = 1 << 4, /* allow multiple tests with the same output file */
64 FLAG_ALLOW_MISSING_INPUT = 1 << 5,
65 } testQemuInfoFlags;
67 struct testQemuConf {
68 GHashTable *capscache;
69 GHashTable *capslatest;
70 GHashTable *qapiSchemaCache;
71 GHashTable *duplicateTests; /* for checking duplicated invocations */
72 GHashTable *existingTestCases; /* for checking missing invocations */
75 typedef enum {
76 QEMU_CPU_DEF_DEFAULT,
77 QEMU_CPU_DEF_HASWELL,
78 QEMU_CPU_DEF_POWER8,
79 QEMU_CPU_DEF_POWER9,
80 QEMU_CPU_DEF_POWER10,
81 } qemuTestCPUDef;
83 struct testQemuArgs {
84 bool newargs;
85 virBitmap *fakeCapsAdd;
86 virBitmap *fakeCapsDel;
87 virBitmap *fakeNbdkitCaps;
88 char *capsver;
89 char *capsarch;
90 const char *capsvariant;
91 qemuTestCPUDef capsHostCPUModel;
92 int gic;
93 GHashTable *fds;
94 GHashTable *vdpafds;
95 bool invalidarg;
98 struct _testQemuInfo {
99 const char *name;
100 char *infile;
101 char *outfile;
102 char *out_xml_active;
103 char *out_xml_inactive;
104 char *errfile;
105 virDomainDef *def; /* parsed domain definition */
106 virQEMUCaps *qemuCaps;
107 qemuNbdkitCaps *nbdkitCaps;
108 const char *migrateFrom;
109 int migrateFd;
110 unsigned int flags;
111 unsigned int parseFlags;
112 virArch arch;
113 GHashTable *qmpSchema; /* borrowed pointer from the cache */
115 /* Some tests have a common prepare step for multiple cases, but
116 * the common setup needs to be invoked with each virTestRun to facilitate
117 * test skipping */
118 bool prepared;
119 bool prep_skip;
121 struct testQemuArgs args;
122 struct testQemuConf *conf;
125 typedef struct _testQemuInfo testQemuInfo;
126 void testQemuInfoFree(testQemuInfo *info);
127 G_DEFINE_AUTOPTR_CLEANUP_FUNC(testQemuInfo, testQemuInfoFree);
129 virQEMUCaps *qemuTestParseCapabilitiesArch(virArch arch,
130 const char *capsFile);
131 virCPUDef *qemuTestGetCPUDef(qemuTestCPUDef d);
133 void qemuTestSetHostArch(virQEMUDriver *driver,
134 virArch arch);
135 void qemuTestSetHostCPU(virQEMUDriver *driver,
136 virArch arch,
137 virCPUDef *cpu);
139 int qemuTestDriverInit(virQEMUDriver *driver);
140 void qemuTestDriverFree(virQEMUDriver *driver);
141 int qemuTestCapsCacheInsert(virFileCache *cache,
142 virQEMUCaps *caps);
144 int testQemuCapsSetGIC(virQEMUCaps *qemuCaps,
145 int gic);
147 char *testQemuGetLatestCapsForArch(const char *arch,
148 const char *suffix);
149 GHashTable *testQemuGetLatestCaps(void);
151 typedef int (*testQemuCapsIterateCallback)(const char *inputDir,
152 const char *prefix,
153 const char *version,
154 const char *archName,
155 const char *variant,
156 const char *suffix,
157 void *opaque);
158 int testQemuCapsIterate(const char *suffix,
159 testQemuCapsIterateCallback callback,
160 void *opaque);
162 void testQemuInfoSetArgs(testQemuInfo *info,
163 va_list argptr);
164 int testQemuInfoInitArgs(testQemuInfo *info);
166 int testQemuPrepareHostBackendChardevOne(virDomainDeviceDef *dev,
167 virDomainChrSourceDef *chardev,
168 void *opaque);
170 virQEMUCaps *
171 testQemuGetRealCaps(const char *arch,
172 const char *version,
173 const char *variant,
174 GHashTable *capsLatestFiles,
175 GHashTable *capsCache,
176 GHashTable *schemaCache,
177 GHashTable **schema);
180 testQemuInsertRealCaps(virFileCache *cache,
181 const char *arch,
182 const char *version,
183 const char *variant,
184 GHashTable *capsLatestFiles,
185 GHashTable *capsCache,
186 GHashTable *schemaCache,
187 GHashTable **schema);
188 #endif