mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 05:35:25 +00:00
qemumonitortestutils: Enforce consumption of all items in test monitor
To prevent unexpected situations where a change in code would stop looking at some of the tested commands go unnoticed add a mechanism to force consumption of all test items. Since there are a few tests which would be hard to fix add also a mechanism to opt-out of the check. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
0274e1b452
commit
4e7f8ba0f3
@ -482,6 +482,8 @@ cpuTestMakeQEMUCaps(const struct data *data)
|
||||
if (!(testMon = qemuMonitorTestNewFromFile(json, driver.xmlopt, true)))
|
||||
goto error;
|
||||
|
||||
qemuMonitorTestAllowUnusedCommands(testMon);
|
||||
|
||||
cpu = virCPUDefNew();
|
||||
|
||||
cpu->model = g_strdup("host");
|
||||
|
@ -453,6 +453,8 @@ testQemuHotplugCpuPrepare(const char *test,
|
||||
&driver, data->vm, qmpschema)))
|
||||
goto error;
|
||||
|
||||
qemuMonitorTestAllowUnusedCommands(data->mon);
|
||||
|
||||
priv->mon = qemuMonitorTestGetMonitor(data->mon);
|
||||
virObjectUnlock(priv->mon);
|
||||
|
||||
|
@ -796,6 +796,8 @@ qemuMonitorJSONTestAttachOneChardev(virDomainXMLOptionPtr xmlopt,
|
||||
if (!(data.test = qemuMonitorTestNewSchema(xmlopt, schema)))
|
||||
goto cleanup;
|
||||
|
||||
qemuMonitorTestAllowUnusedCommands(data.test);
|
||||
|
||||
if (qemuMonitorTestAddItemExpect(data.test, "chardev-add",
|
||||
expectargs, true, jsonreply) < 0)
|
||||
goto cleanup;
|
||||
|
@ -57,6 +57,8 @@ struct _qemuMonitorTest {
|
||||
bool running;
|
||||
bool started;
|
||||
|
||||
bool allowUnusedCommands;
|
||||
|
||||
char *incoming;
|
||||
size_t incomingLength;
|
||||
size_t incomingCapacity;
|
||||
@ -421,8 +423,15 @@ qemuMonitorTestFree(qemuMonitorTestPtr test)
|
||||
VIR_FREE(test->incoming);
|
||||
VIR_FREE(test->outgoing);
|
||||
|
||||
for (i = 0; i < test->nitems; i++)
|
||||
for (i = 0; i < test->nitems; i++) {
|
||||
if (!test->allowUnusedCommands) {
|
||||
g_fprintf(stderr,
|
||||
"\nunused test monitor item '%s'",
|
||||
NULLSTR(test->items[i]->identifier));
|
||||
}
|
||||
|
||||
qemuMonitorTestItemFree(test->items[i]);
|
||||
}
|
||||
VIR_FREE(test->items);
|
||||
|
||||
if (test->tmpdir && rmdir(test->tmpdir) < 0)
|
||||
@ -430,6 +439,11 @@ qemuMonitorTestFree(qemuMonitorTestPtr test)
|
||||
|
||||
VIR_FREE(test->tmpdir);
|
||||
|
||||
if (!test->allowUnusedCommands &&
|
||||
test->nitems != 0) {
|
||||
qemuMonitorTestError("unused test monitor items are not allowed for this test\n");
|
||||
}
|
||||
|
||||
virMutexDestroy(&test->lock);
|
||||
VIR_FREE(test);
|
||||
}
|
||||
@ -1288,6 +1302,21 @@ qemuMonitorTestNewFromFile(const char *fileName,
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* qemuMonitorTestAllowUnusedCommands:
|
||||
* @test: test monitor object
|
||||
*
|
||||
* By default all test items/commands must be used by the test. This function
|
||||
* allows to override the requirement for individual tests e.g. if it's necessary
|
||||
* to test some negative scenarios which would not use all commands.
|
||||
*/
|
||||
void
|
||||
qemuMonitorTestAllowUnusedCommands(qemuMonitorTestPtr test)
|
||||
{
|
||||
test->allowUnusedCommands = true;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
qemuMonitorTestFullAddItem(qemuMonitorTestPtr test,
|
||||
const char *filename,
|
||||
|
@ -50,6 +50,8 @@ void *qemuMonitorTestItemGetPrivateData(qemuMonitorTestItemPtr item);
|
||||
|
||||
int qemuMonitorTestAddErrorResponse(qemuMonitorTestPtr test, const char *errmsg, ...);
|
||||
|
||||
void qemuMonitorTestAllowUnusedCommands(qemuMonitorTestPtr test);
|
||||
|
||||
int qemuMonitorTestAddItem(qemuMonitorTestPtr test,
|
||||
const char *command_name,
|
||||
const char *response);
|
||||
|
Loading…
Reference in New Issue
Block a user