All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH V3 0/5] Testing libvirt XML -> libxl_domain_config conversion
@ 2014-09-04  3:07 Jim Fehlig
  2014-09-04  3:07 ` [PATCH V3 1/5] util: Introduce virJSONStringCompare for JSON doc comparisons Jim Fehlig
                   ` (6 more replies)
  0 siblings, 7 replies; 15+ messages in thread
From: Jim Fehlig @ 2014-09-04  3:07 UTC (permalink / raw)
  To: libvir-list; +Cc: xen-devel

This is version 3 of the work started by danpb:

  https://www.redhat.com/archives/libvir-list/2014-May/msg01102.html

This series tests the conversion of libvirt XML to libxl_domain_config
objects by the libvirt libxl driver.

Changed in v3:

 - Change virJSONStringCompare to accept a list of context paths to
   ignore

 - Report error in virJSONStringCompare in libyajl is not available

 - Fix a bug (4/5) exposed by the new tests

 - Add tests for conversion of both PV and HVM config

 - Define json context paths to ignore based on features defined
   in libxl.h

Daniel P. Berrange (4):
  util: Introduce virJSONStringCompare for JSON doc comparisons
  util: Allow port allocator to skip bind() check
  tests: Add more test suite mock helpers
  libxl: Add a test suite for libxl option generator

Jim Fehlig (1):
  libxl: fix mapping of libvirt and libxl lifecycle actions

 configure.ac                           |   2 +
 src/libvirt_private.syms               |   1 +
 src/libxl/libxl_conf.c                 |  62 +++++++-
 src/libxl/libxl_driver.c               |   5 +-
 src/qemu/qemu_driver.c                 |   9 +-
 src/util/virjson.c                     | 242 +++++++++++++++++++++++++++++++
 src/util/virjson.h                     |  16 +++
 src/util/virportallocator.c            |  14 +-
 src/util/virportallocator.h            |   7 +-
 tests/Makefile.am                      |  25 +++-
 tests/libxlxml2jsondata/basic-hvm.json | 217 ++++++++++++++++++++++++++++
 tests/libxlxml2jsondata/basic-hvm.xml  |  36 +++++
 tests/libxlxml2jsondata/basic-pv.json  | 163 +++++++++++++++++++++
 tests/libxlxml2jsondata/basic-pv.xml   |  28 ++++
 tests/libxlxml2jsontest.c              | 251 +++++++++++++++++++++++++++++++++
 tests/virfirewalltest.c                |   4 +-
 tests/virmock.h                        |  54 +++++--
 tests/virmocklibxl.c                   |  87 ++++++++++++
 tests/virportallocatortest.c           |   4 +-
 tests/virsystemdtest.c                 |   4 +-
 20 files changed, 1198 insertions(+), 33 deletions(-)
 create mode 100644 tests/libxlxml2jsondata/basic-hvm.json
 create mode 100644 tests/libxlxml2jsondata/basic-hvm.xml
 create mode 100644 tests/libxlxml2jsondata/basic-pv.json
 create mode 100644 tests/libxlxml2jsondata/basic-pv.xml
 create mode 100644 tests/libxlxml2jsontest.c
 create mode 100644 tests/virmocklibxl.c

-- 
1.8.4.5

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH V3 1/5] util: Introduce virJSONStringCompare for JSON doc comparisons
  2014-09-04  3:07 [PATCH V3 0/5] Testing libvirt XML -> libxl_domain_config conversion Jim Fehlig
@ 2014-09-04  3:07 ` Jim Fehlig
  2014-09-04  3:07 ` [PATCH V3 2/5] util: Allow port allocator to skip bind() check Jim Fehlig
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 15+ messages in thread
From: Jim Fehlig @ 2014-09-04  3:07 UTC (permalink / raw)
  To: libvir-list; +Cc: Jim Fehlig, Daniel P. Berrange, xen-devel

From: "Daniel P. Berrange" <berrange@redhat.com>

Comparing JSON docs using strcmp is simple, but is not flexible
as it is sensitive to whitespace used in the doc generation.
When comparing objects it may also be desirable to treat the
existance of keys in the actual object but not expected object
as non-fatal. Introduce a virJSONStringCompare function which
takes two strings representing expected and actual JSON docs
and then does a DOM comparison.  Comparison is controled with
the ignore_contexts and flags parameters.  No comparison is
done on context paths specified in ignore_contexts.  The
VIR_JSON_COMPARE_IGNORE_EXPECTED_NULL flag can be used to
ignore actual values that have changed from an expected value
of null.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Signed-off-by: Jim Fehlig <jfehlig@suse.com>
---
 src/libvirt_private.syms |   1 +
 src/util/virjson.c       | 242 +++++++++++++++++++++++++++++++++++++++++++++++
 src/util/virjson.h       |  16 ++++
 3 files changed, 259 insertions(+)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index f136d24..5fca691 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1442,6 +1442,7 @@ virISCSIScanTargets;
 
 
 # util/virjson.h
+virJSONStringCompare;
 virJSONValueArrayAppend;
 virJSONValueArrayGet;
 virJSONValueArraySize;
diff --git a/src/util/virjson.c b/src/util/virjson.c
index ec83b2f..73b71f4 100644
--- a/src/util/virjson.c
+++ b/src/util/virjson.c
@@ -47,6 +47,11 @@
 
 VIR_LOG_INIT("util.json");
 
+VIR_ENUM_DECL(virJSONType)
+VIR_ENUM_IMPL(virJSONType, VIR_JSON_TYPE_LAST,
+              "object", "array", "string",
+              "number", "boolean", "null")
+
 typedef struct _virJSONParserState virJSONParserState;
 typedef virJSONParserState *virJSONParserStatePtr;
 struct _virJSONParserState {
@@ -91,6 +96,7 @@ virJSONValueFree(virJSONValuePtr value)
         break;
     case VIR_JSON_TYPE_BOOLEAN:
     case VIR_JSON_TYPE_NULL:
+    case VIR_JSON_TYPE_LAST:
         break;
     }
 
@@ -1107,6 +1113,204 @@ virJSONParserHandleEndArray(void *ctx)
 }
 
 
+static bool
+virJSONValueCompare(virJSONValuePtr expect,
+                    virJSONValuePtr actual,
+                    const char *context,
+                    const char **ignore_contexts,
+                    unsigned int flags)
+{
+    size_t i, j;
+
+    if (expect->type != actual->type) {
+        if (expect->type == VIR_JSON_TYPE_NULL &&
+            (flags & VIR_JSON_COMPARE_IGNORE_EXPECTED_NULL))
+            return true;
+
+        const char *expectType = virJSONTypeTypeToString(expect->type);
+        const char *actualType = virJSONTypeTypeToString(actual->type);
+
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Expected value type '%s' but got value type '%s' at '%s'"),
+                       expectType, actualType, context);
+        return false;
+    }
+
+    switch (expect->type) {
+    case VIR_JSON_TYPE_OBJECT:
+        /* Ensure actual data contains all expected data */
+        for (i = 0; i < expect->data.object.npairs; i++) {
+            bool found = false;
+            char *childcontext;
+
+            if (virAsprintf(&childcontext, "%s%s%s",
+                            context,
+                            STREQ(context, "/") ? "" : "/",
+                            expect->data.object.pairs[i].key) < 0)
+                return false;
+
+            /* Bypass paths we've been asked to ignore */
+            if (ignore_contexts) {
+                bool ignored = false;
+
+                j = 0;
+                while (ignore_contexts[j]) {
+                    if (STREQ(childcontext, ignore_contexts[j])) {
+                        ignored = true;
+                        break;
+                    }
+                    j++;
+                }
+
+                if (ignored)
+                    continue;
+            }
+
+           for (j = 0; j < actual->data.object.npairs; j++) {
+                if (STREQ(expect->data.object.pairs[i].key,
+                          actual->data.object.pairs[j].key)) {
+                    found = true;
+                    break;
+                }
+            }
+
+            if (!found) {
+                virReportError(VIR_ERR_INTERNAL_ERROR,
+                               _("Expected object key '%s' not found in actual object at '%s'"),
+                               expect->data.object.pairs[i].key, context);
+                VIR_FREE(childcontext);
+                return false;
+            }
+
+            if (!virJSONValueCompare(expect->data.object.pairs[i].value,
+                                     actual->data.object.pairs[j].value,
+                                     childcontext,
+                                     ignore_contexts,
+                                     flags)) {
+                VIR_FREE(childcontext);
+                return false;
+            }
+            VIR_FREE(childcontext);
+        }
+
+        /* Ensure expected data contains all actual data */
+        for (i = 0; i < actual->data.object.npairs; i++) {
+            bool found = false;
+            char *childcontext;
+
+            if (virAsprintf(&childcontext, "%s%s%s",
+                            context,
+                            STREQ(context, "/") ? "" : "/",
+                            actual->data.object.pairs[i].key) < 0)
+                return false;
+
+            /* Bypass paths we've been asked to ignore */
+            if (ignore_contexts) {
+                bool ignored = false;
+
+                j = 0;
+                while (ignore_contexts[j]) {
+                    if (STREQ(childcontext, ignore_contexts[j])) {
+                        ignored = true;
+                        break;
+                    }
+                    j++;
+                }
+
+                if (ignored)
+                    continue;
+            }
+
+            for (j = 0; j < expect->data.object.npairs; j++) {
+                if (STREQ(actual->data.object.pairs[i].key,
+                          expect->data.object.pairs[j].key)) {
+                    found = true;
+                    break;
+                }
+            }
+
+            if (!found) {
+                virReportError(VIR_ERR_INTERNAL_ERROR,
+                               _("Actual object key '%s' not found in expected object at '%s'"),
+                               actual->data.object.pairs[i].key, context);
+                VIR_FREE(childcontext);
+                return false;
+            }
+
+            if (!virJSONValueCompare(actual->data.object.pairs[i].value,
+                                     expect->data.object.pairs[j].value,
+                                     childcontext,
+                                     ignore_contexts,
+                                     flags)) {
+                VIR_FREE(childcontext);
+            }
+        }
+        break;
+
+    case VIR_JSON_TYPE_ARRAY:
+        if (expect->data.array.nvalues !=
+            actual->data.array.nvalues) {
+            virReportError(VIR_ERR_INTERNAL_ERROR,
+                           _("Expected array size '%zu' but got size '%zu' at '%s'"),
+                           expect->data.array.nvalues,
+                           actual->data.array.nvalues,
+                           context);
+            return false;
+        }
+
+        for (i = 0; i < expect->data.array.nvalues; i++) {
+            if (!virJSONValueCompare(expect->data.array.values[i],
+                                     actual->data.array.values[i],
+                                     context,
+                                     ignore_contexts,
+                                     flags))
+                return false;
+        }
+        break;
+
+    case VIR_JSON_TYPE_STRING:
+        if (STRNEQ(expect->data.string,
+                   actual->data.string)) {
+            virReportError(VIR_ERR_INTERNAL_ERROR,
+                           _("Expected string value '%s' but got '%s' at '%s'"),
+                           expect->data.string, actual->data.string, context);
+            return false;
+        }
+        break;
+
+    case VIR_JSON_TYPE_NUMBER:
+        if (STRNEQ(expect->data.number,
+                   actual->data.number)) {
+            virReportError(VIR_ERR_INTERNAL_ERROR,
+                           _("Expected number value '%s' but got '%s' at '%s'"),
+                           expect->data.number, actual->data.number, context);
+            return false;
+        }
+        break;
+
+    case VIR_JSON_TYPE_BOOLEAN:
+        if (expect->data.boolean !=
+            actual->data.boolean) {
+            virReportError(VIR_ERR_INTERNAL_ERROR,
+                           _("Expected bool value '%d' but got '%d' at '%s'"),
+                           expect->data.boolean, actual->data.boolean, context);
+            return false;
+        }
+        break;
+
+    case VIR_JSON_TYPE_NULL:
+        /* trivially equal */
+        break;
+
+    case VIR_JSON_TYPE_LAST:
+        /* nothing */
+        break;
+    }
+
+    return true;
+}
+
+
 static const yajl_callbacks parserCallbacks = {
     virJSONParserHandleNull,
     virJSONParserHandleBoolean,
@@ -1306,6 +1510,30 @@ virJSONValueToString(virJSONValuePtr object,
 }
 
 
+bool
+virJSONStringCompare(const char *expect,
+                     const char *actual,
+                     const char **ignore_contexts,
+                     unsigned int flags)
+{
+    virJSONValuePtr expectVal = NULL;
+    virJSONValuePtr actualVal = NULL;
+    int ret = false;
+
+    if (!(expectVal = virJSONValueFromString(expect)))
+        goto cleanup;
+    if (!(actualVal = virJSONValueFromString(actual)))
+        goto cleanup;
+
+    ret = virJSONValueCompare(expectVal, actualVal, "/", ignore_contexts, flags);
+
+ cleanup:
+    virJSONValueFree(expectVal);
+    virJSONValueFree(actualVal);
+    return ret;
+}
+
+
 #else
 virJSONValuePtr
 virJSONValueFromString(const char *jsonstring ATTRIBUTE_UNUSED)
@@ -1324,4 +1552,18 @@ virJSONValueToString(virJSONValuePtr object ATTRIBUTE_UNUSED,
                    _("No JSON parser implementation is available"));
     return NULL;
 }
