[libvirt] [PATCH v2 2/5] virpcitest: Test virPCIDeviceDetach

Martin Kletzander mkletzan at redhat.com
Fri Nov 1 11:06:17 UTC 2013


On Thu, Oct 31, 2013 at 11:23:39AM +0000, Michal Privoznik wrote:
> This commit introduces yet another test under virpcitest:
> virPCIDeviceDetach. However, in order to be able to do this, the
> virpcimock needs to be extended to model the kernel behavior on PCI
> device binding and unbinding (create 'driver' symlinks under the device
> tree, check for device ID in driver's ID table, etc.)
> 
> Signed-off-by: Michal Privoznik <mprivozn at redhat.com>
> ---
>  cfg.mk             |   2 +-
>  tests/Makefile.am  |  10 +-
>  tests/virpcimock.c | 603 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
>  tests/virpcitest.c |  42 ++++
>  4 files changed, 652 insertions(+), 5 deletions(-)
> 
[...]
> diff --git a/tests/virpcimock.c b/tests/virpcimock.c
> index d545361..2adc337 100644
> --- a/tests/virpcimock.c
> +++ b/tests/virpcimock.c
> @@ -163,12 +323,367 @@ pci_device_new_from_stub(const struct pciDevice *data)
[...]
> +static int
> +pci_driver_handle_unbind(const char *path)
> +{
> +    int ret = -1;
> +    struct pciDevice *dev = pci_device_find_by_content(path);
> +
> +    if (!dev || !dev->driver) {
> +        /* This should never happen (TM) */
> +        errno = ENODEV;
> +        goto cleanup;
> +    }
> +
> +    ret = pci_driver_unbind(dev->driver, dev);
> +cleanup:
> +    return ret;
> +}

One more newline here?  I missed that in v1 ;-)

> +static int
> +pci_driver_handle_new_id(const char *path)
> +{
[...]
> @@ -195,7 +710,10 @@ init_syms(void)
>  
>      LOAD_SYM(access);
>      LOAD_SYM_ALT(lstat, __lxstat);
> +    LOAD_SYM_ALT(stat, __xstat);

I couldn't find what you need stat() for, but this works and makes no
harm.  Moreover it makes us sure there won't be any stat() done wrong
in the future.

[...]
> diff --git a/tests/virpcitest.c b/tests/virpcitest.c
> index 96f11d6..3eaa469 100644
> --- a/tests/virpcitest.c
> +++ b/tests/virpcitest.c
> @@ -60,6 +60,47 @@ cleanup:
>      return ret;
>  }
>  
> +# define CHECK_LIST_COUNT(list, cnt)                                    \
> +    if ((count = virPCIDeviceListCount(list)) != cnt) {                 \
> +        virReportError(VIR_ERR_INTERNAL_ERROR,                          \
> +                       "Unexpected count of items in " #list ": %d, "   \
> +                       "expecting " #cnt, count);                       \
> +        goto cleanup;                                                   \
> +    }
> +
> +static int
> +testVirPCIDeviceDetach(const void *oaque ATTRIBUTE_UNUSED)
> +{
> +    int ret = -1;
> +    virPCIDevicePtr dev;
> +    virPCIDeviceListPtr activeDevs = NULL, inactiveDevs = NULL;
> +    int count;
> +
> +    if (!(dev = virPCIDeviceNew(0, 0, 1, 0)) ||
> +        !(activeDevs = virPCIDeviceListNew()) ||
> +        !(inactiveDevs = virPCIDeviceListNew()))
> +        goto cleanup;
> +
> +    CHECK_LIST_COUNT(activeDevs, 0);
> +    CHECK_LIST_COUNT(inactiveDevs, 0);
> +
> +    if (virPCIDeviceSetStubDriver(dev, "pci-stub") < 0)
> +        goto cleanup;
> +
> +    if (virPCIDeviceDetach(dev, activeDevs, inactiveDevs) < 0)
> +        goto cleanup;
> +

virPCIDeviceDetach() adds a copy, I missed that, thanks.

[...]

It's almost the same as v1 (with one leak fixed and stat() mocking
added), so the same as for v1 applies here.

Martin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20131101/48052a81/attachment-0001.sig>


More information about the libvir-list mailing list