render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
d76c62
From 736c0d3748605b553f065332855b61291503ac25 Mon Sep 17 00:00:00 2001
d76c62
Message-Id: <736c0d3748605b553f065332855b61291503ac25@dist-git>
d76c62
From: Peter Krempa <pkrempa@redhat.com>
d76c62
Date: Tue, 4 Feb 2020 15:08:26 +0100
d76c62
Subject: [PATCH] tests: qemublock: Add tests for
d76c62
 qemuBlockBitmapsHandleBlockcopy
d76c62
MIME-Version: 1.0
d76c62
Content-Type: text/plain; charset=UTF-8
d76c62
Content-Transfer-Encoding: 8bit
d76c62
d76c62
Use some of the existing bitmap data to add tests for
d76c62
qemuBlockBitmapsHandleBlockcopy.
d76c62
d76c62
As the output depends on the ordering in the hash table we must also
d76c62
install the "virdeterministichash" mock preload library.
d76c62
d76c62
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
d76c62
Reviewed-by: Ján Tomko <jtomko@redhat.com>
d76c62
(cherry picked from commit 9b13af73ac336fb1d93ef15e30204fbf9c7e536f)
d76c62
d76c62
https://bugzilla.redhat.com/show_bug.cgi?id=1207659
d76c62
Message-Id: <095e8e63f87edfd7924a8e8d8a4a8def04022d77.1580824112.git.pkrempa@redhat.com>
d76c62
Reviewed-by: Ján Tomko <jtomko@redhat.com>
d76c62
---
d76c62
 tests/qemublocktest.c                         |  71 +++++++++-
d76c62
 .../bitmapblockcopy/basic-deep-out.json       | 117 +++++++++++++++
d76c62
 .../bitmapblockcopy/basic-shallow-out.json    | 117 +++++++++++++++
d76c62
 .../bitmapblockcopy/snapshots-deep-out.json   | 133 ++++++++++++++++++
d76c62
 .../snapshots-shallow-out.json                |  48 +++++++
d76c62
 5 files changed, 485 insertions(+), 1 deletion(-)
d76c62
 create mode 100644 tests/qemublocktestdata/bitmapblockcopy/basic-deep-out.json
d76c62
 create mode 100644 tests/qemublocktestdata/bitmapblockcopy/basic-shallow-out.json
d76c62
 create mode 100644 tests/qemublocktestdata/bitmapblockcopy/snapshots-deep-out.json
d76c62
 create mode 100644 tests/qemublocktestdata/bitmapblockcopy/snapshots-shallow-out.json
d76c62
d76c62
diff --git a/tests/qemublocktest.c b/tests/qemublocktest.c
d76c62
index 3208e90e41..f66d894aed 100644
d76c62
--- a/tests/qemublocktest.c
d76c62
+++ b/tests/qemublocktest.c
d76c62
@@ -799,6 +799,56 @@ testQemuBlockBitmapValidate(const void *opaque)
d76c62
 }
d76c62
 
d76c62
 