+
+
+bool
+virJSONStringCompare(const char *expect ATTRIBUTE_UNUSED,
+                     const char *actual ATTRIBUTE_UNUSED,
+                     const char **ignore_contexts ATTRIBUTE_UNUSED,
+                     unsigned int flags)
+{
+    virCheckFlags(VIR_JSON_COMPARE_IGNORE_EXPECTED_NULL, false);
+
+    virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                   _("No JSON parser implementation is available"));
+    return false;
+}
 #endif
diff --git a/src/util/virjson.h b/src/util/virjson.h
index 9487729..5dc948f 100644
--- a/src/util/virjson.h
+++ b/src/util/virjson.h
@@ -34,6 +34,8 @@ typedef enum {
     VIR_JSON_TYPE_NUMBER,
     VIR_JSON_TYPE_BOOLEAN,
     VIR_JSON_TYPE_NULL,
+
+    VIR_JSON_TYPE_LAST,
 } virJSONType;
 
 typedef struct _virJSONValue virJSONValue;
@@ -141,4 +143,18 @@ virJSONValuePtr virJSONValueFromString(const char *jsonstring);
 char *virJSONValueToString(virJSONValuePtr object,
                            bool pretty);
 
+typedef enum {
+    /*
+     * when comparing two values, if their types are different,
+     * and the 'expected' value type is 'null', then this will
+     * be considered non-fatal.
+     */
+    VIR_JSON_COMPARE_IGNORE_EXPECTED_NULL = (1 << 0),
+} virJSONCompareFlags;
+
+bool virJSONStringCompare(const char *expect,
+                          const char *actual,
+                          const char **ignore_contexts,
+                          unsigned int flags);
+
 #endif /* __VIR_JSON_H_ */
