2013-10-23 13:44:40 +00:00
|
|
|
/*
|
2014-03-17 09:38:38 +00:00
|
|
|
* Copyright (C) 2013, 2014 Red Hat, Inc.
|
2013-10-23 13:44:40 +00:00
|
|
|
*
|
|
|
|
* 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: Michal Privoznik <mprivozn@redhat.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "testutils.h"
|
|
|
|
|
|
|
|
#ifdef __linux__
|
|
|
|
|
|
|
|
# include <stdlib.h>
|
|
|
|
# include <stdio.h>
|
|
|
|
# include <sys/types.h>
|
|
|
|
# include <sys/stat.h>
|
|
|
|
# include <fcntl.h>
|
|
|
|
# include <virpci.h>
|
|
|
|
|
|
|
|
# define VIR_FROM_THIS VIR_FROM_NONE
|
|
|
|
|
2014-01-15 09:20:55 +00:00
|
|
|
static int
|
|
|
|
testVirPCIDeviceCheckDriver(virPCIDevicePtr dev, const char *expected)
|
|
|
|
{
|
|
|
|
char *path = NULL;
|
|
|
|
char *driver = NULL;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
if (virPCIDeviceGetDriverPathAndName(dev, &path, &driver) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (STRNEQ_NULLABLE(driver, expected)) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
"PCI device %s driver mismatch: %s, expecting %s",
|
|
|
|
virPCIDeviceGetName(dev), NULLSTR(driver),
|
|
|
|
NULLSTR(expected));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
2014-03-25 06:53:44 +00:00
|
|
|
cleanup:
|
2014-01-15 09:20:55 +00:00
|
|
|
VIR_FREE(path);
|
|
|
|
VIR_FREE(driver);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-10-23 13:44:40 +00:00
|
|
|
static int
|
|
|
|
testVirPCIDeviceNew(const void *opaque ATTRIBUTE_UNUSED)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
virPCIDevicePtr dev;
|
|
|
|
const char *devName;
|
|
|
|
|
|
|
|
if (!(dev = virPCIDeviceNew(0, 0, 0, 0)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
devName = virPCIDeviceGetName(dev);
|
|
|
|
if (STRNEQ(devName, "0000:00:00.0")) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
"PCI device name mismatch: %s, expecting %s",
|
|
|
|
devName, "0000:00:00.0");
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
2014-03-25 06:53:44 +00:00
|
|
|
cleanup:
|
2013-10-23 13:44:40 +00:00
|
|
|
virPCIDeviceFree(dev);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-10-23 15:55:02 +00:00
|
|
|
# define CHECK_LIST_COUNT(list, cnt) \
|
|
|
|
if ((count = virPCIDeviceListCount(list)) != cnt) { \
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, \
|
|
|
|
"Unexpected count of items in " #list ": %d, " \
|
2013-11-05 14:07:49 +00:00
|
|
|
"expecting %zu", count, (size_t) cnt); \
|
2013-10-23 15:55:02 +00:00
|
|
|
goto cleanup; \
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2016-02-23 09:34:43 +00:00
|
|
|
testVirPCIDeviceDetach(const void *opaque ATTRIBUTE_UNUSED)
|
2013-10-23 15:55:02 +00:00
|
|
|
{
|
|
|
|
int ret = -1;
|
2013-11-05 14:07:49 +00:00
|
|
|
virPCIDevicePtr dev[] = {NULL, NULL, NULL};
|
|
|
|
size_t i, nDev = ARRAY_CARDINALITY(dev);
|
2013-10-23 15:55:02 +00:00
|
|
|
virPCIDeviceListPtr activeDevs = NULL, inactiveDevs = NULL;
|
|
|
|
int count;
|
|
|
|
|
2013-11-05 14:07:49 +00:00
|
|
|
if (!(activeDevs = virPCIDeviceListNew()) ||
|
2013-10-23 15:55:02 +00:00
|
|
|
!(inactiveDevs = virPCIDeviceListNew()))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
CHECK_LIST_COUNT(activeDevs, 0);
|
|
|
|
CHECK_LIST_COUNT(inactiveDevs, 0);
|
|
|
|
|
2013-11-05 14:07:49 +00:00
|
|
|
for (i = 0; i < nDev; i++) {
|
2015-10-23 09:54:07 +00:00
|
|
|
if (!(dev[i] = virPCIDeviceNew(0, 0, i + 1, 0)))
|
2013-11-05 14:07:49 +00:00
|
|
|
goto cleanup;
|
2013-10-23 15:55:02 +00:00
|
|
|
|
2015-10-23 09:54:07 +00:00
|
|
|
virPCIDeviceSetStubDriver(dev[i], VIR_PCI_STUB_DRIVER_KVM);
|
|
|
|
|
2013-11-05 14:07:49 +00:00
|
|
|
if (virPCIDeviceDetach(dev[i], activeDevs, inactiveDevs) < 0)
|
|
|
|
goto cleanup;
|
2013-10-23 15:55:02 +00:00
|
|
|
|
2014-01-15 09:20:55 +00:00
|
|
|
if (testVirPCIDeviceCheckDriver(dev[i], "pci-stub") < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2013-11-05 14:07:49 +00:00
|
|
|
CHECK_LIST_COUNT(activeDevs, 0);
|
|
|
|
CHECK_LIST_COUNT(inactiveDevs, i + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
2014-03-25 06:53:44 +00:00
|
|
|
cleanup:
|
2013-11-05 14:07:49 +00:00
|
|
|
for (i = 0; i < nDev; i++)
|
|
|
|
virPCIDeviceFree(dev[i]);
|
|
|
|
virObjectUnref(activeDevs);
|
|
|
|
virObjectUnref(inactiveDevs);
|
|
|
|
return ret;
|
|
|
|
}
|
2013-10-23 15:55:02 +00:00
|
|
|
|
2013-11-05 14:07:49 +00:00
|
|
|
static int
|
|
|
|
testVirPCIDeviceReset(const void *opaque ATTRIBUTE_UNUSED)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
virPCIDevicePtr dev[] = {NULL, NULL, NULL};
|
|
|
|
size_t i, nDev = ARRAY_CARDINALITY(dev);
|
|
|
|
virPCIDeviceListPtr activeDevs = NULL, inactiveDevs = NULL;
|
|
|
|
int count;
|
|
|
|
|
|
|
|
if (!(activeDevs = virPCIDeviceListNew()) ||
|
|
|
|
!(inactiveDevs = virPCIDeviceListNew()))
|
2013-10-31 11:05:20 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
CHECK_LIST_COUNT(activeDevs, 0);
|
2013-11-05 14:07:49 +00:00
|
|
|
CHECK_LIST_COUNT(inactiveDevs, 0);
|
|
|
|
|
|
|
|
for (i = 0; i < nDev; i++) {
|
2015-10-23 09:54:07 +00:00
|
|
|
if (!(dev[i] = virPCIDeviceNew(0, 0, i + 1, 0)))
|
2013-11-05 14:07:49 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2015-10-23 09:54:07 +00:00
|
|
|
virPCIDeviceSetStubDriver(dev[i], VIR_PCI_STUB_DRIVER_KVM);
|
|
|
|
|
2013-11-05 14:07:49 +00:00
|
|
|
if (virPCIDeviceReset(dev[i], activeDevs, inactiveDevs) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2013-10-31 11:05:20 +00:00
|
|
|
|
2013-10-23 15:55:02 +00:00
|
|
|
ret = 0;
|
2014-03-25 06:53:44 +00:00
|
|
|
cleanup:
|
2013-11-05 14:07:49 +00:00
|
|
|
for (i = 0; i < nDev; i++)
|
|
|
|
virPCIDeviceFree(dev[i]);
|
2013-10-23 15:55:02 +00:00
|
|
|
virObjectUnref(activeDevs);
|
|
|
|
virObjectUnref(inactiveDevs);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-10-31 10:57:56 +00:00
|
|
|
static int
|
2013-11-05 14:07:49 +00:00
|
|
|
testVirPCIDeviceReattach(const void *opaque ATTRIBUTE_UNUSED)
|
2013-10-31 10:57:56 +00:00
|
|
|
{
|
|
|
|
int ret = -1;
|
2013-11-05 14:07:49 +00:00
|
|
|
virPCIDevicePtr dev[] = {NULL, NULL, NULL};
|
|
|
|
size_t i, nDev = ARRAY_CARDINALITY(dev);
|
2013-10-31 10:57:56 +00:00
|
|
|
virPCIDeviceListPtr activeDevs = NULL, inactiveDevs = NULL;
|
|
|
|
int count;
|
|
|
|
|
2013-11-05 14:07:49 +00:00
|
|
|
if (!(activeDevs = virPCIDeviceListNew()) ||
|
2013-10-31 10:57:56 +00:00
|
|
|
!(inactiveDevs = virPCIDeviceListNew()))
|
|
|
|
goto cleanup;
|
|
|
|
|
2013-11-05 14:07:49 +00:00
|
|
|
for (i = 0; i < nDev; i++) {
|
|
|
|
if (!(dev[i] = virPCIDeviceNew(0, 0, i + 1, 0)))
|
|
|
|
goto cleanup;
|
2013-10-31 10:57:56 +00:00
|
|
|
|
2013-11-05 14:07:49 +00:00
|
|
|
if (virPCIDeviceListAdd(inactiveDevs, dev[i]) < 0) {
|
|
|
|
virPCIDeviceFree(dev[i]);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2013-10-31 10:57:56 +00:00
|
|
|
|
2013-11-05 14:07:49 +00:00
|
|
|
CHECK_LIST_COUNT(activeDevs, 0);
|
|
|
|
CHECK_LIST_COUNT(inactiveDevs, i + 1);
|
2013-10-31 10:57:56 +00:00
|
|
|
|
2015-10-23 09:54:07 +00:00
|
|
|
virPCIDeviceSetStubDriver(dev[i], VIR_PCI_STUB_DRIVER_KVM);
|
2013-11-05 14:07:49 +00:00
|
|
|
}
|
2013-10-31 10:57:56 +00:00
|
|
|
|
2013-10-31 11:05:20 +00:00
|
|
|
CHECK_LIST_COUNT(activeDevs, 0);
|
2013-11-05 14:07:49 +00:00
|
|
|
CHECK_LIST_COUNT(inactiveDevs, nDev);
|
2013-10-31 11:05:20 +00:00
|
|
|
|
2013-11-05 14:07:49 +00:00
|
|
|
for (i = 0; i < nDev; i++) {
|
|
|
|
if (virPCIDeviceReattach(dev[i], activeDevs, inactiveDevs) < 0)
|
|
|
|
goto cleanup;
|
2013-10-31 11:05:20 +00:00
|
|
|
|
2013-11-05 14:07:49 +00:00
|
|
|
CHECK_LIST_COUNT(activeDevs, 0);
|
|
|
|
CHECK_LIST_COUNT(inactiveDevs, nDev - i - 1);
|
|
|
|
}
|
2013-10-31 10:57:56 +00:00
|
|
|
|
|
|
|
ret = 0;
|
2014-03-25 06:53:44 +00:00
|
|
|
cleanup:
|
2013-10-31 10:57:56 +00:00
|
|
|
virObjectUnref(activeDevs);
|
|
|
|
virObjectUnref(inactiveDevs);
|
|
|
|
return ret;
|
|
|
|
}
|
2013-11-05 14:07:49 +00:00
|
|
|
|
2013-12-24 18:07:27 +00:00
|
|
|
struct testPCIDevData {
|
|
|
|
unsigned int domain;
|
|
|
|
unsigned int bus;
|
|
|
|
unsigned int slot;
|
|
|
|
unsigned int function;
|
2014-01-15 09:20:55 +00:00
|
|
|
const char *driver;
|
2013-12-24 18:07:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
testVirPCIDeviceIsAssignable(const void *opaque)
|
|
|
|
{
|
|
|
|
const struct testPCIDevData *data = opaque;
|
|
|
|
int ret = -1;
|
|
|
|
virPCIDevicePtr dev;
|
|
|
|
|
|
|
|
if (!(dev = virPCIDeviceNew(data->domain, data->bus, data->slot, data->function)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virPCIDeviceIsAssignable(dev, true))
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
virPCIDeviceFree(dev);
|
2014-03-25 06:53:44 +00:00
|
|
|
cleanup:
|
2013-12-24 18:07:27 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-01-15 09:20:55 +00:00
|
|
|
static int
|
|
|
|
testVirPCIDeviceDetachSingle(const void *opaque)
|
|
|
|
{
|
|
|
|
const struct testPCIDevData *data = opaque;
|
|
|
|
int ret = -1;
|
|
|
|
virPCIDevicePtr dev;
|
|
|
|
|
|
|
|
dev = virPCIDeviceNew(data->domain, data->bus, data->slot, data->function);
|
|
|
|
if (!dev)
|
|
|
|
goto cleanup;
|
|
|
|
|
2015-10-23 09:54:07 +00:00
|
|
|
virPCIDeviceSetStubDriver(dev, VIR_PCI_STUB_DRIVER_KVM);
|
|
|
|
|
|
|
|
if (virPCIDeviceDetach(dev, NULL, NULL) < 0)
|
2014-01-15 09:20:55 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
ret = 0;
|
2014-03-25 06:53:44 +00:00
|
|
|
cleanup:
|
2014-01-15 09:20:55 +00:00
|
|
|
virPCIDeviceFree(dev);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-01-16 13:06:22 +00:00
|
|
|
static int
|
|
|
|
testVirPCIDeviceDetachFail(const void *opaque)
|
|
|
|
{
|
|
|
|
const struct testPCIDevData *data = opaque;
|
|
|
|
int ret = -1;
|
|
|
|
virPCIDevicePtr dev;
|
|
|
|
|
|
|
|
dev = virPCIDeviceNew(data->domain, data->bus, data->slot, data->function);
|
|
|
|
if (!dev)
|
|
|
|
goto cleanup;
|
|
|
|
|
2015-10-23 09:54:07 +00:00
|
|
|
virPCIDeviceSetStubDriver(dev, VIR_PCI_STUB_DRIVER_VFIO);
|
2014-01-16 13:06:22 +00:00
|
|
|
|
|
|
|
if (virPCIDeviceDetach(dev, NULL, NULL) < 0) {
|
|
|
|
if (virTestGetVerbose() || virTestGetDebug())
|
|
|
|
virDispatchError(NULL);
|
|
|
|
virResetLastError();
|
|
|
|
ret = 0;
|
|
|
|
} else {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
"Attaching device %s to %s should have failed",
|
|
|
|
virPCIDeviceGetName(dev),
|
2015-10-23 09:54:07 +00:00
|
|
|
virPCIStubDriverTypeToString(VIR_PCI_STUB_DRIVER_VFIO));
|
2014-01-16 13:06:22 +00:00
|
|
|
}
|
|
|
|
|
2014-03-25 06:53:44 +00:00
|
|
|
cleanup:
|
2014-01-16 13:06:22 +00:00
|
|
|
virPCIDeviceFree(dev);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-01-15 09:20:55 +00:00
|
|
|
static int
|
|
|
|
testVirPCIDeviceReattachSingle(const void *opaque)
|
|
|
|
{
|
|
|
|
const struct testPCIDevData *data = opaque;
|
|
|
|
int ret = -1;
|
|
|
|
virPCIDevicePtr dev;
|
|
|
|
|
|
|
|
dev = virPCIDeviceNew(data->domain, data->bus, data->slot, data->function);
|
|
|
|
if (!dev)
|
|
|
|
goto cleanup;
|
|
|
|
|
2016-01-19 14:58:31 +00:00
|
|
|
virPCIDeviceSetUnbindFromStub(dev, true);
|
|
|
|
virPCIDeviceSetRemoveSlot(dev, true);
|
|
|
|
virPCIDeviceSetReprobe(dev, true);
|
|
|
|
|
2014-01-15 09:20:55 +00:00
|
|
|
if (virPCIDeviceReattach(dev, NULL, NULL) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
ret = 0;
|
2014-03-25 06:53:44 +00:00
|
|
|
cleanup:
|
2014-01-15 09:20:55 +00:00
|
|
|
virPCIDeviceFree(dev);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
testVirPCIDeviceCheckDriverTest(const void *opaque)
|
|
|
|
{
|
|
|
|
const struct testPCIDevData *data = opaque;
|
|
|
|
int ret = -1;
|
|
|
|
virPCIDevicePtr dev;
|
|
|
|
|
|
|
|
dev = virPCIDeviceNew(data->domain, data->bus, data->slot, data->function);
|
|
|
|
if (!dev)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (testVirPCIDeviceCheckDriver(dev, data->driver) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
ret = 0;
|
2014-03-25 06:53:44 +00:00
|
|
|
cleanup:
|
2014-01-15 09:20:55 +00:00
|
|
|
virPCIDeviceFree(dev);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
testVirPCIDeviceUnbind(const void *opaque)
|
|
|
|
{
|
|
|
|
const struct testPCIDevData *data = opaque;
|
|
|
|
int ret = -1;
|
|
|
|
virPCIDevicePtr dev;
|
|
|
|
|
|
|
|
dev = virPCIDeviceNew(data->domain, data->bus, data->slot, data->function);
|
|
|
|
if (!dev)
|
|
|
|
goto cleanup;
|
|
|
|
|
2015-10-29 15:09:54 +00:00
|
|
|
if (virPCIDeviceUnbind(dev) < 0)
|
2014-01-15 09:20:55 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
ret = 0;
|
2014-03-25 06:53:44 +00:00
|
|
|
cleanup:
|
2014-01-15 09:20:55 +00:00
|
|
|
virPCIDeviceFree(dev);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-12-04 12:38:16 +00:00
|
|
|
# define FAKEROOTDIRTEMPLATE abs_builddir "/fakerootdir-XXXXXX"
|
2013-11-05 14:07:49 +00:00
|
|
|
|
2013-10-23 13:44:40 +00:00
|
|
|
static int
|
|
|
|
mymain(void)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
2015-12-04 12:38:16 +00:00
|
|
|
char *fakerootdir;
|
2013-10-23 13:44:40 +00:00
|
|
|
|
2015-12-04 12:38:16 +00:00
|
|
|
if (VIR_STRDUP_QUIET(fakerootdir, FAKEROOTDIRTEMPLATE) < 0) {
|
2015-04-23 17:38:00 +00:00
|
|
|
VIR_TEST_DEBUG("Out of memory\n");
|
2013-10-23 13:44:40 +00:00
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
2015-12-04 12:38:16 +00:00
|
|
|
if (!mkdtemp(fakerootdir)) {
|
|
|
|
VIR_TEST_DEBUG("Cannot create fakerootdir");
|
2013-10-23 13:44:40 +00:00
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
2015-12-04 12:38:16 +00:00
|
|
|
setenv("LIBVIRT_FAKE_ROOT_DIR", fakerootdir, 1);
|
2013-10-23 13:44:40 +00:00
|
|
|
|
|
|
|
# define DO_TEST(fnc) \
|
|
|
|
do { \
|
2016-05-26 15:01:50 +00:00
|
|
|
if (virTestRun(#fnc, fnc, NULL) < 0) \
|
2013-10-23 13:44:40 +00:00
|
|
|
ret = -1; \
|
|
|
|
} while (0)
|
|
|
|
|
2013-12-24 18:07:27 +00:00
|
|
|
# define DO_TEST_PCI(fnc, domain, bus, slot, function) \
|
|
|
|
do { \
|
2014-01-15 09:20:55 +00:00
|
|
|
struct testPCIDevData data = { \
|
|
|
|
domain, bus, slot, function, NULL \
|
|
|
|
}; \
|
2014-01-14 13:59:37 +00:00
|
|
|
char *label = NULL; \
|
|
|
|
if (virAsprintf(&label, "%s(%04x:%02x:%02x.%x)", \
|
|
|
|
#fnc, domain, bus, slot, function) < 0) { \
|
2013-12-24 18:07:27 +00:00
|
|
|
ret = -1; \
|
2014-01-14 13:59:37 +00:00
|
|
|
break; \
|
|
|
|
} \
|
2016-05-26 15:01:50 +00:00
|
|
|
if (virTestRun(label, fnc, &data) < 0) \
|
2014-01-14 13:59:37 +00:00
|
|
|
ret = -1; \
|
|
|
|
VIR_FREE(label); \
|
2013-12-24 18:07:27 +00:00
|
|
|
} while (0)
|
|
|
|
|
2014-01-15 09:20:55 +00:00
|
|
|
# define DO_TEST_PCI_DRIVER(domain, bus, slot, function, driver) \
|
|
|
|
do { \
|
|
|
|
struct testPCIDevData data = { \
|
|
|
|
domain, bus, slot, function, driver \
|
|
|
|
}; \
|
|
|
|
char *label = NULL; \
|
|
|
|
if (virAsprintf(&label, "PCI driver %04x:%02x:%02x.%x is %s", \
|
|
|
|
domain, bus, slot, function, \
|
|
|
|
NULLSTR(driver)) < 0) { \
|
|
|
|
ret = -1; \
|
|
|
|
break; \
|
|
|
|
} \
|
2016-05-26 15:01:50 +00:00
|
|
|
if (virTestRun(label, testVirPCIDeviceCheckDriverTest, \
|
|
|
|
&data) < 0) \
|
2014-01-15 09:20:55 +00:00
|
|
|
ret = -1; \
|
|
|
|
VIR_FREE(label); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
/* Changes made to individual devices are persistent and the
|
|
|
|
* tests often rely on the state set by previous tests.
|
|
|
|
*/
|
|
|
|
|
2013-10-23 13:44:40 +00:00
|
|
|
DO_TEST(testVirPCIDeviceNew);
|
2013-10-23 15:55:02 +00:00
|
|
|
DO_TEST(testVirPCIDeviceDetach);
|
2013-11-05 14:07:49 +00:00
|
|
|
DO_TEST(testVirPCIDeviceReset);
|
2013-10-31 10:57:56 +00:00
|
|
|
DO_TEST(testVirPCIDeviceReattach);
|
2013-12-24 18:07:27 +00:00
|
|
|
DO_TEST_PCI(testVirPCIDeviceIsAssignable, 5, 0x90, 1, 0);
|
|
|
|
DO_TEST_PCI(testVirPCIDeviceIsAssignable, 1, 1, 0, 0);
|
2013-10-23 13:44:40 +00:00
|
|
|
|
2014-01-16 13:06:22 +00:00
|
|
|
DO_TEST_PCI(testVirPCIDeviceDetachFail, 0, 0x0a, 1, 0);
|
|
|
|
|
2014-01-15 09:20:55 +00:00
|
|
|
/* Reattach a device already bound to non-stub a driver */
|
|
|
|
DO_TEST_PCI_DRIVER(0, 0x0a, 1, 0, "i915");
|
|
|
|
DO_TEST_PCI(testVirPCIDeviceReattachSingle, 0, 0x0a, 1, 0);
|
|
|
|
DO_TEST_PCI_DRIVER(0, 0x0a, 1, 0, "i915");
|
|
|
|
|
|
|
|
/* Reattach an unbound device */
|
|
|
|
DO_TEST_PCI(testVirPCIDeviceUnbind, 0, 0x0a, 1, 0);
|
|
|
|
DO_TEST_PCI_DRIVER(0, 0x0a, 1, 0, NULL);
|
|
|
|
DO_TEST_PCI(testVirPCIDeviceReattachSingle, 0, 0x0a, 1, 0);
|
|
|
|
DO_TEST_PCI_DRIVER(0, 0x0a, 1, 0, "i915");
|
|
|
|
|
|
|
|
/* Detach an unbound device */
|
|
|
|
DO_TEST_PCI_DRIVER(0, 0x0a, 2, 0, NULL);
|
|
|
|
DO_TEST_PCI(testVirPCIDeviceDetachSingle, 0, 0x0a, 2, 0);
|
|
|
|
DO_TEST_PCI_DRIVER(0, 0x0a, 2, 0, "pci-stub");
|
|
|
|
|
|
|
|
/* Reattach an unknown unbound device */
|
|
|
|
DO_TEST_PCI_DRIVER(0, 0x0a, 3, 0, NULL);
|
|
|
|
DO_TEST_PCI(testVirPCIDeviceReattachSingle, 0, 0x0a, 3, 0);
|
|
|
|
DO_TEST_PCI_DRIVER(0, 0x0a, 3, 0, NULL);
|
|
|
|
|
2013-10-23 13:44:40 +00:00
|
|
|
if (getenv("LIBVIRT_SKIP_CLEANUP") == NULL)
|
2015-12-04 12:38:16 +00:00
|
|
|
virFileDeleteTree(fakerootdir);
|
2013-10-23 13:44:40 +00:00
|
|
|
|
2015-12-04 12:38:16 +00:00
|
|
|
VIR_FREE(fakerootdir);
|
2013-10-23 13:44:40 +00:00
|
|
|
|
2014-03-17 09:38:38 +00:00
|
|
|
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
|
2013-10-23 13:44:40 +00:00
|
|
|
}
|
|
|
|
|
2017-03-29 14:45:42 +00:00
|
|
|
VIR_TEST_MAIN_PRELOAD(mymain, abs_builddir "/.libs/virpcimock.so")
|
2013-10-23 13:44:40 +00:00
|
|
|
#else
|
|
|
|
int
|
|
|
|
main(void)
|
|
|
|
{
|
|
|
|
return EXIT_AM_SKIP;
|
|
|
|
}
|
|
|
|
#endif
|