1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2024-12-25 01:34:11 +03:00
libvirt/tests/virmocklibxl.c
Jim Fehlig d8e8b63d30 libxl: Add a test suite for libxl_domain_config generator
The libxl library allows a libxl_domain_config object to be serialized
from/to a JSON string. Use this to allow testing of the XML to
libxl_domain_config conversion process. Test XML is converted to
libxl_domain_config, which is then serialized to json. A json template
corresponding to the test XML is converted to a libxl_domain_config
object using libxl_domain_config_from_json(), and then serialized
back to json using libxl_domain_config_to_json(). The two json
docs are then compared.

Using libxl to convert the json template to a libxl_domain_config
object and then back to json provides a simple way to account for
any changes or additions to the json representation across Xen
releases.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
[update to v3.5.0-rc1, improve error reporting, use /bin/true emulator]
Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
2017-08-04 10:17:55 -06:00

88 lines
2.3 KiB
C

/*
* virmocklibxl.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/>.
*
* Author: Daniel P. Berrange <berrange@redhat.com>
*/
#include <config.h>
#if defined(WITH_LIBXL) && defined(WITH_YAJL)
# include "virmock.h"
# include <sys/stat.h>
# include <unistd.h>
# include <libxl.h>
# include <xenstore.h>
# include <xenctrl.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(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_STUB_RET_ARGS(xc_interface_close,
int, 0,
xc_interface *, handle)
VIR_MOCK_STUB_VOID_ARGS(xs_daemon_close,
struct xs_handle *, handle)
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);
}
#endif /* WITH_LIBXL && WITH_YAJL */