Make QEMU test suite independant of host OS capabilities

This commit is contained in:
Daniel P. Berrange 2008-05-16 16:51:30 +00:00
parent a770c2ab1c
commit 40a82f3066
8 changed files with 109 additions and 17 deletions

View File

@ -1,3 +1,15 @@
Fri May 16 12:50:08 EST 2008 Daniel P. Berrange <berrange@redhat.com>
Make QEMU test cases independant of QEMU capabilities on
the host OS.
* src/qemu_conf.c, src/qemu_driver.c: Move stat() check on
qemu binary out of qemudBuildCommandLine() and into caller.
* tests/Makefile.am: Add testutilsqemu.{c,h} to qemu tests
* tests/qemuxml2argvtest.c, tests/qemuxml2xmltest.c: use
stable capability set in tests, independant of host OS.
* tests/testutilsqemu.c, tests/testutilsqemu.h: Define a
stable capability set for test suites
Fri May 16 11:29:30 CEST 2008 Jim Meyering <meyering@redhat.com>
* src/xml.c: Include "c-ctype.h".

View File

@ -2326,7 +2326,6 @@ int qemudBuildCommandLine(virConnectPtr conn,
char memory[50];
char vcpus[50];
char boot[QEMUD_MAX_BOOT_DEVS+1];
struct stat sb;
struct qemud_vm_disk_def *disk = vm->def->disks;
struct qemud_vm_net_def *net = vm->def->nets;
struct qemud_vm_input_def *input = vm->def->inputs;
@ -2336,18 +2335,6 @@ int qemudBuildCommandLine(virConnectPtr conn,
struct utsname ut;
int disableKQEMU = 0;
/* Make sure the binary we are about to try exec'ing exists.
* Technically we could catch the exec() failure, but that's
* in a sub-process so its hard to feed back a useful error
*/
if (stat(vm->def->os.binary, &sb) < 0) {
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
_("Cannot find QEMU binary %s: %s"),
vm->def->os.binary,
strerror(errno));
return -1;
}
if (vm->qemuVersion == 0) {
if (qemudExtractVersionInfo(vm->def->os.binary,
&(vm->qemuVersion),

View File

@ -646,6 +646,7 @@ static int qemudStartVMDaemon(virConnectPtr conn,
char **argv = NULL, **tmp;
int i, ret;
char logfile[PATH_MAX];
struct stat sb;
if (qemudIsActiveVM(vm)) {
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
@ -702,6 +703,19 @@ static int qemudStartVMDaemon(virConnectPtr conn,
return -1;
}
/* Make sure the binary we are about to try exec'ing exists.
* Technically we could catch the exec() failure, but that's
* in a sub-process so its hard to feed back a useful error
*/
if (stat(vm->def->os.binary, &sb) < 0) {
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
_("Cannot find QEMU binary %s: %s"),
vm->def->os.binary,
strerror(errno));
return -1;
}
if (qemudBuildCommandLine(conn, driver, vm, &argv) < 0) {
close(vm->logfile);
vm->logfile = -1;

View File

@ -100,12 +100,12 @@ xmconfigtest_SOURCES = \
xmconfigtest_LDADD = $(LDADDS)
qemuxml2argvtest_SOURCES = \
qemuxml2argvtest.c \
qemuxml2argvtest.c testutilsqemu.c testutilsqemu.h \
testutils.c testutils.h
qemuxml2argvtest_LDADD = $(LDADDS)
qemuxml2xmltest_SOURCES = \
qemuxml2xmltest.c \
qemuxml2xmltest.c testutilsqemu.c testutilsqemu.h \
testutils.c testutils.h
qemuxml2xmltest_LDADD = $(LDADDS)

View File

@ -14,6 +14,8 @@
#include "testutils.h"
#include "qemu_conf.h"
#include "testutilsqemu.h"
static char *progname;
static char *abs_srcdir;
static struct qemud_driver driver;
@ -130,7 +132,7 @@ main(int argc, char **argv)
if (!abs_srcdir)
abs_srcdir = getcwd(cwd, sizeof(cwd));
driver.caps = qemudCapsInit();
driver.caps = testQemuCapsInit();
#define DO_TEST(name, extraFlags) \
do { \

View File

@ -13,6 +13,7 @@
#include "internal.h"
#include "testutils.h"
#include "qemu_conf.h"
#include "testutilsqemu.h"
static char *progname;
static char *abs_srcdir;
@ -86,7 +87,7 @@ main(int argc, char **argv)
if (!abs_srcdir)
abs_srcdir = getcwd(cwd, sizeof(cwd));
driver.caps = qemudCapsInit();
driver.caps = testQemuCapsInit();
#define DO_TEST(name) \
if (virtTestRun("QEMU XML-2-XML " name, \

71
tests/testutilsqemu.c Normal file
View File

@ -0,0 +1,71 @@
#include <sys/utsname.h>
#include <stdlib.h>
#include "testutilsqemu.h"
virCapsPtr testQemuCapsInit(void) {
struct utsname utsname;
virCapsPtr caps;
virCapsGuestPtr guest;
static const char *const x86_machines[] = {
"pc", "isapc"
};
static const char *const xen_machines[] = {
"xenner"
};
uname (&utsname);
if ((caps = virCapabilitiesNew(utsname.machine,
0, 0)) == NULL)
return NULL;
if ((guest = virCapabilitiesAddGuest(caps, "hvm", "i686", 32,
"/usr/bin/qemu", NULL,
2, x86_machines)) == NULL)
goto cleanup;
if (virCapabilitiesAddGuestDomain(guest,
"qemu",
NULL,
NULL,
0,
NULL) == NULL)
goto cleanup;
if ((guest = virCapabilitiesAddGuest(caps, "hvm", "x86_64", 64,
"/usr/bin/qemu-system-x86_64", NULL,
2, x86_machines)) == NULL)
goto cleanup;
if (virCapabilitiesAddGuestDomain(guest,
"qemu",
NULL,
NULL,
0,
NULL) == NULL)
goto cleanup;
if (virCapabilitiesAddGuestDomain(guest,
"kvm",
"/usr/bin/kvm",
NULL,
0,
NULL) == NULL)
goto cleanup;
if ((guest = virCapabilitiesAddGuest(caps, "xen", "x86_64", 64,
"/usr/bin/xenner", NULL,
1, xen_machines)) == NULL)
goto cleanup;
if (virCapabilitiesAddGuestDomain(guest,
"kvm",
"/usr/bin/kvm",
NULL,
0,
NULL) == NULL)
goto cleanup;
return caps;
cleanup:
virCapabilitiesFree(caps);
return NULL;
}

5
tests/testutilsqemu.h Normal file
View File

@ -0,0 +1,5 @@
#include "capabilities.h"
virCapsPtr testQemuCapsInit(void);