1 /*
2 * libxlmock.c: mocking of xenstore/libxs for libxl
3 *
4 * Copyright (C) 2014 Red Hat, Inc.
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library. If not, see
18 * <http://www.gnu.org/licenses/>.
19 */
20
21 #include <config.h>
22
23 #if defined(WITH_LIBXL) && defined(WITH_YAJL)
24 # include "virmock.h"
25 # include <sys/stat.h>
26 # include <unistd.h>
27 # include <libxl.h>
28 # include <xenstore.h>
29 # include <xenctrl.h>
30
31 # include "virfile.h"
32 # include "virsocket.h"
33 # include "libxl/libxl_capabilities.h"
34
VIR_MOCK_IMPL_RET_VOID(xs_daemon_open,struct xs_handle *)35 VIR_MOCK_IMPL_RET_VOID(xs_daemon_open,
36 struct xs_handle *)
37 {
38 VIR_MOCK_REAL_INIT(xs_daemon_open);
39 return (void*)0x1;
40 }
41
VIR_MOCK_IMPL_RET_ARGS(xs_open,struct xs_handle *,unsigned long,flags)42 VIR_MOCK_IMPL_RET_ARGS(xs_open,
43 struct xs_handle *,
44 unsigned long, flags)
45 {
46 VIR_MOCK_REAL_INIT(xs_open);
47 return (void*)0x1;
48 }
49
VIR_MOCK_IMPL_RET_ARGS(xc_interface_open,xc_interface *,xentoollog_logger *,logger,xentoollog_logger *,dombuild_logger,unsigned,open_flags)50 VIR_MOCK_IMPL_RET_ARGS(xc_interface_open,
51 xc_interface *,
52 xentoollog_logger *, logger,
53 xentoollog_logger *, dombuild_logger,
54 unsigned, open_flags)
55 {
56 VIR_MOCK_REAL_INIT(xc_interface_open);
57 return (void*)0x1;
58 }
59
60
VIR_MOCK_IMPL_RET_ARGS(libxl_get_version_info,const libxl_version_info *,libxl_ctx *,ctx)61 VIR_MOCK_IMPL_RET_ARGS(libxl_get_version_info,
62 const libxl_version_info*,
63 libxl_ctx *, ctx)
64 {
65 static libxl_version_info info;
66
67 memset(&info, 0, sizeof(info));
68
69 /* silence gcc warning about unused function */
70 if (0)
71 real_libxl_get_version_info(ctx);
72 return &info;
73 }
74
75 VIR_MOCK_STUB_RET_ARGS(libxl_get_free_memory,
76 int, 0,
77 libxl_ctx *, ctx,
78 # if LIBXL_API_VERSION < 0x040800
79 uint32_t *,
80 # else
81 uint64_t *,
82 # endif
83 memkb);
84
85 VIR_MOCK_STUB_RET_ARGS(xc_interface_close,
86 int, 0,
87 xc_interface *, handle)
88
89 VIR_MOCK_STUB_RET_ARGS(xc_physinfo,
90 int, 0,
91 xc_interface *, handle,
92 xc_physinfo_t *, put_info)
93
94 VIR_MOCK_STUB_RET_ARGS(xc_sharing_freed_pages,
95 long, 0,
96 xc_interface *, handle)
97
98 VIR_MOCK_STUB_RET_ARGS(xc_sharing_used_frames,
99 long, 0,
100 xc_interface *, handle)
101
VIR_MOCK_STUB_VOID_ARGS(xs_daemon_close,struct xs_handle *,handle)102 VIR_MOCK_STUB_VOID_ARGS(xs_daemon_close,
103 struct xs_handle *, handle)
104
105 VIR_MOCK_STUB_VOID_ARGS(xs_close,
106 struct xs_handle *, xsh)
107
108 VIR_MOCK_STUB_RET_ARGS(bind,
109 int, 0,
110 int, sockfd,
111 const struct sockaddr *, addr,
112 socklen_t, addrlen)
113
114 VIR_MOCK_IMPL_RET_ARGS(__xstat, int,
115 int, ver,
116 const char *, path,
117 struct stat *, sb)
118 {
119 VIR_MOCK_REAL_INIT(__xstat);
120
121 if (strstr(path, "xenstored.pid")) {
122 memset(sb, 0, sizeof(*sb));
123 return 0;
124 }
125
126 return real___xstat(ver, path, sb);
127 }
128
VIR_MOCK_IMPL_RET_ARGS(stat,int,const char *,path,struct stat *,sb)129 VIR_MOCK_IMPL_RET_ARGS(stat, int,
130 const char *, path,
131 struct stat *, sb)
132 {
133 VIR_MOCK_REAL_INIT(stat);
134
135 if (strstr(path, "xenstored.pid")) {
136 memset(sb, 0, sizeof(*sb));
137 return 0;
138 }
139
140 return real_stat(path, sb);
141 }
142
143 int
libxlDomainGetEmulatorType(const virDomainDef * def G_GNUC_UNUSED)144 libxlDomainGetEmulatorType(const virDomainDef *def G_GNUC_UNUSED)
145 {
146 return LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN;
147 }
148
149 #endif /* WITH_LIBXL && WITH_YAJL */
150