diff --git a/ChangeLog b/ChangeLog
index bd2d4cf116..dfdaf6ff7d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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".
diff --git a/src/qemu_conf.c b/src/qemu_conf.c
index ff7c63e89d..dfe28696b4 100644
--- a/src/qemu_conf.c
+++ b/src/qemu_conf.c
@@ -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),
diff --git a/src/qemu_driver.c b/src/qemu_driver.c
index 1744751fe3..e9808a6163 100644
--- a/src/qemu_driver.c
+++ b/src/qemu_driver.c
@@ -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;
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 5da694702d..c1688e798f 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -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)
 
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index 91af71fcd7..e0e9474604 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -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 {                                                                \
diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c
index eaff097579..7b3df0ea8b 100644
--- a/tests/qemuxml2xmltest.c
+++ b/tests/qemuxml2xmltest.c
@@ -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, \
diff --git a/tests/testutilsqemu.c b/tests/testutilsqemu.c
new file mode 100644
index 0000000000..7c9a970ad8
--- /dev/null
+++ b/tests/testutilsqemu.c
@@ -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;
+}
diff --git a/tests/testutilsqemu.h b/tests/testutilsqemu.h
new file mode 100644
index 0000000000..b147a9d969
--- /dev/null
+++ b/tests/testutilsqemu.h
@@ -0,0 +1,5 @@
+
+#include "capabilities.h"
+
+virCapsPtr testQemuCapsInit(void);
+