dcavalca / rpms / qemu

Forked from rpms/qemu a year ago
Clone

Blame 0003-tests-make-filemonitor-test-more-robust-to-event-ord.patch

964eff
From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= <berrange@redhat.com>
964eff
Date: Wed, 21 Aug 2019 16:14:27 +0100
964eff
Subject: [PATCH] tests: make filemonitor test more robust to event ordering
964eff
MIME-Version: 1.0
964eff
Content-Type: text/plain; charset=UTF-8
964eff
Content-Transfer-Encoding: 8bit
964eff
964eff
The ordering of events that are emitted during the rmdir
964eff
test have changed with kernel >= 5.3. Semantically both
964eff
new & old orderings are correct, so we must be able to
964eff
cope with either.
964eff
964eff
To cope with this, when we see an unexpected event, we
964eff
push it back onto the queue and look and the subsequent
964eff
event to see if that matches instead.
964eff
964eff
Tested-by: Peter Xu <peterx@redhat.com>
964eff
Tested-by: Wei Yang <richardw.yang@linux.intel.com>
964eff
Tested-by: Cornelia Huck <cohuck@redhat.com>
964eff
Reviewed-by: Thomas Huth <thuth@redhat.com>
964eff
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
964eff
(cherry picked from commit bf9e0313c27d8e6ecd7f7de3d63e1cb25d8f6311)
964eff
---
964eff
 tests/test-util-filemonitor.c | 43 +++++++++++++++++++++++++++--------
964eff
 1 file changed, 34 insertions(+), 9 deletions(-)
964eff
964eff
diff --git a/tests/test-util-filemonitor.c b/tests/test-util-filemonitor.c
964eff
index 46e781c022..301cd2db61 100644
964eff
--- a/tests/test-util-filemonitor.c
964eff
+++ b/tests/test-util-filemonitor.c
964eff
@@ -45,6 +45,11 @@ typedef struct {
964eff
     const char *filedst;
964eff
     int64_t *watchid;
964eff
     int eventid;
964eff
+    /*
964eff
+     * Only valid with OP_EVENT - this event might be
964eff
+     * swapped with the next OP_EVENT
964eff
+     */
964eff
+    bool swapnext;
964eff
 } QFileMonitorTestOp;
964eff
 
964eff
 typedef struct {
964eff
@@ -98,6 +103,10 @@ qemu_file_monitor_test_handler(int64_t id,
964eff
     QFileMonitorTestData *data = opaque;
964eff
     QFileMonitorTestRecord *rec = g_new0(QFileMonitorTestRecord, 1);
964eff
 
964eff
+    if (debug) {
964eff
+        g_printerr("Queue event id %" PRIx64 " event %d file %s\n",
964eff
+                   id, event, filename);
964eff
+    }
964eff
     rec->id = id;
964eff
     rec->event = event;
964eff
     rec->filename = g_strdup(filename);
964eff
@@ -125,7 +134,8 @@ qemu_file_monitor_test_record_free(QFileMonitorTestRecord *rec)
964eff
  * to wait for the event to be queued for us.
964eff
  */
964eff
 static QFileMonitorTestRecord *
964eff
-qemu_file_monitor_test_next_record(QFileMonitorTestData *data)
964eff
+qemu_file_monitor_test_next_record(QFileMonitorTestData *data,
964eff
+                                   QFileMonitorTestRecord *pushback)
964eff
 {
964eff
     GTimer *timer = g_timer_new();
964eff
     QFileMonitorTestRecord *record = NULL;
964eff
@@ -139,9 +149,15 @@ qemu_file_monitor_test_next_record(QFileMonitorTestData *data)
964eff
     }
964eff
     if (data->records) {
964eff
         record = data->records->data;
964eff
-        tmp = data->records;
964eff
-        data->records = g_list_remove_link(data->records, tmp);
964eff
-        g_list_free(tmp);
964eff
+        if (pushback) {
964eff
+            data->records->data = pushback;
964eff
+        } else {
964eff
+            tmp = data->records;
964eff
+            data->records = g_list_remove_link(data->records, tmp);
964eff
+            g_list_free(tmp);
964eff
+        }
964eff
+    } else if (pushback) {
964eff
+        qemu_file_monitor_test_record_free(pushback);
964eff
     }
964eff
     qemu_mutex_unlock(&data->lock);
964eff
 
964eff
@@ -158,13 +174,15 @@ static bool
964eff
 qemu_file_monitor_test_expect(QFileMonitorTestData *data,
964eff
                               int64_t id,
964eff
                               QFileMonitorEvent event,
964eff
-                              const char *filename)
964eff
+                              const char *filename,
964eff
+                              bool swapnext)
964eff
 {
964eff
     QFileMonitorTestRecord *rec;
964eff
     bool ret = false;
964eff
 
964eff
-    rec = qemu_file_monitor_test_next_record(data);
964eff
+    rec = qemu_file_monitor_test_next_record(data, NULL);
964eff
 
964eff
+ retry:
964eff
     if (!rec) {
964eff
         g_printerr("Missing event watch id %" PRIx64 " event %d file %s\n",
964eff
                    id, event, filename);
964eff
@@ -172,6 +190,11 @@ qemu_file_monitor_test_expect(QFileMonitorTestData *data,
964eff
     }
964eff
 
964eff
     if (id != rec->id) {
964eff
+        if (swapnext) {
964eff
+            rec = qemu_file_monitor_test_next_record(data, rec);
964eff
+            swapnext = false;
964eff
+            goto retry;
964eff
+        }
964eff
         g_printerr("Expected watch id %" PRIx64 " but got %" PRIx64 "\n",
964eff
                    id, rec->id);
964eff
         goto cleanup;
964eff
@@ -347,7 +370,8 @@ test_file_monitor_events(void)
964eff
           .filesrc = "fish", },
964eff
         { .type = QFILE_MONITOR_TEST_OP_EVENT,
964eff
           .filesrc = "", .watchid = &watch4,
964eff
-          .eventid = QFILE_MONITOR_EVENT_IGNORED },
964eff
+          .eventid = QFILE_MONITOR_EVENT_IGNORED,
964eff
+          .swapnext = true },
964eff
         { .type = QFILE_MONITOR_TEST_OP_EVENT,
964eff
           .filesrc = "fish", .watchid = &watch0,
964eff
           .eventid = QFILE_MONITOR_EVENT_DELETED },
964eff
@@ -493,8 +517,9 @@ test_file_monitor_events(void)
964eff
                 g_printerr("Event id=%" PRIx64 " event=%d file=%s\n",
964eff
                            *op->watchid, op->eventid, op->filesrc);
964eff
             }
964eff
-            if (!qemu_file_monitor_test_expect(
964eff
-                    &data, *op->watchid, op->eventid, op->filesrc))
964eff
+            if (!qemu_file_monitor_test_expect(&data, *op->watchid,
964eff
+                                               op->eventid, op->filesrc,
964eff
+                                               op->swapnext))
964eff
                 goto cleanup;
964eff
             break;
964eff
         case QFILE_MONITOR_TEST_OP_CREATE: