render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
Blob Blame History Raw
From 736c0d3748605b553f065332855b61291503ac25 Mon Sep 17 00:00:00 2001
Message-Id: <736c0d3748605b553f065332855b61291503ac25@dist-git>
From: Peter Krempa <pkrempa@redhat.com>
Date: Tue, 4 Feb 2020 15:08:26 +0100
Subject: [PATCH] tests: qemublock: Add tests for
 qemuBlockBitmapsHandleBlockcopy
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Use some of the existing bitmap data to add tests for
qemuBlockBitmapsHandleBlockcopy.

As the output depends on the ordering in the hash table we must also
install the "virdeterministichash" mock preload library.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
(cherry picked from commit 9b13af73ac336fb1d93ef15e30204fbf9c7e536f)

https://bugzilla.redhat.com/show_bug.cgi?id=1207659
Message-Id: <095e8e63f87edfd7924a8e8d8a4a8def04022d77.1580824112.git.pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
---
 tests/qemublocktest.c                         |  71 +++++++++-
 .../bitmapblockcopy/basic-deep-out.json       | 117 +++++++++++++++
 .../bitmapblockcopy/basic-shallow-out.json    | 117 +++++++++++++++
 .../bitmapblockcopy/snapshots-deep-out.json   | 133 ++++++++++++++++++
 .../snapshots-shallow-out.json                |  48 +++++++
 5 files changed, 485 insertions(+), 1 deletion(-)
 create mode 100644 tests/qemublocktestdata/bitmapblockcopy/basic-deep-out.json
 create mode 100644 tests/qemublocktestdata/bitmapblockcopy/basic-shallow-out.json
 create mode 100644 tests/qemublocktestdata/bitmapblockcopy/snapshots-deep-out.json
 create mode 100644 tests/qemublocktestdata/bitmapblockcopy/snapshots-shallow-out.json

diff --git a/tests/qemublocktest.c b/tests/qemublocktest.c
index 3208e90e41..f66d894aed 100644
--- a/tests/qemublocktest.c
+++ b/tests/qemublocktest.c
@@ -799,6 +799,56 @@ testQemuBlockBitmapValidate(const void *opaque)
 }
 
 
+static const char *blockcopyPrefix = "qemublocktestdata/bitmapblockcopy/";
+
+struct testQemuBlockBitmapBlockcopyData {
+    const char *name;
+    bool shallow;
+    virStorageSourcePtr chain;
+    const char *nodedatafile;
+};
+
+
+static int
+testQemuBlockBitmapBlockcopy(const void *opaque)
+{
+    const struct testQemuBlockBitmapBlockcopyData *data = opaque;
+    g_autofree char *actual = NULL;
+    g_autofree char *expectpath = NULL;
+    g_autoptr(virJSONValue) actions = NULL;
+    g_autoptr(virJSONValue) nodedatajson = NULL;
+    g_autoptr(virHashTable) nodedata = NULL;
+    g_autoptr(virStorageSource) fakemirror = virStorageSourceNew();
+
+    if (!fakemirror)
+        return -1;
+
+    fakemirror->nodeformat = g_strdup("mirror-format-node");
+
+    expectpath = g_strdup_printf("%s/%s%s-out.json", abs_srcdir,
+                                 blockcopyPrefix, data->name);
+
+    if (!(nodedatajson = virTestLoadFileJSON(bitmapDetectPrefix, data->nodedatafile,
+                                             ".json", NULL)))
+        return -1;
+
+    if (!(nodedata = qemuMonitorJSONBlockGetNamedNodeDataJSON(nodedatajson))) {
+        VIR_TEST_VERBOSE("failed to load nodedata JSON\n");
+        return -1;
+    }
+
+    if (qemuBlockBitmapsHandleBlockcopy(data->chain, fakemirror, nodedata,
+                                        data->shallow, &actions) < 0)
+        return -1;
+
+    if (actions &&
+        !(actual = virJSONValueToString(actions, true)))
+        return -1;
+
+    return virTestCompareToFile(actual, expectpath);
+}
+
+
 static int
 mymain(void)
 {
@@ -810,6 +860,7 @@ mymain(void)
     struct testQemuBackupIncrementalBitmapCalculateData backupbitmapcalcdata;
     struct testQemuCheckpointDeleteMergeData checkpointdeletedata;
     struct testQemuBlockBitmapValidateData blockbitmapvalidatedata;
+    struct testQemuBlockBitmapBlockcopyData blockbitmapblockcopydata;
     char *capslatest_x86_64 = NULL;
     virQEMUCapsPtr caps_x86_64 = NULL;
     g_autoptr(virStorageSource) bitmapSourceChain = NULL;
@@ -1120,6 +1171,24 @@ mymain(void)
     TEST_BITMAP_VALIDATE("snapshots-synthetic-broken", "d", false);
     TEST_BITMAP_VALIDATE("snapshots-synthetic-broken", "current", true);
 
+#define TEST_BITMAP_BLOCKCOPY(testname, shllw, ndf) \
+    do { \
+        blockbitmapblockcopydata.name = testname; \
+        blockbitmapblockcopydata.shallow = shllw; \
+        blockbitmapblockcopydata.nodedatafile = ndf; \
+        blockbitmapblockcopydata.chain = bitmapSourceChain;\
+        if (virTestRun("bitmap block copy " testname, \
+                       testQemuBlockBitmapBlockcopy, \
+                       &blockbitmapblockcopydata) < 0) \
+            ret = -1; \
+    } while (0)
+
+    TEST_BITMAP_BLOCKCOPY("basic-shallow", true, "basic");
+    TEST_BITMAP_BLOCKCOPY("basic-deep", false, "basic");
+
+    TEST_BITMAP_BLOCKCOPY("snapshots-shallow", true, "snapshots");
+    TEST_BITMAP_BLOCKCOPY("snapshots-deep", false, "snapshots");
+
  cleanup:
     virHashFree(diskxmljsondata.schema);
     qemuTestDriverFree(&driver);
@@ -1129,4 +1198,4 @@ mymain(void)
     return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
 }
 
