Fix filemonitor test broken with newest Linux kernel

-----BEGIN PGP SIGNATURE-----
 
 iQIzBAABCAAdFiEE2vOm/bJrYpEtDo4/vobrtBUQT98FAl14vtkACgkQvobrtBUQ
 T9/4DA//QoRu1K1pghGWgD4UmDRh0x6jz7TaKVfHDZFowLlnBbx1Uj48K854dXc9
 /BwNwXjS11JGUufZR7vuoOhWLUwinLkcWWQRWiMhB1NsL6Ceuz/ufJXZqBKTP99f
 qXDR0I8z6WnHHKo+PmxWFXWwpronkqYhNW4fwP/sryuSyRJKm4R5sKKcgDNk59Wf
 AP8ySXt0C10FyHT21Z4eVjwSxuZLDuwkU9tTvPWQ9tuI2ADJpBbapiq6r8J2fDs8
 FhjeaEEW4lrXM5l7G8SCSCjLkGfNISLJi9fI1jqtaSe30Rn9JPziKsNZl3iZRZNr
 EAlUoTX5sx0FF5Mz94mkRY0UFpWZ3s39Cw4kmVt/28hT5UuulForYEICUJ9UJivp
 jRzRpjRopp9FWY54p6Hl5sSawR6QIIiIR676QWQ1h/1OnkPWl78W7zpuK7RwnqqZ
 P5V1tQJ2pSab7qIhwBQ0N8ZZJnYCmemlBCX5kIJL2L8vCXSodf+OzxKl1g7NhCzD
 OKXBPN6EErd9lI9EPUkj6qwQIhBjv0MxjqCCeQMIcZRW10DgTJBdmCeLMNyEp8os
 NMSNV7V0VbV4SDnG6Fbv79/M3xAaAFhdXPBqPMWP+aFYeZX3Dv5NNsiruETjV7Xa
 mwwO/MKFquwrI+mW/mZpQ0Ny27SBOOwr9IgMO8N1tsAfg0JNajU=
 =uGDi
 -----END PGP SIGNATURE-----

Merge remote-tracking branch 'remotes/berrange/tags/filemon-test-pull-request' into staging

Fix filemonitor test broken with newest Linux kernel

# gpg: Signature made Wed 11 Sep 2019 10:31:05 BST
# gpg:                using RSA key DAF3A6FDB26B62912D0E8E3FBE86EBB415104FDF
# gpg: Good signature from "Daniel P. Berrange <dan@berrange.com>" [full]
# gpg:                 aka "Daniel P. Berrange <berrange@redhat.com>" [full]
# Primary key fingerprint: DAF3 A6FD B26B 6291 2D0E  8E3F BE86 EBB4 1510 4FDF

* remotes/berrange/tags/filemon-test-pull-request:
  tests: make filemonitor test more robust to event ordering

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
Peter Maydell 2019-09-13 10:20:28 +01:00
commit 7ff9127862
1 changed files with 34 additions and 9 deletions

View File

@ -45,6 +45,11 @@ typedef struct {
const char *filedst;
int64_t *watchid;
int eventid;
/*
* Only valid with OP_EVENT - this event might be
* swapped with the next OP_EVENT
*/
bool swapnext;
} QFileMonitorTestOp;
typedef struct {
@ -98,6 +103,10 @@ qemu_file_monitor_test_handler(int64_t id,
QFileMonitorTestData *data = opaque;
QFileMonitorTestRecord *rec = g_new0(QFileMonitorTestRecord, 1);
if (debug) {
g_printerr("Queue event id %" PRIx64 " event %d file %s\n",
id, event, filename);
}
rec->id = id;
rec->event = event;
rec->filename = g_strdup(filename);
@ -125,7 +134,8 @@ qemu_file_monitor_test_record_free(QFileMonitorTestRecord *rec)
* to wait for the event to be queued for us.
*/
static QFileMonitorTestRecord *
qemu_file_monitor_test_next_record(QFileMonitorTestData *data)
qemu_file_monitor_test_next_record(QFileMonitorTestData *data,
QFileMonitorTestRecord *pushback)
{
GTimer *timer = g_timer_new();
QFileMonitorTestRecord *record = NULL;
@ -139,9 +149,15 @@ qemu_file_monitor_test_next_record(QFileMonitorTestData *data)
}
if (data->records) {
record = data->records->data;
tmp = data->records;
data->records = g_list_remove_link(data->records, tmp);
g_list_free(tmp);
if (pushback) {
data->records->data = pushback;
} else {
tmp = data->records;
data->records = g_list_remove_link(data->records, tmp);
g_list_free(tmp);
}
} else if (pushback) {
qemu_file_monitor_test_record_free(pushback);
}
qemu_mutex_unlock(&data->lock);
@ -158,13 +174,15 @@ static bool
qemu_file_monitor_test_expect(QFileMonitorTestData *data,
int64_t id,
QFileMonitorEvent event,
const char *filename)
const char *filename,
bool swapnext)
{
QFileMonitorTestRecord *rec;
bool ret = false;
rec = qemu_file_monitor_test_next_record(data);
rec = qemu_file_monitor_test_next_record(data, NULL);
retry:
if (!rec) {
g_printerr("Missing event watch id %" PRIx64 " event %d file %s\n",
id, event, filename);
@ -172,6 +190,11 @@ qemu_file_monitor_test_expect(QFileMonitorTestData *data,
}
if (id != rec->id) {
if (swapnext) {
rec = qemu_file_monitor_test_next_record(data, rec);
swapnext = false;
goto retry;
}
g_printerr("Expected watch id %" PRIx64 " but got %" PRIx64 "\n",
id, rec->id);
goto cleanup;
@ -347,7 +370,8 @@ test_file_monitor_events(void)
.filesrc = "fish", },
{ .type = QFILE_MONITOR_TEST_OP_EVENT,
.filesrc = "", .watchid = &watch4,
.eventid = QFILE_MONITOR_EVENT_IGNORED },
.eventid = QFILE_MONITOR_EVENT_IGNORED,
.swapnext = true },
{ .type = QFILE_MONITOR_TEST_OP_EVENT,
.filesrc = "fish", .watchid = &watch0,
.eventid = QFILE_MONITOR_EVENT_DELETED },
@ -493,8 +517,9 @@ test_file_monitor_events(void)
g_printerr("Event id=%" PRIx64 " event=%d file=%s\n",
*op->watchid, op->eventid, op->filesrc);
}
if (!qemu_file_monitor_test_expect(
&data, *op->watchid, op->eventid, op->filesrc))
if (!qemu_file_monitor_test_expect(&data, *op->watchid,
op->eventid, op->filesrc,
op->swapnext))
goto cleanup;
break;
case QFILE_MONITOR_TEST_OP_CREATE: