backup: Wire up qemu full pull backup commands over QMP
[libvirt/ericb.git] / tests / libxlmock.c
blob4476cf728f2bd979f34e4caa5d38ab6a75a42d96
1 /*
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/>.
21 #include <config.h>
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 # include <sys/socket.h>
32 # include "virfile.h"
34 VIR_MOCK_IMPL_RET_VOID(xs_daemon_open,
35 struct xs_handle *)
37 VIR_MOCK_REAL_INIT(xs_daemon_open);
38 return (void*)0x1;
41 VIR_MOCK_IMPL_RET_ARGS(xc_interface_open,
42 xc_interface *,
43 xentoollog_logger *, logger,
44 xentoollog_logger *, dombuild_logger,
45 unsigned, open_flags)
47 VIR_MOCK_REAL_INIT(xc_interface_open);
48 return (void*)0x1;
52 VIR_MOCK_IMPL_RET_ARGS(libxl_get_version_info,
53 const libxl_version_info*,
54 libxl_ctx *, ctx)
56 static libxl_version_info info;
58 memset(&info, 0, sizeof(info));
60 /* silence gcc warning about unused function */
61 if (0)
62 real_libxl_get_version_info(ctx);
63 return &info;
66 VIR_MOCK_STUB_RET_ARGS(libxl_get_free_memory,
67 int, 0,
68 libxl_ctx *, ctx,
69 uint32_t *, memkb);
71 VIR_MOCK_STUB_RET_ARGS(xc_interface_close,
72 int, 0,
73 xc_interface *, handle)
75 VIR_MOCK_STUB_RET_ARGS(xc_physinfo,
76 int, 0,
77 xc_interface *, handle,
78 xc_physinfo_t *, put_info)
80 VIR_MOCK_STUB_RET_ARGS(xc_sharing_freed_pages,
81 long, 0,
82 xc_interface *, handle)
84 VIR_MOCK_STUB_RET_ARGS(xc_sharing_used_frames,
85 long, 0,
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,
92 int, 0,
93 int, sockfd,
94 const struct sockaddr *, addr,
95 socklen_t, addrlen)
97 VIR_MOCK_IMPL_RET_ARGS(virFileMakePath, int,
98 const char *, path)
100 /* replace log path with a writable directory */
101 if (strstr(path, "/log/")) {
102 snprintf((char*)path, strlen(path), ".");
103 return 0;
105 return real_virFileMakePath(path);
108 VIR_MOCK_IMPL_RET_ARGS(__xstat, int,
109 int, ver,
110 const char *, path,
111 struct stat *, sb)
113 VIR_MOCK_REAL_INIT(__xstat);
115 if (strstr(path, "xenstored.pid")) {
116 memset(sb, 0, sizeof(*sb));
117 return 0;
120 return real___xstat(ver, path, sb);
123 VIR_MOCK_IMPL_RET_ARGS(stat, int,
124 const char *, path,
125 struct stat *, sb)
127 VIR_MOCK_REAL_INIT(stat);
129 if (strstr(path, "xenstored.pid")) {
130 memset(sb, 0, sizeof(*sb));
131 return 0;
134 return real_stat(path, sb);
137 #endif /* WITH_LIBXL && WITH_YAJL */