{
struct pciDevice *dev;
char *devpath;
+ char *configSrc, *configDst;
char tmp[32];
+ struct stat sb;
if (VIR_ALLOC_QUIET(dev) < 0 ||
+ virAsprintfQuiet(&configSrc, "%s/virpcitestdata/%s.config", abs_builddir, data->id) < 0 ||
virAsprintfQuiet(&devpath, "%s/devices/%s", fakesysfsdir, data->id) < 0)
ABORT_OOM();
if (virFileMakePath(devpath) < 0)
ABORT("Unable to create: %s", devpath);
- make_file(devpath, "config", "some dummy config");
+ /* If there is a config file for the device within virpcitestdata dir,
+ * symlink it. Otherwise create a dummy config file. */
+ if ((realstat && realstat(configSrc, &sb) == 0) ||
+ (real__xstat && real__xstat(_STAT_VER, configSrc, &sb) == 0)) {
+ /* On success make symlink to @configSrc */
+ if (virAsprintfQuiet(&configDst, "%s/config", devpath) < 0)
+ ABORT_OOM();
+
+ if (symlink(configSrc, configDst) < 0)
+ ABORT("Unable to create symlink: %s", configDst);
+ } else {
+ /* If there's no config data in the virpcitestdata dir, create a dummy
+ * config file */
+ make_file(devpath, "config", "some dummy config");
+ }
if (snprintf(tmp, sizeof(tmp), "0x%.4x", dev->vendor) < 0)
ABORT("@tmp overflow");
if ((count = virPCIDeviceListCount(list)) != cnt) { \
virReportError(VIR_ERR_INTERNAL_ERROR, \
"Unexpected count of items in " #list ": %d, " \
- "expecting " #cnt, count); \
+ "expecting %zu", count, (size_t) cnt); \
goto cleanup; \
}
testVirPCIDeviceDetach(const void *oaque ATTRIBUTE_UNUSED)
{
int ret = -1;
- virPCIDevicePtr dev = NULL, unbindedDev = NULL;
+ virPCIDevicePtr dev[] = {NULL, NULL, NULL};
+ size_t i, nDev = ARRAY_CARDINALITY(dev);
virPCIDeviceListPtr activeDevs = NULL, inactiveDevs = NULL;
int count;
- if (!(dev = virPCIDeviceNew(0, 0, 1, 0)) ||
- !(unbindedDev = virPCIDeviceNew(0, 0, 3, 0)) ||
- !(activeDevs = virPCIDeviceListNew()) ||
+ if (!(activeDevs = virPCIDeviceListNew()) ||
!(inactiveDevs = virPCIDeviceListNew()))
goto cleanup;
CHECK_LIST_COUNT(activeDevs, 0);
CHECK_LIST_COUNT(inactiveDevs, 0);
- if (virPCIDeviceSetStubDriver(dev, "pci-stub") < 0 ||
- virPCIDeviceSetStubDriver(unbindedDev, "pci-stub") < 0)
- goto cleanup;
+ for (i = 0; i < nDev; i++) {
+ if (!(dev[i] = virPCIDeviceNew(0, 0, i + 1, 0)) ||
+ virPCIDeviceSetStubDriver(dev[i], "pci-stub") < 0)
+ goto cleanup;
- if (virPCIDeviceDetach(dev, activeDevs, inactiveDevs) < 0)
- goto cleanup;
+ if (virPCIDeviceDetach(dev[i], activeDevs, inactiveDevs) < 0)
+ goto cleanup;
- CHECK_LIST_COUNT(activeDevs, 0);
- CHECK_LIST_COUNT(inactiveDevs, 1);
+ CHECK_LIST_COUNT(activeDevs, 0);
+ CHECK_LIST_COUNT(inactiveDevs, i + 1);
+ }
+
+ ret = 0;
+cleanup:
+ for (i = 0; i < nDev; i++)
+ virPCIDeviceFree(dev[i]);
+ virObjectUnref(activeDevs);
+ virObjectUnref(inactiveDevs);
+ return ret;
+}
- if (virPCIDeviceDetach(unbindedDev, activeDevs, inactiveDevs) < 0)
+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()))
goto cleanup;
CHECK_LIST_COUNT(activeDevs, 0);
- CHECK_LIST_COUNT(inactiveDevs, 2);
+ CHECK_LIST_COUNT(inactiveDevs, 0);
+
+ for (i = 0; i < nDev; i++) {
+ if (!(dev[i] = virPCIDeviceNew(0, 0, i + 1, 0)) ||
+ virPCIDeviceSetStubDriver(dev[i], "pci-stub") < 0)
+ goto cleanup;
+
+ if (virPCIDeviceReset(dev[i], activeDevs, inactiveDevs) < 0)
+ goto cleanup;
+ }
ret = 0;
cleanup:
- virPCIDeviceFree(dev);
- virPCIDeviceFree(unbindedDev);
+ for (i = 0; i < nDev; i++)
+ virPCIDeviceFree(dev[i]);
virObjectUnref(activeDevs);
virObjectUnref(inactiveDevs);
return ret;
}
-# define FAKESYSFSDIRTEMPLATE abs_builddir "/fakesysfsdir-XXXXXX"
-
static int
-testVirPCIDeviceReattach(const void *oaque ATTRIBUTE_UNUSED)
+testVirPCIDeviceReattach(const void *opaque ATTRIBUTE_UNUSED)
{
int ret = -1;
- virPCIDevicePtr dev = NULL, unbindedDev = NULL;
+ virPCIDevicePtr dev[] = {NULL, NULL, NULL};
+ size_t i, nDev = ARRAY_CARDINALITY(dev);
virPCIDeviceListPtr activeDevs = NULL, inactiveDevs = NULL;
int count;
- if (!(dev = virPCIDeviceNew(0, 0, 1, 0)) ||
- !(unbindedDev = virPCIDeviceNew(0, 0, 3, 0)) ||
- !(activeDevs = virPCIDeviceListNew()) ||
+ if (!(activeDevs = virPCIDeviceListNew()) ||
!(inactiveDevs = virPCIDeviceListNew()))
goto cleanup;
- if (virPCIDeviceListAdd(inactiveDevs, dev) < 0) {
- virPCIDeviceFree(dev);
- virPCIDeviceFree(unbindedDev);
- goto cleanup;
- }
-
- if (virPCIDeviceListAdd(inactiveDevs, unbindedDev) < 0) {
- virPCIDeviceFree(unbindedDev);
- goto cleanup;
- }
+ for (i = 0; i < nDev; i++) {
+ if (!(dev[i] = virPCIDeviceNew(0, 0, i + 1, 0)))
+ goto cleanup;
- CHECK_LIST_COUNT(activeDevs, 0);
- CHECK_LIST_COUNT(inactiveDevs, 2);
+ if (virPCIDeviceListAdd(inactiveDevs, dev[i]) < 0) {
+ virPCIDeviceFree(dev[i]);
+ goto cleanup;
+ }
- if (virPCIDeviceSetStubDriver(dev, "pci-stub") < 0)
- goto cleanup;
+ CHECK_LIST_COUNT(activeDevs, 0);
+ CHECK_LIST_COUNT(inactiveDevs, i + 1);
- if (virPCIDeviceReattach(dev, activeDevs, inactiveDevs) < 0)
- goto cleanup;
+ if (virPCIDeviceSetStubDriver(dev[i], "pci-stub") < 0)
+ goto cleanup;
+ }
CHECK_LIST_COUNT(activeDevs, 0);
- CHECK_LIST_COUNT(inactiveDevs, 1);
+ CHECK_LIST_COUNT(inactiveDevs, nDev);
- if (virPCIDeviceReattach(unbindedDev, activeDevs, inactiveDevs) < 0)
- goto cleanup;
+ for (i = 0; i < nDev; i++) {
+ if (virPCIDeviceReattach(dev[i], activeDevs, inactiveDevs) < 0)
+ goto cleanup;
- CHECK_LIST_COUNT(activeDevs, 0);
- CHECK_LIST_COUNT(inactiveDevs, 0);
+ CHECK_LIST_COUNT(activeDevs, 0);
+ CHECK_LIST_COUNT(inactiveDevs, nDev - i - 1);
+ }
ret = 0;
cleanup:
virObjectUnref(inactiveDevs);
return ret;
}
+
+# define FAKESYSFSDIRTEMPLATE abs_builddir "/fakesysfsdir-XXXXXX"
+
static int
mymain(void)
{
DO_TEST(testVirPCIDeviceNew);
DO_TEST(testVirPCIDeviceDetach);
+ DO_TEST(testVirPCIDeviceReset);
DO_TEST(testVirPCIDeviceReattach);
if (getenv("LIBVIRT_SKIP_CLEANUP") == NULL)