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/>.
23 #include "vircommand.h"
24 #include "vircrypto.h"
26 #include "virnetdev.h"
27 #include "virnetdevip.h"
28 #include "virnetdevtap.h"
29 #include "virnetdevopenvswitch.h"
31 #include "virrandom.h"
33 #include "virscsivhost.h"
34 #include "virstring.h"
37 #include "qemu/qemu_interface.h"
38 #include "qemu/qemu_command.h"
43 #define VIR_FROM_THIS VIR_FROM_NONE
45 long virGetSystemPageSize(void)
50 time_t time(time_t *t
)
52 const time_t ret
= 1234567890;
59 virNumaIsAvailable(void)
65 virNumaGetMaxNode(void)
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 */
75 virNumaNodeIsAvailable(int node
)
77 return node
>= 0 && node
<= virNumaGetMaxNode();
81 virNumaNodesetIsAvailable(virBitmapPtr nodeset
)
88 while ((bit
= virBitmapNextSetBit(nodeset
, bit
)) >= 0) {
89 if (virNumaNodeIsAvailable(bit
))
99 virTPMCreateCancelPath(const char *devpath
)
104 ignore_value(VIR_STRDUP(path
, "/sys/class/misc/tpm0/device/cancel"));
110 * Large values for memory would fail on 32 bit systems, despite having
111 * variables that support it.
114 virMemoryMaxValue(bool capped ATTRIBUTE_UNUSED
)
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
)
128 ignore_value(VIR_STRDUP(ret
, "sg0"));
133 virSCSIVHostOpenVhostSCSI(int *vhostfd
)
135 *vhostfd
= STDERR_FILENO
+ 1;
141 virNetDevTapCreate(char **ifname
,
142 const char *tunpath ATTRIBUTE_UNUSED
,
145 unsigned int flags ATTRIBUTE_UNUSED
)
149 for (i
= 0; i
< tapfdSize
; i
++)
150 tapfd
[i
] = STDERR_FILENO
+ 1 + i
;
153 return VIR_STRDUP(*ifname
, "vnet0");
157 virNetDevSetMAC(const char *ifname ATTRIBUTE_UNUSED
,
158 const virMacAddr
*macaddr ATTRIBUTE_UNUSED
)
163 int virNetDevIPAddrAdd(const char *ifname ATTRIBUTE_UNUSED
,
164 virSocketAddr
*addr ATTRIBUTE_UNUSED
,
165 virSocketAddr
*peer ATTRIBUTE_UNUSED
,
166 unsigned int prefix ATTRIBUTE_UNUSED
)
172 virNetDevSetOnline(const char *ifname ATTRIBUTE_UNUSED
,
173 bool online ATTRIBUTE_UNUSED
)
179 virNetDevRunEthernetScript(const char *ifname ATTRIBUTE_UNUSED
,
180 const char *script ATTRIBUTE_UNUSED
)
186 virHostGetDRMRenderNode(void)
190 ignore_value(VIR_STRDUP(dst
, "/dev/dri/foo"));
194 static void (*real_virCommandPassFD
)(virCommandPtr cmd
, int fd
, unsigned int flags
);
196 static const int testCommandPassSafeFDs
[] = { 1730, 1731 };
199 virCommandPassFD(virCommandPtr cmd
,
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
);
217 virNetDevOpenvswitchGetVhostuserIfname(const char *path ATTRIBUTE_UNUSED
,
220 return VIR_STRDUP(*ifname
, "vhost-user0");
224 qemuInterfaceOpenVhostNet(virDomainDefPtr def ATTRIBUTE_UNUSED
,
225 virDomainNetDefPtr net
,
231 if (!virDomainNetIsVirtioModel(net
)) {
236 for (i
= 0; i
< *vhostfdSize
; i
++)
237 vhostfd
[i
] = STDERR_FILENO
+ 42 + i
;
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
253 if (fcntl(1729, F_GETFD
) != -1)
260 qemuBuildTPMOpenBackendFDs(const char *tpmdev ATTRIBUTE_UNUSED
,
261 const char *cancel_path ATTRIBUTE_UNUSED
,
265 if (fcntl(1730, F_GETFD
) != -1 ||
266 fcntl(1731, F_GETFD
) != -1)