summaryrefslogtreecommitdiff
path: root/tests/storagepoolcapstest.c
diff options
context:
space:
mode:
authorJohn Ferlan <jferlan@redhat.com>2019-02-07 12:07:16 -0500
committerJohn Ferlan <jferlan@redhat.com>2019-03-06 11:12:48 -0500
commit73426c55b7f368a2ace2c054c82b4f75cb51a1aa (patch)
tree19dbf01271625af3a8ed4647fec309a81834d8e6 /tests/storagepoolcapstest.c
parent3b1988f3e3a8d4e103a24e0dc6542a00ccc9a1a0 (diff)
downloadlibvirt-73426c55b7f368a2ace2c054c82b4f75cb51a1aa.tar.gz
tests: Introduce storage pool capabilites test
Add a new test for the storage pool capabilities. There will be one test mocked with every backend available (full) and one where only the file system pool is available. Signed-off-by: John Ferlan <jferlan@redhat.com> ACKed-by: Michal Privoznik <mprivozn@redhat.com>
Diffstat (limited to 'tests/storagepoolcapstest.c')
-rw-r--r--tests/storagepoolcapstest.c124
1 files changed, 124 insertions, 0 deletions
diff --git a/tests/storagepoolcapstest.c b/tests/storagepoolcapstest.c
new file mode 100644
index 0000000000..d31f50c957
--- /dev/null
+++ b/tests/storagepoolcapstest.c
@@ -0,0 +1,124 @@
+/*
+ * Copyright (C) Red Hat, Inc. 2019
+ *
+ * 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/>.
+ */
+
+#include <config.h>
+
+#include "testutils.h"
+#include "storage_conf.h"
+#include "storage_capabilities.h"
+
+
+#define VIR_FROM_THIS VIR_FROM_NONE
+
+
+struct test_virStoragePoolCapsFormatData {
+ const char *filename;
+ virCapsPtr driverCaps;
+};
+
+static void
+test_virCapabilitiesAddFullStoragePool(virCapsPtr caps)
+{
+ size_t i;
+
+ for (i = 0; i < VIR_STORAGE_POOL_LAST; i++)
+ virCapabilitiesAddStoragePool(caps, i);
+}
+
+
+static void
+test_virCapabilitiesAddFSStoragePool(virCapsPtr caps)
+{
+ virCapabilitiesAddStoragePool(caps, VIR_STORAGE_POOL_FS);
+}
+
+
+static int
+test_virStoragePoolCapsFormat(const void *opaque)
+{
+ struct test_virStoragePoolCapsFormatData *data =
+ (struct test_virStoragePoolCapsFormatData *) opaque;
+ virCapsPtr driverCaps = data->driverCaps;
+ virStoragePoolCapsPtr poolCaps = NULL;
+ int ret = -1;
+ VIR_AUTOFREE(char *) path = NULL;
+ VIR_AUTOFREE(char *) poolCapsFromFile = NULL;
+ VIR_AUTOFREE(char *) poolCapsXML = NULL;
+
+
+ if (!(poolCaps = virStoragePoolCapsNew(driverCaps)))
+ goto cleanup;
+
+ if (virAsprintf(&path, "%s/storagepoolcapsschemadata/poolcaps-%s.xml",
+ abs_srcdir, data->filename) < 0)
+ goto cleanup;
+
+ if (virFileReadAll(path, 8192, &poolCapsFromFile) < 0)
+ goto cleanup;
+
+ if (!(poolCapsXML = virStoragePoolCapsFormat(poolCaps)))
+ goto cleanup;
+
+ if (STRNEQ(poolCapsFromFile, poolCapsXML)) {
+ virTestDifference(stderr, poolCapsFromFile, poolCapsXML);
+ goto cleanup;
+ }
+
+ ret = 0;
+
+ cleanup:
+ virObjectUnref(poolCaps);
+ return ret;
+}
+
+
+static int
+mymain(void)
+{
+ int ret = -1;
+ virCapsPtr fullCaps = NULL;
+ virCapsPtr fsCaps = NULL;
+
+#define DO_TEST(Filename, DriverCaps) \
+ do { \
+ struct test_virStoragePoolCapsFormatData data = \
+ {.filename = Filename, .driverCaps = DriverCaps }; \
+ if (virTestRun(Filename, test_virStoragePoolCapsFormat, &data) < 0) \
+ goto cleanup; \
+ } while (0)
+
+ if (!(fullCaps = virCapabilitiesNew(VIR_ARCH_NONE, false, false)) ||
+ !(fsCaps = virCapabilitiesNew(VIR_ARCH_NONE, false, false)))
+ goto cleanup;
+
+ test_virCapabilitiesAddFullStoragePool(fullCaps);
+ test_virCapabilitiesAddFSStoragePool(fsCaps);
+
+ DO_TEST("full", fullCaps);
+ DO_TEST("fs", fsCaps);
+
+ ret = 0;
+
+ cleanup:
+ virObjectUnref(fullCaps);
+ virObjectUnref(fsCaps);
+
+ return ret;
+}
+
+VIR_TEST_MAIN(mymain)