-- 
1.8.4.5

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH V3 2/5] util: Allow port allocator to skip bind() check
  2014-09-04  3:07 [PATCH V3 0/5] Testing libvirt XML -> libxl_domain_config conversion Jim Fehlig
  2014-09-04  3:07 ` [PATCH V3 1/5] util: Introduce virJSONStringCompare for JSON doc comparisons Jim Fehlig
@ 2014-09-04  3:07 ` Jim Fehlig
  2014-09-11 10:46   ` Daniel P. Berrange
  2014-09-04  3:07 ` [PATCH V3 3/5] tests: Add more test suite mock helpers Jim Fehlig
                   ` (4 subsequent siblings)
  6 siblings, 1 reply; 15+ messages in thread
From: Jim Fehlig @ 2014-09-04  3:07 UTC (permalink / raw)
  To: libvir-list; +Cc: Jim Fehlig, Daniel P. Berrange, xen-devel

From: "Daniel P. Berrange" <berrange@redhat.com>

Test suites using the port allocator don't want to have different
behaviour depending on whether a port is in use on the host. Add
a VIR_PORT_ALLOCATOR_SKIP_BIND_CHECK which test suites can use
to skip the bind() test. The port allocator will thus only track
ports in use by the test suite process itself. This is fine when
using the port allocator to generate guest configs which won't
actually be launched

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Signed-off-by: Jim Fehlig <jfehlig@suse.com>
---
 src/libxl/libxl_driver.c     |  5 +++--
 src/qemu/qemu_driver.c       |  9 ++++++---
 src/util/virportallocator.c  | 14 ++++++++++----
 src/util/virportallocator.h  |  7 ++++++-
 tests/virportallocatortest.c |  4 ++--
 5 files changed, 27 insertions(+), 12 deletions(-)

diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index 67fd7bc6..17d6257 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -301,14 +301,15 @@ libxlStateInitialize(bool privileged,
     if (!(libxl_driver->reservedVNCPorts =
           virPortAllocatorNew(_("VNC"),
                               LIBXL_VNC_PORT_MIN,
-                              LIBXL_VNC_PORT_MAX)))
+                              LIBXL_VNC_PORT_MAX,
+                              0)))
         goto error;
 
     /* Allocate bitmap for migration port reservation */
     if (!(libxl_driver->migrationPorts =
           virPortAllocatorNew(_("migration"),
                               LIBXL_MIGRATION_PORT_MIN,
-                              LIBXL_MIGRATION_PORT_MAX)))
+                              LIBXL_MIGRATION_PORT_MAX, 0)))
         goto error;
 
     if (!(libxl_driver->domains = virDomainObjListNew()))
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 239a300..6b4dbf3 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -731,19 +731,22 @@ qemuStateInitialize(bool privileged,
     if ((qemu_driver->remotePorts =
          virPortAllocatorNew(_("display"),
                              cfg->remotePortMin,
-                             cfg->remotePortMax)) == NULL)
+                             cfg->remotePortMax,
+                             0)) == NULL)
         goto error;
 
     if ((qemu_driver->webSocketPorts =
          virPortAllocatorNew(_("webSocket"),
                              cfg->webSocketPortMin,
-                             cfg->webSocketPortMax)) == NULL)
+                             cfg->webSocketPortMax,
+                             0)) == NULL)
         goto error;
 
     if ((qemu_driver->migrationPorts =
          virPortAllocatorNew(_("migration"),
                              cfg->migrationPortMin,
-                             cfg->migrationPortMax)) == NULL)
+                             cfg->migrationPortMax,
+                             0)) == NULL)
         goto error;
 
     if (qemuSecurityInit(qemu_driver) < 0)
diff --git a/src/util/virportallocator.c b/src/util/virportallocator.c
index ff5691a..d40c6b1 100644
--- a/src/util/virportallocator.c
+++ b/src/util/virportallocator.c
@@ -43,6 +43,8 @@ struct _virPortAllocator {
 
     unsigned short start;
     unsigned short end;
+
+    unsigned int flags;
 };
 
 static virClassPtr virPortAllocatorClass;
@@ -71,7 +73,8 @@ VIR_ONCE_GLOBAL_INIT(virPortAllocator)
 
 virPortAllocatorPtr virPortAllocatorNew(const char *name,
                                         unsigned short start,
-                                        unsigned short end)
+                                        unsigned short end,
+                                        unsigned int flags)
 {
     virPortAllocatorPtr pa;
 
@@ -87,6 +90,7 @@ virPortAllocatorPtr virPortAllocatorNew(const char *name,
     if (!(pa = virObjectLockableNew(virPortAllocatorClass)))
         return NULL;
 
+    pa->flags = flags;
     pa->start = start;
     pa->end = end;
 
@@ -193,9 +197,11 @@ int virPortAllocatorAcquire(virPortAllocatorPtr pa,
         if (used)
             continue;
 
-        if (virPortAllocatorBindToPort(&v6used, i, AF_INET6) < 0 ||
-            virPortAllocatorBindToPort(&used, i, AF_INET) < 0)
-            goto cleanup;
+        if (!(pa->flags & VIR_PORT_ALLOCATOR_SKIP_BIND_CHECK)) {
+            if (virPortAllocatorBindToPort(&v6used, i, AF_INET6) < 0 ||
+                virPortAllocatorBindToPort(&used, i, AF_INET) < 0)
+                goto cleanup;
+        }
 
         if (!used && !v6used) {
             /* Add port to bitmap of reserved ports */
diff --git a/src/util/virportallocator.h b/src/util/virportallocator.h
index e5ee56d..14c3b24 100644
--- a/src/util/virportallocator.h
+++ b/src/util/virportallocator.h
@@ -28,9 +28,14 @@
 typedef struct _virPortAllocator virPortAllocator;
 typedef virPortAllocator *virPortAllocatorPtr;
 
+typedef enum {
+    VIR_PORT_ALLOCATOR_SKIP_BIND_CHECK = (1 << 0),
+} virPortAllocatorFlags;
+
 virPortAllocatorPtr virPortAllocatorNew(const char *name,
                                         unsigned short start,
-                                        unsigned short end);
+                                        unsigned short end,
+                                        unsigned int flags);
 
 int virPortAllocatorAcquire(virPortAllocatorPtr pa,
                             unsigned short *port);
diff --git a/tests/virportallocatortest.c b/tests/virportallocatortest.c
index 48d2c9a..96d2ade 100644
--- a/tests/virportallocatortest.c
+++ b/tests/virportallocatortest.c
@@ -122,7 +122,7 @@ VIR_LOG_INIT("tests.portallocatortest");
 
 static int testAllocAll(const void *args ATTRIBUTE_UNUSED)
 {
-    virPortAllocatorPtr alloc = virPortAllocatorNew("test", 5900, 5909);
+    virPortAllocatorPtr alloc = virPortAllocatorNew("test", 5900, 5909, 0);
     int ret = -1;
     unsigned short p1, p2, p3, p4, p5, p6, p7;
 
@@ -193,7 +193,7 @@ static int testAllocAll(const void *args ATTRIBUTE_UNUSED)
 
 static int testAllocReuse(const void *args ATTRIBUTE_UNUSED)
 {
-    virPortAllocatorPtr alloc = virPortAllocatorNew("test", 5900, 5910);
+    virPortAllocatorPtr alloc = virPortAllocatorNew("test", 5900, 5910, 0);
     int ret = -1;
     unsigned short p1, p2, p3, p4;
 
-- 
1.8.4.5

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH V3 3/5] tests: Add more test suite mock helpers
  2014-09-04  3:07 [PATCH V3 0/5] Testing libvirt XML -> libxl_domain_config conversion Jim Fehlig
  2014-09-04  3:07 ` [PATCH V3 1/5] util: Introduce virJSONStringCompare for JSON doc comparisons Jim Fehlig
  2014-09-04  3:07 ` [PATCH V3 2/5] util: Allow port allocator to skip bind() check Jim Fehlig
@ 2014-09-04  3:07 ` Jim Fehlig
  2014-09-11 10:46   ` Daniel P. Berrange
  2014-09-04  3:07 ` [PATCH V3 4/5] libxl: fix mapping of lifecycle actions Jim Fehlig
                   ` (3 subsequent siblings)
  6 siblings, 1 reply; 15+ messages in thread
From: Jim Fehlig @ 2014-09-04  3:07 UTC (permalink / raw)
  To: libvir-list; +Cc: Jim Fehlig, Daniel P. Berrange, xen-devel

From: "Daniel P. Berrange" <berrange@redhat.com>

Rename the VIR_MOCK_IMPL* macros to VIR_MOCK_WRAP*
and add new VIR_MOCK_IMPL macros which let you directly
implement overrides in the preloaded source.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Signed-off-by: Jim Fehlig <jfehlig@suse.com>
---
 tests/virfirewalltest.c |  4 ++--
 tests/virmock.h         | 54 +++++++++++++++++++++++++++++++++++++------------
 tests/virsystemdtest.c  |  4 ++--
 3 files changed, 45 insertions(+), 17 deletions(-)

diff --git a/tests/virfirewalltest.c b/tests/virfirewalltest.c
index ba2e6ad..81c5557 100644
--- a/tests/virfirewalltest.c
+++ b/tests/virfirewalltest.c
@@ -67,7 +67,7 @@ static bool fwError;
     "target     prot opt source               destination\n"
 
 # if WITH_DBUS
-VIR_MOCK_IMPL_RET_ARGS(dbus_connection_send_with_reply_and_block,
+VIR_MOCK_WRAP_RET_ARGS(dbus_connection_send_with_reply_and_block,
                        DBusMessage *,
                        DBusConnection *, connection,
                        DBusMessage *, message,
@@ -82,7 +82,7 @@ VIR_MOCK_IMPL_RET_ARGS(dbus_connection_send_with_reply_and_block,
     char **args = NULL;
     char *type = NULL;
 
-    VIR_MOCK_IMPL_INIT_REAL(dbus_connection_send_with_reply_and_block);
+    VIR_MOCK_REAL_INIT(dbus_connection_send_with_reply_and_block);
 
     if (STREQ(service, "org.freedesktop.DBus") &&
         STREQ(member, "ListNames")) {
diff --git a/tests/virmock.h b/tests/virmock.h
index 0dd8bb5..8352e30 100644
--- a/tests/virmock.h
+++ b/tests/virmock.h
@@ -234,33 +234,61 @@
  */
 
 # define VIR_MOCK_IMPL_RET_ARGS(name, rettype, ...)                     \
+    rettype name(VIR_MOCK_ARGTYPENAMES(__VA_ARGS__));                   \
+    static rettype (*real_##name)(VIR_MOCK_ARGTYPES(__VA_ARGS__));      \
+    rettype name(VIR_MOCK_ARGTYPENAMES_UNUSED(__VA_ARGS__))
+
+# define VIR_MOCK_IMPL_RET_VOID(name, rettype)                          \
+    rettype name(void);                                                 \
+    static rettype (*real_##name)(void);                                \
+    rettype name(void)
+
+# define VIR_MOCK_IMPL_VOID_ARGS(name, ...)                             \
+    void name(VIR_MOCK_ARGTYPENAMES(__VA_ARGS__));                      \
+    static void (*real_##name)(VIR_MOCK_ARGTYPES(__VA_ARGS__));         \
+    void name(VIR_MOCK_ARGTYPENAMES_UNUSED(__VA_ARGS__))
+
+# define VIR_MOCK_IMPL_VOID_VOID(name)                                  \
+    void name(void);                                                    \
+    static void (*real_##name)(void);                                   \
+    void name(void)
+
+/*
+ * The VIR_MOCK_WRAP_NNN_MMM() macros are intended for use in the
+ * individual test suites. The define a stub implementation of
+ * the wrapped method and insert the caller provided code snippet
+ * as the body of the method.
+ */
+
+# define VIR_MOCK_WRAP_RET_ARGS(name, rettype, ...)                     \
     rettype wrap_##name(VIR_MOCK_ARGTYPENAMES(__VA_ARGS__));            \
     static rettype (*real_##name)(VIR_MOCK_ARGTYPES(__VA_ARGS__));      \
     rettype wrap_##name(VIR_MOCK_ARGTYPENAMES_UNUSED(__VA_ARGS__))
 
-# define VIR_MOCK_IMPL_INIT_REAL(name)                                  \
-    do {                                                                \
-        if (real_##name == NULL &&                                      \
-            !(real_##name = dlsym(RTLD_NEXT,                            \
-                                  #name))) {                            \
-            fprintf(stderr, "Missing symbol '" #name "'\n");            \
-            abort();                                                    \
-        }                                                               \
-    } while (0)
-
-# define VIR_MOCK_IMPL_RET_VOID(name, rettype)                          \
+# define VIR_MOCK_WRAP_RET_VOID(name, rettype)                          \
     rettype wrap_##name(void);                                          \
     static rettype (*real_##name)(void);                                \
     rettype wrap_##name(void)
 
-# define VIR_MOCK_IMPL_VOID_ARGS(name, ...)                             \
+# define VIR_MOCK_WRAP_VOID_ARGS(name, ...)                             \
     void wrap_##name(VIR_MOCK_ARGTYPENAMES(__VA_ARGS__));               \
     static void (*real_##name)(VIR_MOCK_ARGTYPES(__VA_ARGS__));         \
     void wrap_##name(VIR_MOCK_ARGTYPENAMES_UNUSED(__VA_ARGS__))
 
-# define VIR_MOCK_IMPL_VOID_VOID(name)                                  \
+# define VIR_MOCK_WRAP_VOID_VOID(name)                                  \
     void wrap_##name(void);                                             \
     static void (*real_##name)(void);                                   \
     void wrap_##name(void)
 
+
+# define VIR_MOCK_REAL_INIT(name)                                       \
+    do {                                                                \
+        if (real_##name == NULL &&                                      \
+            !(real_##name = dlsym(RTLD_NEXT,                            \
+                                  #name))) {                            \
+            fprintf(stderr, "Missing symbol '" #name "'\n");            \
+            abort();                                                    \
+        }                                                               \
+    } while (0)
+
 #endif /* __VIR_MOCK_H__ */
diff --git a/tests/virsystemdtest.c b/tests/virsystemdtest.c
index 8f7b47e..0d57a6a 100644
--- a/tests/virsystemdtest.c
+++ b/tests/virsystemdtest.c
@@ -34,7 +34,7 @@
 
 VIR_LOG_INIT("tests.systemdtest");
 
-VIR_MOCK_IMPL_RET_ARGS(dbus_connection_send_with_reply_and_block,
+VIR_MOCK_WRAP_RET_ARGS(dbus_connection_send_with_reply_and_block,
                        DBusMessage *,
                        DBusConnection *, connection,
                        DBusMessage *, message,
@@ -45,7 +45,7 @@ VIR_MOCK_IMPL_RET_ARGS(dbus_connection_send_with_reply_and_block,
     const char *service = dbus_message_get_destination(message);
     const char *member = dbus_message_get_member(message);
 
-    VIR_MOCK_IMPL_INIT_REAL(dbus_connection_send_with_reply_and_block);
+    VIR_MOCK_REAL_INIT(dbus_connection_send_with_reply_and_block);
 
     if (STREQ(service, "org.freedesktop.machine1")) {
         if (getenv("FAIL_BAD_SERVICE")) {
-- 
1.8.4.5

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH V3 4/5] libxl: fix mapping of lifecycle actions
  2014-09-04  3:07 [PATCH V3 0/5] Testing libvirt XML -> libxl_domain_config conversion Jim Fehlig
                   ` (2 preceding siblings ...)
  2014-09-04  3:07 ` [PATCH V3 3/5] tests: Add more test suite mock helpers Jim Fehlig
@ 2014-09-04  3:07 ` Jim Fehlig
  2014-09-04  3:07 ` [PATCH V3 5/5] libxl: Add a test suite for libxl option generator Jim Fehlig
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 15+ messages in thread
From: Jim Fehlig @ 2014-09-04  3:07 UTC (permalink / raw)
  To: libvir-list; +Cc: Jim Fehlig, xen-devel

The libxl driver was blindly assigning libvirt's
virDomainLifecycleAction to libxl's libxl_action_on_shutdown, when
in fact the various actions take on different values in these enums.

Introduce helpers to properly map the enum values.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
---
 src/libxl/libxl_conf.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 59 insertions(+), 3 deletions(-)

diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c
index 1dbdd9c..a9139bf 100644
--- a/src/libxl/libxl_conf.c
+++ b/src/libxl/libxl_conf.c
@@ -102,6 +102,62 @@ libxlDriverConfigDispose(void *obj)
     VIR_FREE(cfg->autoDumpDir);
 }
 
+
+static libxl_action_on_shutdown
+libxlActionFromVirLifecycle(virDomainLifecycleAction action)
+{
+    switch (action) {
+    case VIR_DOMAIN_LIFECYCLE_DESTROY:
+        return LIBXL_ACTION_ON_SHUTDOWN_DESTROY;
+
+    case VIR_DOMAIN_LIFECYCLE_RESTART:
+        return  LIBXL_ACTION_ON_SHUTDOWN_RESTART;
+
+    case VIR_DOMAIN_LIFECYCLE_RESTART_RENAME:
+        return LIBXL_ACTION_ON_SHUTDOWN_RESTART_RENAME;
+
+    case VIR_DOMAIN_LIFECYCLE_PRESERVE:
+        return LIBXL_ACTION_ON_SHUTDOWN_PRESERVE;
+
+    case VIR_DOMAIN_LIFECYCLE_LAST:
+        break;
+    }
+
+    return 0;
+}
+
+
+static libxl_action_on_shutdown
+libxlActionFromVirLifecycleCrash(virDomainLifecycleCrashAction action)
+{
+
+    switch (action) {
+    case VIR_DOMAIN_LIFECYCLE_CRASH_DESTROY:
+        return LIBXL_ACTION_ON_SHUTDOWN_DESTROY;
+
+    case VIR_DOMAIN_LIFECYCLE_CRASH_RESTART:
+        return  LIBXL_ACTION_ON_SHUTDOWN_RESTART;
+
+    case VIR_DOMAIN_LIFECYCLE_CRASH_RESTART_RENAME:
+        return LIBXL_ACTION_ON_SHUTDOWN_RESTART_RENAME;
+
+    case VIR_DOMAIN_LIFECYCLE_CRASH_PRESERVE:
+        return LIBXL_ACTION_ON_SHUTDOWN_PRESERVE;
+
+    case VIR_DOMAIN_LIFECYCLE_CRASH_COREDUMP_DESTROY:
+        return LIBXL_ACTION_ON_SHUTDOWN_COREDUMP_DESTROY;
+
+    case VIR_DOMAIN_LIFECYCLE_CRASH_COREDUMP_RESTART:
+        return LIBXL_ACTION_ON_SHUTDOWN_COREDUMP_RESTART;
+
+    case VIR_DOMAIN_LIFECYCLE_CRASH_LAST:
+        break;
+    }
+
+    return 0;
+}
+
+
 static int
 libxlCapsInitHost(libxl_ctx *ctx, virCapsPtr caps)
 {
@@ -1436,9 +1492,9 @@ libxlBuildDomainConfig(virPortAllocatorPtr graphicsports,
     if (libxlMakePCIList(def, d_config) < 0)
         return -1;
 
-    d_config->on_reboot = def->onReboot;
-    d_config->on_poweroff = def->onPoweroff;
-    d_config->on_crash = def->onCrash;
+    d_config->on_reboot = libxlActionFromVirLifecycle(def->onReboot);
+    d_config->on_poweroff = libxlActionFromVirLifecycle(def->onPoweroff);
+    d_config->on_crash = libxlActionFromVirLifecycleCrash(def->onCrash);
 
     return 0;
 }
-- 
1.8.4.5

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH V3 5/5] libxl: Add a test suite for libxl option generator
  2014-09-04  3:07 [PATCH V3 0/5] Testing libvirt XML -> libxl_domain_config conversion Jim Fehlig
                   ` (3 preceding siblings ...)
  2014-09-04  3:07 ` [PATCH V3 4/5] libxl: fix mapping of lifecycle actions Jim Fehlig
@ 2014-09-04  3:07 ` Jim Fehlig
  2014-09-11 10:58   ` Daniel P. Berrange
       [not found]   ` <20140911105842.GE7035@redhat.com>
       [not found] ` <1409800059-16884-2-git-send-email-jfehlig@suse.com>
       [not found] ` <1409800059-16884-5-git-send-email-jfehlig@suse.com>
  6 siblings, 2 replies; 15+ messages in thread
