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

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