xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Jim Fehlig <jfehlig@suse.com>
To: "Daniel P. Berrange" <berrange@redhat.com>
Cc: libvir-list@redhat.com, xen-devel@lists.xensource.com,
	Ian Campbell <Ian.Campbell@citrix.com>
Subject: Re: [PATCH 0/5] Testing libvirt XML -> libxl_domain_config conversion
Date: Mon, 02 Jun 2014 16:43:25 -0600	[thread overview]
Message-ID: <538CFE0D.3000700@suse.com> (raw)
In-Reply-To: <20140602124928.GH28039@redhat.com>

Daniel P. Berrange wrote:
> On Mon, Jun 02, 2014 at 01:41:58PM +0100, Ian Campbell wrote:
>   
>>>    I hacked around this, but it is a little dirty too. libvirt
>>>    already links to libyajl for the QEMU driver, but we  don't
>>>    really need the raw YAJL objects. It'd be nice to have a
>>>
>>>       char * libxl_domain_config_as_json(libxl_domain_config *p)
>>>
>>>    as a higher level wrapper around libxl_domain_config_gen_json
>>>    avoiding the pain of dealing with YAJL's different APIs.
>>>
>>>    Ian J mentioned to me that he thought there was already such a
>>>    method, but AFAICT, the only such code is in the 'xl' command
>>>    line tool itself (xl_cmdimpl.c - printf_info_one_json)
>>>       
>> That was me not Ian J I think.
>>     
>
> Opps, my bad, was talking to too many people to remember things clearly :-)
>  
>   
>> The function you need is libxl_domain_config_to_json (which is
>> autogenerated, so in _libxl_types.[hc]). I think the general
>> libxl_*_to_json support has been there since Xen 4.2, but IIRC
>> libxl_domain_config only got moved into the autogenerated/IDL layer in
>> 4.3.
>>     
>
> Ahhh, so I was looking in the wrong place - no wonder 'git grep' failed
> to find it :-)
>   

This patch becomes a bit smaller by using libxl_domain_config_to_json()
- see below diff.  It works with Xen 4.2-4.4, although the test fails on
all but 4.4 due to changes in the json noted earlier (e.g. additional
c_info fields added to the returned json).

Thanks for looking at this btw!  Great topic for the hackathon.  I was
groaning about the need for round-trip config testing last week while
reviewing some other patches, just before you posted this series!  Awesome!

Regards,
Jim


diff --git a/tests/libxlxml2jsontest.c b/tests/libxlxml2jsontest.c
index 02808b7..ed7c256 100644
--- a/tests/libxlxml2jsontest.c
+++ b/tests/libxlxml2jsontest.c
@@ -40,24 +40,11 @@
 # include "virmock.h"
 # include "testutilsxen.h"
 
-# ifdef WITH_YAJL2
-#  define HAVE_YAJL_V2
-# endif
-
-# include <yajl/yajl_gen.h>
-# include <libxl_json.h>
-
 # define VIR_FROM_THIS VIR_FROM_XEN
 
 static const char *abs_top_srcdir;
 static virCapsPtr xencaps;
 
