[PATCH 2/4] tests: Skip Xen-HVM tests for root on dom0

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Several tests fail when run as root on a Xen-dom0-system, since
virInitialize() then succeeds to open /proc/xen/privcmd and returns the
actual supported features instead of the faked one when calling
xenHypervisorMakeCapabilitiesInternal(). Since Xen-4.1 supports
additional features like "hap" and "viridian", the xencapstest fails.

For now disable those 4 tests and return EXIT_AM_SKIP for them.

A better fix would probably just check for the minimum required features
instead of comparing the two XML documents for bit-equivalence.

mergeTestRun() is implemented locally instead of globally in
testutils.c, since the merge strategy for compound tests heavily depends
on the specific test cases being merged.

Signed-off-by: Philipp Hahn <hahn@xxxxxxxxxxxxx>
---
 tests/xencapstest.c |   95 +++++++++++++++++++++++++++++++++++----------------
 1 files changed, 65 insertions(+), 30 deletions(-)

diff --git a/tests/xencapstest.c b/tests/xencapstest.c
index 9c1eba4..0bc830d 100644
--- a/tests/xencapstest.c
+++ b/tests/xencapstest.c
@@ -2,6 +2,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <stdbool.h>
 #include <string.h>
 #include <unistd.h>
 
@@ -11,6 +12,31 @@
 #include "xen/xen_hypervisor.h"
 #include "virfile.h"
 
+/* When building as root in a Xen-4.1-dom0, the Hypervisor is accessible and
+ * reports additional features (hap, viridian), which breaks all HVM tests,
+ * since the XML-documents are compared for bit-equivalence. */
+static bool
+skip_if_root(void)
+{
+  if (getuid())
+    return false;
+  if (getenv("FAKEROOTKEY"))
+    return false;
+  return true;
+}
+
+static int
+mergeTestRun(int ret, int tr)
+{
+  switch (tr) {
+    default:
+      return -1;
+    case 0:
+    case EXIT_AM_SKIP:
+      return ret;
+  }
+}
+
 static int
 testCompareFiles(const char *hostmachine, const char *xml_rel,
                  const char *cpuinfo_rel, const char *capabilities_rel)
