mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-23 06:05:27 +00:00
tests: Support for faking emulator in qemuxml2argv
This patch allows for using custom scripts instead of /usr/bin/qemu emulator in domain XML. To do so, one would specify relative path to the custom script in <emulator/>. The path needs to be relative to qemuxml2argvdata directory and it will be transparently made absolute in runtime. The expected command line needs to contain the exact relative path as was used in domain XML. The problem is RelaxNG schema for domain XML only allows for absolute path within <emulator/>. To workaround it, an extra '/' must be added at the beginning of the path. That is, instead of "./qemu.sh" or "../emulator/qemu.sh" one would use "/./qemu.sh" or "/../emulator/qemu.sh". The extra slash is removed before further processing. I don't like this workaround, it's very ugly but it's the best option I was able to come up with. Relaxing domain XML schema is not an option IMO.
This commit is contained in:
parent
a7283d849c
commit
9237e9558a
@ -41,6 +41,7 @@ static int testCompareXMLToArgvFiles(const char *xml,
|
||||
virDomainChrDef monitor_chr;
|
||||
virConnectPtr conn;
|
||||
char *log = NULL;
|
||||
char *emulator = NULL;
|
||||
|
||||
if (!(conn = virGetConnect()))
|
||||
goto fail;
|
||||
@ -52,6 +53,26 @@ static int testCompareXMLToArgvFiles(const char *xml,
|
||||
VIR_DOMAIN_XML_INACTIVE)))
|
||||
goto fail;
|
||||
|
||||
/*
|
||||
* For test purposes, we may want to fake emulator's output by providing
|
||||
* our own script instead of a real emulator. For this to work we need to
|
||||
* specify a relative path in <emulator/> element, which, however, is not
|
||||
* allowed by RelaxNG schema for domain XML. To work around it we add an
|
||||
* extra '/' at the beginning of relative emulator path so that it looks
|
||||
* like, e.g., "/./qemu.sh" or "/../emulator/qemu.sh" instead of
|
||||
* "./qemu.sh" or "../emulator/qemu.sh" respectively. The following code
|
||||
* detects such paths, strips the extra '/' and makes the path absolute.
|
||||
*/
|
||||
if (vmdef->emulator && STRPREFIX(vmdef->emulator, "/.")) {
|
||||
if (!(emulator = strdup(vmdef->emulator + 1)))
|
||||
goto fail;
|
||||
free(vmdef->emulator);
|
||||
vmdef->emulator = NULL;
|
||||
if (virAsprintf(&vmdef->emulator, "%s/qemuxml2argvdata/%s",
|
||||
abs_srcdir, emulator) < 0)
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (extraFlags & QEMUD_CMD_FLAG_DOMID)
|
||||
vmdef->id = 6;
|
||||
else
|
||||
@ -104,6 +125,12 @@ static int testCompareXMLToArgvFiles(const char *xml,
|
||||
virResetLastError();
|
||||
}
|
||||
|
||||
if (emulator && *argv) {
|
||||
free(*(char**) argv);
|
||||
*argv = emulator;
|
||||
emulator = NULL;
|
||||
}
|
||||
|
||||
len = 1; /* for trailing newline */
|
||||
tmp = qenv;
|
||||
while (*tmp) {
|
||||
@ -144,6 +171,7 @@ static int testCompareXMLToArgvFiles(const char *xml,
|
||||
|
||||
fail:
|
||||
free(log);
|
||||
free(emulator);
|
||||
free(actualargv);
|
||||
if (argv) {
|
||||
tmp = argv;
|
||||
|
Loading…
Reference in New Issue
Block a user