-# ifdef WITH_YAJL2
-#  define yajl_size_t size_t
-# else
-#  define yajl_size_t unsigned int
-# endif
-
 static int testCompareXMLToJSONFiles(const char *xml,
                                      const char *cmdline)
 {
@@ -69,31 +56,10 @@ static int testCompareXMLToJSONFiles(const char *xml,
     libxl_domain_config config;
     xentoollog_logger *log = NULL;
     virDomainXMLOptionPtr xmlopt = NULL;
-    yajl_gen gen;
-# ifndef WITH_YAJL2
-    yajl_gen_config conf = { 1, "    " };
-# endif
-    const unsigned char *actualargv;
-    yajl_size_t actualargvlen;
+    char *actualargv = NULL;
 
     libxl_domain_config_init(&config);
 
-# ifdef WITH_YAJL2
-    gen = yajl_gen_alloc(NULL);
-    if (gen) {
-        yajl_gen_config(gen, yajl_gen_beautify, 1);
-        yajl_gen_config(gen, yajl_gen_indent_string, "    ");
-        yajl_gen_config(gen, yajl_gen_validate_utf8, 1);
-    }
-# else
-    gen = yajl_gen_alloc(&conf, NULL);
-# endif
-    if (!gen) {
-        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                       "Unable to create JSON formatter");
-        goto cleanup;
-    }
-
     if (!(log = (xentoollog_logger
*)xtl_createlogger_stdiostream(stderr, XTL_DEBUG, 0)))
         goto cleanup;
 
@@ -114,24 +80,18 @@ static int testCompareXMLToJSONFiles(const char *xml,
     if (libxlBuildDomainConfig(gports, vmdef, ctx, &config) < 0)
         goto cleanup;
 
-    libxl_domain_config_gen_json(gen, &config);
-
-    if (yajl_gen_get_buf(gen, &actualargv, &actualargvlen) !=
yajl_gen_status_ok) {
-        virReportOOMError();
-        goto cleanup;
-    }
-
+    actualargv = libxl_domain_config_to_json(ctx, &config);
     virtTestLoadFile(cmdline, &expectargv);
 
-    if (STRNEQ(expectargv, (char *)actualargv)) {
-        virtTestDifference(stderr, expectargv, (char *)actualargv);
+    if (STRNEQ(expectargv, actualargv)) {
+        virtTestDifference(stderr, expectargv, actualargv);
         goto cleanup;
     }
 
     ret = 0;
 
  cleanup:
-    yajl_gen_free(gen);
+    VIR_FREE(actualargv);
     VIR_FREE(expectargv);
     virDomainDefFree(vmdef);
     virObjectUnref(gports);

  reply	other threads:[~2014-06-02 22:43 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-30 17:24 [libvirt] [PATCH 0/5] Testing libvirt XML -> libxl_domain_config conversion Daniel P. Berrange
2014-05-30 17:24 ` [libvirt] [PATCH 1/5] Don't pass virDomainObjPtr to libxlBuildDomainConfig Daniel P. Berrange
2014-05-30 22:26   ` Jim Fehlig
2014-05-30 17:24 ` [libvirt] [PATCH 2/5] Don't pass libxlDriverPrivatePtr into libxlBuildDomainConfig Daniel P. Berrange
2014-05-30 22:34   ` Jim Fehlig
2014-05-30 17:24 ` [libvirt] [PATCH 3/5] libxl: Move virDomainXMLOptionNew into libxlCreateXMLConf Daniel P. Berrange
2014-05-30 22:41   ` Jim Fehlig
2014-06-02  9:33     ` Daniel P. Berrange
2014-05-30 17:24 ` [libvirt] [PATCH 4/5] Add more test suite mock helpers Daniel P. Berrange
2014-05-30 17:24 ` [PATCH 5/5] Add a test suite for libxl option generator Daniel P. Berrange
2014-06-02 12:53   ` Ian Campbell
2014-06-02 12:57     ` [libvirt] [Xen-devel] " Daniel P. Berrange
2014-06-02 21:42       ` Jim Fehlig
2014-06-02 12:41 ` [PATCH 0/5] Testing libvirt XML -> libxl_domain_config conversion Ian Campbell
2014-06-02 12:49   ` [libvirt] [Xen-devel] " Daniel P. Berrange
2014-06-02 22:43     ` Jim Fehlig [this message]
2014-06-03  9:26       ` Daniel P. Berrange
2014-06-02 12:57   ` Ian Campbell
2014-06-02 13:15     ` Processed: " xen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=538CFE0D.3000700@suse.com \
    --to=jfehlig@suse.com \
    --cc=Ian.Campbell@citrix.com \
    --cc=berrange@redhat.com \
    --cc=libvir-list@redhat.com \
    --cc=xen-devel@lists.xensource.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).