@@ -81,6 +107,8 @@ static int testXeni686PAE(const void *data ATTRIBUTE_UNUSED) {
 }
 
 static int testXeni686PAEHVM(const void *data ATTRIBUTE_UNUSED) {
+  if (skip_if_root())
+    return EXIT_AM_SKIP;
   return testCompareFiles("i686",
                           "xencapsdata/xen-i686-pae-hvm.xml",
                           "xencapsdata/xen-i686-pae-hvm.cpuinfo",
@@ -105,6 +133,8 @@ static int testXenx86_64(const void *data ATTRIBUTE_UNUSED) {
                           "xencapsdata/xen-x86_64.caps");
 }
 static int testXenx86_64HVM(const void *data ATTRIBUTE_UNUSED) {
+  if (skip_if_root())
+    return EXIT_AM_SKIP;
   return testCompareFiles("x86_64",
                           "xencapsdata/xen-x86_64-hvm.xml",
                           "xencapsdata/xen-x86_64-hvm.cpuinfo",
@@ -125,12 +155,16 @@ static int testXenia64BE(const void *data ATTRIBUTE_UNUSED) {
 }
 
 static int testXenia64HVM(const void *data ATTRIBUTE_UNUSED) {
+  if (skip_if_root())
+    return EXIT_AM_SKIP;
   return testCompareFiles("ia64",
                           "xencapsdata/xen-ia64-hvm.xml",
                           "xencapsdata/xen-ia64-hvm.cpuinfo",
                           "xencapsdata/xen-ia64-hvm.caps");
 }
 static int testXenia64BEHVM(const void *data ATTRIBUTE_UNUSED) {
+  if (skip_if_root())
+    return EXIT_AM_SKIP;
   return testCompareFiles("ia64",
                           "xencapsdata/xen-ia64-be-hvm.xml",
                           "xencapsdata/xen-ia64-be-hvm.cpuinfo",
@@ -148,17 +182,18 @@ static int testXenppc64(const void *data ATTRIBUTE_UNUSED) {
 static int
 mymain(void)
 {
+    int tr;
     int ret = 0;
 
     virInitialize();
 
-    if (virtTestRun("Capabilities for i686, no PAE, no HVM",
-                    1, testXeni686, NULL) != 0)
-        ret = -1;
+    tr = virtTestRun("Capabilities for i686, no PAE, no HVM",
+                     1, testXeni686, NULL);
+    ret = mergeTestRun(ret, tr);
 
-    if (virtTestRun("Capabilities for i686, PAE, no HVM",
-                    1, testXeni686PAE, NULL) != 0)
-        ret = -1;
+    tr = virtTestRun("Capabilities for i686, PAE, no HVM",
+                     1, testXeni686PAE, NULL);
+    ret = mergeTestRun(ret, tr);
 
     /* No PAE + HVM is non-sensical - all VMX capable
        CPUs have PAE */
@@ -167,37 +202,37 @@ mymain(void)
         ret = -1;
     */
 
-    if (virtTestRun("Capabilities for i686, PAE, HVM",
-                    1, testXeni686PAEHVM, NULL) != 0)
-        ret = -1;
+    tr = virtTestRun("Capabilities for i686, PAE, HVM",
+                     1, testXeni686PAEHVM, NULL);
+    ret = mergeTestRun(ret, tr);
 
-    if (virtTestRun("Capabilities for x86_64, no HVM",
-                    1, testXenx86_64, NULL) != 0)
-        ret = -1;
+    tr = virtTestRun("Capabilities for x86_64, no HVM",
+                     1, testXenx86_64, NULL);
+    ret = mergeTestRun(ret, tr);
 
-    if (virtTestRun("Capabilities for x86_64, HVM",
-                    1, testXenx86_64HVM, NULL) != 0)
-        ret = -1;
+    tr = virtTestRun("Capabilities for x86_64, HVM",
+                     1, testXenx86_64HVM, NULL);
+    ret = mergeTestRun(ret, tr);
 
-    if (virtTestRun("Capabilities for ia64, no HVM, LE",
-                    1, testXenia64, NULL) != 0)
-        ret = -1;
+    tr = virtTestRun("Capabilities for ia64, no HVM, LE",
+                     1, testXenia64, NULL);
+    ret = mergeTestRun(ret, tr);
 
-    if (virtTestRun("Capabilities for ia64, HVM, LE",
-                    1, testXenia64HVM, NULL) != 0)
-        ret = -1;
+    tr = virtTestRun("Capabilities for ia64, HVM, LE",
+                     1, testXenia64HVM, NULL);
+    ret = mergeTestRun(ret, tr);
 
-    if (virtTestRun("Capabilities for ia64, no HVM, BE",
-                    1, testXenia64BE, NULL) != 0)
-        ret = -1;
+    tr = virtTestRun("Capabilities for ia64, no HVM, BE",
+                     1, testXenia64BE, NULL);
+    ret = mergeTestRun(ret, tr);
 
-    if (virtTestRun("Capabilities for ia64, HVM, BE",
-                    1, testXenia64BEHVM, NULL) != 0)
-        ret = -1;
+    tr = virtTestRun("Capabilities for ia64, HVM, BE",
+                     1, testXenia64BEHVM, NULL);
+    ret = mergeTestRun(ret, tr);
 
-    if (virtTestRun("Capabilities for ppc64",
-                    1, testXenppc64, NULL) != 0)
-        ret = -1;
+    tr = virtTestRun("Capabilities for ppc64",
+                     1, testXenppc64, NULL);
+    ret = mergeTestRun(ret, tr);
 
 
     return(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);
-- 
1.7.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]