d76c62
+static const char *blockcopyPrefix = "qemublocktestdata/bitmapblockcopy/";
d76c62
+
d76c62
+struct testQemuBlockBitmapBlockcopyData {
d76c62
+    const char *name;
d76c62
+    bool shallow;
d76c62
+    virStorageSourcePtr chain;
d76c62
+    const char *nodedatafile;
d76c62
+};
d76c62
+
d76c62
+
d76c62
+static int
d76c62
+testQemuBlockBitmapBlockcopy(const void *opaque)
d76c62
+{
d76c62
+    const struct testQemuBlockBitmapBlockcopyData *data = opaque;
d76c62
+    g_autofree char *actual = NULL;
d76c62
+    g_autofree char *expectpath = NULL;
d76c62
+    g_autoptr(virJSONValue) actions = NULL;
d76c62
+    g_autoptr(virJSONValue) nodedatajson = NULL;
d76c62
+    g_autoptr(virHashTable) nodedata = NULL;
d76c62
+    g_autoptr(virStorageSource) fakemirror = virStorageSourceNew();
d76c62
+
d76c62
+    if (!fakemirror)
d76c62
+        return -1;
d76c62
+
d76c62
+    fakemirror->nodeformat = g_strdup("mirror-format-node");
d76c62
+
d76c62
+    expectpath = g_strdup_printf("%s/%s%s-out.json", abs_srcdir,
d76c62
+                                 blockcopyPrefix, data->name);
d76c62
+
d76c62
+    if (!(nodedatajson = virTestLoadFileJSON(bitmapDetectPrefix, data->nodedatafile,
d76c62
+                                             ".json", NULL)))
d76c62
+        return -1;
d76c62
+
d76c62
+    if (!(nodedata = qemuMonitorJSONBlockGetNamedNodeDataJSON(nodedatajson))) {
d76c62
+        VIR_TEST_VERBOSE("failed to load nodedata JSON\n");
d76c62
+        return -1;
d76c62
+    }
d76c62
+
d76c62
+    if (qemuBlockBitmapsHandleBlockcopy(data->chain, fakemirror, nodedata,
d76c62
+                                        data->shallow, &actions) < 0)
d76c62
+        return -1;
d76c62
+
d76c62
+    if (actions &&
d76c62
+        !(actual = virJSONValueToString(actions, true)))
d76c62
+        return -1;
d76c62
+
d76c62
+    return virTestCompareToFile(actual, expectpath);
d76c62
+}
d76c62
+
d76c62
+
d76c62
 static int
d76c62
 mymain(void)
d76c62
 {
d76c62
@@ -810,6 +860,7 @@ mymain(void)
d76c62
     struct testQemuBackupIncrementalBitmapCalculateData backupbitmapcalcdata;
d76c62
     struct testQemuCheckpointDeleteMergeData checkpointdeletedata;
d76c62
     struct testQemuBlockBitmapValidateData blockbitmapvalidatedata;
d76c62
+    struct testQemuBlockBitmapBlockcopyData blockbitmapblockcopydata;
d76c62
     char *capslatest_x86_64 = NULL;
d76c62
     virQEMUCapsPtr caps_x86_64 = NULL;
d76c62
     g_autoptr(virStorageSource) bitmapSourceChain = NULL;
d76c62
@@ -1120,6 +1171,24 @@ mymain(void)
d76c62
     TEST_BITMAP_VALIDATE("snapshots-synthetic-broken", "d", false);
d76c62
     TEST_BITMAP_VALIDATE("snapshots-synthetic-broken", "current", true);
d76c62
 
d76c62
+#define TEST_BITMAP_BLOCKCOPY(testname, shllw, ndf) \
d76c62
+    do { \
d76c62
+        blockbitmapblockcopydata.name = testname; \
d76c62
+        blockbitmapblockcopydata.shallow = shllw; \
d76c62
+        blockbitmapblockcopydata.nodedatafile = ndf; \
d76c62
+        blockbitmapblockcopydata.chain = bitmapSourceChain;\
d76c62
+        if (virTestRun("bitmap block copy " testname, \
d76c62
+                       testQemuBlockBitmapBlockcopy, \
d76c62
+                       &blockbitmapblockcopydata) < 0) \
d76c62
+            ret = -1; \
d76c62
+    } while (0)
d76c62
+
d76c62
+    TEST_BITMAP_BLOCKCOPY("basic-shallow", true, "basic");
d76c62
+    TEST_BITMAP_BLOCKCOPY("basic-deep", false, "basic");
d76c62
+
d76c62
+    TEST_BITMAP_BLOCKCOPY("snapshots-shallow", true, "snapshots");
d76c62
+    TEST_BITMAP_BLOCKCOPY("snapshots-deep", false, "snapshots");
d76c62
+
d76c62
  cleanup:
d76c62
     virHashFree(diskxmljsondata.schema);
d76c62
     qemuTestDriverFree(&driver);
d76c62
@@ -1129,4 +1198,4 @@ mymain(void)
d76c62
     return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
d76c62
 }
d76c62
 
