Blame SOURCES/libvirt-tests-qemublock-Add-tests-for-qemuBlockBitmapsHandleBlockcopy.patch

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