From: Jim Fehlig @ 2014-09-04  3:07 UTC (permalink / raw)
  To: libvir-list; +Cc: Jim Fehlig, Daniel P. Berrange, xen-devel

From: "Daniel P. Berrange" <berrange@redhat.com>

The libxl library allows a libxl_domain_config object to be
serialized to a JSON string. Use this to allow testing of
the XML -> libxl_domain_config conversion process

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Signed-off-by: Jim Fehlig <jfehlig@suse.com>
---
 configure.ac                           |   2 +
 tests/Makefile.am                      |  25 +++-
 tests/libxlxml2jsondata/basic-hvm.json | 217 ++++++++++++++++++++++++++++
 tests/libxlxml2jsondata/basic-hvm.xml  |  36 +++++
 tests/libxlxml2jsondata/basic-pv.json  | 163 +++++++++++++++++++++
 tests/libxlxml2jsondata/basic-pv.xml   |  28 ++++
 tests/libxlxml2jsontest.c              | 251 +++++++++++++++++++++++++++++++++
 tests/virmocklibxl.c                   |  87 ++++++++++++
 8 files changed, 808 insertions(+), 1 deletion(-)

diff --git a/configure.ac b/configure.ac
index b4fb99a..80c331f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -875,6 +875,8 @@ if test "$with_libxl" != "no" ; then
     AC_CHECK_LIB([xenlight], [libxl_ctx_alloc], [
         with_libxl=yes
         LIBXL_LIBS="$LIBXL_LIBS -lxenlight -lxenctrl"
+        LIBS="$LIBS -lxenlight -lxenctrl"
+        AC_CHECK_FUNCS([libxl_domain_config_to_json])
     ],[
         if test "$with_libxl" = "yes"; then
             fail=1
diff --git a/tests/Makefile.am b/tests/Makefile.am
index d6c3cfb..a8e4e88 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -84,6 +84,7 @@ EXTRA_DIST =		\
 	domainsnapshotxml2xmlout \
 	fchostdata \
 	interfaceschemadata \
+	libxlxml2jsondata \
 	lxcconf2xmldata \
 	lxcxml2xmldata \
 	lxcxml2xmloutdata \
@@ -222,6 +223,9 @@ if WITH_XEN
 test_programs += xml2sexprtest sexpr2xmltest \
 	xmconfigtest xencapstest statstest reconnect
 endif WITH_XEN
+if WITH_LIBXL
+test_programs += libxlxml2jsontest
+endif WITH_LIBXL
 if WITH_QEMU
 test_programs += qemuxml2argvtest qemuxml2xmltest qemuxmlnstest \
 	qemuargv2xmltest qemuhelptest domainsnapshotxml2xmltest \
@@ -393,7 +397,9 @@ test_libraries += libqemumonitortestutils.la \
 		qemuxml2argvmock.la \
 		$(NULL)
 endif WITH_QEMU
-
+if WITH_LIBXL
+test_libraries += virmocklibxl.la
+endif WITH_LIBXL
 if WITH_BHYVE
 test_libraries += bhyvexml2argvmock.la
 endif WITH_BHYVE
@@ -593,6 +599,23 @@ EXTRA_DIST += qemuxml2argvtest.c qemuxml2xmltest.c qemuargv2xmltest.c \
 	$(QEMUMONITORTESTUTILS_SOURCES)
 endif ! WITH_QEMU
 
+if WITH_LIBXL
+libxl_LDADDS = ../src/libvirt_driver_libxl_impl.la
+libxl_LDADDS += $(LDADDS)
+
+libxlxml2jsontest_SOURCES = \
+	libxlxml2jsontest.c testutilsxen.c testutilsxen.h \
+	testutils.c testutils.h
+libxlxml2jsontest_LDADD = $(libxl_LDADDS) $(LIBXML_LIBS)
+
+virmocklibxl_la_SOURCES = \
+	virmocklibxl.c
+virmocklibxl_la_CFLAGS = $(AM_CFLAGS)
+virmocklibxl_la_LDFLAGS = -module -avoid-version \
+        -rpath /evil/libtool/hack/to/force/shared/lib/creation
+
+endif WITH_LIBXL
+
 if WITH_LXC
 
 lxc_LDADDS = ../src/libvirt_driver_lxc_impl.la
diff --git a/tests/libxlxml2jsondata/basic-hvm.json b/tests/libxlxml2jsondata/basic-hvm.json
new file mode 100644
index 0000000..b02e299
--- /dev/null
+++ b/tests/libxlxml2jsondata/basic-hvm.json
@@ -0,0 +1,217 @@
+{
+    "c_info": {
+        "type": "hvm",
+        "hap": "<default>",
+        "oos": "<default>",
+        "ssidref": 0,
+        "name": "sles-hvm",
+        "uuid": "2147d599-9cc6-c0dc-92ab-4064b5446e9b",
+        "xsdata": {
+
+        },
+        "platformdata": {
+
+        },
+        "poolid": 0,
+        "run_hotplug_scripts": "<default>",
+        "pvh": "<default>",
+        "driver_domain": "<default>"
+    },
+    "b_info": {
+        "max_vcpus": 4,
+        "avail_vcpus": [
+            0,
+            1,
+            2,
+            3
+        ],
+        "cpumap": [
+
+        ],
+        "nodemap": [
+
+        ],
+        "numa_placement": "<default>",
+        "tsc_mode": "default",
+        "max_memkb": 1048576,
+        "target_memkb": 1048576,
+        "video_memkb": -1,
+        "shadow_memkb": 12288,
+        "rtc_timeoffset": 0,
+        "exec_ssidref": 0,
+        "localtime": "<default>",
+        "disable_migrate": "<default>",
+        "cpuid": [
+
+        ],
+        "blkdev_start": null,
+        "device_model_version": "unknown",
+        "device_model_stubdomain": "<default>",
+        "device_model": null,
+        "device_model_ssidref": 0,
+        "extra": [
+
+        ],
+        "extra_pv": [
+
+        ],
+        "extra_hvm": [
+
+        ],
+        "sched_params": {
+            "sched": "unknown",
+            "weight": 1000,
+            "cap": -1,
+            "period": -1,
+            "slice": -1,
+            "latency": -1,
+            "extratime": -1
+        },
+        "ioports": [
+
+        ],
+        "irqs": [
+
+        ],
+        "iomem": [
+
+        ],
+        "claim_mode": "<default>",
+        "event_channels": 0,
+        "u": {
+            "firmware": null,
+            "kernel": null,
+            "cmdline": null,
+            "ramdisk": null,
+            "bios": "unknown",
+            "pae": "True",
+            "apic": "True",
+            "acpi": "True",
+            "acpi_s3": "<default>",
+            "acpi_s4": "<default>",
+            "nx": "<default>",
+            "viridian": "<default>",
+            "timeoffset": null,
+            "hpet": "<default>",
+            "vpt_align": "<default>",
+            "timer_mode": "unknown",
+            "nested_hvm": "<default>",
+            "smbios_firmware": null,
+            "acpi_firmware": null,
+            "nographic": "<default>",
+            "vga": {
+               "kind": "cirrus"
+            },
+            "vnc": {
+                "enable": "True",
+                "listen": "0.0.0.0",
+                "passwd": null,
+                "display": 0,
+                "findunused": "False"
+            },
+            "keymap": null,
+            "sdl": {
+                "enable": "<default>",
+                "opengl": "<default>",
+                "display": null,
+                "xauthority": null
+            },
+            "spice": {
+                "enable": "<default>",
+                "port": 0,
+                "tls_port": 0,
+                "host": null,
+                "disable_ticketing": "<default>",
+                "passwd": null,
+                "agent_mouse": "<default>",
+                "vdagent": "<default>",
+                "clipboard_sharing": "<default>",
+                "usbredirection": 0
+            },
+            "gfx_passthru": "<default>",
+            "serial": null,
+            "boot": "c",
+            "usb": "<default>",
+            "usbversion": 0,
+            "usbdevice": null,
+            "soundhw": null,
+            "xen_platform_pci": "<default>",
+            "usbdevice_list": [
+
+            ],
+            "vendor_device": "none",
+            "watchdog": null,
+            "watchdog_action": null
+         }
+    },
+    "disks": [
+        {
+            "backend_domid": 0,
+            "backend_domname": null,
+            "pdev_path": "/var/lib/xen/images/sles-hvm.img",
+            "vdev": "hda",
+            "backend": "qdisk",
+            "format": "raw",
+            "script": null,
+            "removable": 1,
+            "readwrite": 1,
+            "is_cdrom": 0
+        }
+    ],
+    "nics": [
+        {
+            "backend_domid": 0,
+            "backend_domname": null,
+            "devid": 0,
+            "mtu": 0,
+            "model": null,
+            "mac": "00:16:3e:66:12:b4",
+            "ip": null,
+            "bridge": "br0",
+            "ifname": null,
+            "script": "/etc/xen/scripts/vif-bridge",
+            "nictype": "vif_ioemu",
+            "rate_bytes_per_interval": 0,
+            "rate_interval_usecs": 0,
+            "gatewaydev": null
+        }
+    ],
+    "pcidevs": [
+
+    ],
+    "vfbs": [
+        {
+            "backend_domid": 0,
+            "backend_domname": null,
+            "devid": -1,
+            "vnc": {
+                "enable": "True",
+                "listen": "0.0.0.0",
+                "passwd": null,
+                "display": 0,
+                "findunused": "False"
+            },
+            "sdl": {
+                "enable": "<default>",
+                "opengl": "<default>",
+                "display": null,
+                "xauthority": null
+            },
+            "keymap": null
+        }
+    ],
+    "vkbs": [
+        {
+            "backend_domid": 0,
+            "backend_domname": null,
+            "devid": -1
+        }
+    ],
+    "vtpms": [
+
+    ],
+    "on_poweroff": "destroy",
+    "on_reboot": "restart",
+    "on_watchdog": "destroy",
+    "on_crash": "destroy"
+}
diff --git a/tests/libxlxml2jsondata/basic-hvm.xml b/tests/libxlxml2jsondata/basic-hvm.xml
new file mode 100644
index 0000000..693a715
--- /dev/null
+++ b/tests/libxlxml2jsondata/basic-hvm.xml
@@ -0,0 +1,36 @@
+<domain type='xen'>
+  <name>sles-hvm</name>
+  <description>None</description>
+  <uuid>2147d599-9cc6-c0dc-92ab-4064b5446e9b</uuid>
+  <memory>1048576</memory>
+  <currentMemory>1048576</currentMemory>
+  <vcpu>4</vcpu>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>restart</on_reboot>
+  <on_crash>destroy</on_crash>
+  <clock sync='utc'/>
+  <os>
+    <type>hvm</type>
+    <loader>/usr/lib/xen/boot/hvmloader</loader>
+    <boot dev='hd'/>
+  </os>
+  <features>
+    <apic/>
+    <acpi/>
+    <pae/>
+  </features>
+  <devices>
+    <emulator>/usr/lib/xen/bin/qemu-system-i386</emulator>
+    <disk type='file' device='disk'>
+      <driver name='qemu'/>
+      <source file='/var/lib/xen/images/sles-hvm.img'/>
+      <target dev='hda'/>
+    </disk>
+    <interface type='bridge'>
+      <source bridge='br0'/>
+      <mac address='00:16:3e:66:12:b4'/>
+      <script path='/etc/xen/scripts/vif-bridge'/>
+    </interface>
+    <graphics type='vnc' port='-1' autoport='yes' listen='0.0.0.0'/>
+  </devices>
+</domain>
diff --git a/tests/libxlxml2jsondata/basic-pv.json b/tests/libxlxml2jsondata/basic-pv.json
new file mode 100644
index 0000000..326b705
--- /dev/null
+++ b/tests/libxlxml2jsondata/basic-pv.json
@@ -0,0 +1,163 @@
+{
+    "c_info": {
+        "type": "pv",
+        "hap": "<default>",
+        "oos": "<default>",
+        "ssidref": 0,
+        "name": "sles11-pv",
+        "uuid": "039e9ee6-4a84-3055-4c81-8ba426ae2656",
+        "xsdata": {
+
+        },
+        "platformdata": {
+
+        },
+        "poolid": 0,
+        "run_hotplug_scripts": "<default>",
+        "pvh": "<default>",
+        "driver_domain": "<default>"
+    },
+    "b_info": {
+        "max_vcpus": 4,
+        "avail_vcpus": [
+            0,
+            1,
+            2,
+            3
+        ],
+        "cpumap": [
+
+        ],
+        "nodemap": [
+
+        ],
+        "numa_placement": "<default>",
+        "tsc_mode": "default",
+        "max_memkb": 524288,
+        "target_memkb": 524288,
+        "video_memkb": -1,
+        "shadow_memkb": -1,
+        "rtc_timeoffset": 0,
+        "exec_ssidref": 0,
+        "localtime": "<default>",
+        "disable_migrate": "<default>",
+        "cpuid": [
+
+        ],
+        "blkdev_start": null,
+        "device_model_version": "unknown",
+        "device_model_stubdomain": "<default>",
+        "device_model": null,
+        "device_model_ssidref": 0,
+        "extra": [
+
+        ],
+        "extra_pv": [
+
+        ],
+        "extra_hvm": [
+
+        ],
+        "sched_params": {
+            "sched": "unknown",
+            "weight": 1000,
+            "cap": -1,
+            "period": -1,
+            "slice": -1,
+            "latency": -1,
+            "extratime": -1
+        },
+        "ioports": [
+
+        ],
+        "irqs": [
+
+        ],
+        "iomem": [
+
+        ],
+        "claim_mode": "<default>",
+        "event_channels": 0,
+        "u": {
+            "kernel": null,
+            "slack_memkb": -1,
+            "bootloader": "pygrub",
+            "bootloader_args": [
+
+            ],
+            "cmdline": null,
+            "ramdisk": null,
+            "e820_host": "<default>"
+        }
+    },
+    "disks": [
+        {
+            "backend_domid": 0,
+            "backend_domname": null,
+            "pdev_path": "/var/lib/xen/images/sles11-pv.img",
+            "vdev": "xvda",
+            "backend": "qdisk",
+            "format": "raw",
+            "script": null,
+            "removable": 1,
+            "readwrite": 1,
+            "is_cdrom": 0
+        }
+    ],
+    "nics": [
+        {
+            "backend_domid": 0,
+            "backend_domname": null,
+            "devid": 0,
+            "mtu": 0,
+            "model": null,
+            "mac": "00:16:3e:3e:86:60",
+            "ip": null,
+            "bridge": "br0",
+            "ifname": null,
+            "script": "/etc/xen/scripts/vif-bridge",
+            "nictype": "vif",
+            "rate_bytes_per_interval": 0,
+            "rate_interval_usecs": 0,
+            "gatewaydev": null
+        }
+    ],
+    "pcidevs": [
+
+    ],
+    "vfbs": [
+        {
+            "backend_domid": 0,
+            "backend_domname": null,
+            "devid": -1,
+            "vnc": {
+                "enable": "True",
+                "listen": "0.0.0.0",
+                "passwd": null,
+                "display": 0,
+                "findunused": "False"
+            },
+            "sdl": {
+                "enable": "<default>",
+                "opengl": "<default>",
+                "display": null,
+                "xauthority": null
+            },
+            "keymap": null
+        }
+    ],
+    "vkbs": [
+        {
+            "backend_domid": 0,
+            "backend_domname": null,
+            "devid": -1
+        }
+    ],
+    "vtpms": [
+
+    ],
+    "on_poweroff": "destroy",
+    "on_reboot": "restart",
+    "on_watchdog": "destroy",
+    "on_crash": "destroy"
+}
diff --git a/tests/libxlxml2jsondata/basic-pv.xml b/tests/libxlxml2jsondata/basic-pv.xml
new file mode 100644
index 0000000..109e657
--- /dev/null
+++ b/tests/libxlxml2jsondata/basic-pv.xml
@@ -0,0 +1,28 @@
+<domain type='xen'>
+  <name>sles11-pv</name>
+  <uuid>039e9ee6-4a84-3055-4c81-8ba426ae2656</uuid>
+  <memory>524288</memory>
+  <currentMemory>524288</currentMemory>
+  <vcpu>4</vcpu>
+  <bootloader>pygrub</bootloader>
+  <os>
+    <type arch='i686' machine='xenpv'>linux</type>
+  </os>
+  <clock offset='utc'/>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>restart</on_reboot>
+  <on_crash>destroy</on_crash>
+  <devices>
+    <disk type='file' device='disk'>
+      <driver name='qemu'/>
+      <source file='/var/lib/xen/images/sles11-pv.img'/>
+      <target dev='xvda'/>
+    </disk>
+    <interface type='bridge'>
+      <source bridge='br0'/>
+      <mac address='00:16:3e:3e:86:60'/>
+      <script path='/etc/xen/scripts/vif-bridge'/>
+    </interface>
+    <graphics type='vnc' port='-1' autoport='yes' listen='0.0.0.0'/>
+  </devices>
+</domain>
diff --git a/tests/libxlxml2jsontest.c b/tests/libxlxml2jsontest.c
new file mode 100644
index 0000000..6ae654a
--- /dev/null
+++ b/tests/libxlxml2jsontest.c
@@ -0,0 +1,251 @@
+/*
+ * Copyright (C) 2014 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library.  If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ * Author: Daniel P. Berrange <berrange@redhat.com>
+ */
+
+#include <config.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+
+#include <sys/types.h>
+#include <fcntl.h>
+
+#include "testutils.h"
+
+#if defined(WITH_LIBXL) && defined(WITH_YAJL) && defined(HAVE_LIBXL_DOMAIN_CONFIG_TO_JSON)
+
+# include "internal.h"
+# include "viralloc.h"
+# include "libxl/libxl_conf.h"
+# include "datatypes.h"
+# include "virstring.h"
+# include "virmock.h"
+# include "virjson.h"
+# include "testutilsxen.h"
+
+# define VIR_FROM_THIS VIR_FROM_XEN
+
+static const char *abs_top_srcdir;
+static virCapsPtr xencaps;
+
+#if defined LIBXL_HAVE_BUILDINFO_HVM_VENDOR_DEVICE
+/*
+* Currently no paths ignored on Xen 4.4
+*/
+static const char **ignore_paths = NULL;
+#elif defined LIBXL_HAVE_DOMAIN_NODEAFFINITY
+/*
+* These paths must be ignored if running on Xen 4.3
+*/
+static const char *ignore_paths[] = {
+    "/c_info/pvh",
+    "/c_info/driver_domain",
+    "/b_info/device_model_version",
+    "/b_info/event_channels",
+    "/b_info/u/kernel",
+    "/b_info/u/cmdline",
+    "/b_info/u/ramdisk",
+    "/b_info/u/bios",
+    "/b_info/u/timer_mode",
+    "/b_info/u/vga/kind",
+    "/b_info/u/spice/vdagent",
+    "/b_info/u/spice/clipboard_sharing",
+    "/b_info/u/spice/usbredirection",
+    "/b_info/u/usbversion",
+    "/b_info/u/vendor_device",
+    "/on_watchdog",
+    NULL
+};
+#else
+/*
+ * These paths must be ignored if running on Xen 4.2
+ */
+static const char *ignore_paths[] = {
+    "/c_info/pvh",
+    "/c_info/driver_domain",
+    "/b_info/nodemap",
+    "/b_info/exec_ssidref",
+    "/b_info/iomem",
+    "/b_info/claim_mode",
+    "/b_info/device_model_version",
+    "/b_info/event_channels",
+    "/b_info/u/usbdevice_list",
+    "/b_info/u/kernel",
+    "/b_info/u/cmdline",
+    "/b_info/u/ramdisk",
+    "/b_info/u/bios",
+    "/b_info/u/timer_mode",
+    "/b_info/u/vga/kind",
+    "/b_info/u/spice/vdagent",
+    "/b_info/u/spice/clipboard_sharing",
+    "/b_info/u/spice/usbredirection",
+    "/b_info/u/usbversion",
+    "/b_info/u/vendor_device",
+    "/disks/backend_domname",
+    "/nics/backend_domname",
+    "/nics/gatewaydev",
+    "/vfbs/backend_domname",
+    "/vkbs/backend_domname",
+    "/vtpms",
+    "/on_watchdog",
+    NULL
+};
+#endif
+
+
+static int testCompareXMLToJSONFiles(const char *xml,
+                                     const char *cmdline)
+{
+    char *expectargv = NULL;
+    int ret = -1;
+    virDomainDefPtr vmdef = NULL;
+    virPortAllocatorPtr gports = NULL;
+    libxl_ctx *ctx = NULL;
+    libxl_domain_config config;
+    xentoollog_logger *log = NULL;
+    virDomainXMLOptionPtr xmlopt = NULL;
+    char *actualargv;
+
+    libxl_domain_config_init(&config);
+
+    if (!(log = (xentoollog_logger *)xtl_createlogger_stdiostream(stderr, XTL_DEBUG, 0)))
+        goto cleanup;
+
+    if (libxl_ctx_alloc(&ctx, LIBXL_VERSION, 0, log) < 0)
+        goto cleanup;
+
+    if (!(gports = virPortAllocatorNew("vnc", 5900, 6000,
+                                       VIR_PORT_ALLOCATOR_SKIP_BIND_CHECK)))
+        goto cleanup;
+
+    if (!(xmlopt = libxlCreateXMLConf()))
+        goto cleanup;
+
+    if (!(vmdef = virDomainDefParseFile(xml, xencaps, xmlopt,
+                                        1 << VIR_DOMAIN_VIRT_XEN,
+                                        VIR_DOMAIN_XML_INACTIVE)))
+        goto cleanup;
+
+    if (libxlBuildDomainConfig(gports, vmdef, ctx, &config) < 0)
+        goto cleanup;
+
+    if (!(actualargv = libxl_domain_config_to_json(ctx, &config))) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       "Failed to create JSON doc for xl config");
+        goto cleanup;
+    }
+
+    virtTestLoadFile(cmdline, &expectargv);
+
+    if (!virJSONStringCompare(expectargv, actualargv, ignore_paths,
+                              VIR_JSON_COMPARE_IGNORE_EXPECTED_NULL))
+        goto cleanup;
+
+    ret = 0;
+
+ cleanup:
+    VIR_FREE(expectargv);
+    VIR_FREE(actualargv);
+    virDomainDefFree(vmdef);
+    virObjectUnref(gports);
+    virObjectUnref(xmlopt);
+    libxl_ctx_free(ctx);
+    libxl_domain_config_dispose(&config);
+    xtl_logger_destroy(log);
+    return ret;
+}
+
+
+struct testInfo {
+    const char *name;
+};
+
+static int
+testCompareXMLToJSONHelper(const void *data)
+{
+    int ret = -1;
+    const struct testInfo *info = data;
+    char *xml = NULL;
+    char *args = NULL;
+
+    if (virAsprintf(&xml, "%s/libxlxml2jsondata/%s.xml",
+                    abs_srcdir, info->name) < 0 ||
+        virAsprintf(&args, "%s/libxlxml2jsondata/%s.json",
+                    abs_srcdir, info->name) < 0)
+        goto cleanup;
+
+    ret = testCompareXMLToJSONFiles(xml, args);
+
+ cleanup:
+    VIR_FREE(xml);
+    VIR_FREE(args);
+    return ret;
+}
+
+
+static int
+mymain(void)
+{
+    int ret = 0;
+
+    abs_top_srcdir = getenv("abs_top_srcdir");
+    if (!abs_top_srcdir)
+        abs_top_srcdir = abs_srcdir "/..";
+
+    /* Set the timezone because we are mocking the time() function.
+     * If we don't do that, then localtime() may return unpredictable
+     * results. In order to detect things that just work by a blind
+     * chance, we need to set an virtual timezone that no libvirt
+     * developer resides in. */
+    if (setenv("TZ", "VIR00:30", 1) < 0) {
+        perror("setenv");
+        return EXIT_FAILURE;
+    }
+
+    if ((xencaps = testXenCapsInit()) == NULL)
+        return EXIT_FAILURE;
+
+# define DO_TEST(name)                                                  \
+    do {                                                                \
+        static struct testInfo info = {                                 \
+            name,                                                       \
+        };                                                              \
+        if (virtTestRun("LibXL XML-2-JSON " name,                       \
+                        testCompareXMLToJSONHelper, &info) < 0)         \
+            ret = -1;                                                   \
+    } while (0)
+
+    DO_TEST("basic-pv");
+    DO_TEST("basic-hvm");
+
+    return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
+}
+
+VIRT_TEST_MAIN_PRELOAD(mymain, abs_builddir "/.libs/virmocklibxl.so")
+
+#else
+
+int main(void)
+{
+    return EXIT_AM_SKIP;
+}
+
+#endif /* WITH_XEN && WITH_YAJL && HAVE_LIBXL_DOMAIN_CONFIG_TO_JSON */
diff --git a/tests/virmocklibxl.c b/tests/virmocklibxl.c
new file mode 100644
index 0000000..bc4b53d
--- /dev/null
+++ b/tests/virmocklibxl.c
@@ -0,0 +1,87 @@
+/*
+ * virmocklibxl.c: mocking of xenstore/libxs for libxl
+ *
+ * Copyright (C) 2014 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library.  If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ * Author: Daniel P. Berrange <berrange@redhat.com>
+ */
+
+#include <config.h>
+
+#if defined(WITH_LIBXL) && defined(WITH_YAJL)
+# include "virmock.h"
+# include <sys/stat.h>
+# include <unistd.h>
+# include <libxl.h>
+# include <xenstore.h>
+# include <xenctrl.h>
+
+VIR_MOCK_IMPL_RET_VOID(xs_daemon_open,
+                       struct xs_handle *)
+{
+    VIR_MOCK_REAL_INIT(xs_daemon_open);
+    return (void*)0x1;
+}
+
+VIR_MOCK_IMPL_RET_ARGS(xc_interface_open,
+                       xc_interface *,
+                       xentoollog_logger *, logger,
+                       xentoollog_logger *, dombuild_logger,
+                       unsigned, open_flags)
+{
+    VIR_MOCK_REAL_INIT(xc_interface_open);
+    return (void*)0x1;
+}
+
+
+VIR_MOCK_STUB_RET_ARGS(xc_interface_close,
+                       int, 0,
+                       xc_interface *, handle)
+
+VIR_MOCK_STUB_VOID_ARGS(xs_daemon_close,
+                        struct xs_handle *, handle)
+
+VIR_MOCK_IMPL_RET_ARGS(__xstat, int,
+                       int, ver,
+                       const char *, path,
+                       struct stat *, sb)
+{
+    VIR_MOCK_REAL_INIT(__xstat);
+
+    if (strstr(path, "xenstored.pid")) {
+        memset(sb, 0, sizeof(*sb));
+        return 0;
+    }
+
+    return real___xstat(ver, path, sb);
+}
+
+VIR_MOCK_IMPL_RET_ARGS(stat, int,
+                       const char *, path,
+                       struct stat *, sb)
+{
+    VIR_MOCK_REAL_INIT(stat);
+
+    if (strstr(path, "xenstored.pid")) {
+        memset(sb, 0, sizeof(*sb));
+        return 0;
+    }
+
+    return real_stat(path, sb);
+}
+
+#endif /* WITH_LIBXL && WITH_YAJL */
-- 
1.8.4.5

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* Re: [PATCH V3 1/5] util: Introduce virJSONStringCompare for JSON doc comparisons
       [not found] ` <1409800059-16884-2-git-send-email-jfehlig@suse.com>
@ 2014-09-11 10:45   ` Daniel P. Berrange
       [not found]   ` <20140911104519.GA7035@redhat.com>
  1 sibling, 0 replies; 15+ messages in thread
From: Daniel P. Berrange @ 2014-09-11 10:45 UTC (permalink / raw)
  To: Jim Fehlig; +Cc: libvir-list, xen-devel

On Wed, Sep 03, 2014 at 09:07:35PM -0600, Jim Fehlig wrote:
> From: "Daniel P. Berrange" <berrange@redhat.com>
> 
> Comparing JSON docs using strcmp is simple, but is not flexible
> as it is sensitive to whitespace used in the doc generation.
> When comparing objects it may also be desirable to treat the
> existance of keys in the actual object but not expected object
> as non-fatal. Introduce a virJSONStringCompare function which
> takes two strings representing expected and actual JSON docs
> and then does a DOM comparison.  Comparison is controled with
> the ignore_contexts and flags parameters.  No comparison is
> done on context paths specified in ignore_contexts.  The
> VIR_JSON_COMPARE_IGNORE_EXPECTED_NULL flag can be used to
> ignore actual values that have changed from an expected value
> of null.
> 
> Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
> Signed-off-by: Jim Fehlig <jfehlig@suse.com>
> ---
>  src/libvirt_private.syms |   1 +
>  src/util/virjson.c       | 242 +++++++++++++++++++++++++++++++++++++++++++++++
>  src/util/virjson.h       |  16 ++++
>  3 files changed, 259 insertions(+)

Looks good, but perhaps we should also add to tests/virjsontest.c
to verify the ignore context support is working as intended

Regards,
Daniel
-- 
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH V3 2/5] util: Allow port allocator to skip bind() check
  2014-09-04  3:07 ` [PATCH V3 2/5] util: Allow port allocator to skip bind() check Jim Fehlig
