summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Kletzander <mkletzan@redhat.com>2014-10-06 12:26:27 +0200
committerMartin Kletzander <mkletzan@redhat.com>2014-10-06 17:20:32 +0200
commit09b157076f24ef4eedbb60466087b44612517c8b (patch)
tree721682e96623a2b469ba6a721a917c13edc887af
parentc34113f9f676dbfacf458bab204e52186d2bf59a (diff)
downloadlibvirt-python-09b157076f24ef4eedbb60466087b44612517c8b.tar.gz
sanitytest: check for exported enums
We are already collecting list of enums exported and list of enums we want to have available. Event though there was an issue with one enum fixed with 014d9bbaf368b33a881f1d6b2fd8a5dd285a4f71, there was no test for it and this commit tries to fix that. Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
-rw-r--r--sanitytest.py53
1 files changed, 51 insertions, 2 deletions
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]