summaryrefslogtreecommitdiff
path: root/gentest.py
diff options
context:
space:
mode:
authorMike Hommey <mh@glandium.org>2005-02-05 12:06:19 +0000
committerMike Hommey <mh@glandium.org>2005-02-05 12:06:19 +0000
commita7457388701e6ccba9091ba3ec09505dc903b758 (patch)
tree80a7d0fba3968fee73cc71a62ffe1af039396f29 /gentest.py
parentf51dd67f3a3f472af0620391eb588eeca4533689 (diff)
downloadlibxml2-a7457388701e6ccba9091ba3ec09505dc903b758.tar.gz
Load /tmp/tmp.5kkLmZ/libxml2-2.6.17 intoupstream/2.6.17
packages/libxml2/branches/upstream/current.
Diffstat (limited to 'gentest.py')
-rwxr-xr-xgentest.py133
1 files changed, 93 insertions, 40 deletions
diff --git a/gentest.py b/gentest.py
index 8975cd9..12dd718 100755
--- a/gentest.py
+++ b/gentest.py
@@ -11,8 +11,13 @@ except:
print "libxml2 python bindings not available, skipping testapi.c generation"
sys.exit(0)
+if len(sys.argv) > 1:
+ srcPref = sys.argv[1] + '/'
+else:
+ srcPref = ''
+
#
-# Modules we don't want skip in API test
+# Modules we want to skip in API test
#
skipped_modules = [ "SAX", "xlink", "threads", "globals",
"xmlmemory", "xmlversion", "xmlexports",
@@ -39,6 +44,7 @@ modules_defines = {
"xmlautomata" : "LIBXML_AUTOMATA_ENABLED",
"xmlsave" : "LIBXML_OUTPUT_ENABLED",
"DOCBparser" : "LIBXML_DOCB_ENABLED",
+ "xmlmodule" : "LIBXML_MODULES_ENABLED",
}
#
@@ -96,7 +102,7 @@ function_defines = {
}
#
-# Some function really need to be skipped for the tests.
+# Some functions really need to be skipped for the tests.
#
skipped_functions = [
# block on I/O
@@ -156,7 +162,7 @@ skipped_functions = [
]
#
-# Those functions have side effect on the global state
+# These functions have side effects on the global state
# and hence generate errors on memory allocation tests
#
skipped_memcheck = [ "xmlLoadCatalog", "xmlAddEncodingAlias",
@@ -165,7 +171,7 @@ skipped_memcheck = [ "xmlLoadCatalog", "xmlAddEncodingAlias",
"xmlCatalogRemove", "xmlLoadCatalogs", "xmlCleanupCharEncodingHandlers",
"xmlInitCharEncodingHandlers", "xmlCatalogCleanup",
"xmlSchemaGetBuiltInType",
- "htmlParseFile", # loads the catalogs
+ "htmlParseFile", "htmlCtxtReadFile" # loads the catalogs
]
#
@@ -331,15 +337,15 @@ def type_convert(str, name, info, module, function, pos):
if function == 'xmlIOHTTPOpenW':
return('xmlNanoHTTPCtxtPtr')
if string.find(name, "data") != -1:
- return('userdata');
+ return('userdata')
if string.find(name, "user") != -1:
- return('userdata');
+ return('userdata')
if res == 'xmlDoc_ptr':
- res = 'xmlDocPtr';
+ res = 'xmlDocPtr'
if res == 'xmlNode_ptr':
- res = 'xmlNodePtr';
+ res = 'xmlNodePtr'
if res == 'xmlDict_ptr':
- res = 'xmlDictPtr';
+ res = 'xmlDictPtr'
if res == 'xmlNodePtr' and pos != 0:
if (function == 'xmlAddChild' and pos == 2) or \
(function == 'xmlAddChildList' and pos == 2) or \
@@ -351,7 +357,7 @@ def type_convert(str, name, info, module, function, pos):
(function == 'xmlAddPrevSibling' and pos == 2):
return('xmlNodePtr_in');
if res == 'const xmlBufferPtr':
- res = 'xmlBufferPtr';
+ res = 'xmlBufferPtr'
if res == 'xmlChar_ptr' and name == 'name' and \
string.find(function, "EatName") != -1:
return('eaten_name')
@@ -370,7 +376,7 @@ def type_convert(str, name, info, module, function, pos):
if res == 'int' and name == 'options':
if module == 'parser' or module == 'xmlreader':
res = 'parseroptions'
-
+
return res
known_param_types = []
@@ -425,17 +431,26 @@ def is_known_return_type(name):
# Copy the beginning of the C test program result
#
-input = open("testapi.c", "r")
+try:
+ input = open("testapi.c", "r")
+except:
+ input = open(srcPref + "testapi.c", "r")
test = open('testapi.c.new', 'w')
def compare_and_save():
global test
test.close()
- input = open("testapi.c", "r").read()
+ try:
+ input = open("testapi.c", "r").read()
+ except:
+ input = ''
test = open('testapi.c.new', "r").read()
if input != test:
- os.system("rm testapi.c ; mv testapi.c.new testapi.c")
+ try:
+ os.system("rm testapi.c; mv testapi.c.new testapi.c")
+ except:
+ os.system("mv testapi.c.new testapi.c")
print("Updated testapi.c")
else:
print("Generated testapi.c is identical")
@@ -467,24 +482,53 @@ test.write("/* CUT HERE: everything below that line is generated */\n")
#
# Open the input API description
#
-doc = libxml2.readFile('doc/libxml2-api.xml', None, 0)
+doc = libxml2.readFile(srcPref + 'doc/libxml2-api.xml', None, 0)
if doc == None:
print "Failed to load doc/libxml2-api.xml"
sys.exit(1)
ctxt = doc.xpathNewContext()
#
+# Generate a list of all function parameters and select only
+# those used in the api tests
+#
+argtypes = {}
+args = ctxt.xpathEval("/api/symbols/function/arg")
+for arg in args:
+ mod = arg.xpathEval('string(../@file)')
+ func = arg.xpathEval('string(../@name)')
+ if (mod not in skipped_modules) and (func not in skipped_functions):
+ type = arg.xpathEval('string(@type)')
+ if not argtypes.has_key(type):
+ argtypes[type] = func
+
+# similarly for return types
+rettypes = {}
+rets = ctxt.xpathEval("/api/symbols/function/return")
+for ret in rets:
+ mod = ret.xpathEval('string(../@file)')
+ func = ret.xpathEval('string(../@name)')
+ if (mod not in skipped_modules) and (func not in skipped_functions):
+ type = ret.xpathEval('string(@type)')
+ if not rettypes.has_key(type):
+ rettypes[type] = func
+
+#
# Generate constructors and return type handling for all enums
+# which are used as function parameters
#
enums = ctxt.xpathEval("/api/symbols/typedef[@type='enum']")
for enum in enums:
+ module = enum.xpathEval('string(@file)')
name = enum.xpathEval('string(@name)')
- if name == None:
+ #
+ # Skip any enums which are not in our filtered lists
+ #
+ if (name == None) or ((name not in argtypes) and (name not in rettypes)):
continue;
- module = enum.xpathEval('string(@file)')
define = 0
- if is_known_param_type(name, name) == 0:
+ if argtypes.has_key(name) and is_known_param_type(name, name) == 0:
values = ctxt.xpathEval("/api/symbols/enum[@type='%s']" % name)
i = 0
vals = []
@@ -497,7 +541,7 @@ for enum in enums:
break;
vals.append(vname)
if vals == []:
- print "Didn't found any value for enum %s" % (name)
+ print "Didn't find any value for enum %s" % (name)
continue
if modules_defines.has_key(module):
test.write("#ifdef %s\n" % (modules_defines[module]))
@@ -511,19 +555,21 @@ for enum in enums:
i = i + 1
test.write(""" return(0);
}
-""");
+
+static void des_%s(int no ATTRIBUTE_UNUSED, %s val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
+}
+
+""" % (name, name));
known_param_types.append(name)
- if is_known_return_type(name) == 0:
+ if (is_known_return_type(name) == 0) and (name in rettypes):
if define == 0 and modules_defines.has_key(module):
test.write("#ifdef %s\n" % (modules_defines[module]))
define = 1
- test.write("""static void des_%s(int no ATTRIBUTE_UNUSED, %s val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {
-}
-static void desret_%s(%s val ATTRIBUTE_UNUSED) {
+ test.write("""static void desret_%s(%s val ATTRIBUTE_UNUSED) {
}
-""" % (name, name, name, name))
+""" % (name, name))
known_return_types.append(name)
if define == 1:
test.write("#endif\n\n")
@@ -628,7 +674,12 @@ def generate_test(module, node):
if is_known_param_type(type, rtype) == 0:
add_missing_type(type, name);
no_gen = 1
- t_args.append((nam, type, rtype, info))
+ if (type[-3:] == 'Ptr' or type[-4:] == '_ptr') and \
+ rtype[0:6] == 'const ':
+ crtype = rtype[6:]
+ else:
+ crtype = rtype
+ t_args.append((nam, type, rtype, crtype, info))
try:
rets = node.xpathEval("return")
@@ -667,7 +718,7 @@ test_%s(void) {
try:
conds = node.xpathEval("cond")
for cond in conds:
- test.write("#ifdef %s\n" % (cond.get_content()))
+ test.write("#if %s\n" % (cond.get_content()))
nb_cond = nb_cond + 1
except:
pass
@@ -688,12 +739,7 @@ test_%s(void) {
# Declare the arguments
for arg in t_args:
- (nam, type, rtype, info) = arg;
- if (type[-3:] == 'Ptr' or type[-4:] == '_ptr') and \
- rtype[0:6] == 'const ':
- crtype = rtype[6:]
- else:
- crtype = rtype
+ (nam, type, rtype, crtype, info) = arg;
# add declaration
test.write(" %s %s; /* %s */\n" % (crtype, nam, info))
test.write(" int n_%s;\n" % (nam))
@@ -701,7 +747,7 @@ test_%s(void) {
# Cascade loop on of each argument list of values
for arg in t_args:
- (nam, type, rtype, info) = arg;
+ (nam, type, rtype, crtype, info) = arg;
#
test.write(" for (n_%s = 0;n_%s < gen_nb_%s;n_%s++) {\n" % (
nam, nam, type, nam))
@@ -713,7 +759,7 @@ test_%s(void) {
# prepare the call
i = 0;
for arg in t_args:
- (nam, type, rtype, info) = arg;
+ (nam, type, rtype, crtype, info) = arg;
#
test.write(" %s = gen_%s(n_%s, %d);\n" % (nam, type, nam, i))
i = i + 1;
@@ -725,11 +771,13 @@ test_%s(void) {
test.write("\n ret_val = %s(" % (name))
need = 0
for arg in t_args:
- (nam, type, rtype, info) = arg
+ (nam, type, rtype, crtype, info) = arg
if need:
test.write(", ")
else:
need = 1
+ if rtype != crtype:
+ test.write("(%s)" % rtype)
test.write("%s" % nam);
test.write(");\n")
if extra_post_call.has_key(name):
@@ -739,11 +787,13 @@ test_%s(void) {
test.write("\n %s(" % (name));
need = 0;
for arg in t_args:
- (nam, type, rtype, info) = arg;
+ (nam, type, rtype, crtype, info) = arg;
if need:
test.write(", ")
else:
need = 1
+ if rtype != crtype:
+ test.write("(%s)" % rtype)
test.write("%s" % nam)
test.write(");\n")
if extra_post_call.has_key(name):
@@ -754,9 +804,12 @@ test_%s(void) {
# Free the arguments
i = 0;
for arg in t_args:
- (nam, type, rtype, info) = arg;
+ (nam, type, rtype, crtype, info) = arg;
#
- test.write(" des_%s(n_%s, %s, %d);\n" % (type, nam, nam, i))
+ test.write(" des_%s(n_%s, " % (type, nam))
+ if rtype != crtype:
+ test.write("(%s)" % rtype)
+ test.write("%s, %d);\n" % (nam, i))
i = i + 1;
test.write(" xmlResetLastError();\n");
@@ -768,7 +821,7 @@ test_%s(void) {
test_ret++;
""" % (name));
for arg in t_args:
- (nam, type, rtype, info) = arg;
+ (nam, type, rtype, crtype, info) = arg;
test.write(""" printf(" %%d", n_%s);\n""" % (nam))
test.write(""" printf("\\n");\n""")
test.write(" }\n")