From: Ian Campbell Subject: Re: [PATCH RFC V2 09/10] libxl/gentest.py: test JSON parser Date: Tue, 22 Apr 2014 16:47:22 +0100 Message-ID: <1398181642.4880.71.camel@kazak.uk.xensource.com> References: <1397733191-31892-1-git-send-email-wei.liu2@citrix.com> <1397733191-31892-10-git-send-email-wei.liu2@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1397733191-31892-10-git-send-email-wei.liu2@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Wei Liu Cc: ian.jackson@eu.citrix.com, xen-devel@lists.xen.org List-Id: xen-devel@lists.xenproject.org On Thu, 2014-04-17 at 12:13 +0100, Wei Liu wrote: > @@ -240,20 +241,36 @@ int main(int argc, char **argv) > exit(1); > } > """) > - f.write(" printf(\"Testing TYPE_to_json()\\n\");\n") > + f.write(" printf(\"Testing TYPE_to/from_json()\\n\");\n") > f.write(" printf(\"----------------------\\n\");\n") > f.write(" printf(\"\\n\");\n") > for ty in [t for t in types if t.json_gen_fn is not None]: > arg = ty.typename + "_val" > f.write(" %s_rand_init(%s);\n" % (ty.typename, \ > ty.pass_arg(arg, isref=False, passby=idl.PASS_BY_REFERENCE))) > + if not isinstance(ty, idl.Enumeration): > + f.write(" %s_init(%s_new);\n" % (ty.typename, \ > + ty.pass_arg(arg, isref=False, passby=idl.PASS_BY_REFERENCE))) > f.write(" s = %s_to_json(ctx, %s);\n" % \ > (ty.typename, ty.pass_arg(arg, isref=False))) > f.write(" printf(\"%%s: %%s\\n\", \"%s\", s);\n" % ty.typename) > f.write(" if (s == NULL) abort();\n") > + f.write(" rc = %s_from_json(ctx, &%s_val_new, s);\n" % \ > + (ty.typename, ty.typename)) > + f.write(" if (rc) abort();\n") > + f.write(" new_s = %s_to_json(ctx, %s_new);\n" % \ > + (ty.typename, ty.pass_arg(arg, isref=False))) > + f.write(" if (new_s == NULL) abort();\n") > + f.write(" if (strcmp(s, new_s)) {\n") > + f.write(" printf(\"Huh? Regenerated string different from original string.\\n\");\n") > + f.write(" printf(\"Regenerated string: %s\\n\", new_s);\n") This could use some hint as to which struct went wrong. Perhaps including the original string too for comparison?