[libvirt] [RFC PATCH 10/16] tests: qemublock: Add test for checkpoint deletion bitmap merge

Peter Krempa posted 16 patches 6 years, 1 month ago
[libvirt] [RFC PATCH 10/16] tests: qemublock: Add test for checkpoint deletion bitmap merge
Posted by Peter Krempa 6 years, 1 month ago
Add test infrastructure and a basic test for bitmap deletion.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
---
 tests/qemublocktest.c                         | 59 +++++++++++++++++++
 .../checkpointdelete/basic-noparent-out.json  |  9 +++
 2 files changed, 68 insertions(+)
 create mode 100644 tests/qemublocktestdata/checkpointdelete/basic-noparent-out.json

diff --git a/tests/qemublocktest.c b/tests/qemublocktest.c
index 3e9edb85f0..3ed2486ad2 100644
--- a/tests/qemublocktest.c
+++ b/tests/qemublocktest.c
@@ -27,6 +27,7 @@
 #include "qemu/qemu_qapi.h"
 #include "qemu/qemu_monitor_json.h"
 #include "qemu/qemu_backup.h"
+#include "qemu/qemu_checkpoint.h"

 #include "qemu/qemu_command.h"

@@ -696,6 +697,50 @@ testQemuBackupIncrementalBitmapCalculate(const void *opaque)
 }