@ 2014-09-11 10:46   ` Daniel P. Berrange
  0 siblings, 0 replies; 15+ messages in thread
From: Daniel P. Berrange @ 2014-09-11 10:46 UTC (permalink / raw)
  To: Jim Fehlig; +Cc: libvir-list, xen-devel

On Wed, Sep 03, 2014 at 09:07:36PM -0600, Jim Fehlig wrote:
> From: "Daniel P. Berrange" <berrange@redhat.com>
> 
> Test suites using the port allocator don't want to have different
> behaviour depending on whether a port is in use on the host. Add
> a VIR_PORT_ALLOCATOR_SKIP_BIND_CHECK which test suites can use
> to skip the bind() test. The port allocator will thus only track
> ports in use by the test suite process itself. This is fine when
> using the port allocator to generate guest configs which won't
> actually be launched
> 
> Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
> Signed-off-by: Jim Fehlig <jfehlig@suse.com>
> ---
>  src/libxl/libxl_driver.c     |  5 +++--
>  src/qemu/qemu_driver.c       |  9 ++++++---
>  src/util/virportallocator.c  | 14 ++++++++++----
>  src/util/virportallocator.h  |  7 ++++++-
>  tests/virportallocatortest.c |  4 ++--
>  5 files changed, 27 insertions(+), 12 deletions(-)

ACK, can push this independant of the rest

Regards,
Daniel
-- 
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH V3 3/5] tests: Add more test suite mock helpers
  2014-09-04  3:07 ` [PATCH V3 3/5] tests: Add more test suite mock helpers Jim Fehlig
