render / rpms / libvirt

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