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 166 167 168 169 170 171
|
/*
* libxlmock.c: mocking of xenstore/libxs for libxl
*
* Copyright (C) 2014 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/>.
*/
#include <config.h>
#if defined(WITH_LIBXL)
# include "virmock.h"
# include <sys/stat.h>
# include <unistd.h>
# include <libxl.h>
# include <xenstore.h>
# include <xenctrl.h>
# include "libxl/libxl_capabilities.h"
VIR_MOCK_IMPL_RET_VOID(xs_daemon_open,
struct xs_handle *)
{
VIR_MOCK_REAL_INIT(xs_daemon_open);
return (void*)0x1;
}
VIR_MOCK_IMPL_RET_ARGS(xs_open,
struct xs_handle *,
unsigned long, flags)
{
VIR_MOCK_REAL_INIT(xs_open);
return (void*)0x1;
}
VIR_MOCK_IMPL_RET_ARGS(xc_interface_open,
xc_interface *,
xentoollog_logger *, logger,
xentoollog_logger *, dombuild_logger,
unsigned, open_flags)
{
VIR_MOCK_REAL_INIT(xc_interface_open);
return (void*)0x1;
}
VIR_MOCK_IMPL_RET_ARGS(libxl_get_version_info,
const libxl_version_info*,
libxl_ctx *, ctx)
{
static libxl_version_info info = { 0 };
/* silence gcc warning about unused function */
if (0)
real_libxl_get_version_info(ctx);
return &info;
}
VIR_MOCK_IMPL_RET_ARGS(libxl_get_physinfo,
int,
libxl_ctx *, ctx,
libxl_physinfo *, physinfo)
{
memset(physinfo, 0, sizeof(*physinfo));
physinfo->nr_nodes = 6;
/* silence gcc warning about unused function */
if (0)
real_libxl_get_physinfo(ctx, physinfo);
return 0;
}
VIR_MOCK_STUB_RET_ARGS(libxl_get_free_memory,
int, 0,
libxl_ctx *, ctx,
# if LIBXL_API_VERSION < 0x040800
uint32_t *,
# else
uint64_t *,
# endif
memkb);
VIR_MOCK_STUB_RET_ARGS(xc_interface_close,
int, 0,
xc_interface *, handle)
VIR_MOCK_STUB_RET_ARGS(xc_physinfo,
int, 0,
xc_interface *, handle,
xc_physinfo_t *, put_info)
VIR_MOCK_STUB_RET_ARGS(xc_sharing_freed_pages,
long, 0,
xc_interface *, handle)
VIR_MOCK_STUB_RET_ARGS(xc_sharing_used_frames,
long, 0,
xc_interface *, handle)
VIR_MOCK_STUB_VOID_ARGS(xs_daemon_close,
struct xs_handle *, handle)
VIR_MOCK_STUB_VOID_ARGS(xs_close,
struct xs_handle *, xsh)
VIR_MOCK_STUB_RET_ARGS(bind,
int, 0,
int, sockfd,
const struct sockaddr *, addr,
socklen_t, addrlen)
VIR_MOCK_IMPL_RET_ARGS(libxl_get_required_shadow_memory,
unsigned long,
unsigned long, maxmem_kb,
unsigned int, smp_cpus)
{
/* silence gcc warning about unused function */
if (0)
real_libxl_get_required_shadow_memory(maxmem_kb, smp_cpus);
return 1234;
}
VIR_MOCK_IMPL_RET_ARGS(__xstat, int,
int, ver,
const char *, path,
struct stat *, sb)
{
VIR_MOCK_REAL_INIT(__xstat);
if (strstr(path, "xenstored.pid")) {
memset(sb, 0, sizeof(*sb));
return 0;
}
return real___xstat(ver, path, sb);
}
VIR_MOCK_IMPL_RET_ARGS(stat, int,
const char *, path,
struct stat *, sb)
{
VIR_MOCK_REAL_INIT(stat);
if (strstr(path, "xenstored.pid")) {
memset(sb, 0, sizeof(*sb));
return 0;
}
return real_stat(path, sb);
}
int
libxlDomainGetEmulatorType(const virDomainDef *def G_GNUC_UNUSED)
{
return LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN;
}
#endif /* WITH_LIBXL */
|