diff --git a/sanitytest.py b/sanitytest.py index 3c1568b..8cb0154 100644 --- a/sanitytest.py +++ b/sanitytest.py @@ -16,7 +16,10 @@ f = open(xml, "r") tree = lxml.etree.parse(f) verbose = False +fail = False +enumvals = {} +second_pass = [] wantenums = [] wantfunctions = [] @@ -25,11 +28,51 @@ set = tree.xpath('/api/files/file/exports[@type="function"]/@symbol') for n in set: wantfunctions.append(n) +set = tree.xpath('/api/symbols/enum') +for n in set: + typ = n.attrib['type'] + name = n.attrib['name'] + val = n.attrib['value'] + + if typ not in enumvals: + enumvals[typ] = {} + + # If the value cannot be converted to int, it is reference to + # another enum and needs to be sorted out later on + try: + val = int(val) + except ValueError: + second_pass.append(n) + continue + + enumvals[typ][name] = int(val) + +for n in second_pass: + typ = n.attrib['type'] + name = n.attrib['name'] + val = n.attrib['value'] + + for v in enumvals.values(): + if val in v: + val = int(v[val]) + break + + if type(val) != int: + fail = True + print("Cannot get a value of enum %s (originally %s)" % (val, name)) + enumvals[typ][name] = val + set = tree.xpath('/api/files/file/exports[@type="enum"]/@symbol') for n in set: + for enumval in enumvals.values(): + if n in enumval: + enum = enumval + break + # Eliminate sentinels + if n.endswith('_LAST') and enum[n] == max(enum.values()): + continue wantenums.append(n) - # Phase 2: Identify all classes and methods in the 'libvirt' python module gotenums = [] gottypes = [] @@ -51,6 +94,13 @@ for name in dir(libvirt): else: pass +for enum in wantenums: + if enum not in gotenums: + fail = True + for typ, enumval in enumvals.items(): + if enum in enumval: + print("FAIL Missing exported enum %s of type %s" % (enum, typ)) + for klassname in gottypes: klassobj = getattr(libvirt, klassname) for name in dir(klassobj): @@ -241,7 +291,6 @@ for name in sorted(basicklassmap): # Phase 5: Validate sure that every C API is mapped to a python API -fail = False usedfunctions = {} for name in sorted(finalklassmap): klass = finalklassmap[name][0]