Files
libvirt/tests/bhyvexml2argvmock.c
T

117 lines
3.1 KiB
C
Raw Normal View History

2014-03-26 20:53:49 +04:00
#include <config.h>
2021-02-22 13:46:13 +04:00
#include <dirent.h>
2026-01-23 18:59:56 +01:00
#include "configmake.h"
#include "viralloc.h"
2026-01-23 18:59:56 +01:00
#include "virfile.h"
2014-03-26 20:53:49 +04:00
#include "virstring.h"
#include "virnetdev.h"
#include "virnetdevtap.h"
2021-02-22 13:46:13 +04:00
#include "virmock.h"
2014-03-26 20:53:49 +04:00
#include "internal.h"
#include "cpu/cpu.h"
#include "testutilshostcpus.h"
2014-03-26 20:53:49 +04:00
#define VIR_FROM_THIS VIR_FROM_BHYVE
2021-02-22 13:46:13 +04:00
static DIR * (*real_opendir)(const char *name);
2026-01-23 18:59:56 +01:00
static bool (*real_virFileExists)(const char *path);
2021-02-22 13:46:13 +04:00
static void
init_syms(void)
{
2026-01-23 18:59:56 +01:00
if (!real_opendir)
VIR_MOCK_REAL_INIT(opendir);
if (!real_virFileExists)
VIR_MOCK_REAL_INIT(virFileExists);
2021-02-22 13:46:13 +04:00
}
#define FAKEFIRMWAREDIR abs_srcdir "/bhyvefirmwaredata/three_firmwares"
#define FAKEFIRMWAREEMPTYDIR abs_srcdir "/bhyvefirmwaredata/empty"
DIR *
opendir(const char *path)
{
g_autofree char *path_override = NULL;
init_syms();
2021-02-22 13:46:13 +04:00
if (STREQ(path, "fakefirmwaredir")) {
path_override = g_strdup(FAKEFIRMWAREDIR);
} else if (STREQ(path, "fakefirmwareemptydir")) {
path_override = g_strdup(FAKEFIRMWAREEMPTYDIR);
}
if (!path_override)
path_override = g_strdup(path);
return real_opendir(path_override);
}
2014-03-26 20:53:49 +04:00
void virMacAddrGenerate(const unsigned char prefix[VIR_MAC_PREFIX_BUFLEN],
2021-03-11 08:16:13 +01:00
virMacAddr *addr)
2014-03-26 20:53:49 +04:00
{
addr->addr[0] = prefix[0];
addr->addr[1] = prefix[1];
addr->addr[2] = prefix[2];
addr->addr[3] = 0;
addr->addr[4] = 0;
addr->addr[5] = 0;
}
2019-10-14 14:45:03 +02:00
int virNetDevTapCreateInBridgePort(const char *brname G_GNUC_UNUSED,
2014-03-26 20:53:49 +04:00
char **ifname,
2019-10-14 14:45:03 +02:00
const virMacAddr *macaddr G_GNUC_UNUSED,
const unsigned char *vmuuid G_GNUC_UNUSED,
const char *tunpath G_GNUC_UNUSED,
int *tapfd G_GNUC_UNUSED,
size_t tapfdSize G_GNUC_UNUSED,
const virNetDevVPortProfile *virtPortProfile G_GNUC_UNUSED,
const virNetDevVlan *virtVlan G_GNUC_UNUSED,
virTristateBool isolatedPort G_GNUC_UNUSED,
2021-03-11 08:16:13 +01:00
virNetDevCoalesce *coalesce G_GNUC_UNUSED,
2019-10-14 14:45:03 +02:00
unsigned int mtu G_GNUC_UNUSED,
unsigned int *actualMTU G_GNUC_UNUSED,
unsigned int fakeflags G_GNUC_UNUSED)
2014-03-26 20:53:49 +04:00
{
VIR_FREE(*ifname);
2019-10-20 13:49:46 +02:00
*ifname = g_strdup("vnet0");
2014-03-26 20:53:49 +04:00
return 0;
}
2019-10-14 14:45:03 +02:00
char *virNetDevTapGetRealDeviceName(char *name G_GNUC_UNUSED)
2014-03-26 20:53:49 +04:00
{
2021-10-22 10:56:01 +02:00
return g_strdup("faketapdev");
2014-03-26 20:53:49 +04:00
}
2019-10-14 14:45:03 +02:00
int virNetDevSetOnline(const char *ifname G_GNUC_UNUSED,
bool online G_GNUC_UNUSED)
2014-03-26 20:53:49 +04:00
{
return 0;
}
2018-02-06 12:09:09 +03:00
2019-10-14 14:45:03 +02:00
int bind(int sockfd G_GNUC_UNUSED,
const struct sockaddr *addr G_GNUC_UNUSED,
socklen_t addrlen G_GNUC_UNUSED)
2018-02-06 12:09:09 +03:00
{
return 0;
}
virCPUDef *
virCPUProbeHost(virArch arch)
{
return testUtilsHostCpusGetDefForArch(arch);
}
2026-01-23 18:59:56 +01:00
bool
virFileExists(const char *path)
{
init_syms();
if (STREQ(path, "fakeubootpath/u-boot.bin"))
return true;
return real_virFileExists(path);
}