mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-07 09:19:19 +00:00
tests: qemumonitorjsontest: Do some actual testing in qemuMonitorJSONTestAttachChardev
Until now the test was rather useless since it didn't check the arguments formatted and didn't use properly configured chardev objects. Add the expected arguments and instrument the test to validate them. Modify some test cases to actually add valid data. Note that the UDP test data is currently wrong due to a bug.
This commit is contained in:
parent
4c75ba7f37
commit
3da5008125
@ -747,6 +747,7 @@ static int
|
|||||||
qemuMonitorJSONTestAttachOneChardev(virDomainXMLOptionPtr xmlopt,
|
qemuMonitorJSONTestAttachOneChardev(virDomainXMLOptionPtr xmlopt,
|
||||||
const char *label,
|
const char *label,
|
||||||
virDomainChrSourceDefPtr chr,
|
virDomainChrSourceDefPtr chr,
|
||||||
|
const char *expectargs,
|
||||||
const char *reply,
|
const char *reply,
|
||||||
const char *expectPty,
|
const char *expectPty,
|
||||||
bool fail)
|
bool fail)
|
||||||
@ -772,7 +773,8 @@ qemuMonitorJSONTestAttachOneChardev(virDomainXMLOptionPtr xmlopt,
|
|||||||
if (!(data.test = qemuMonitorTestNewSimple(true, xmlopt)))
|
if (!(data.test = qemuMonitorTestNewSimple(true, xmlopt)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (qemuMonitorTestAddItem(data.test, "chardev-add", jsonreply) < 0)
|
if (qemuMonitorTestAddItemExpect(data.test, "chardev-add",
|
||||||
|
expectargs, true, jsonreply) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virTestRun(fulllabel, &testQemuMonitorJSONAttachChardev, &data) < 0)
|
if (virTestRun(fulllabel, &testQemuMonitorJSONAttachChardev, &data) < 0)
|
||||||
@ -793,49 +795,90 @@ qemuMonitorJSONTestAttachChardev(virDomainXMLOptionPtr xmlopt)
|
|||||||
virDomainChrSourceDef chr;
|
virDomainChrSourceDef chr;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
#define CHECK(label, fail) \
|
#define CHECK(label, fail, expectargs) \
|
||||||
if (qemuMonitorJSONTestAttachOneChardev(xmlopt, label, &chr, NULL, NULL, \
|
if (qemuMonitorJSONTestAttachOneChardev(xmlopt, label, &chr, expectargs, \
|
||||||
fail) < 0) \
|
NULL, NULL, fail) < 0) \
|
||||||
ret = -1
|
ret = -1
|
||||||
|
|
||||||
chr = (virDomainChrSourceDef) { .type = VIR_DOMAIN_CHR_TYPE_NULL };
|
chr = (virDomainChrSourceDef) { .type = VIR_DOMAIN_CHR_TYPE_NULL };
|
||||||
CHECK("null", false);
|
CHECK("null", false,
|
||||||
|
"{'id':'alias','backend':{'type':'null','data':{}}}");
|
||||||
|
|
||||||
chr = (virDomainChrSourceDef) { .type = VIR_DOMAIN_CHR_TYPE_VC };
|
chr = (virDomainChrSourceDef) { .type = VIR_DOMAIN_CHR_TYPE_VC };
|
||||||
CHECK("vc", false);
|
CHECK("vc", false,
|
||||||
|
"{'id':'alias','backend':{'type':'null','data':{}}}");
|
||||||
|
|
||||||
chr = (virDomainChrSourceDef) { .type = VIR_DOMAIN_CHR_TYPE_PTY };
|
chr = (virDomainChrSourceDef) { .type = VIR_DOMAIN_CHR_TYPE_PTY };
|
||||||
if (qemuMonitorJSONTestAttachOneChardev(xmlopt, "pty", &chr,
|
if (qemuMonitorJSONTestAttachOneChardev(xmlopt, "pty", &chr,
|
||||||
|
"{'id':'alias',"
|
||||||
|
"'backend':{'type':'pty',"
|
||||||
|
"'data':{}}}",
|
||||||
"\"pty\" : \"/dev/pts/0\"",
|
"\"pty\" : \"/dev/pts/0\"",
|
||||||
"/dev/pts/0", false) < 0)
|
"/dev/pts/0", false) < 0)
|
||||||
ret = -1;
|
ret = -1;
|
||||||
|
|
||||||
chr = (virDomainChrSourceDef) { .type = VIR_DOMAIN_CHR_TYPE_PTY };
|
chr = (virDomainChrSourceDef) { .type = VIR_DOMAIN_CHR_TYPE_PTY };
|
||||||
CHECK("pty missing path", true);
|
CHECK("pty missing path", true,
|
||||||
|
"{'id':'alias','backend':{'type':'pty','data':{}}}");
|
||||||
|
|
||||||
chr = (virDomainChrSourceDef) { .type = VIR_DOMAIN_CHR_TYPE_FILE };
|
memset(&chr, 0, sizeof(chr));
|
||||||
CHECK("file", false);
|
chr.type = VIR_DOMAIN_CHR_TYPE_FILE;
|
||||||
|
chr.data.file.path = (char *) "/test/path";
|
||||||
|
CHECK("file", false,
|
||||||
|
"{'id':'alias','backend':{'type':'file','data':{'out':'/test/path'}}}");
|
||||||
|
|
||||||
chr = (virDomainChrSourceDef) { .type = VIR_DOMAIN_CHR_TYPE_DEV };
|
memset(&chr, 0, sizeof(chr));
|
||||||
CHECK("device", false);
|
chr.type = VIR_DOMAIN_CHR_TYPE_DEV;
|
||||||
|
chr.data.file.path = (char *) "/test/path";
|
||||||
|
CHECK("device", false,
|
||||||
|
"{'id':'alias','backend':{'type':'serial','data':{'device':'/test/path'}}}");
|
||||||
|
|
||||||
chr = (virDomainChrSourceDef) { .type = VIR_DOMAIN_CHR_TYPE_TCP };
|
memset(&chr, 0, sizeof(chr));
|
||||||
CHECK("tcp", false);
|
chr.type = VIR_DOMAIN_CHR_TYPE_TCP;
|
||||||
|
chr.data.tcp.host = (char *) "example.com";
|
||||||
|
chr.data.tcp.service = (char *) "1234";
|
||||||
|
CHECK("tcp", false,
|
||||||
|
"{'id':'alias',"
|
||||||
|
"'backend':{'type':'socket',"
|
||||||
|
"'data':{'addr':{'type':'inet',"
|
||||||
|
"'data':{'host':'example.com',"
|
||||||
|
"'port':'1234'}},"
|
||||||
|
"'wait':false,"
|
||||||
|
"'telnet':false,"
|
||||||
|
"'server':false}}}");
|
||||||
|
|
||||||
chr = (virDomainChrSourceDef) { .type = VIR_DOMAIN_CHR_TYPE_UDP };
|
memset(&chr, 0, sizeof(chr));
|
||||||
CHECK("udp", false);
|
chr.type = VIR_DOMAIN_CHR_TYPE_UDP;
|
||||||
|
chr.data.udp.connectHost = (char *) "example.com";
|
||||||
|
chr.data.udp.connectService = (char *) "1234";
|
||||||
|
CHECK("udp", false,
|
||||||
|
"{'id':'alias',"
|
||||||
|
"'backend':{'type':'socket',"
|
||||||
|
"'data':{'addr':{'type':'inet',"
|
||||||
|
"'data':{'host':'example.com',"
|
||||||
|
"'port':'1234'}}}}}");
|
||||||
|
|
||||||
chr = (virDomainChrSourceDef) { .type = VIR_DOMAIN_CHR_TYPE_UNIX };
|
memset(&chr, 0, sizeof(chr));
|
||||||
CHECK("unix", false);
|
chr.type = VIR_DOMAIN_CHR_TYPE_UNIX;
|
||||||
|
chr.data.nix.path = (char *) "/path/to/socket";
|
||||||
|
CHECK("unix", false,
|
||||||
|
"{'id':'alias',"
|
||||||
|
"'backend':{'type':'socket',"
|
||||||
|
"'data':{'addr':{'type':'unix',"
|
||||||
|
"'data':{'path':'/path/to/socket'}},"
|
||||||
|
"'wait':false,"
|
||||||
|
"'server':false}}}");
|
||||||
|
|
||||||
chr = (virDomainChrSourceDef) { .type = VIR_DOMAIN_CHR_TYPE_SPICEVMC };
|
chr = (virDomainChrSourceDef) { .type = VIR_DOMAIN_CHR_TYPE_SPICEVMC };
|
||||||
CHECK("spicevmc", false);
|
CHECK("spicevmc", false,
|
||||||
|
"{'id':'alias','backend':{'type':'spicevmc','"
|
||||||
|
"data':{'type':'vdagent'}}}");
|
||||||
|
|
||||||
chr = (virDomainChrSourceDef) { .type = VIR_DOMAIN_CHR_TYPE_PIPE };
|
chr = (virDomainChrSourceDef) { .type = VIR_DOMAIN_CHR_TYPE_PIPE };
|
||||||
CHECK("pipe", true);
|
CHECK("pipe", true, "");
|
||||||
|
|
||||||
chr = (virDomainChrSourceDef) { .type = VIR_DOMAIN_CHR_TYPE_STDIO };
|
chr = (virDomainChrSourceDef) { .type = VIR_DOMAIN_CHR_TYPE_STDIO };
|
||||||
CHECK("stdio", true);
|
CHECK("stdio", true, "");
|
||||||
#undef CHECK
|
#undef CHECK
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
Loading…
Reference in New Issue
Block a user