mirror of
https://gitlab.com/qemu-project/qemu
synced 2024-09-06 09:55:55 +00:00
tests: make filemonitor test more robust to event ordering
The ordering of events that are emitted during the rmdir test have changed with kernel >= 5.3. Semantically both new & old orderings are correct, so we must be able to cope with either. To cope with this, when we see an unexpected event, we push it back onto the queue and look and the subsequent event to see if that matches instead. Tested-by: Peter Xu <peterx@redhat.com> Tested-by: Wei Yang <richardw.yang@linux.intel.com> Tested-by: Cornelia Huck <cohuck@redhat.com> Reviewed-by: Thomas Huth <thuth@redhat.com> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
parent
89ea03a7dc
commit
bf9e0313c2
|
@ -45,6 +45,11 @@ typedef struct {
|
||||||
const char *filedst;
|
const char *filedst;
|
||||||
int64_t *watchid;
|
int64_t *watchid;
|
||||||
int eventid;
|
int eventid;
|
||||||
|
/*
|
||||||
|
* Only valid with OP_EVENT - this event might be
|
||||||
|
* swapped with the next OP_EVENT
|
||||||
|
*/
|
||||||
|
bool swapnext;
|
||||||
} QFileMonitorTestOp;
|
} QFileMonitorTestOp;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
@ -98,6 +103,10 @@ qemu_file_monitor_test_handler(int64_t id,
|
||||||
QFileMonitorTestData *data = opaque;
|
QFileMonitorTestData *data = opaque;
|
||||||
QFileMonitorTestRecord *rec = g_new0(QFileMonitorTestRecord, 1);
|
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->id = id;
|
||||||
rec->event = event;
|
rec->event = event;
|
||||||
rec->filename = g_strdup(filename);
|
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.
|
* to wait for the event to be queued for us.
|
||||||
*/
|
*/
|
||||||
static QFileMonitorTestRecord *
|
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();
|
GTimer *timer = g_timer_new();
|
||||||
QFileMonitorTestRecord *record = NULL;
|
QFileMonitorTestRecord *record = NULL;
|
||||||
|
@ -139,9 +149,15 @@ qemu_file_monitor_test_next_record(QFileMonitorTestData *data)
|
||||||
}
|
}
|
||||||
if (data->records) {
|
if (data->records) {
|
||||||
record = data->records->data;
|
record = data->records->data;
|
||||||
tmp = data->records;
|
if (pushback) {
|
||||||
data->records = g_list_remove_link(data->records, tmp);
|
data->records->data = pushback;
|
||||||
g_list_free(tmp);
|
} 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);
|
qemu_mutex_unlock(&data->lock);
|
||||||
|
|
||||||
|
@ -158,13 +174,15 @@ static bool
|
||||||
qemu_file_monitor_test_expect(QFileMonitorTestData *data,
|
qemu_file_monitor_test_expect(QFileMonitorTestData *data,
|
||||||
int64_t id,
|
int64_t id,
|
||||||
QFileMonitorEvent event,
|
QFileMonitorEvent event,
|
||||||
const char *filename)
|
const char *filename,
|
||||||
|
bool swapnext)
|
||||||
{
|
{
|
||||||
QFileMonitorTestRecord *rec;
|
QFileMonitorTestRecord *rec;
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
|
|
||||||
rec = qemu_file_monitor_test_next_record(data);
|
rec = qemu_file_monitor_test_next_record(data, NULL);
|
||||||
|
|
||||||
|
retry:
|
||||||
if (!rec) {
|
if (!rec) {
|
||||||
g_printerr("Missing event watch id %" PRIx64 " event %d file %s\n",
|
g_printerr("Missing event watch id %" PRIx64 " event %d file %s\n",
|
||||||
id, event, filename);
|
id, event, filename);
|
||||||
|
@ -172,6 +190,11 @@ qemu_file_monitor_test_expect(QFileMonitorTestData *data,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (id != rec->id) {
|
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",
|
g_printerr("Expected watch id %" PRIx64 " but got %" PRIx64 "\n",
|
||||||
id, rec->id);
|
id, rec->id);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
@ -347,7 +370,8 @@ test_file_monitor_events(void)
|
||||||
.filesrc = "fish", },
|
.filesrc = "fish", },
|
||||||
{ .type = QFILE_MONITOR_TEST_OP_EVENT,
|
{ .type = QFILE_MONITOR_TEST_OP_EVENT,
|
||||||
.filesrc = "", .watchid = &watch4,
|
.filesrc = "", .watchid = &watch4,
|
||||||
.eventid = QFILE_MONITOR_EVENT_IGNORED },
|
.eventid = QFILE_MONITOR_EVENT_IGNORED,
|
||||||
|
.swapnext = true },
|
||||||
{ .type = QFILE_MONITOR_TEST_OP_EVENT,
|
{ .type = QFILE_MONITOR_TEST_OP_EVENT,
|
||||||
.filesrc = "fish", .watchid = &watch0,
|
.filesrc = "fish", .watchid = &watch0,
|
||||||
.eventid = QFILE_MONITOR_EVENT_DELETED },
|
.eventid = QFILE_MONITOR_EVENT_DELETED },
|
||||||
|
@ -493,8 +517,9 @@ test_file_monitor_events(void)
|
||||||
g_printerr("Event id=%" PRIx64 " event=%d file=%s\n",
|
g_printerr("Event id=%" PRIx64 " event=%d file=%s\n",
|
||||||
*op->watchid, op->eventid, op->filesrc);
|
*op->watchid, op->eventid, op->filesrc);
|
||||||
}
|
}
|
||||||
if (!qemu_file_monitor_test_expect(
|
if (!qemu_file_monitor_test_expect(&data, *op->watchid,
|
||||||
&data, *op->watchid, op->eventid, op->filesrc))
|
op->eventid, op->filesrc,
|
||||||
|
op->swapnext))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
break;
|
break;
|
||||||
case QFILE_MONITOR_TEST_OP_CREATE:
|
case QFILE_MONITOR_TEST_OP_CREATE:
|
||||||
|
|
Loading…
Reference in a new issue