[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [libvirt] [PATCH V2 2/2] libxl: Add a test suite for libxl_domain_config generator



On 07/28/2017 05:07 PM, Jim Fehlig wrote:
> 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>
> ---
>  m4/virt-driver-libxl.m4                        |   4 +
>  tests/Makefile.am                              |  18 ++-
>  tests/libxlxml2domconfigdata/basic-hvm.json    |  89 +++++++++++
>  tests/libxlxml2domconfigdata/basic-hvm.xml     |  36 +++++
>  tests/libxlxml2domconfigdata/basic-pv.json     |  65 ++++++++
>  tests/libxlxml2domconfigdata/basic-pv.xml      |  28 ++++
>  tests/libxlxml2domconfigdata/moredevs-hvm.json | 111 +++++++++++++
>  tests/libxlxml2domconfigdata/moredevs-hvm.xml  |  63 ++++++++
>  tests/libxlxml2domconfigtest.c                 | 209 +++++++++++++++++++++++++
>  tests/virmocklibxl.c                           | 106 +++++++++++++
>  10 files changed, 727 insertions(+), 2 deletions(-)
[...]
>
> diff --git a/tests/virmocklibxl.c b/tests/virmocklibxl.c
> new file mode 100644
> index 000000000..605f41223
> --- /dev/null
> +++ b/tests/virmocklibxl.c
> @@ -0,0 +1,106 @@
> +/*
> + * 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>
> +
> +# 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(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);
> +}
> +
> +/*
> + * The following emulator checks are implemented in
> + * src/libxl/libxl_capabilities.c. Mock them here to
> + * avoid probing any <emulator> specified in test files.
> + */
> +int
> +libxlCapsGetEmulatorType(const virDomainDef *def ATTRIBUTE_UNUSED)
> +{
> +    return LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN;
> +}
> +
> +int
> +libxlCapsCheckEmulator(const virDomainDef *def ATTRIBUTE_UNUSED)
> +{
> +    return 0;
> +}

Hmm, these mocked functions are not called. I suppose trying to mock a function
in the driver that is called within the driver is a futile effort...

Regards,
Jim


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]