-VIR_TEST_MAIN(mymain)
+VIR_TEST_MAIN_PRELOAD(mymain, VIR_TEST_MOCK("virdeterministichash"))
diff --git a/tests/qemublocktestdata/bitmapblockcopy/basic-deep-out.json b/tests/qemublocktestdata/bitmapblockcopy/basic-deep-out.json
new file mode 100644
index 0000000000..4ed2b97e95
--- /dev/null
+++ b/tests/qemublocktestdata/bitmapblockcopy/basic-deep-out.json
@@ -0,0 +1,117 @@
+[
+  {
+    "type": "block-dirty-bitmap-add",
+    "data": {
+      "node": "mirror-format-node",
+      "name": "a",
+      "persistent": true,
+      "disabled": true,
+      "granularity": 65536
+    }
+  },
+  {
+    "type": "block-dirty-bitmap-merge",
+    "data": {
+      "node": "mirror-format-node",
+      "target": "a",
+      "bitmaps": [
+        {
+          "node": "libvirt-1-format",
+          "name": "a"
+        }
+      ]
+    }
+  },
+  {
+    "type": "block-dirty-bitmap-add",
+    "data": {
+      "node": "mirror-format-node",
+      "name": "b",
+      "persistent": true,
+      "disabled": true,
+      "granularity": 65536
+    }
+  },
+  {
+    "type": "block-dirty-bitmap-merge",
+    "data": {
+      "node": "mirror-format-node",
+      "target": "b",
+      "bitmaps": [
+        {
+          "node": "libvirt-1-format",
+          "name": "b"
+        }
+      ]
+    }
+  },
+  {
+    "type": "block-dirty-bitmap-add",
+    "data": {
+      "node": "mirror-format-node",
+      "name": "current",
+      "persistent": true,
+      "disabled": false,
+      "granularity": 65536
+    }
+  },
+  {
+    "type": "block-dirty-bitmap-merge",
+    "data": {
+      "node": "mirror-format-node",
+      "target": "current",
+      "bitmaps": [
+        {
+          "node": "libvirt-1-format",
+          "name": "current"
+        }
+      ]
+    }
+  },
+  {
+    "type": "block-dirty-bitmap-add",
+    "data": {
+      "node": "mirror-format-node",
+      "name": "c",
+      "persistent": true,
+      "disabled": true,
+      "granularity": 65536
+    }
+  },
+  {
+    "type": "block-dirty-bitmap-merge",
+    "data": {
+      "node": "mirror-format-node",
+      "target": "c",
+      "bitmaps": [
+        {
+          "node": "libvirt-1-format",
+          "name": "c"
+        }
+      ]
+    }
+  },
+  {
+    "type": "block-dirty-bitmap-add",
+    "data": {
+      "node": "mirror-format-node",
+      "name": "d",
+      "persistent": true,
+      "disabled": true,
+      "granularity": 65536
+    }
+  },
+  {
+    "type": "block-dirty-bitmap-merge",
+    "data": {
+      "node": "mirror-format-node",
+      "target": "d",
+      "bitmaps": [
+        {
+          "node": "libvirt-1-format",
+          "name": "d"
+        }
+      ]
+    }
+  }
+]
diff --git a/tests/qemublocktestdata/bitmapblockcopy/basic-shallow-out.json b/tests/qemublocktestdata/bitmapblockcopy/basic-shallow-out.json
new file mode 100644
index 0000000000..4ed2b97e95
--- /dev/null
+++ b/tests/qemublocktestdata/bitmapblockcopy/basic-shallow-out.json
@@ -0,0 +1,117 @@
+[
+  {
+    "type": "block-dirty-bitmap-add",
+    "data": {
+      "node": "mirror-format-node",
+      "name": "a",
+      "persistent": true,
+      "disabled": true,
+      "granularity": 65536
+    }
+  },
+  {
+    "type": "block-dirty-bitmap-merge",
+    "data": {
+      "node": "mirror-format-node",
+      "target": "a",
+      "bitmaps": [
+        {
+          "node": "libvirt-1-format",
+          "name": "a"
+        }
+      ]
+    }
+  },
+  {
+    "type": "block-dirty-bitmap-add",
+    "data": {
+      "node": "mirror-format-node",
+      "name": "b",
+      "persistent": true,
+      "disabled": true,
+      "granularity": 65536
+    }
+  },
+  {
+    "type": "block-dirty-bitmap-merge",
+    "data": {
+      "node": "mirror-format-node",
+      "target": "b",
+      "bitmaps": [
+        {
+          "node": "libvirt-1-format",
+          "name": "b"
+        }
+      ]
+    }
+  },
+  {
+    "type": "block-dirty-bitmap-add",
+    "data": {
+      "node": "mirror-format-node",
+      "name": "current",
+      "persistent": true,
+      "disabled": false,
+      "granularity": 65536
+    }
+  },
+  {
+    "type": "block-dirty-bitmap-merge",
+    "data": {
+      "node": "mirror-format-node",
+      "target": "current",
+      "bitmaps": [
+        {
+          "node": "libvirt-1-format",
+          "name": "current"
+        }
+      ]
+    }
+  },
+  {
+    "type": "block-dirty-bitmap-add",
+    "data": {
+      "node": "mirror-format-node",
+      "name": "c",
+      "persistent": true,
+      "disabled": true,
+      "granularity": 65536
+    }
+  },
+  {
+    "type": "block-dirty-bitmap-merge",
+    "data": {
+      "node": "mirror-format-node",
+      "target": "c",
+      "bitmaps": [
+        {
+          "node": "libvirt-1-format",
+          "name": "c"
+        }
+      ]
+    }
+  },
+  {
+    "type": "block-dirty-bitmap-add",
+    "data": {
+      "node": "mirror-format-node",
+      "name": "d",
+      "persistent": true,
+      "disabled": true,
+      "granularity": 65536
+    }
+  },
+  {
+    "type": "block-dirty-bitmap-merge",
+    "data": {
+      "node": "mirror-format-node",
+      "target": "d",
+      "bitmaps": [
+        {
+          "node": "libvirt-1-format",
+          "name": "d"
+        }
+      ]
+    }
+  }
+]
diff --git a/tests/qemublocktestdata/bitmapblockcopy/snapshots-deep-out.json b/tests/qemublocktestdata/bitmapblockcopy/snapshots-deep-out.json
new file mode 100644
index 0000000000..5456553d78
--- /dev/null
+++ b/tests/qemublocktestdata/bitmapblockcopy/snapshots-deep-out.json
@@ -0,0 +1,133 @@
+[
+  {
+    "type": "block-dirty-bitmap-add",
+    "data": {
+      "node": "mirror-format-node",
+      "name": "a",
+      "persistent": true,
+      "disabled": true,
+      "granularity": 65536
+    }
+  },
+  {
+    "type": "block-dirty-bitmap-merge",
+    "data": {
+      "node": "mirror-format-node",
+      "target": "a",
+      "bitmaps": [
+        {
+          "node": "libvirt-3-format",
+          "name": "a"
+        },
+        {
+          "node": "libvirt-4-format",
+          "name": "a"
+        },
+        {
+          "node": "libvirt-5-format",
+          "name": "a"
+        }
+      ]
+    }
+  },
+  {
+    "type": "block-dirty-bitmap-add",
+    "data": {
+      "node": "mirror-format-node",
+      "name": "b",
+      "persistent": true,
+      "disabled": true,
+      "granularity": 65536
+    }
+  },
+  {
+    "type": "block-dirty-bitmap-merge",
+    "data": {
+      "node": "mirror-format-node",
+      "target": "b",
+      "bitmaps": [
+        {
+          "node": "libvirt-3-format",
+          "name": "b"
+        }
+      ]
+    }
+  },
+  {
+    "type": "block-dirty-bitmap-add",
+    "data": {
+      "node": "mirror-format-node",
+      "name": "current",
+      "persistent": true,
+      "disabled": false,
+      "granularity": 65536
+    }
+  },
+  {
+    "type": "block-dirty-bitmap-merge",
+    "data": {
+      "node": "mirror-format-node",
+      "target": "current",
+      "bitmaps": [
+        {
+          "node": "libvirt-1-format",
+          "name": "current"
+        }
+      ]
+    }
+  },
+  {
+    "type": "block-dirty-bitmap-add",
+    "data": {
+      "node": "mirror-format-node",
+      "name": "c",
+      "persistent": true,
+      "disabled": true,
+      "granularity": 65536
+    }
+  },
+  {
+    "type": "block-dirty-bitmap-merge",
+    "data": {
+      "node": "mirror-format-node",
+      "target": "c",
+      "bitmaps": [
+        {
+          "node": "libvirt-2-format",
+          "name": "c"
+        },
+        {
+          "node": "libvirt-3-format",
+          "name": "c"
+        }
+      ]
+    }
+  },
+  {
+    "type": "block-dirty-bitmap-add",
+    "data": {
+      "node": "mirror-format-node",
+      "name": "d",
+      "persistent": true,
+      "disabled": true,
+      "granularity": 65536
+    }
+  },
+  {
+    "type": "block-dirty-bitmap-merge",
+    "data": {
+      "node": "mirror-format-node",
+      "target": "d",
+      "bitmaps": [
+        {
+          "node": "libvirt-1-format",
+          "name": "d"
+        },
+        {
+          "node": "libvirt-2-format",
+          "name": "d"
+        }
+      ]
+    }
+  }
+]
diff --git a/tests/qemublocktestdata/bitmapblockcopy/snapshots-shallow-out.json b/tests/qemublocktestdata/bitmapblockcopy/snapshots-shallow-out.json
new file mode 100644
index 0000000000..ddd47f7ee1
--- /dev/null
+++ b/tests/qemublocktestdata/bitmapblockcopy/snapshots-shallow-out.json
@@ -0,0 +1,48 @@
+[
+  {
+    "type": "block-dirty-bitmap-add",
+    "data": {
+      "node": "mirror-format-node",
+      "name": "current",
+      "persistent": true,
+      "disabled": false,
+      "granularity": 65536
+    }
+  },
+  {
+    "type": "block-dirty-bitmap-merge",
+    "data": {
+      "node": "mirror-format-node",
+      "target": "current",
+      "bitmaps": [
+        {
+          "node": "libvirt-1-format",
+          "name": "current"
+        }
+      ]
+    }
+  },
+  {
+    "type": "block-dirty-bitmap-add",
+    "data": {
+      "node": "mirror-format-node",
+      "name": "d",
+      "persistent": true,
+      "disabled": true,
+      "granularity": 65536
+    }
+  },
+  {
+    "type": "block-dirty-bitmap-merge",
+    "data": {
+      "node": "mirror-format-node",
+      "target": "d",
+      "bitmaps": [
+        {
+          "node": "libvirt-1-format",
+          "name": "d"
+        }
+      ]
+    }
+  }
+]
-- 
2.25.0