# HG changeset patch # User Ian Campbell # Date 1307109705 -3600 # Node ID b433d9d9716fa8deccb565bc822703817768d588 # Parent 03f8d29478ef61137d318ccc3d37d938828d2bcd imported patch libxl-debug-test-enum-strings.patch diff -r 03f8d29478ef -r b433d9d9716f tools/libxl/Makefile --- a/tools/libxl/Makefile Fri Jun 03 14:59:31 2011 +0100 +++ b/tools/libxl/Makefile Fri Jun 03 15:01:45 2011 +0100 @@ -44,12 +44,17 @@ AUTOSRCS= libxlu_cfg_y.c libxlu_cfg_l.c LIBXLU_OBJS = libxlu_cfg_y.o libxlu_cfg_l.o libxlu_cfg.o $(LIBXLU_OBJS): CFLAGS += $(CFLAGS_libxenctrl) # For xentoollog.h -CLIENTS = xl +CLIENTS = xl testenum XL_OBJS = xl.o xl_cmdimpl.o xl_cmdtable.o $(XL_OBJS): CFLAGS += $(CFLAGS_libxenctrl) # For xentoollog.h $(XL_OBJS): CFLAGS += $(CFLAGS_libxenlight) +testenum.o: CFLAGS += $(CFLAGS_libxenctrl) $(CFLAGS_libxenlight) +testenum.c: libxl.idl gentest.py + $(PYTHON) gentest.py libxl.idl testenum.c.new + mv testenum.c.new testenum.c + .PHONY: all all: $(CLIENTS) libxenlight.so libxenlight.a libxlutil.so libxlutil.a \ $(AUTOSRCS) $(AUTOINCS) @@ -106,9 +111,12 @@ libxlutil.so.$(XLUMAJOR).$(XLUMINOR): $( libxlutil.a: $(LIBXLU_OBJS) $(AR) rcs libxlutil.a $^ -$(CLIENTS): $(XL_OBJS) libxlutil.so libxenlight.so +xl: $(XL_OBJS) libxlutil.so libxenlight.so $(CC) $(LDFLAGS) -o $@ $(XL_OBJS) libxlutil.so $(LDLIBS_libxenlight) $(LDLIBS_libxenctrl) +testenum: testenum.o libxlutil.so libxenlight.so + $(CC) $(LDFLAGS) -o $@ testenum.o libxlutil.so $(LDLIBS_libxenlight) $(LDLIBS_libxenctrl) + .PHONY: install install: all $(INSTALL_DIR) $(DESTDIR)$(SBINDIR) diff -r 03f8d29478ef -r b433d9d9716f tools/libxl/gentest.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/libxl/gentest.py Fri Jun 03 15:01:45 2011 +0100 @@ -0,0 +1,63 @@ +#!/usr/bin/python + +import sys +import re +import random + +import libxltypes +def randomize_char(c): + if random.random() < 0.5: + return str.lower(c) + else: + return str.upper(c) + +def randomize_case(s): + r = [randomize_char(c) for c in s] + return "".join(r) + +if __name__ == '__main__': + if len(sys.argv) < 3: + print >>sys.stderr, "Usage: gentest.py " + sys.exit(1) + + random.seed() + + idl = sys.argv[1] + (_,types) = libxltypes.parse(idl) + + impl = sys.argv[2] + f = open(impl, "w") + f.write(""" +#include +#include \"libxl.h\" + +int main(int argc, char **argv) +{ +""") + + for ty in [t for t in types if isinstance(t,libxltypes.Enumeration)]: + f.write(" %s %s_val;\n" % (ty.typename, ty.typename)) + f.write(" int rc;\n") + f.write("\n") + + for ty in [t for t in types if isinstance(t,libxltypes.Enumeration)]: + f.write(" printf(\"%s -- to string:\\n\");\n" % (ty.typename)) + for v in ty.values: + f.write(" printf(\"\\t%s = %%d = \\\"%%s\\\"\\n\", %s, %s_to_string(%s));\n" %\ + (v.valuename, v.name, ty.typename, v.name)) + f.write("\n") + + f.write(" printf(\"%s -- from string:\\n\");\n" % (ty.typename)) + for v in [v.valuename for v in ty.values] + ["AN INVALID VALUE"]: + n = randomize_case(v) + f.write(" %s_val = -1;\n" % (ty.typename)) + f.write(" rc = %s_from_string(\"%s\", &%s_val);\n" %\ + (ty.typename, n, ty.typename)) + + f.write(" printf(\"\\t%s = \\\"%%s\\\" = %%d (rc %%d)\\n\", \"%s\", %s_val, rc);\n" %\ + (v, n, ty.typename)) + f.write("\n") + + f.write("""return 0; +} +""")