backup: Wire up qemu full pull backup commands over QMP
[libvirt/ericb.git] / tests / qemuxml2argvmock.c
blob3f0c1c3fef894a5fd0073540f3ce48cee852645a
1 /*
2 * Copyright (C) 2014-2016 Red Hat, Inc.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library. If not, see
16 * <http://www.gnu.org/licenses/>.
19 #include <config.h>
21 #include "internal.h"
22 #include "viralloc.h"
23 #include "vircommand.h"
24 #include "vircrypto.h"
25 #include "virmock.h"
26 #include "virnetdev.h"
27 #include "virnetdevip.h"
28 #include "virnetdevtap.h"
29 #include "virnetdevopenvswitch.h"
30 #include "virnuma.h"
31 #include "virrandom.h"
32 #include "virscsi.h"
33 #include "virscsivhost.h"
34 #include "virstring.h"
35 #include "virtpm.h"
36 #include "virutil.h"
37 #include "qemu/qemu_interface.h"
38 #include "qemu/qemu_command.h"
39 #include <time.h>
40 #include <unistd.h>
41 #include <fcntl.h>
43 #define VIR_FROM_THIS VIR_FROM_NONE
45 long virGetSystemPageSize(void)
47 return 4096;
50 time_t time(time_t *t)
52 const time_t ret = 1234567890;
53 if (t)
54 *t = ret;
55 return ret;
58 bool
59 virNumaIsAvailable(void)
61 return true;
64 int
65 virNumaGetMaxNode(void)
67 return 7;
70 /* We shouldn't need to mock virNumaNodeIsAvailable() and *definitely* not
71 * virNumaNodesetIsAvailable(), but it seems to be the only way to get
72 * mocking to work with Clang on FreeBSD, so keep these duplicates around
73 * until we figure out a cleaner solution */
74 bool
75 virNumaNodeIsAvailable(int node)
77 return node >= 0 && node <= virNumaGetMaxNode();
80 bool
81 virNumaNodesetIsAvailable(virBitmapPtr nodeset)
83 ssize_t bit = -1;
85 if (!nodeset)
86 return true;
88 while ((bit = virBitmapNextSetBit(nodeset, bit)) >= 0) {
89 if (virNumaNodeIsAvailable(bit))
90 continue;
92 return false;
95 return true;
98 char *
99 virTPMCreateCancelPath(const char *devpath)
101 char *path;
102 (void)devpath;
104 ignore_value(VIR_STRDUP(path, "/sys/class/misc/tpm0/device/cancel"));
106 return path;
110 * Large values for memory would fail on 32 bit systems, despite having
111 * variables that support it.
113 unsigned long long
114 virMemoryMaxValue(bool capped ATTRIBUTE_UNUSED)
116 return LLONG_MAX;
119 char *
120 virSCSIDeviceGetSgName(const char *sysfs_prefix ATTRIBUTE_UNUSED,
121 const char *adapter ATTRIBUTE_UNUSED,
122 unsigned int bus ATTRIBUTE_UNUSED,
123 unsigned int target ATTRIBUTE_UNUSED,
124 unsigned long long unit ATTRIBUTE_UNUSED)
126 char *ret;
128 ignore_value(VIR_STRDUP(ret, "sg0"));
129 return ret;
133 virSCSIVHostOpenVhostSCSI(int *vhostfd)
135 *vhostfd = STDERR_FILENO + 1;
137 return 0;
141 virNetDevTapCreate(char **ifname,
142 const char *tunpath ATTRIBUTE_UNUSED,
143 int *tapfd,
144 size_t tapfdSize,
145 unsigned int flags ATTRIBUTE_UNUSED)
147 size_t i;
149 for (i = 0; i < tapfdSize; i++)
150 tapfd[i] = STDERR_FILENO + 1 + i;
152 VIR_FREE(*ifname);
153 return VIR_STRDUP(*ifname, "vnet0");
157 virNetDevSetMAC(const char *ifname ATTRIBUTE_UNUSED,
158 const virMacAddr *macaddr ATTRIBUTE_UNUSED)
160 return 0;
163 int virNetDevIPAddrAdd(const char *ifname ATTRIBUTE_UNUSED,
164 virSocketAddr *addr ATTRIBUTE_UNUSED,
165 virSocketAddr *peer ATTRIBUTE_UNUSED,
166 unsigned int prefix ATTRIBUTE_UNUSED)
168 return 0;
172 virNetDevSetOnline(const char *ifname ATTRIBUTE_UNUSED,
173 bool online ATTRIBUTE_UNUSED)
175 return 0;
179 virNetDevRunEthernetScript(const char *ifname ATTRIBUTE_UNUSED,
180 const char *script ATTRIBUTE_UNUSED)
182 return 0;
185 char *
186 virHostGetDRMRenderNode(void)
188 char *dst = NULL;
190 ignore_value(VIR_STRDUP(dst, "/dev/dri/foo"));
191 return dst;
194 static void (*real_virCommandPassFD)(virCommandPtr cmd, int fd, unsigned int flags);
196 static const int testCommandPassSafeFDs[] = { 1730, 1731 };
198 void
199 virCommandPassFD(virCommandPtr cmd,
200 int fd,
201 unsigned int flags)
203 size_t i;
205 for (i = 0; i < ARRAY_CARDINALITY(testCommandPassSafeFDs); i++) {
206 if (testCommandPassSafeFDs[i] == fd) {
207 if (!real_virCommandPassFD)
208 VIR_MOCK_REAL_INIT(virCommandPassFD);
210 real_virCommandPassFD(cmd, fd, flags);
211 return;
217 virNetDevOpenvswitchGetVhostuserIfname(const char *path ATTRIBUTE_UNUSED,
218 char **ifname)
220 return VIR_STRDUP(*ifname, "vhost-user0");
224 qemuInterfaceOpenVhostNet(virDomainDefPtr def ATTRIBUTE_UNUSED,
225 virDomainNetDefPtr net,
226 int *vhostfd,
227 size_t *vhostfdSize)
229 size_t i;
231 if (!virDomainNetIsVirtioModel(net)) {
232 *vhostfdSize = 0;
233 return 0;
236 for (i = 0; i < *vhostfdSize; i++)
237 vhostfd[i] = STDERR_FILENO + 42 + i;
238 return 0;
243 qemuOpenChrChardevUNIXSocket(const virDomainChrSourceDef *dev ATTRIBUTE_UNUSED)
246 /* We need to return an FD number for a UNIX listener socket,
247 * which will be given to QEMU via a CLI arg. We need a fixed
248 * number to get stable tests. This is obviously not a real
249 * FD number, so when virCommand closes the FD in the parent
250 * it will get EINVAL, but that's (hopefully) not going to
251 * be a problem....
253 if (fcntl(1729, F_GETFD) != -1)
254 abort();
255 return 1729;
260 qemuBuildTPMOpenBackendFDs(const char *tpmdev ATTRIBUTE_UNUSED,
261 const char *cancel_path ATTRIBUTE_UNUSED,
262 int *tpmfd,
263 int *cancelfd)
265 if (fcntl(1730, F_GETFD) != -1 ||
266 fcntl(1731, F_GETFD) != -1)
267 abort();
269 *tpmfd = 1730;
270 *cancelfd = 1731;
271 return 0;