@ 2014-09-11 10:46   ` Daniel P. Berrange
  0 siblings, 0 replies; 15+ messages in thread
From: Daniel P. Berrange @ 2014-09-11 10:46 UTC (permalink / raw)
  To: Jim Fehlig; +Cc: libvir-list, xen-devel

On Wed, Sep 03, 2014 at 09:07:37PM -0600, Jim Fehlig wrote:
> From: "Daniel P. Berrange" <berrange@redhat.com>
> 
> Rename the VIR_MOCK_IMPL* macros to VIR_MOCK_WRAP*
> and add new VIR_MOCK_IMPL macros which let you directly
> implement overrides in the preloaded source.
> 
> Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
> Signed-off-by: Jim Fehlig <jfehlig@suse.com>
> ---
>  tests/virfirewalltest.c |  4 ++--
>  tests/virmock.h         | 54 +++++++++++++++++++++++++++++++++++++------------
>  tests/virsystemdtest.c  |  4 ++--
>  3 files changed, 45 insertions(+), 17 deletions(-)

ACK, might as well push this now too.

Regards,
Daniel
-- 
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [libvirt] [PATCH V3 4/5] libxl: fix mapping of lifecycle actions
       [not found] ` <1409800059-16884-5-git-send-email-jfehlig@suse.com>