d76c62
-VIR_TEST_MAIN(mymain)
d76c62
+VIR_TEST_MAIN_PRELOAD(mymain, VIR_TEST_MOCK("virdeterministichash"))
d76c62
diff --git a/tests/qemublocktestdata/bitmapblockcopy/basic-deep-out.json b/tests/qemublocktestdata/bitmapblockcopy/basic-deep-out.json
d76c62
new file mode 100644
d76c62
index 0000000000..4ed2b97e95
d76c62
--- /dev/null
d76c62
+++ b/tests/qemublocktestdata/bitmapblockcopy/basic-deep-out.json
d76c62
@@ -0,0 +1,117 @@
d76c62
+[
d76c62
+  {
d76c62
+    "type": "block-dirty-bitmap-add",
d76c62
+    "data": {
d76c62
+      "node": "mirror-format-node",
d76c62
+      "name": "a",
d76c62
+      "persistent": true,
d76c62
+      "disabled": true,
d76c62
+      "granularity": 65536
d76c62
+    }
d76c62
+  },
d76c62
+  {
d76c62
+    "type": "block-dirty-bitmap-merge",
d76c62
+    "data": {
d76c62
+      "node": "mirror-format-node",
d76c62
+      "target": "a",
d76c62
+      "bitmaps": [
d76c62
+        {
d76c62
+          "node": "libvirt-1-format",
d76c62
+          "name": "a"
d76c62
+        }
d76c62
+      ]
d76c62
+    }
d76c62
+  },
d76c62
+  {
d76c62
+    "type": "block-dirty-bitmap-add",
d76c62
+    "data": {
d76c62
+      "node": "mirror-format-node",
d76c62
+      "name": "b",
d76c62
+      "persistent": true,
d76c62
+      "disabled": true,
d76c62
+      "granularity": 65536
d76c62
+    }
d76c62
+  },
d76c62
+  {
d76c62
+    "type": "block-dirty-bitmap-merge",
d76c62
+    "data": {
d76c62
+      "node": "mirror-format-node",
d76c62
+      "target": "b",
d76c62
+      "bitmaps": [
d76c62
+        {
d76c62
+          "node": "libvirt-1-format",
d76c62
+          "name": "b"
d76c62
+        }
d76c62
+      ]
d76c62
+    }
d76c62
+  },
d76c62
+  {
d76c62
+    "type": "block-dirty-bitmap-add",
d76c62
+    "data": {
d76c62
+      "node": "mirror-format-node",
d76c62
+      "name": "current",
d76c62
+      "persistent": true,
d76c62
+      "disabled": false,
d76c62
+      "granularity": 65536
d76c62
+    }
d76c62
+  },
d76c62
+  {
d76c62
+    "type": "block-dirty-bitmap-merge",
d76c62
+    "data": {
d76c62
+      "node": "mirror-format-node",
d76c62
+      "target": "current",
d76c62
+      "bitmaps": [
d76c62
+        {
d76c62
+          "node": "libvirt-1-format",
d76c62
+          "name": "current"
d76c62
+        }
d76c62
+      ]
d76c62
+    }
d76c62
+  },
d76c62
+  {
d76c62
+    "type": "block-dirty-bitmap-add",
d76c62
+    "data": {
d76c62
+      "node": "mirror-format-node",
d76c62
+      "name": "c",
d76c62
+      "persistent": true,
d76c62
+      "disabled": true,
d76c62
+      "granularity": 65536
d76c62
+    }
d76c62
+  },
d76c62
+  {
d76c62
+    "type": "block-dirty-bitmap-merge",
d76c62
+    "data": {
d76c62
+      "node": "mirror-format-node",
d76c62
+      "target": "c",
d76c62
+      "bitmaps": [
d76c62
+        {
d76c62
+          "node": "libvirt-1-format",
d76c62
+          "name": "c"
d76c62
+        }
d76c62
+      ]
d76c62
+    }
d76c62
+  },
d76c62
+  {
d76c62
+    "type": "block-dirty-bitmap-add",
d76c62
+    "data": {
d76c62
+      "node": "mirror-format-node",
d76c62
+      "name": "d",
d76c62
+      "persistent": true,
d76c62
+      "disabled": true,
d76c62
+      "granularity": 65536
d76c62
+    }
d76c62
+  },
d76c62
+  {
d76c62
+    "type": "block-dirty-bitmap-merge",
d76c62
+    "data": {
d76c62
+      "node": "mirror-format-node",
d76c62
+      "target": "d",
d76c62
+      "bitmaps": [
d76c62
+        {
d76c62
+          "node": "libvirt-1-format",
d76c62
+          "name": "d"
d76c62
+        }
d76c62
+      ]
d76c62
+    }
d76c62
+  }
d76c62
+]
d76c62
diff --git a/tests/qemublocktestdata/bitmapblockcopy/basic-shallow-out.json b/tests/qemublocktestdata/bitmapblockcopy/basic-shallow-out.json
d76c62
new file mode 100644
d76c62
index 0000000000..4ed2b97e95
d76c62
--- /dev/null
d76c62
+++ b/tests/qemublocktestdata/bitmapblockcopy/basic-shallow-out.json
d76c62
@@ -0,0 +1,117 @@
d76c62
+[
d76c62
+  {
d76c62
+    "type": "block-dirty-bitmap-add",
d76c62
+    "data": {
d76c62
+      "node": "mirror-format-node",
d76c62
+      "name": "a",
d76c62
+      "persistent": true,
d76c62
+      "disabled": true,
d76c62
+      "granularity": 65536
d76c62
+    }
d76c62
+  },
d76c62
+  {
d76c62
+    "type": "block-dirty-bitmap-merge",
d76c62
+    "data": {
d76c62
+      "node": "mirror-format-node",
d76c62
+      "target": "a",
d76c62
+      "bitmaps": [
d76c62
+        {
d76c62
+          "node": "libvirt-1-format",
d76c62
+          "name": "a"
d76c62
+        }
d76c62
+      ]
d76c62
+    }
d76c62
+  },
d76c62
+  {
d76c62
+    "type": "block-dirty-bitmap-add",
d76c62
+    "data": {
d76c62
+      "node": "mirror-format-node",
d76c62
+      "name": "b",
d76c62
+      "persistent": true,
d76c62
+      "disabled": true,
d76c62
+      "granularity": 65536
d76c62
+    }
d76c62
+  },
d76c62
+  {
d76c62
+    "type": "block-dirty-bitmap-merge",
d76c62
+    "data": {
d76c62
+      "node": "mirror-format-node",
d76c62
+      "target": "b",
d76c62
+      "bitmaps": [
d76c62
+        {
d76c62
+          "node": "libvirt-1-format",
d76c62
+          "name": "b"
d76c62
+        }
d76c62
+      ]
d76c62
+    }
d76c62
+  },
d76c62
+  {
d76c62
+    "type": "block-dirty-bitmap-add",
d76c62
+    "data": {
d76c62
+      "node": "mirror-format-node",
d76c62
+      "name": "current",
d76c62
+      "persistent": true,
d76c62
+      "disabled": false,
d76c62
+      "granularity": 65536
d76c62
+    }
d76c62
+  },
d76c62
+  {
d76c62
+    "type": "block-dirty-bitmap-merge",
d76c62
+    "data": {
d76c62
+      "node": "mirror-format-node",
d76c62
+      "target": "current",
d76c62
+      "bitmaps": [
d76c62
+        {
d76c62
+          "node": "libvirt-1-format",
d76c62
+          "name": "current"
d76c62
+        }
d76c62
+      ]
d76c62
+    }
d76c62
+  },
d76c62
+  {
d76c62
+    "type": "block-dirty-bitmap-add",
d76c62
+    "data": {
d76c62
+      "node": "mirror-format-node",
d76c62
+      "name": "c",
d76c62
+      "persistent": true,
d76c62
+      "disabled": true,
d76c62
+      "granularity": 65536
d76c62
+    }
d76c62
+  },
d76c62
+  {
d76c62
+    "type": "block-dirty-bitmap-merge",
d76c62
+    "data": {
d76c62
+      "node": "mirror-format-node",
d76c62
+      "target": "c",
d76c62
+      "bitmaps": [
d76c62
+        {
d76c62
+          "node": "libvirt-1-format",
d76c62
+          "name": "c"
d76c62
+        }
d76c62
+      ]
d76c62
+    }
d76c62
+  },
d76c62
+  {
d76c62
+    "type": "block-dirty-bitmap-add",
d76c62
+    "data": {
d76c62
+      "node": "mirror-format-node",
d76c62
+      "name": "d",
d76c62
+      "persistent": true,
d76c62
+      "disabled": true,
d76c62
+      "granularity": 65536
d76c62
+    }
d76c62
+  },
d76c62
+  {
d76c62
+    "type": "block-dirty-bitmap-merge",
d76c62
+    "data": {
d76c62
+      "node": "mirror-format-node",
d76c62
+      "target": "d",
d76c62
+      "bitmaps": [
d76c62
+        {
d76c62
+          "node": "libvirt-1-format",
d76c62
+          "name": "d"
d76c62
+        }
d76c62
+      ]
d76c62
+    }
d76c62
+  }
d76c62
+]
d76c62
diff --git a/tests/qemublocktestdata/bitmapblockcopy/snapshots-deep-out.json b/tests/qemublocktestdata/bitmapblockcopy/snapshots-deep-out.json
d76c62
new file mode 100644
d76c62
index 0000000000..5456553d78
d76c62
--- /dev/null
d76c62
+++ b/tests/qemublocktestdata/bitmapblockcopy/snapshots-deep-out.json
d76c62
@@ -0,0 +1,133 @@
d76c62
+[
d76c62
+  {
d76c62
+    "type": "block-dirty-bitmap-add",
d76c62
+    "data": {
d76c62
+      "node": "mirror-format-node",
d76c62
+      "name": "a",
d76c62
+      "persistent": true,
d76c62
+      "disabled": true,
d76c62
+      "granularity": 65536
d76c62
+    }
d76c62
+  },
d76c62
+  {
d76c62
+    "type": "block-dirty-bitmap-merge",
d76c62
+    "data": {
d76c62
+      "node": "mirror-format-node",
d76c62
+      "target": "a",
d76c62
+      "bitmaps": [
d76c62
+        {
d76c62
+          "node": "libvirt-3-format",
d76c62
+          "name": "a"
d76c62
+        },
d76c62
+        {
d76c62
+          "node": "libvirt-4-format",
d76c62
+          "name": "a"
d76c62
+        },
d76c62
+        {
d76c62
+          "node": "libvirt-5-format",
d76c62
+          "name": "a"
d76c62
+        }
d76c62
+      ]
d76c62
+    }
d76c62
+  },
d76c62
+  {
d76c62
+    "type": "block-dirty-bitmap-add",
d76c62
+    "data": {
d76c62
+      "node": "mirror-format-node",
d76c62
+      "name": "b",
d76c62
+      "persistent": true,
d76c62
+      "disabled": true,
d76c62
+      "granularity": 65536
d76c62
+    }
d76c62
+  },
d76c62
+  {
d76c62
+    "type": "block-dirty-bitmap-merge",
d76c62
+    "data": {
d76c62
+      "node": "mirror-format-node",
d76c62
+      "target": "b",
d76c62
+      "bitmaps": [
d76c62
+        {
d76c62
+          "node": "libvirt-3-format",
d76c62
+          "name": "b"
d76c62
+        }
d76c62
+      ]
d76c62
+    }
d76c62
+  },
d76c62
+  {
d76c62
+    "type": "block-dirty-bitmap-add",
d76c62
+    "data": {
d76c62
+      "node": "mirror-format-node",
d76c62
+      "name": "current",
d76c62
+      "persistent": true,
d76c62
+      "disabled": false,
d76c62
+      "granularity": 65536
d76c62
+    }
d76c62
+  },
d76c62
+  {
d76c62
+    "type": "block-dirty-bitmap-merge",
d76c62
+    "data": {
d76c62
+      "node": "mirror-format-node",
d76c62
+      "target": "current",
d76c62
+      "bitmaps": [
d76c62
+        {
d76c62
+          "node": "libvirt-1-format",
d76c62
+          "name": "current"
d76c62
+        }
d76c62
+      ]
d76c62
+    }
d76c62
+  },
d76c62
+  {
d76c62
+    "type": "block-dirty-bitmap-add",
d76c62
+    "data": {
d76c62
+      "node": "mirror-format-node",
d76c62
+      "name": "c",
d76c62
+      "persistent": true,
d76c62
+      "disabled": true,
d76c62
+      "granularity": 65536
d76c62
+    }
d76c62
+  },
d76c62
+  {
d76c62
+    "type": "block-dirty-bitmap-merge",
d76c62
+    "data": {
d76c62
+      "node": "mirror-format-node",
d76c62
+      "target": "c",
d76c62
+      "bitmaps": [
d76c62
+        {
d76c62
+          "node": "libvirt-2-format",
d76c62
+          "name": "c"
d76c62
+        },
d76c62
+        {
d76c62
+          "node": "libvirt-3-format",
d76c62
+          "name": "c"
d76c62
+        }
d76c62
+      ]
d76c62
+    }
d76c62
+  },
d76c62
+  {
d76c62
+    "type": "block-dirty-bitmap-add",
d76c62
+    "data": {
d76c62
+      "node": "mirror-format-node",
d76c62
+      "name": "d",
d76c62
+      "persistent": true,
d76c62
+      "disabled": true,
d76c62
+      "granularity": 65536
d76c62
+    }
d76c62
+  },
d76c62
+  {
d76c62
+    "type": "block-dirty-bitmap-merge",
d76c62
+    "data": {
d76c62
+      "node": "mirror-format-node",
d76c62
+      "target": "d",
d76c62
+      "bitmaps": [
d76c62
+        {
d76c62
+          "node": "libvirt-1-format",
d76c62
+          "name": "d"
d76c62
+        },
d76c62
+        {
d76c62
+          "node": "libvirt-2-format",
d76c62
+          "name": "d"
d76c62
+        }
d76c62
+      ]
d76c62
+    }
d76c62
+  }
d76c62
+]
d76c62
diff --git a/tests/qemublocktestdata/bitmapblockcopy/snapshots-shallow-out.json b/tests/qemublocktestdata/bitmapblockcopy/snapshots-shallow-out.json
d76c62
new file mode 100644
d76c62
index 0000000000..ddd47f7ee1
d76c62
--- /dev/null
d76c62
+++ b/tests/qemublocktestdata/bitmapblockcopy/snapshots-shallow-out.json
d76c62
@@ -0,0 +1,48 @@
d76c62
+[
d76c62
+  {
d76c62
+    "type": "block-dirty-bitmap-add",
d76c62
+    "data": {
d76c62
+      "node": "mirror-format-node",
d76c62
+      "name": "current",
d76c62
+      "persistent": true,
d76c62
+      "disabled": false,
d76c62
+      "granularity": 65536
d76c62
+    }
d76c62
+  },
d76c62
+  {
d76c62
+    "type": "block-dirty-bitmap-merge",
d76c62
+    "data": {
d76c62
+      "node": "mirror-format-node",
d76c62
+      "target": "current",
d76c62
+      "bitmaps": [
d76c62
+        {
d76c62
+          "node": "libvirt-1-format",
d76c62
+          "name": "current"
d76c62
+        }
d76c62
+      ]
d76c62
+    }
d76c62
+  },
d76c62
+  {
d76c62
+    "type": "block-dirty-bitmap-add",
d76c62
+    "data": {
d76c62
+      "node": "mirror-format-node",
d76c62
+      "name": "d",
d76c62
+      "persistent": true,
d76c62
+      "disabled": true,
d76c62
+      "granularity": 65536
d76c62
+    }
d76c62
+  },
d76c62
+  {
d76c62
+    "type": "block-dirty-bitmap-merge",
d76c62
+    "data": {
d76c62
+      "node": "mirror-format-node",
d76c62
+      "target": "d",
d76c62
+      "bitmaps": [
d76c62
+        {
d76c62
+          "node": "libvirt-1-format",
d76c62
+          "name": "d"
d76c62
+        }
d76c62
+      ]
d76c62
+    }
d76c62
+  }
d76c62
+]
d76c62
-- 
d76c62
2.25.0
d76c62