Blame SOURCES/libvirt-tests-qemublock-Add-test-for-checkpoint-deletion-bitmap-merge.patch

a41c76
From c71d50132b3ac8dcfefc1acc11ab5d5bd7bc024a Mon Sep 17 00:00:00 2001
a41c76
Message-Id: <c71d50132b3ac8dcfefc1acc11ab5d5bd7bc024a@dist-git>
a41c76
From: Peter Krempa <pkrempa@redhat.com>
a41c76
Date: Tue, 4 Feb 2020 15:08:09 +0100
a41c76
Subject: [PATCH] tests: qemublock: Add test for checkpoint deletion bitmap
a41c76
 merge
a41c76
MIME-Version: 1.0
a41c76
Content-Type: text/plain; charset=UTF-8
a41c76
Content-Transfer-Encoding: 8bit
a41c76
a41c76
Add test infrastructure and a basic test for bitmap deletion.
a41c76
a41c76
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
a41c76
Reviewed-by: Ján Tomko <jtomko@redhat.com>
a41c76
(cherry picked from commit 25f74899720afce52dcf01f230da5c816deaea71)
a41c76
a41c76
https://bugzilla.redhat.com/show_bug.cgi?id=1207659
a41c76
Message-Id: <50b8789a34b762114b6ea2f87bba1a130be206de.1580824112.git.pkrempa@redhat.com>
a41c76
Reviewed-by: Ján Tomko <jtomko@redhat.com>
a41c76
---
a41c76
 tests/qemublocktest.c                         | 59 +++++++++++++++++++
a41c76
 .../checkpointdelete/basic-noparent-out.json  |  9 +++
a41c76
 2 files changed, 68 insertions(+)
a41c76
 create mode 100644 tests/qemublocktestdata/checkpointdelete/basic-noparent-out.json
a41c76
a41c76
diff --git a/tests/qemublocktest.c b/tests/qemublocktest.c
a41c76
index 7ff6a6b17b..80355d1340 100644
a41c76
--- a/tests/qemublocktest.c
a41c76
+++ b/tests/qemublocktest.c
a41c76
@@ -27,6 +27,7 @@
a41c76
 #include "qemu/qemu_qapi.h"
a41c76
 #include "qemu/qemu_monitor_json.h"
a41c76
 #include "qemu/qemu_backup.h"
a41c76
+#include "qemu/qemu_checkpoint.h"
a41c76
 
a41c76
 #include "qemu/qemu_command.h"
a41c76
 
a41c76
@@ -696,6 +697,50 @@ testQemuBackupIncrementalBitmapCalculate(const void *opaque)
a41c76
 }
a41c76
 
a41c76
 
a41c76
+static const char *checkpointDeletePrefix = "qemublocktestdata/checkpointdelete/";
a41c76
+
a41c76
+struct testQemuCheckpointDeleteMergeData {
a41c76
+    const char *name;
a41c76
+    virStorageSourcePtr chain;
a41c76
+    const char *deletebitmap;
a41c76
+    const char *parentbitmap;
a41c76
+};
a41c76
+
a41c76
+
a41c76
+static int
a41c76
+testQemuCheckpointDeleteMerge(const void *opaque)
a41c76
+{
a41c76
+    const struct testQemuCheckpointDeleteMergeData *data = opaque;
a41c76
+    g_autofree char *actual = NULL;
a41c76
+    g_autofree char *expectpath = NULL;
a41c76
+    g_autoptr(virJSONValue) actions = NULL;
a41c76
+    bool currentcheckpoint;
a41c76
+
a41c76
+    expectpath = g_strdup_printf("%s/%s%s-out.json", abs_srcdir,
a41c76
+                                 checkpointDeletePrefix, data->name);
a41c76
+
a41c76
+    if (!(actions = virJSONValueNewArray()))
a41c76
+        return -1;
a41c76
+
a41c76
+    /* hack to get the 'current' state until the function stops accepting it */
a41c76
+    currentcheckpoint = STREQ("current", data->deletebitmap);
a41c76
+
a41c76
+    if (qemuCheckpointDiscardDiskBitmaps(data->chain,
a41c76
+                                         data->deletebitmap,
a41c76
+                                         data->parentbitmap,
a41c76
+                                         currentcheckpoint,
a41c76
+                                         actions) < 0) {
a41c76
+        VIR_TEST_VERBOSE("failed to generate checkpoint delete transaction\n");
a41c76
+        return -1;
a41c76
+    }
a41c76
+
a41c76
+    if (!(actual = virJSONValueToString(actions, true)))
a41c76
+        return -1;
a41c76
+
a41c76
+    return virTestCompareToFile(actual, expectpath);
a41c76
+}
a41c76
+
a41c76
+
a41c76
 static int
a41c76
 mymain(void)
a41c76
 {
a41c76
@@ -705,6 +750,7 @@ mymain(void)
a41c76
     struct testQemuDiskXMLToJSONData diskxmljsondata;
a41c76
     struct testQemuImageCreateData imagecreatedata;
a41c76
     struct testQemuBackupIncrementalBitmapCalculateData backupbitmapcalcdata;
a41c76
+    struct testQemuCheckpointDeleteMergeData checkpointdeletedata;
a41c76
     char *capslatest_x86_64 = NULL;
a41c76
     virQEMUCapsPtr caps_x86_64 = NULL;
a41c76
     g_autoptr(virStorageSource) bitmapSourceChain = NULL;
a41c76
@@ -941,6 +987,19 @@ mymain(void)
a41c76
     TEST_BACKUP_BITMAP_CALCULATE("snapshot-intermediate", bitmapSourceChain, "d", "snapshots");
a41c76
     TEST_BACKUP_BITMAP_CALCULATE("snapshot-deep", bitmapSourceChain, "a", "snapshots");
a41c76
 
a41c76
+#define TEST_CHECKPOINT_DELETE_MERGE(testname, delbmp, parbmp) \
a41c76
+    do { \
a41c76
+        checkpointdeletedata.name = testname; \
a41c76
+        checkpointdeletedata.chain = bitmapSourceChain; \
a41c76
+        checkpointdeletedata.deletebitmap = delbmp; \
a41c76
+        checkpointdeletedata.parentbitmap = parbmp; \
a41c76
+        if (virTestRun("checkpoint delete " testname, \
a41c76
+                       testQemuCheckpointDeleteMerge, &checkpointdeletedata) < 0) \
a41c76
+        ret = -1; \
a41c76
+    } while (0)
a41c76
+
a41c76
+    TEST_CHECKPOINT_DELETE_MERGE("basic-noparent", "a", NULL);
a41c76
+
a41c76
  cleanup:
a41c76
     virHashFree(diskxmljsondata.schema);
a41c76
     qemuTestDriverFree(&driver);
a41c76
diff --git a/tests/qemublocktestdata/checkpointdelete/basic-noparent-out.json b/tests/qemublocktestdata/checkpointdelete/basic-noparent-out.json
a41c76
new file mode 100644
a41c76
index 0000000000..e87382fdb4
a41c76
--- /dev/null
a41c76
+++ b/tests/qemublocktestdata/checkpointdelete/basic-noparent-out.json
a41c76
@@ -0,0 +1,9 @@
a41c76
+[
a41c76
+  {
a41c76
+    "type": "block-dirty-bitmap-remove",
a41c76
+    "data": {
a41c76
+      "node": "libvirt-1-format",
a41c76
+      "name": "a"
a41c76
+    }
a41c76
+  }
a41c76
+]
a41c76
-- 
a41c76
2.25.0
a41c76