@ 2014-09-11 10:47   ` Daniel P. Berrange
       [not found]   ` <20140911104716.GD7035@redhat.com>
  2014-09-11 21:59   ` Jim Fehlig
  2 siblings, 0 replies; 15+ messages in thread
From: Daniel P. Berrange @ 2014-09-11 10:47 UTC (permalink / raw)
  To: Jim Fehlig; +Cc: libvir-list, xen-devel

On Wed, Sep 03, 2014 at 09:07:38PM -0600, Jim Fehlig wrote:
> The libxl driver was blindly assigning libvirt's
> virDomainLifecycleAction to libxl's libxl_action_on_shutdown, when
> in fact the various actions take on different values in these enums.
> 
> Introduce helpers to properly map the enum values.
> 
> Signed-off-by: Jim Fehlig <jfehlig@suse.com>
> ---
>  src/libxl/libxl_conf.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++---
>  1 file changed, 59 insertions(+), 3 deletions(-)

ACK

Regards,
Daniel
-- 
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH V3 5/5] libxl: Add a test suite for libxl option generator
  2014-09-04  3:07 ` [PATCH V3 5/5] libxl: Add a test suite for libxl option generator Jim Fehlig
@ 2014-09-11 10:58   ` Daniel P. Berrange
       [not found]   ` <20140911105842.GE7035@redhat.com>
  1 sibling, 0 replies; 15+ messages in thread
From: Daniel P. Berrange @ 2014-09-11 10:58 UTC (permalink / raw)
  To: Jim Fehlig; +Cc: libvir-list, xen-devel

On Wed, Sep 03, 2014 at 09:07:39PM -0600, Jim Fehlig wrote:
> From: "Daniel P. Berrange" <berrange@redhat.com>
> 
> The libxl library allows a libxl_domain_config object to be
> serialized to a JSON string. Use this to allow testing of
> the XML -> libxl_domain_config conversion process
> 
> Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
> Signed-off-by: Jim Fehlig <jfehlig@suse.com>
> ---
>  configure.ac                           |   2 +
>  tests/Makefile.am                      |  25 +++-
>  tests/libxlxml2jsondata/basic-hvm.json | 217 ++++++++++++++++++++++++++++
>  tests/libxlxml2jsondata/basic-hvm.xml  |  36 +++++
>  tests/libxlxml2jsondata/basic-pv.json  | 163 +++++++++++++++++++++
>  tests/libxlxml2jsondata/basic-pv.xml   |  28 ++++
>  tests/libxlxml2jsontest.c              | 251 +++++++++++++++++++++++++++++++++
>  tests/virmocklibxl.c                   |  87 ++++++++++++
>  8 files changed, 808 insertions(+), 1 deletion(-)

> diff --git a/tests/libxlxml2jsontest.c b/tests/libxlxml2jsontest.c
> new file mode 100644
> index 0000000..6ae654a
> --- /dev/null
> +++ b/tests/libxlxml2jsontest.c


> +#if defined LIBXL_HAVE_BUILDINFO_HVM_VENDOR_DEVICE
> +/*
> +* Currently no paths ignored on Xen 4.4
> +*/
> +static const char **ignore_paths = NULL;
> +#elif defined LIBXL_HAVE_DOMAIN_NODEAFFINITY
> +/*
> +* These paths must be ignored if running on Xen 4.3
> +*/
> +static const char *ignore_paths[] = {
> +    "/c_info/pvh",
> +    "/c_info/driver_domain",
> +    "/b_info/device_model_version",
> +    "/b_info/event_channels",
> +    "/b_info/u/kernel",
> +    "/b_info/u/cmdline",
> +    "/b_info/u/ramdisk",
> +    "/b_info/u/bios",
> +    "/b_info/u/timer_mode",
> +    "/b_info/u/vga/kind",
> +    "/b_info/u/spice/vdagent",
> +    "/b_info/u/spice/clipboard_sharing",
> +    "/b_info/u/spice/usbredirection",
> +    "/b_info/u/usbversion",
> +    "/b_info/u/vendor_device",
> +    "/on_watchdog",
> +    NULL
> +};
> +#else
> +/*
> + * These paths must be ignored if running on Xen 4.2
> + */
> +static const char *ignore_paths[] = {
> +    "/c_info/pvh",
> +    "/c_info/driver_domain",
> +    "/b_info/nodemap",
> +    "/b_info/exec_ssidref",
> +    "/b_info/iomem",
> +    "/b_info/claim_mode",
> +    "/b_info/device_model_version",
> +    "/b_info/event_channels",
> +    "/b_info/u/usbdevice_list",
> +    "/b_info/u/kernel",
> +    "/b_info/u/cmdline",
> +    "/b_info/u/ramdisk",
> +    "/b_info/u/bios",
> +    "/b_info/u/timer_mode",
> +    "/b_info/u/vga/kind",
> +    "/b_info/u/spice/vdagent",
> +    "/b_info/u/spice/clipboard_sharing",
> +    "/b_info/u/spice/usbredirection",
> +    "/b_info/u/usbversion",
> +    "/b_info/u/vendor_device",
> +    "/disks/backend_domname",
> +    "/nics/backend_domname",
> +    "/nics/gatewaydev",
> +    "/vfbs/backend_domname",
> +    "/vkbs/backend_domname",
> +    "/vtpms",
> +    "/on_watchdog",
> +    NULL
> +};
> +#endif

As more & more versions of Xen are released I think we might
end up with quite alot of duplication between these lists.
Could we structure it a little differently to avoid this
perhaps in this way:


   #if defined LIBXL_HAVE_BUILDINFO_HVM_VENDOR_DEVICE
   # define LIBXL_VERSION 4004
   #elif define LIBXL_HAVE_DOMAIN_NODEAFFINITY
   # define LIBXL_VERSION 4003
   #else
   # define LIBXL_VERSION 4002
   #endif

   static const char *ignore_paths[] = {
   #if LIBXL_VERSION < 4004
       "/c_info/pvh",
       "/c_info/driver_domain",
       "/b_info/device_model_version",
       "/b_info/event_channels",
       "/b_info/u/kernel",
       "/b_info/u/cmdline",
       "/b_info/u/ramdisk",
       "/b_info/u/bios",
       "/b_info/u/timer_mode",
       "/b_info/u/vga/kind",
       "/b_info/u/spice/vdagent",
       "/b_info/u/spice/clipboard_sharing",
       "/b_info/u/spice/usbredirection",
       "/b_info/u/usbversion",
       "/b_info/u/vendor_device",
       "/on_watchdog",
   #endif
   #if LIBXL_VERSION < 4003
       "/b_info/nodemap",
       "/b_info/exec_ssidref",
       "/b_info/iomem",
       "/b_info/claim_mode",
       "/b_info/u/usbdevice_list",
       "/disks/backend_domname",
       "/nics/backend_domname",
       "/nics/gatewaydev",
       "/vfbs/backend_domname",
       "/vkbs/backend_domname",
       "/vtpms",
   #endif
       NULL
   };



Regards,
Daniel
-- 
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [libvirt] [PATCH V3 4/5] libxl: fix mapping of lifecycle actions
       [not found]   ` <20140911104716.GD7035@redhat.com>
@ 2014-09-11 21:56     ` Jim Fehlig
  0 siblings, 0 replies; 15+ messages in thread
From: Jim Fehlig @ 2014-09-11 21:56 UTC (permalink / raw)
  To: Daniel P. Berrange; +Cc: libvir-list, xen-devel

Daniel P. Berrange wrote:
> On Wed, Sep 03, 2014 at 09:07:38PM -0600, Jim Fehlig wrote:
>   
>> The libxl driver was blindly assigning libvirt's
>> virDomainLifecycleAction to libxl's libxl_action_on_shutdown, when
>> in fact the various actions take on different values in these enums.
>>
>> Introduce helpers to properly map the enum values.
>>
>> Signed-off-by: Jim Fehlig <jfehlig@suse.com>
>> ---
>>  src/libxl/libxl_conf.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++---
>>  1 file changed, 59 insertions(+), 3 deletions(-)
>>     
>
> ACK
>   

Thanks.  I've pushed 2-4.

Regards,
Jim

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH V3 1/5] util: Introduce virJSONStringCompare for JSON doc comparisons
       [not found]   ` <20140911104519.GA7035@redhat.com>
@ 2014-09-11 21:57     ` Jim Fehlig
  0 siblings, 0 replies; 15+ messages in thread