+static const char *checkpointDeletePrefix = "qemublocktestdata/checkpointdelete/";
+
+struct testQemuCheckpointDeleteMergeData {
+    const char *name;
+    virStorageSourcePtr chain;
+    const char *deletebitmap;
+    const char *parentbitmap;
+};
+
+
+static int
+testQemuCheckpointDeleteMerge(const void *opaque)
+{
+    const struct testQemuCheckpointDeleteMergeData *data = opaque;
+    g_autofree char *actual = NULL;
+    g_autofree char *expectpath = NULL;
+    g_autoptr(virJSONValue) actions = NULL;
+    bool currentcheckpoint;
+
+    expectpath = g_strdup_printf("%s/%s%s-out.json", abs_srcdir,
+                                 checkpointDeletePrefix, data->name);
+
+    if (!(actions = virJSONValueNewArray()))
+        return -1;
+
+    /* hack to get the 'current' state until the function stops accepting it */
+    currentcheckpoint = STREQ("current", data->deletebitmap);
+
+    if (qemuCheckpointDiscardDiskBitmaps(data->chain,
+                                         data->deletebitmap,
+                                         data->parentbitmap,
+                                         currentcheckpoint,
+                                         actions) < 0) {
+        VIR_TEST_VERBOSE("failed to generate checkpoint delete transaction\n");
+        return -1;
+    }
+
+    if (!(actual = virJSONValueToString(actions, true)))
+        return -1;
+
+    return virTestCompareToFile(actual, expectpath);
+}
+
+
 static int
 mymain(void)
 {
@@ -705,6 +750,7 @@ mymain(void)
     struct testQemuDiskXMLToJSONData diskxmljsondata;
     struct testQemuImageCreateData imagecreatedata;
     struct testQemuBackupIncrementalBitmapCalculateData backupbitmapcalcdata;
+    struct testQemuCheckpointDeleteMergeData checkpointdeletedata;
     char *capslatest_x86_64 = NULL;
     virQEMUCapsPtr caps_x86_64 = NULL;
     g_autoptr(virStorageSource) bitmapSourceChain = NULL;
@@ -941,6 +987,19 @@ mymain(void)
     TEST_BACKUP_BITMAP_CALCULATE("snapshot-intermediate", bitmapSourceChain, "d", "snapshots");
     TEST_BACKUP_BITMAP_CALCULATE("snapshot-deep", bitmapSourceChain, "a", "snapshots");

+#define TEST_CHECKPOINT_DELETE_MERGE(testname, delbmp, parbmp) \
+    do { \
+        checkpointdeletedata.name = testname; \
+        checkpointdeletedata.chain = bitmapSourceChain; \
+        checkpointdeletedata.deletebitmap = delbmp; \
+        checkpointdeletedata.parentbitmap = parbmp; \
+        if (virTestRun("checkpoint delete " testname, \
+                       testQemuCheckpointDeleteMerge, &checkpointdeletedata) < 0) \
+        ret = -1; \
+    } while (0)
+
+    TEST_CHECKPOINT_DELETE_MERGE("basic-noparent", "a", NULL);
+
  cleanup:
     virHashFree(diskxmljsondata.schema);
     qemuTestDriverFree(&driver);
diff --git a/tests/qemublocktestdata/checkpointdelete/basic-noparent-out.json b/tests/qemublocktestdata/checkpointdelete/basic-noparent-out.json
new file mode 100644
index 0000000000..e87382fdb4
--- /dev/null
+++ b/tests/qemublocktestdata/checkpointdelete/basic-noparent-out.json
@@ -0,0 +1,9 @@
+[
+  {
+    "type": "block-dirty-bitmap-remove",
+    "data": {
+      "node": "libvirt-1-format",
+      "name": "a"
+    }
+  }
+]
-- 
2.24.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [RFC PATCH 10/16] tests: qemublock: Add test for checkpoint deletion bitmap merge
Posted by Eric Blake 6 years ago
On 1/9/20 12:21 PM, Peter Krempa wrote:
> Add test infrastructure and a basic test for bitmap deletion.
> 
> Signed-off-by: Peter Krempa <pkrempa@redhat.com>
> ---
>   tests/qemublocktest.c                         | 59 +++++++++++++++++++
>   .../checkpointdelete/basic-noparent-out.json  |  9 +++
>   2 files changed, 68 insertions(+)
>   create mode 100644 tests/qemublocktestdata/checkpointdelete/basic-noparent-out.json
> 

> +static int
> +testQemuCheckpointDeleteMerge(const void *opaque)
> +{
> +    const struct testQemuCheckpointDeleteMergeData *data = opaque;
> +    g_autofree char *actual = NULL;
> +    g_autofree char *expectpath = NULL;
> +    g_autoptr(virJSONValue) actions = NULL;
> +    bool currentcheckpoint;
> +
> +    expectpath = g_strdup_printf("%s/%s%s-out.json", abs_srcdir,
> +                                 checkpointDeletePrefix, data->name);
> +
> +    if (!(actions = virJSONValueNewArray()))
> +        return -1;
> +
> +    /* hack to get the 'current' state until the function stops accepting it */
> +    currentcheckpoint = STREQ("current", data->deletebitmap);
> +
> +    if (qemuCheckpointDiscardDiskBitmaps(data->chain,
> +                                         data->deletebitmap,
> +                                         data->parentbitmap,
> +                                         currentcheckpoint,
> +                                         actions) < 0) {

Are there patches planned later on to change this? Or is this comment 
going to be an instance of technical debt for an unknown length of time?

At any rate, the test looks sane enough;
Reviewed-by: Eric Blake <eblake@redhat.com>


-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org

Re: [RFC PATCH 10/16] tests: qemublock: Add test for checkpoint deletion bitmap merge
Posted by Peter Krempa 6 years ago
On Mon, Jan 27, 2020 at 12:55:02 -0600, Eric Blake wrote:
> On 1/9/20 12:21 PM, Peter Krempa wrote:
> > Add test infrastructure and a basic test for bitmap deletion.
> > 
> > Signed-off-by: Peter Krempa <pkrempa@redhat.com>
> > ---
> >   tests/qemublocktest.c                         | 59 +++++++++++++++++++
> >   .../checkpointdelete/basic-noparent-out.json  |  9 +++
> >   2 files changed, 68 insertions(+)
> >   create mode 100644 tests/qemublocktestdata/checkpointdelete/basic-noparent-out.json
> > 
> 
> > +static int
> > +testQemuCheckpointDeleteMerge(const void *opaque)
> > +{
> > +    const struct testQemuCheckpointDeleteMergeData *data = opaque;
> > +    g_autofree char *actual = NULL;
> > +    g_autofree char *expectpath = NULL;
> > +    g_autoptr(virJSONValue) actions = NULL;
> > +    bool currentcheckpoint;
> > +
> > +    expectpath = g_strdup_printf("%s/%s%s-out.json", abs_srcdir,
> > +                                 checkpointDeletePrefix, data->name);
> > +
> > +    if (!(actions = virJSONValueNewArray()))
> > +        return -1;
> > +
> > +    /* hack to get the 'current' state until the function stops accepting it */
> > +    currentcheckpoint = STREQ("current", data->deletebitmap);
> > +
> > +    if (qemuCheckpointDiscardDiskBitmaps(data->chain,
> > +                                         data->deletebitmap,
> > +                                         data->parentbitmap,
> > +                                         currentcheckpoint,
> > +                                         actions) < 0) {
> 
> Are there patches planned later on to change this? Or is this comment going
> to be an instance of technical debt for an unknown length of time?

Patch 13 modifies qemuCheckpointDiscardDiskBitmaps to work accross the
backing chain and after that modification it doesn't require the
parameter any more.