2 * libxlmock.c: mocking of xenstore/libxs for libxl
4 * Copyright (C) 2014 Red Hat, Inc.
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.
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.
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/>.
23 #if defined(WITH_LIBXL) && defined(WITH_YAJL)
25 # include <sys/stat.h>
28 # include <xenstore.h>
30 # include <sys/socket.h>
34 VIR_MOCK_IMPL_RET_VOID(xs_daemon_open
,
37 VIR_MOCK_REAL_INIT(xs_daemon_open
);
41 VIR_MOCK_IMPL_RET_ARGS(xc_interface_open
,
43 xentoollog_logger
*, logger
,
44 xentoollog_logger
*, dombuild_logger
,
47 VIR_MOCK_REAL_INIT(xc_interface_open
);
52 VIR_MOCK_IMPL_RET_ARGS(libxl_get_version_info
,
53 const libxl_version_info
*,
56 static libxl_version_info info
;
58 memset(&info
, 0, sizeof(info
));
60 /* silence gcc warning about unused function */
62 real_libxl_get_version_info(ctx
);
66 VIR_MOCK_STUB_RET_ARGS(libxl_get_free_memory
,
71 VIR_MOCK_STUB_RET_ARGS(xc_interface_close
,
73 xc_interface
*, handle
)
75 VIR_MOCK_STUB_RET_ARGS(xc_physinfo
,
77 xc_interface
*, handle
,
78 xc_physinfo_t
*, put_info
)
80 VIR_MOCK_STUB_RET_ARGS(xc_sharing_freed_pages
,
82 xc_interface
*, handle
)
84 VIR_MOCK_STUB_RET_ARGS(xc_sharing_used_frames
,
86 xc_interface
*, handle
)
88 VIR_MOCK_STUB_VOID_ARGS(xs_daemon_close
,
89 struct xs_handle
*, handle
)
91 VIR_MOCK_STUB_RET_ARGS(bind
,
94 const struct sockaddr
*, addr
,
97 VIR_MOCK_IMPL_RET_ARGS(virFileMakePath
, int,
100 /* replace log path with a writable directory */
101 if (strstr(path
, "/log/")) {
102 snprintf((char*)path
, strlen(path
), ".");
105 return real_virFileMakePath(path
);
108 VIR_MOCK_IMPL_RET_ARGS(__xstat
, int,
113 VIR_MOCK_REAL_INIT(__xstat
);
115 if (strstr(path
, "xenstored.pid")) {
116 memset(sb
, 0, sizeof(*sb
));
120 return real___xstat(ver
, path
, sb
);
123 VIR_MOCK_IMPL_RET_ARGS(stat
, int,
127 VIR_MOCK_REAL_INIT(stat
);
129 if (strstr(path
, "xenstored.pid")) {
130 memset(sb
, 0, sizeof(*sb
));
134 return real_stat(path
, sb
);
137 #endif /* WITH_LIBXL && WITH_YAJL */