From: Jim Fehlig @ 2014-09-11 21:57 UTC (permalink / raw)
  To: Daniel P. Berrange; +Cc: libvir-list, xen-devel

Daniel P. Berrange wrote:
> On Wed, Sep 03, 2014 at 09:07:35PM -0600, Jim Fehlig wrote:
>   
>> From: "Daniel P. Berrange" <berrange@redhat.com>
>>
>> Comparing JSON docs using strcmp is simple, but is not flexible
>> as it is sensitive to whitespace used in the doc generation.
>> When comparing objects it may also be desirable to treat the
>> existance of keys in the actual object but not expected object
>> as non-fatal. Introduce a virJSONStringCompare function which
>> takes two strings representing expected and actual JSON docs
>> and then does a DOM comparison.  Comparison is controled with
>> the ignore_contexts and flags parameters.  No comparison is
>> done on context paths specified in ignore_contexts.  The
>> VIR_JSON_COMPARE_IGNORE_EXPECTED_NULL flag can be used to
>> ignore actual values that have changed from an expected value
>> of null.
>>
>> Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
>> Signed-off-by: Jim Fehlig <jfehlig@suse.com>
>> ---
>>  src/libvirt_private.syms |   1 +
>>  src/util/virjson.c       | 242 +++++++++++++++++++++++++++++++++++++++++++++++
>>  src/util/virjson.h       |  16 ++++
>>  3 files changed, 259 insertions(+)
>>     
>
> Looks good, but perhaps we should also add to tests/virjsontest.c
> to verify the ignore context support is working as intended
>   

Yes, good idea.  I'll include that in V4.

Regards,
Jim

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH V3 4/5] libxl: fix mapping of lifecycle actions
       [not found] ` <1409800059-16884-5-git-send-email-jfehlig@suse.com>
  2014-09-11 10:47   ` [libvirt] [PATCH V3 4/5] libxl: fix mapping of lifecycle actions Daniel P. Berrange
       [not found]   ` <20140911104716.GD7035@redhat.com>
@ 2014-09-11 21:59   ` Jim Fehlig
  2 siblings, 0 replies; 15+ messages in thread
From: Jim Fehlig @ 2014-09-11 21:59 UTC (permalink / raw)
  To: libvir-list; +Cc: xen-devel

Jim Fehlig wrote:
> The libxl driver was blindly assigning libvirt's
> virDomainLifecycleAction to libxl's libxl_action_on_shutdown, when
> in fact the various actions take on different values in these enums.
>
> Introduce helpers to properly map the enum values.
>   

BTW, forgot to mention that this is the first bug found by the proposed
unit tests :-).

Regards,
Jim

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH V3 5/5] libxl: Add a test suite for libxl option generator
       [not found]   ` <20140911105842.GE7035@redhat.com>
@ 2014-09-11 22:01     ` Jim Fehlig
  0 siblings, 0 replies; 15+ messages in thread
From: Jim Fehlig @ 2014-09-11 22:01 UTC (permalink / raw)
  To: Daniel P. Berrange; +Cc: libvir-list, xen-devel

Daniel P. Berrange wrote:
> On Wed, Sep 03, 2014 at 09:07:39PM -0600, Jim Fehlig wrote:
>   
>> From: "Daniel P. Berrange" <berrange@redhat.com>
>>
>> The libxl library allows a libxl_domain_config object to be
>> serialized to a JSON string. Use this to allow testing of
>> the XML -> libxl_domain_config conversion process
>>
>> Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
>> Signed-off-by: Jim Fehlig <jfehlig@suse.com>
>> ---
>>  configure.ac                           |   2 +
>>  tests/Makefile.am                      |  25 +++-
>>  tests/libxlxml2jsondata/basic-hvm.json | 217 ++++++++++++++++++++++++++++
>>  tests/libxlxml2jsondata/basic-hvm.xml  |  36 +++++
>>  tests/libxlxml2jsondata/basic-pv.json  | 163 +++++++++++++++++++++
>>  tests/libxlxml2jsondata/basic-pv.xml   |  28 ++++
>>  tests/libxlxml2jsontest.c              | 251 +++++++++++++++++++++++++++++++++
>>  tests/virmocklibxl.c                   |  87 ++++++++++++
>>  8 files changed, 808 insertions(+), 1 deletion(-)
>>     
>
>   
>> diff --git a/tests/libxlxml2jsontest.c b/tests/libxlxml2jsontest.c
>> new file mode 100644
>> index 0000000..6ae654a
>> --- /dev/null
>> +++ b/tests/libxlxml2jsontest.c
>>     
>
>
>   
>> +#if defined LIBXL_HAVE_BUILDINFO_HVM_VENDOR_DEVICE
>> +/*
>> +* Currently no paths ignored on Xen 4.4
>> +*/
>> +static const char **ignore_paths = NULL;
>> +#elif defined LIBXL_HAVE_DOMAIN_NODEAFFINITY
>> +/*
>> +* These paths must be ignored if running on Xen 4.3
>> +*/
>> +static const char *ignore_paths[] = {
>> +    "/c_info/pvh",
>> +    "/c_info/driver_domain",
>> +    "/b_info/device_model_version",
>> +    "/b_info/event_channels",
>> +    "/b_info/u/kernel",
>> +    "/b_info/u/cmdline",
>> +    "/b_info/u/ramdisk",
>> +    "/b_info/u/bios",
>> +    "/b_info/u/timer_mode",
>> +    "/b_info/u/vga/kind",
>> +    "/b_info/u/spice/vdagent",
>> +    "/b_info/u/spice/clipboard_sharing",
>> +    "/b_info/u/spice/usbredirection",
>> +    "/b_info/u/usbversion",
>> +    "/b_info/u/vendor_device",
>> +    "/on_watchdog",
>> +    NULL
>> +};
>> +#else
>> +/*
>> + * These paths must be ignored if running on Xen 4.2
>> + */
>> +static const char *ignore_paths[] = {
>> +    "/c_info/pvh",
>> +    "/c_info/driver_domain",
>> +    "/b_info/nodemap",
>> +    "/b_info/exec_ssidref",
>> +    "/b_info/iomem",
>> +    "/b_info/claim_mode",
>> +    "/b_info/device_model_version",
>> +    "/b_info/event_channels",
>> +    "/b_info/u/usbdevice_list",
>> +    "/b_info/u/kernel",
>> +    "/b_info/u/cmdline",
>> +    "/b_info/u/ramdisk",
>> +    "/b_info/u/bios",
>> +    "/b_info/u/timer_mode",
>> +    "/b_info/u/vga/kind",
>> +    "/b_info/u/spice/vdagent",
>> +    "/b_info/u/spice/clipboard_sharing",
>> +    "/b_info/u/spice/usbredirection",
>> +    "/b_info/u/usbversion",
>> +    "/b_info/u/vendor_device",
>> +    "/disks/backend_domname",
>> +    "/nics/backend_domname",
>> +    "/nics/gatewaydev",
>> +    "/vfbs/backend_domname",
>> +    "/vkbs/backend_domname",
>> +    "/vtpms",
>> +    "/on_watchdog",
>> +    NULL
>> +};
>> +#endif
>>     
>
> As more & more versions of Xen are released I think we might
> end up with quite alot of duplication between these lists.
> Could we structure it a little differently to avoid this
> perhaps in this way:
>   

Yes, your suggestion is much better.  I meant to make a similar change
before sending this patch...

Regards,
Jim

>
>    #if defined LIBXL_HAVE_BUILDINFO_HVM_VENDOR_DEVICE
>    # define LIBXL_VERSION 4004
>    #elif define LIBXL_HAVE_DOMAIN_NODEAFFINITY
>    # define LIBXL_VERSION 4003
>    #else
>    # define LIBXL_VERSION 4002
>    #endif
>
>    static const char *ignore_paths[] = {
>    #if LIBXL_VERSION < 4004
>        "/c_info/pvh",
>        "/c_info/driver_domain",
>        "/b_info/device_model_version",
>        "/b_info/event_channels",
>        "/b_info/u/kernel",
>        "/b_info/u/cmdline",
>        "/b_info/u/ramdisk",
>        "/b_info/u/bios",
>        "/b_info/u/timer_mode",
>        "/b_info/u/vga/kind",
>        "/b_info/u/spice/vdagent",
>        "/b_info/u/spice/clipboard_sharing",
>        "/b_info/u/spice/usbredirection",
>        "/b_info/u/usbversion",
>        "/b_info/u/vendor_device",
>        "/on_watchdog",
>    #endif
>    #if LIBXL_VERSION < 4003
>        "/b_info/nodemap",
>        "/b_info/exec_ssidref",
>        "/b_info/iomem",
>        "/b_info/claim_mode",
>        "/b_info/u/usbdevice_list",
>        "/disks/backend_domname",
>        "/nics/backend_domname",
>        "/nics/gatewaydev",
>        "/vfbs/backend_domname",
>        "/vkbs/backend_domname",
>        "/vtpms",
>    #endif
>        NULL
>    };
>
>
>
> Regards,
> Daniel
>   

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2014-09-11 22:01 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-04  3:07 [PATCH V3 0/5] Testing libvirt XML -> libxl_domain_config conversion Jim Fehlig
2014-09-04  3:07 ` [PATCH V3 1/5] util: Introduce virJSONStringCompare for JSON doc comparisons Jim Fehlig
2014-09-04  3:07 ` [PATCH V3 2/5] util: Allow port allocator to skip bind() check Jim Fehlig
2014-09-11 10:46   ` Daniel P. Berrange
2014-09-04  3:07 ` [PATCH V3 3/5] tests: Add more test suite mock helpers Jim Fehlig
2014-09-11 10:46   ` Daniel P. Berrange
2014-09-04  3:07 ` [PATCH V3 4/5] libxl: fix mapping of lifecycle actions Jim Fehlig
2014-09-04  3:07 ` [PATCH V3 5/5] libxl: Add a test suite for libxl option generator Jim Fehlig
2014-09-11 10:58   ` Daniel P. Berrange
     [not found]   ` <20140911105842.GE7035@redhat.com>
2014-09-11 22:01     ` Jim Fehlig
     [not found] ` <1409800059-16884-2-git-send-email-jfehlig@suse.com>
2014-09-11 10:45   ` [PATCH V3 1/5] util: Introduce virJSONStringCompare for JSON doc comparisons Daniel P. Berrange
     [not found]   ` <20140911104519.GA7035@redhat.com>
2014-09-11 21:57     ` Jim Fehlig
     [not found] ` <1409800059-16884-5-git-send-email-jfehlig@suse.com>
2014-09-11 10:47   ` [libvirt] [PATCH V3 4/5] libxl: fix mapping of lifecycle actions Daniel P. Berrange
     [not found]   ` <20140911104716.GD7035@redhat.com>
2014-09-11 21:56     ` Jim Fehlig
2014-09-11 21:59   ` Jim Fehlig

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.