Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 1 | #!/usr/bin/python -u |
| 2 | # |
| 3 | # generate a tester program for the API |
| 4 | # |
| 5 | import sys |
Daniel Veillard | 34099b4 | 2004-11-04 17:34:35 +0000 | [diff] [blame] | 6 | import os |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 7 | import string |
| 8 | try: |
| 9 | import libxml2 |
| 10 | except: |
| 11 | print "libxml2 python bindings not available, skipping testapi.c generation" |
| 12 | sys.exit(0) |
| 13 | |
| 14 | # |
William M. Brack | 094dd86 | 2004-11-14 14:28:34 +0000 | [diff] [blame] | 15 | # Modules we want to skip in API test |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 16 | # |
Daniel Veillard | 2a4fb5a | 2004-11-08 14:02:18 +0000 | [diff] [blame] | 17 | skipped_modules = [ "SAX", "xlink", "threads", "globals", |
Daniel Veillard | a82b182 | 2004-11-08 16:24:57 +0000 | [diff] [blame] | 18 | "xmlmemory", "xmlversion", "xmlexports", |
| 19 | #deprecated |
| 20 | "DOCBparser", |
Daniel Veillard | d005b9e | 2004-11-03 17:07:05 +0000 | [diff] [blame] | 21 | ] |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 22 | |
| 23 | # |
Daniel Veillard | a521d28 | 2004-11-09 14:59:59 +0000 | [diff] [blame] | 24 | # defines for each module |
| 25 | # |
| 26 | modules_defines = { |
| 27 | "HTMLparser": "LIBXML_HTML_ENABLED", |
| 28 | "catalog": "LIBXML_CATALOG_ENABLED", |
| 29 | "xmlreader": "LIBXML_READER_ENABLED", |
| 30 | "relaxng": "LIBXML_SCHEMAS_ENABLED", |
| 31 | "schemasInternals": "LIBXML_SCHEMAS_ENABLED", |
| 32 | "xmlschemas": "LIBXML_SCHEMAS_ENABLED", |
| 33 | "xmlschemastypes": "LIBXML_SCHEMAS_ENABLED", |
| 34 | "xpath": "LIBXML_XPATH_ENABLED", |
| 35 | "xpathInternals": "LIBXML_XPATH_ENABLED", |
| 36 | "xinclude": "LIBXML_XINCLUDE_ENABLED", |
| 37 | "xpointer": "LIBXML_XPTR_ENABLED", |
| 38 | "xmlregexp" : "LIBXML_REGEXP_ENABLED", |
| 39 | "xmlautomata" : "LIBXML_AUTOMATA_ENABLED", |
| 40 | "xmlsave" : "LIBXML_OUTPUT_ENABLED", |
| 41 | "DOCBparser" : "LIBXML_DOCB_ENABLED", |
| 42 | } |
| 43 | |
| 44 | # |
| 45 | # defines for specific functions |
| 46 | # |
| 47 | function_defines = { |
| 48 | "htmlDefaultSAXHandlerInit": "LIBXML_HTML_ENABLED", |
| 49 | "xmlSAX2EndElement" : "LIBXML_SAX1_ENABLED", |
| 50 | "xmlSAX2StartElement" : "LIBXML_SAX1_ENABLED", |
| 51 | "xmlSAXDefaultVersion" : "LIBXML_SAX1_ENABLED", |
| 52 | "UTF8Toisolat1" : "LIBXML_OUTPUT_ENABLED", |
| 53 | "xmlCleanupPredefinedEntities": "LIBXML_LEGACY_ENABLED", |
| 54 | "xmlInitializePredefinedEntities": "LIBXML_LEGACY_ENABLED", |
| 55 | "xmlSetFeature": "LIBXML_LEGACY_ENABLED", |
| 56 | "xmlGetFeature": "LIBXML_LEGACY_ENABLED", |
| 57 | "xmlGetFeaturesList": "LIBXML_LEGACY_ENABLED", |
| 58 | "xmlIOParseDTD": "LIBXML_VALID_ENABLED", |
| 59 | "xmlParseDTD": "LIBXML_VALID_ENABLED", |
| 60 | "xmlParseDoc": "LIBXML_SAX1_ENABLED", |
| 61 | "xmlParseMemory": "LIBXML_SAX1_ENABLED", |
| 62 | "xmlRecoverDoc": "LIBXML_SAX1_ENABLED", |
| 63 | "xmlParseFile": "LIBXML_SAX1_ENABLED", |
| 64 | "xmlRecoverFile": "LIBXML_SAX1_ENABLED", |
| 65 | "xmlRecoverMemory": "LIBXML_SAX1_ENABLED", |
| 66 | "xmlSAXParseFileWithData": "LIBXML_SAX1_ENABLED", |
| 67 | "xmlSAXParseMemory": "LIBXML_SAX1_ENABLED", |
| 68 | "xmlSAXUserParseMemory": "LIBXML_SAX1_ENABLED", |
| 69 | "xmlSAXParseDoc": "LIBXML_SAX1_ENABLED", |
| 70 | "xmlSAXParseDTD": "LIBXML_SAX1_ENABLED", |
| 71 | "xmlSAXUserParseFile": "LIBXML_SAX1_ENABLED", |
| 72 | "xmlParseEntity": "LIBXML_SAX1_ENABLED", |
| 73 | "xmlParseExternalEntity": "LIBXML_SAX1_ENABLED", |
| 74 | "xmlSAXParseMemoryWithData": "LIBXML_SAX1_ENABLED", |
| 75 | "xmlParseBalancedChunkMemory": "LIBXML_SAX1_ENABLED", |
| 76 | "xmlParseBalancedChunkMemoryRecover": "LIBXML_SAX1_ENABLED", |
| 77 | "xmlSetupParserForBuffer": "LIBXML_SAX1_ENABLED", |
| 78 | "xmlStopParser": "LIBXML_PUSH_ENABLED", |
| 79 | "xmlAttrSerializeTxtContent": "LIBXML_OUTPUT_ENABLED", |
| 80 | "xmlSAXParseFile": "LIBXML_SAX1_ENABLED", |
| 81 | "xmlSAXParseEntity": "LIBXML_SAX1_ENABLED", |
| 82 | "xmlNewTextChild": "LIBXML_TREE_ENABLED", |
| 83 | "xmlNewDocRawNode": "LIBXML_TREE_ENABLED", |
| 84 | "xmlNewProp": "LIBXML_TREE_ENABLED", |
| 85 | "xmlReconciliateNs": "LIBXML_TREE_ENABLED", |
| 86 | "xmlValidateNCName": "LIBXML_TREE_ENABLED", |
| 87 | "xmlValidateNMToken": "LIBXML_TREE_ENABLED", |
| 88 | "xmlValidateName": "LIBXML_TREE_ENABLED", |
| 89 | "xmlNewChild": "LIBXML_TREE_ENABLED", |
| 90 | "xmlValidateQName": "LIBXML_TREE_ENABLED", |
| 91 | "xmlSprintfElementContent": "LIBXML_OUTPUT_ENABLED", |
| 92 | "xmlValidGetPotentialChildren" : "LIBXML_VALID_ENABLED", |
| 93 | "xmlValidGetValidElements" : "LIBXML_VALID_ENABLED", |
| 94 | "docbDefaultSAXHandlerInit" : "LIBXML_DOCB_ENABLED", |
Daniel Veillard | d0cf7f6 | 2004-11-09 16:17:02 +0000 | [diff] [blame] | 95 | "xmlTextReaderPreservePattern" : "LIBXML_PATTERN_ENABLED", |
Daniel Veillard | a521d28 | 2004-11-09 14:59:59 +0000 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | # |
William M. Brack | 094dd86 | 2004-11-14 14:28:34 +0000 | [diff] [blame] | 99 | # Some functions really need to be skipped for the tests. |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 100 | # |
Daniel Veillard | dd6d300 | 2004-11-03 14:20:29 +0000 | [diff] [blame] | 101 | skipped_functions = [ |
| 102 | # block on I/O |
| 103 | "xmlFdRead", "xmlReadFd", "xmlCtxtReadFd", |
| 104 | "htmlFdRead", "htmlReadFd", "htmlCtxtReadFd", |
Daniel Veillard | 1ba06bb | 2004-11-04 12:32:18 +0000 | [diff] [blame] | 105 | "xmlReaderNewFd", "xmlReaderForFd", |
Daniel Veillard | b1b3a3e | 2004-11-03 23:25:47 +0000 | [diff] [blame] | 106 | "xmlIORead", "xmlReadIO", "xmlCtxtReadIO", |
| 107 | "htmlIORead", "htmlReadIO", "htmlCtxtReadIO", |
Daniel Veillard | 27f2010 | 2004-11-05 11:50:11 +0000 | [diff] [blame] | 108 | "xmlReaderNewIO", "xmlBufferDump", "xmlNanoFTPConnect", |
| 109 | "xmlNanoFTPConnectTo", |
Daniel Veillard | 4259532 | 2004-11-08 10:52:06 +0000 | [diff] [blame] | 110 | # Complex I/O APIs |
| 111 | "xmlCreateIOParserCtxt", "xmlParserInputBufferCreateIO", |
| 112 | "xmlRegisterInputCallbacks", "xmlReaderForIO", |
| 113 | "xmlOutputBufferCreateIO", "xmlRegisterOutputCallbacks", |
| 114 | "xmlSaveToIO", |
Daniel Veillard | dd6d300 | 2004-11-03 14:20:29 +0000 | [diff] [blame] | 115 | # library state cleanup, generate false leak informations and other |
| 116 | # troubles, heavillyb tested otherwise. |
Daniel Veillard | ce244ad | 2004-11-05 10:03:46 +0000 | [diff] [blame] | 117 | "xmlCleanupParser", "xmlRelaxNGCleanupTypes", "xmlSetListDoc", |
| 118 | "xmlSetTreeDoc", "xmlUnlinkNode", |
Daniel Veillard | dd6d300 | 2004-11-03 14:20:29 +0000 | [diff] [blame] | 119 | # hard to avoid leaks in the tests |
Daniel Veillard | d5cc0f7 | 2004-11-06 19:24:28 +0000 | [diff] [blame] | 120 | "xmlStrcat", "xmlStrncat", "xmlCatalogAddLocal", "xmlNewTextWriterDoc", |
Daniel Veillard | a82b182 | 2004-11-08 16:24:57 +0000 | [diff] [blame] | 121 | "xmlXPathNewValueTree", "xmlXPathWrapString", |
Daniel Veillard | dd6d300 | 2004-11-03 14:20:29 +0000 | [diff] [blame] | 122 | # unimplemented |
| 123 | "xmlTextReaderReadInnerXml", "xmlTextReaderReadOuterXml", |
Daniel Veillard | d005b9e | 2004-11-03 17:07:05 +0000 | [diff] [blame] | 124 | "xmlTextReaderReadString", |
| 125 | # destructor |
Daniel Veillard | 27f2010 | 2004-11-05 11:50:11 +0000 | [diff] [blame] | 126 | "xmlListDelete", "xmlOutputBufferClose", "xmlNanoFTPClose", |
Daniel Veillard | d005b9e | 2004-11-03 17:07:05 +0000 | [diff] [blame] | 127 | # deprecated |
| 128 | "xmlCatalogGetPublic", "xmlCatalogGetSystem", "xmlEncodeEntities", |
Daniel Veillard | 2a4fb5a | 2004-11-08 14:02:18 +0000 | [diff] [blame] | 129 | "xmlNewGlobalNs", "xmlHandleEntity", "xmlNamespaceParseNCName", |
| 130 | "xmlNamespaceParseNSDef", "xmlNamespaceParseQName", |
| 131 | "xmlParseNamespace", "xmlParseQuotedString", "xmlParserHandleReference", |
| 132 | "xmlScanName", |
Daniel Veillard | a82b182 | 2004-11-08 16:24:57 +0000 | [diff] [blame] | 133 | "xmlDecodeEntities", |
Daniel Veillard | b1b3a3e | 2004-11-03 23:25:47 +0000 | [diff] [blame] | 134 | # allocators |
| 135 | "xmlMemFree", |
Daniel Veillard | c2c894f | 2004-11-07 12:17:35 +0000 | [diff] [blame] | 136 | # verbosity |
Daniel Veillard | a82b182 | 2004-11-08 16:24:57 +0000 | [diff] [blame] | 137 | "xmlCatalogSetDebug", "xmlShellPrintXPathError", "xmlShellPrintNode", |
Daniel Veillard | 2a4fb5a | 2004-11-08 14:02:18 +0000 | [diff] [blame] | 138 | # Internal functions, no user space should really call them |
| 139 | "xmlParseAttribute", "xmlParseAttributeListDecl", "xmlParseName", |
| 140 | "xmlParseNmtoken", "xmlParseEntityValue", "xmlParseAttValue", |
| 141 | "xmlParseSystemLiteral", "xmlParsePubidLiteral", "xmlParseCharData", |
| 142 | "xmlParseExternalID", "xmlParseComment", "xmlParsePITarget", "xmlParsePI", |
| 143 | "xmlParseNotationDecl", "xmlParseEntityDecl", "xmlParseDefaultDecl", |
| 144 | "xmlParseNotationType", "xmlParseEnumerationType", "xmlParseEnumeratedType", |
| 145 | "xmlParseAttributeType", "xmlParseAttributeListDecl", |
| 146 | "xmlParseElementMixedContentDecl", "xmlParseElementChildrenContentDecl", |
| 147 | "xmlParseElementContentDecl", "xmlParseElementDecl", "xmlParseMarkupDecl", |
| 148 | "xmlParseCharRef", "xmlParseEntityRef", "xmlParseReference", |
| 149 | "xmlParsePEReference", "xmlParseDocTypeDecl", "xmlParseAttribute", |
| 150 | "xmlParseStartTag", "xmlParseEndTag", "xmlParseCDSect", "xmlParseContent", |
| 151 | "xmlParseElement", "xmlParseVersionNum", "xmlParseVersionInfo", |
| 152 | "xmlParseEncName", "xmlParseEncodingDecl", "xmlParseSDDecl", |
| 153 | "xmlParseXMLDecl", "xmlParseTextDecl", "xmlParseMisc", |
| 154 | "xmlParseExternalSubset", "xmlParserHandlePEReference", |
| 155 | "xmlSkipBlankChars", |
Daniel Veillard | dd6d300 | 2004-11-03 14:20:29 +0000 | [diff] [blame] | 156 | ] |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 157 | |
| 158 | # |
William M. Brack | 094dd86 | 2004-11-14 14:28:34 +0000 | [diff] [blame] | 159 | # These functions have side effects on the global state |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 160 | # and hence generate errors on memory allocation tests |
| 161 | # |
| 162 | skipped_memcheck = [ "xmlLoadCatalog", "xmlAddEncodingAlias", |
| 163 | "xmlSchemaInitTypes", "xmlNanoFTPProxy", "xmlNanoFTPScanProxy", |
| 164 | "xmlNanoHTTPScanProxy", "xmlResetLastError", "xmlCatalogConvert", |
| 165 | "xmlCatalogRemove", "xmlLoadCatalogs", "xmlCleanupCharEncodingHandlers", |
Daniel Veillard | a03e365 | 2004-11-02 18:45:30 +0000 | [diff] [blame] | 166 | "xmlInitCharEncodingHandlers", "xmlCatalogCleanup", |
Daniel Veillard | 4259532 | 2004-11-08 10:52:06 +0000 | [diff] [blame] | 167 | "xmlSchemaGetBuiltInType", |
| 168 | "htmlParseFile", # loads the catalogs |
Daniel Veillard | a03e365 | 2004-11-02 18:45:30 +0000 | [diff] [blame] | 169 | ] |
| 170 | |
| 171 | # |
| 172 | # Extra code needed for some test cases |
| 173 | # |
Daniel Veillard | 34099b4 | 2004-11-04 17:34:35 +0000 | [diff] [blame] | 174 | extra_pre_call = { |
Daniel Veillard | a521d28 | 2004-11-09 14:59:59 +0000 | [diff] [blame] | 175 | "xmlSAXUserParseFile": """ |
| 176 | #ifdef LIBXML_SAX1_ENABLED |
| 177 | if (sax == (xmlSAXHandlerPtr)&xmlDefaultSAXHandler) user_data = NULL; |
| 178 | #endif |
| 179 | """, |
| 180 | "xmlSAXUserParseMemory": """ |
| 181 | #ifdef LIBXML_SAX1_ENABLED |
| 182 | if (sax == (xmlSAXHandlerPtr)&xmlDefaultSAXHandler) user_data = NULL; |
| 183 | #endif |
| 184 | """, |
| 185 | "xmlParseBalancedChunkMemory": """ |
| 186 | #ifdef LIBXML_SAX1_ENABLED |
| 187 | if (sax == (xmlSAXHandlerPtr)&xmlDefaultSAXHandler) user_data = NULL; |
| 188 | #endif |
| 189 | """, |
| 190 | "xmlParseBalancedChunkMemoryRecover": """ |
| 191 | #ifdef LIBXML_SAX1_ENABLED |
| 192 | if (sax == (xmlSAXHandlerPtr)&xmlDefaultSAXHandler) user_data = NULL; |
| 193 | #endif |
| 194 | """, |
Daniel Veillard | d5cc0f7 | 2004-11-06 19:24:28 +0000 | [diff] [blame] | 195 | "xmlParserInputBufferCreateFd": |
| 196 | "if (fd >= 0) fd = -1;", |
Daniel Veillard | 34099b4 | 2004-11-04 17:34:35 +0000 | [diff] [blame] | 197 | } |
Daniel Veillard | a03e365 | 2004-11-02 18:45:30 +0000 | [diff] [blame] | 198 | extra_post_call = { |
| 199 | "xmlAddChild": |
| 200 | "if (ret_val == NULL) { xmlFreeNode(cur) ; cur = NULL ; }", |
| 201 | "xmlAddChildList": |
| 202 | "if (ret_val == NULL) { xmlFreeNodeList(cur) ; cur = NULL ; }", |
| 203 | "xmlAddSibling": |
| 204 | "if (ret_val == NULL) { xmlFreeNode(elem) ; elem = NULL ; }", |
| 205 | "xmlAddNextSibling": |
| 206 | "if (ret_val == NULL) { xmlFreeNode(elem) ; elem = NULL ; }", |
| 207 | "xmlAddPrevSibling": |
| 208 | "if (ret_val == NULL) { xmlFreeNode(elem) ; elem = NULL ; }", |
| 209 | "xmlDocSetRootElement": |
| 210 | "if (doc == NULL) { xmlFreeNode(root) ; root = NULL ; }", |
| 211 | "xmlReplaceNode": |
Daniel Veillard | ce244ad | 2004-11-05 10:03:46 +0000 | [diff] [blame] | 212 | """if (cur != NULL) { |
| 213 | xmlUnlinkNode(cur); |
| 214 | xmlFreeNode(cur) ; cur = NULL ; } |
| 215 | if (old != NULL) { |
| 216 | xmlUnlinkNode(old); |
| 217 | xmlFreeNode(old) ; old = NULL ; } |
| 218 | ret_val = NULL;""", |
Daniel Veillard | a03e365 | 2004-11-02 18:45:30 +0000 | [diff] [blame] | 219 | "xmlTextMerge": |
| 220 | """if ((first != NULL) && (first->type != XML_TEXT_NODE)) { |
Daniel Veillard | ce244ad | 2004-11-05 10:03:46 +0000 | [diff] [blame] | 221 | xmlUnlinkNode(second); |
Daniel Veillard | a03e365 | 2004-11-02 18:45:30 +0000 | [diff] [blame] | 222 | xmlFreeNode(second) ; second = NULL ; }""", |
Daniel Veillard | 8a32fe4 | 2004-11-02 22:10:16 +0000 | [diff] [blame] | 223 | "xmlBuildQName": |
| 224 | """if ((ret_val != NULL) && (ret_val != ncname) && |
| 225 | (ret_val != prefix) && (ret_val != memory)) |
| 226 | xmlFree(ret_val); |
| 227 | ret_val = NULL;""", |
Daniel Veillard | 1ba06bb | 2004-11-04 12:32:18 +0000 | [diff] [blame] | 228 | "xmlDictReference": "xmlDictFree(dict);", |
Daniel Veillard | 3d97e66 | 2004-11-04 10:49:00 +0000 | [diff] [blame] | 229 | # Functions which deallocates one of their parameters |
| 230 | "xmlXPathConvertBoolean": """val = NULL;""", |
| 231 | "xmlXPathConvertNumber": """val = NULL;""", |
| 232 | "xmlXPathConvertString": """val = NULL;""", |
| 233 | "xmlSaveFileTo": """buf = NULL;""", |
Daniel Veillard | 34099b4 | 2004-11-04 17:34:35 +0000 | [diff] [blame] | 234 | "xmlSaveFormatFileTo": """buf = NULL;""", |
| 235 | "xmlIOParseDTD": "input = NULL;", |
Daniel Veillard | ce244ad | 2004-11-05 10:03:46 +0000 | [diff] [blame] | 236 | "xmlRemoveProp": "cur = NULL;", |
Daniel Veillard | d5cc0f7 | 2004-11-06 19:24:28 +0000 | [diff] [blame] | 237 | "xmlNewNs": "if ((node == NULL) && (ret_val != NULL)) xmlFreeNs(ret_val);", |
| 238 | "xmlCopyNamespace": "if (ret_val != NULL) xmlFreeNs(ret_val);", |
| 239 | "xmlCopyNamespaceList": "if (ret_val != NULL) xmlFreeNsList(ret_val);", |
| 240 | "xmlNewTextWriter": "if (ret_val != NULL) out = NULL;", |
Daniel Veillard | a521d28 | 2004-11-09 14:59:59 +0000 | [diff] [blame] | 241 | "xmlNewTextWriterPushParser": "if (ctxt != NULL) {xmlFreeDoc(ctxt->myDoc); ctxt->myDoc = NULL;} if (ret_val != NULL) ctxt = NULL;", |
Daniel Veillard | 4259532 | 2004-11-08 10:52:06 +0000 | [diff] [blame] | 242 | "xmlNewIOInputStream": "if (ret_val != NULL) input = NULL;", |
Daniel Veillard | a521d28 | 2004-11-09 14:59:59 +0000 | [diff] [blame] | 243 | "htmlParseChunk": "if (ctxt != NULL) {xmlFreeDoc(ctxt->myDoc); ctxt->myDoc = NULL;}", |
| 244 | "htmlParseDocument": "if (ctxt != NULL) {xmlFreeDoc(ctxt->myDoc); ctxt->myDoc = NULL;}", |
| 245 | "xmlParseDocument": "if (ctxt != NULL) {xmlFreeDoc(ctxt->myDoc); ctxt->myDoc = NULL;}", |
| 246 | "xmlParseChunk": "if (ctxt != NULL) {xmlFreeDoc(ctxt->myDoc); ctxt->myDoc = NULL;}", |
| 247 | "xmlParseExtParsedEnt": "if (ctxt != NULL) {xmlFreeDoc(ctxt->myDoc); ctxt->myDoc = NULL;}", |
Daniel Veillard | a03e365 | 2004-11-02 18:45:30 +0000 | [diff] [blame] | 248 | } |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 249 | |
| 250 | modules = [] |
| 251 | |
| 252 | def is_skipped_module(name): |
| 253 | for mod in skipped_modules: |
| 254 | if mod == name: |
| 255 | return 1 |
| 256 | return 0 |
| 257 | |
| 258 | def is_skipped_function(name): |
| 259 | for fun in skipped_functions: |
| 260 | if fun == name: |
| 261 | return 1 |
| 262 | # Do not test destructors |
| 263 | if string.find(name, 'Free') != -1: |
| 264 | return 1 |
| 265 | return 0 |
| 266 | |
| 267 | def is_skipped_memcheck(name): |
| 268 | for fun in skipped_memcheck: |
| 269 | if fun == name: |
| 270 | return 1 |
| 271 | return 0 |
| 272 | |
| 273 | missing_types = {} |
| 274 | def add_missing_type(name, func): |
| 275 | try: |
| 276 | list = missing_types[name] |
| 277 | list.append(func) |
| 278 | except: |
| 279 | missing_types[name] = [func] |
| 280 | |
Daniel Veillard | ce682bc | 2004-11-05 17:22:25 +0000 | [diff] [blame] | 281 | generated_param_types = [] |
| 282 | def add_generated_param_type(name): |
| 283 | generated_param_types.append(name) |
| 284 | |
| 285 | generated_return_types = [] |
| 286 | def add_generated_return_type(name): |
| 287 | generated_return_types.append(name) |
| 288 | |
Daniel Veillard | 34099b4 | 2004-11-04 17:34:35 +0000 | [diff] [blame] | 289 | missing_functions = {} |
Daniel Veillard | 0ea9c9f | 2004-11-05 14:30:41 +0000 | [diff] [blame] | 290 | missing_functions_nr = 0 |
Daniel Veillard | 34099b4 | 2004-11-04 17:34:35 +0000 | [diff] [blame] | 291 | def add_missing_functions(name, module): |
Daniel Veillard | 0ea9c9f | 2004-11-05 14:30:41 +0000 | [diff] [blame] | 292 | global missing_functions_nr |
| 293 | |
| 294 | missing_functions_nr = missing_functions_nr + 1 |
Daniel Veillard | 34099b4 | 2004-11-04 17:34:35 +0000 | [diff] [blame] | 295 | try: |
| 296 | list = missing_functions[module] |
| 297 | list.append(name) |
| 298 | except: |
| 299 | missing_functions[module] = [name] |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 300 | |
| 301 | # |
| 302 | # Provide the type generators and destructors for the parameters |
| 303 | # |
| 304 | |
Daniel Veillard | a03e365 | 2004-11-02 18:45:30 +0000 | [diff] [blame] | 305 | def type_convert(str, name, info, module, function, pos): |
Daniel Veillard | d5cc0f7 | 2004-11-06 19:24:28 +0000 | [diff] [blame] | 306 | # res = string.replace(str, " ", " ") |
| 307 | # res = string.replace(str, " ", " ") |
| 308 | # res = string.replace(str, " ", " ") |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 309 | res = string.replace(str, " *", "_ptr") |
Daniel Veillard | d5cc0f7 | 2004-11-06 19:24:28 +0000 | [diff] [blame] | 310 | # res = string.replace(str, "*", "_ptr") |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 311 | res = string.replace(res, " ", "_") |
| 312 | if res == 'const_char_ptr': |
| 313 | if string.find(name, "file") != -1 or \ |
| 314 | string.find(name, "uri") != -1 or \ |
| 315 | string.find(name, "URI") != -1 or \ |
| 316 | string.find(info, "filename") != -1 or \ |
| 317 | string.find(info, "URI") != -1 or \ |
| 318 | string.find(info, "URL") != -1: |
William M. Brack | 83d9c37 | 2004-11-08 02:26:08 +0000 | [diff] [blame] | 319 | if string.find(function, "Save") != -1 or \ |
| 320 | string.find(function, "Create") != -1 or \ |
| 321 | string.find(function, "Write") != -1: |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 322 | return('fileoutput') |
| 323 | return('filepath') |
| 324 | if res == 'void_ptr': |
| 325 | if module == 'nanoftp' and name == 'ctx': |
| 326 | return('xmlNanoFTPCtxtPtr') |
Daniel Veillard | b1b3a3e | 2004-11-03 23:25:47 +0000 | [diff] [blame] | 327 | if function == 'xmlNanoFTPNewCtxt': |
| 328 | return('xmlNanoFTPCtxtPtr') |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 329 | if module == 'nanohttp' and name == 'ctx': |
| 330 | return('xmlNanoHTTPCtxtPtr') |
Daniel Veillard | b1b3a3e | 2004-11-03 23:25:47 +0000 | [diff] [blame] | 331 | if function == 'xmlIOHTTPOpenW': |
| 332 | return('xmlNanoHTTPCtxtPtr') |
Daniel Veillard | 8a32fe4 | 2004-11-02 22:10:16 +0000 | [diff] [blame] | 333 | if string.find(name, "data") != -1: |
William M. Brack | 094dd86 | 2004-11-14 14:28:34 +0000 | [diff] [blame] | 334 | return('userdata') |
Daniel Veillard | d005b9e | 2004-11-03 17:07:05 +0000 | [diff] [blame] | 335 | if string.find(name, "user") != -1: |
William M. Brack | 094dd86 | 2004-11-14 14:28:34 +0000 | [diff] [blame] | 336 | return('userdata') |
Daniel Veillard | 3d97e66 | 2004-11-04 10:49:00 +0000 | [diff] [blame] | 337 | if res == 'xmlDoc_ptr': |
William M. Brack | 094dd86 | 2004-11-14 14:28:34 +0000 | [diff] [blame] | 338 | res = 'xmlDocPtr' |
Daniel Veillard | 3d97e66 | 2004-11-04 10:49:00 +0000 | [diff] [blame] | 339 | if res == 'xmlNode_ptr': |
William M. Brack | 094dd86 | 2004-11-14 14:28:34 +0000 | [diff] [blame] | 340 | res = 'xmlNodePtr' |
Daniel Veillard | 3d97e66 | 2004-11-04 10:49:00 +0000 | [diff] [blame] | 341 | if res == 'xmlDict_ptr': |
William M. Brack | 094dd86 | 2004-11-14 14:28:34 +0000 | [diff] [blame] | 342 | res = 'xmlDictPtr' |
Daniel Veillard | a03e365 | 2004-11-02 18:45:30 +0000 | [diff] [blame] | 343 | if res == 'xmlNodePtr' and pos != 0: |
| 344 | if (function == 'xmlAddChild' and pos == 2) or \ |
| 345 | (function == 'xmlAddChildList' and pos == 2) or \ |
| 346 | (function == 'xmlAddNextSibling' and pos == 2) or \ |
| 347 | (function == 'xmlAddSibling' and pos == 2) or \ |
| 348 | (function == 'xmlDocSetRootElement' and pos == 2) or \ |
| 349 | (function == 'xmlReplaceNode' and pos == 2) or \ |
| 350 | (function == 'xmlTextMerge') or \ |
| 351 | (function == 'xmlAddPrevSibling' and pos == 2): |
| 352 | return('xmlNodePtr_in'); |
Daniel Veillard | 34099b4 | 2004-11-04 17:34:35 +0000 | [diff] [blame] | 353 | if res == 'const xmlBufferPtr': |
William M. Brack | 094dd86 | 2004-11-14 14:28:34 +0000 | [diff] [blame] | 354 | res = 'xmlBufferPtr' |
Daniel Veillard | 27f2010 | 2004-11-05 11:50:11 +0000 | [diff] [blame] | 355 | if res == 'xmlChar_ptr' and name == 'name' and \ |
| 356 | string.find(function, "EatName") != -1: |
| 357 | return('eaten_name') |
Daniel Veillard | d5cc0f7 | 2004-11-06 19:24:28 +0000 | [diff] [blame] | 358 | if res == 'void_ptr*': |
| 359 | res = 'void_ptr_ptr' |
| 360 | if res == 'char_ptr*': |
| 361 | res = 'char_ptr_ptr' |
| 362 | if res == 'xmlChar_ptr*': |
| 363 | res = 'xmlChar_ptr_ptr' |
| 364 | if res == 'const_xmlChar_ptr*': |
| 365 | res = 'const_xmlChar_ptr_ptr' |
| 366 | if res == 'const_char_ptr*': |
| 367 | res = 'const_char_ptr_ptr' |
Daniel Veillard | a82b182 | 2004-11-08 16:24:57 +0000 | [diff] [blame] | 368 | if res == 'FILE_ptr' and module == 'debugXML': |
| 369 | res = 'debug_FILE_ptr'; |
Daniel Veillard | 6128c01 | 2004-11-08 17:16:15 +0000 | [diff] [blame] | 370 | if res == 'int' and name == 'options': |
| 371 | if module == 'parser' or module == 'xmlreader': |
| 372 | res = 'parseroptions' |
William M. Brack | 094dd86 | 2004-11-14 14:28:34 +0000 | [diff] [blame] | 373 | |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 374 | return res |
| 375 | |
Daniel Veillard | 34099b4 | 2004-11-04 17:34:35 +0000 | [diff] [blame] | 376 | known_param_types = [] |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 377 | |
Daniel Veillard | ce682bc | 2004-11-05 17:22:25 +0000 | [diff] [blame] | 378 | def is_known_param_type(name, rtype): |
| 379 | global test |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 380 | for type in known_param_types: |
| 381 | if type == name: |
| 382 | return 1 |
Daniel Veillard | ce682bc | 2004-11-05 17:22:25 +0000 | [diff] [blame] | 383 | for type in generated_param_types: |
| 384 | if type == name: |
| 385 | return 1 |
| 386 | |
| 387 | if name[-3:] == 'Ptr' or name[-4:] == '_ptr': |
| 388 | if rtype[0:6] == 'const ': |
| 389 | crtype = rtype[6:] |
| 390 | else: |
| 391 | crtype = rtype |
| 392 | |
Daniel Veillard | a521d28 | 2004-11-09 14:59:59 +0000 | [diff] [blame] | 393 | define = 0 |
| 394 | if modules_defines.has_key(module): |
| 395 | test.write("#ifdef %s\n" % (modules_defines[module])) |
| 396 | define = 1 |
Daniel Veillard | ce682bc | 2004-11-05 17:22:25 +0000 | [diff] [blame] | 397 | test.write(""" |
| 398 | #define gen_nb_%s 1 |
| 399 | static %s gen_%s(int no ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) { |
| 400 | return(NULL); |
| 401 | } |
| 402 | static void des_%s(int no ATTRIBUTE_UNUSED, %s val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) { |
| 403 | } |
| 404 | """ % (name, crtype, name, name, rtype)) |
Daniel Veillard | a521d28 | 2004-11-09 14:59:59 +0000 | [diff] [blame] | 405 | if define == 1: |
| 406 | test.write("#endif\n\n") |
Daniel Veillard | ce682bc | 2004-11-05 17:22:25 +0000 | [diff] [blame] | 407 | add_generated_param_type(name) |
| 408 | return 1 |
| 409 | |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 410 | return 0 |
| 411 | |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 412 | # |
| 413 | # Provide the type destructors for the return values |
| 414 | # |
| 415 | |
Daniel Veillard | 34099b4 | 2004-11-04 17:34:35 +0000 | [diff] [blame] | 416 | known_return_types = [] |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 417 | |
| 418 | def is_known_return_type(name): |
| 419 | for type in known_return_types: |
| 420 | if type == name: |
| 421 | return 1 |
| 422 | return 0 |
| 423 | |
Daniel Veillard | 34099b4 | 2004-11-04 17:34:35 +0000 | [diff] [blame] | 424 | # |
| 425 | # Copy the beginning of the C test program result |
| 426 | # |
| 427 | |
| 428 | input = open("testapi.c", "r") |
| 429 | test = open('testapi.c.new', 'w') |
| 430 | |
| 431 | def compare_and_save(): |
| 432 | global test |
| 433 | |
| 434 | test.close() |
| 435 | input = open("testapi.c", "r").read() |
| 436 | test = open('testapi.c.new', "r").read() |
| 437 | if input != test: |
| 438 | os.system("rm testapi.c ; mv testapi.c.new testapi.c") |
| 439 | print("Updated testapi.c") |
| 440 | else: |
| 441 | print("Generated testapi.c is identical") |
| 442 | |
| 443 | line = input.readline() |
| 444 | while line != "": |
| 445 | if line == "/* CUT HERE: everything below that line is generated */\n": |
| 446 | break; |
| 447 | if line[0:15] == "#define gen_nb_": |
| 448 | type = string.split(line[15:])[0] |
| 449 | known_param_types.append(type) |
| 450 | if line[0:19] == "static void desret_": |
| 451 | type = string.split(line[19:], '(')[0] |
| 452 | known_return_types.append(type) |
| 453 | test.write(line) |
| 454 | line = input.readline() |
| 455 | input.close() |
| 456 | |
| 457 | if line == "": |
| 458 | print "Could not find the CUT marker in testapi.c skipping generation" |
| 459 | test.close() |
| 460 | sys.exit(0) |
| 461 | |
| 462 | print("Scanned testapi.c: found %d parameters types and %d return types\n" % ( |
| 463 | len(known_param_types), len(known_return_types))) |
| 464 | test.write("/* CUT HERE: everything below that line is generated */\n") |
| 465 | |
| 466 | |
| 467 | # |
| 468 | # Open the input API description |
| 469 | # |
| 470 | doc = libxml2.readFile('doc/libxml2-api.xml', None, 0) |
| 471 | if doc == None: |
| 472 | print "Failed to load doc/libxml2-api.xml" |
| 473 | sys.exit(1) |
| 474 | ctxt = doc.xpathNewContext() |
Daniel Veillard | 57b2516 | 2004-11-06 14:50:18 +0000 | [diff] [blame] | 475 | |
| 476 | # |
William M. Brack | 094dd86 | 2004-11-14 14:28:34 +0000 | [diff] [blame] | 477 | # Generate a list of all function parameters and select only |
| 478 | # those used in the api tests |
| 479 | # |
| 480 | argtypes = {} |
| 481 | args = ctxt.xpathEval("/api/symbols/function/arg") |
| 482 | for arg in args: |
| 483 | mod = arg.xpathEval('string(../@file)') |
| 484 | func = arg.xpathEval('string(../@name)') |
| 485 | if (mod not in skipped_modules) and (func not in skipped_functions): |
| 486 | type = arg.xpathEval('string(@type)') |
| 487 | if not argtypes.has_key(type): |
| 488 | argtypes[type] = func |
| 489 | |
| 490 | # similarly for return types |
| 491 | rettypes = {} |
| 492 | rets = ctxt.xpathEval("/api/symbols/function/return") |
| 493 | for ret in rets: |
| 494 | mod = ret.xpathEval('string(../@file)') |
| 495 | func = ret.xpathEval('string(../@name)') |
| 496 | if (mod not in skipped_modules) and (func not in skipped_functions): |
| 497 | type = ret.xpathEval('string(@type)') |
| 498 | if not rettypes.has_key(type): |
| 499 | rettypes[type] = func |
| 500 | |
| 501 | # |
Daniel Veillard | 57b2516 | 2004-11-06 14:50:18 +0000 | [diff] [blame] | 502 | # Generate constructors and return type handling for all enums |
William M. Brack | 094dd86 | 2004-11-14 14:28:34 +0000 | [diff] [blame] | 503 | # which are used as function parameters |
Daniel Veillard | 57b2516 | 2004-11-06 14:50:18 +0000 | [diff] [blame] | 504 | # |
| 505 | enums = ctxt.xpathEval("/api/symbols/typedef[@type='enum']") |
| 506 | for enum in enums: |
Daniel Veillard | a521d28 | 2004-11-09 14:59:59 +0000 | [diff] [blame] | 507 | module = enum.xpathEval('string(@file)') |
William M. Brack | 094dd86 | 2004-11-14 14:28:34 +0000 | [diff] [blame] | 508 | name = enum.xpathEval('string(@name)') |
| 509 | # |
| 510 | # Skip any enums which are not in our filtered lists |
| 511 | # |
| 512 | if (name == None) or ((name not in argtypes) and (name not in rettypes)): |
| 513 | continue; |
Daniel Veillard | a521d28 | 2004-11-09 14:59:59 +0000 | [diff] [blame] | 514 | define = 0 |
Daniel Veillard | 57b2516 | 2004-11-06 14:50:18 +0000 | [diff] [blame] | 515 | |
William M. Brack | 094dd86 | 2004-11-14 14:28:34 +0000 | [diff] [blame] | 516 | if argtypes.has_key(name) and is_known_param_type(name, name) == 0: |
Daniel Veillard | 57b2516 | 2004-11-06 14:50:18 +0000 | [diff] [blame] | 517 | values = ctxt.xpathEval("/api/symbols/enum[@type='%s']" % name) |
| 518 | i = 0 |
| 519 | vals = [] |
| 520 | for value in values: |
| 521 | vname = value.xpathEval('string(@name)') |
| 522 | if vname == None: |
| 523 | continue; |
| 524 | i = i + 1 |
| 525 | if i >= 5: |
| 526 | break; |
| 527 | vals.append(vname) |
| 528 | if vals == []: |
William M. Brack | 094dd86 | 2004-11-14 14:28:34 +0000 | [diff] [blame] | 529 | print "Didn't find any value for enum %s" % (name) |
Daniel Veillard | 57b2516 | 2004-11-06 14:50:18 +0000 | [diff] [blame] | 530 | continue |
Daniel Veillard | a521d28 | 2004-11-09 14:59:59 +0000 | [diff] [blame] | 531 | if modules_defines.has_key(module): |
| 532 | test.write("#ifdef %s\n" % (modules_defines[module])) |
| 533 | define = 1 |
Daniel Veillard | 57b2516 | 2004-11-06 14:50:18 +0000 | [diff] [blame] | 534 | test.write("#define gen_nb_%s %d\n" % (name, len(vals))) |
| 535 | test.write("""static %s gen_%s(int no, int nr ATTRIBUTE_UNUSED) {\n""" % |
| 536 | (name, name)) |
| 537 | i = 1 |
| 538 | for value in vals: |
| 539 | test.write(" if (no == %d) return(%s);\n" % (i, value)) |
| 540 | i = i + 1 |
| 541 | test.write(""" return(0); |
| 542 | } |
William M. Brack | 094dd86 | 2004-11-14 14:28:34 +0000 | [diff] [blame] | 543 | |
| 544 | static void des_%s(int no ATTRIBUTE_UNUSED, %s val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) { |
| 545 | } |
| 546 | |
| 547 | """ % (name, name)); |
Daniel Veillard | 57b2516 | 2004-11-06 14:50:18 +0000 | [diff] [blame] | 548 | known_param_types.append(name) |
| 549 | |
William M. Brack | 094dd86 | 2004-11-14 14:28:34 +0000 | [diff] [blame] | 550 | if (is_known_return_type(name) == 0) and (name in rettypes): |
Daniel Veillard | a521d28 | 2004-11-09 14:59:59 +0000 | [diff] [blame] | 551 | if define == 0 and modules_defines.has_key(module): |
| 552 | test.write("#ifdef %s\n" % (modules_defines[module])) |
| 553 | define = 1 |
William M. Brack | 094dd86 | 2004-11-14 14:28:34 +0000 | [diff] [blame] | 554 | test.write("""static void desret_%s(%s val ATTRIBUTE_UNUSED) { |
Daniel Veillard | 57b2516 | 2004-11-06 14:50:18 +0000 | [diff] [blame] | 555 | } |
| 556 | |
William M. Brack | 094dd86 | 2004-11-14 14:28:34 +0000 | [diff] [blame] | 557 | """ % (name, name)) |
Daniel Veillard | 57b2516 | 2004-11-06 14:50:18 +0000 | [diff] [blame] | 558 | known_return_types.append(name) |
Daniel Veillard | a521d28 | 2004-11-09 14:59:59 +0000 | [diff] [blame] | 559 | if define == 1: |
| 560 | test.write("#endif\n\n") |
Daniel Veillard | 34099b4 | 2004-11-04 17:34:35 +0000 | [diff] [blame] | 561 | |
| 562 | # |
| 563 | # Load the interfaces |
| 564 | # |
Daniel Veillard | 57b2516 | 2004-11-06 14:50:18 +0000 | [diff] [blame] | 565 | headers = ctxt.xpathEval("/api/files/file") |
Daniel Veillard | 34099b4 | 2004-11-04 17:34:35 +0000 | [diff] [blame] | 566 | for file in headers: |
| 567 | name = file.xpathEval('string(@name)') |
| 568 | if (name == None) or (name == ''): |
| 569 | continue |
| 570 | |
| 571 | # |
| 572 | # Some module may be skipped because they don't really consists |
| 573 | # of user callable APIs |
| 574 | # |
| 575 | if is_skipped_module(name): |
| 576 | continue |
| 577 | |
| 578 | # |
| 579 | # do not test deprecated APIs |
| 580 | # |
| 581 | desc = file.xpathEval('string(description)') |
| 582 | if string.find(desc, 'DEPRECATED') != -1: |
| 583 | print "Skipping deprecated interface %s" % name |
| 584 | continue; |
| 585 | |
| 586 | test.write("#include <libxml/%s.h>\n" % name) |
| 587 | modules.append(name) |
| 588 | |
| 589 | # |
| 590 | # Generate the callers signatures |
| 591 | # |
| 592 | for module in modules: |
| 593 | test.write("static int test_%s(void);\n" % module); |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 594 | |
| 595 | # |
| 596 | # Generate the top caller |
| 597 | # |
| 598 | |
| 599 | test.write(""" |
| 600 | /** |
| 601 | * testlibxml2: |
| 602 | * |
| 603 | * Main entry point of the tester for the full libxml2 module, |
| 604 | * it calls all the tester entry point for each module. |
| 605 | * |
| 606 | * Returns the number of error found |
| 607 | */ |
| 608 | static int |
| 609 | testlibxml2(void) |
| 610 | { |
Daniel Veillard | 4259532 | 2004-11-08 10:52:06 +0000 | [diff] [blame] | 611 | int test_ret = 0; |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 612 | |
| 613 | """) |
| 614 | |
| 615 | for module in modules: |
Daniel Veillard | 4259532 | 2004-11-08 10:52:06 +0000 | [diff] [blame] | 616 | test.write(" test_ret += test_%s();\n" % module) |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 617 | |
| 618 | test.write(""" |
Daniel Veillard | 3d97e66 | 2004-11-04 10:49:00 +0000 | [diff] [blame] | 619 | printf("Total: %d functions, %d tests, %d errors\\n", |
Daniel Veillard | 4259532 | 2004-11-08 10:52:06 +0000 | [diff] [blame] | 620 | function_tests, call_tests, test_ret); |
| 621 | return(test_ret); |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 622 | } |
| 623 | |
| 624 | """) |
| 625 | |
| 626 | # |
| 627 | # How to handle a function |
| 628 | # |
| 629 | nb_tests = 0 |
| 630 | |
| 631 | def generate_test(module, node): |
| 632 | global test |
| 633 | global nb_tests |
| 634 | nb_cond = 0 |
| 635 | no_gen = 0 |
| 636 | |
| 637 | name = node.xpathEval('string(@name)') |
| 638 | if is_skipped_function(name): |
| 639 | return |
| 640 | |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 641 | # |
| 642 | # check we know how to handle the args and return values |
| 643 | # and store the informations for the generation |
| 644 | # |
| 645 | try: |
| 646 | args = node.xpathEval("arg") |
| 647 | except: |
| 648 | args = [] |
| 649 | t_args = [] |
Daniel Veillard | a03e365 | 2004-11-02 18:45:30 +0000 | [diff] [blame] | 650 | n = 0 |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 651 | for arg in args: |
Daniel Veillard | a03e365 | 2004-11-02 18:45:30 +0000 | [diff] [blame] | 652 | n = n + 1 |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 653 | rtype = arg.xpathEval("string(@type)") |
| 654 | if rtype == 'void': |
| 655 | break; |
| 656 | info = arg.xpathEval("string(@info)") |
| 657 | nam = arg.xpathEval("string(@name)") |
Daniel Veillard | a03e365 | 2004-11-02 18:45:30 +0000 | [diff] [blame] | 658 | type = type_convert(rtype, nam, info, module, name, n) |
Daniel Veillard | ce682bc | 2004-11-05 17:22:25 +0000 | [diff] [blame] | 659 | if is_known_param_type(type, rtype) == 0: |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 660 | add_missing_type(type, name); |
| 661 | no_gen = 1 |
William M. Brack | f13f77f | 2004-11-12 16:03:48 +0000 | [diff] [blame] | 662 | if (type[-3:] == 'Ptr' or type[-4:] == '_ptr') and \ |
| 663 | rtype[0:6] == 'const ': |
| 664 | crtype = rtype[6:] |
| 665 | else: |
| 666 | crtype = rtype |
| 667 | t_args.append((nam, type, rtype, crtype, info)) |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 668 | |
| 669 | try: |
| 670 | rets = node.xpathEval("return") |
| 671 | except: |
| 672 | rets = [] |
| 673 | t_ret = None |
| 674 | for ret in rets: |
| 675 | rtype = ret.xpathEval("string(@type)") |
| 676 | info = ret.xpathEval("string(@info)") |
Daniel Veillard | a03e365 | 2004-11-02 18:45:30 +0000 | [diff] [blame] | 677 | type = type_convert(rtype, 'return', info, module, name, 0) |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 678 | if rtype == 'void': |
| 679 | break |
| 680 | if is_known_return_type(type) == 0: |
| 681 | add_missing_type(type, name); |
| 682 | no_gen = 1 |
| 683 | t_ret = (type, rtype, info) |
| 684 | break |
| 685 | |
Daniel Veillard | 0ea9c9f | 2004-11-05 14:30:41 +0000 | [diff] [blame] | 686 | test.write(""" |
| 687 | static int |
| 688 | test_%s(void) { |
Daniel Veillard | 4259532 | 2004-11-08 10:52:06 +0000 | [diff] [blame] | 689 | int test_ret = 0; |
Daniel Veillard | 0ea9c9f | 2004-11-05 14:30:41 +0000 | [diff] [blame] | 690 | |
| 691 | """ % (name)) |
| 692 | |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 693 | if no_gen == 1: |
Daniel Veillard | 34099b4 | 2004-11-04 17:34:35 +0000 | [diff] [blame] | 694 | add_missing_functions(name, module) |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 695 | test.write(""" |
| 696 | /* missing type support */ |
Daniel Veillard | 4259532 | 2004-11-08 10:52:06 +0000 | [diff] [blame] | 697 | return(test_ret); |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 698 | } |
| 699 | |
| 700 | """) |
| 701 | return |
| 702 | |
| 703 | try: |
| 704 | conds = node.xpathEval("cond") |
| 705 | for cond in conds: |
| 706 | test.write("#ifdef %s\n" % (cond.get_content())) |
| 707 | nb_cond = nb_cond + 1 |
| 708 | except: |
| 709 | pass |
Daniel Veillard | a521d28 | 2004-11-09 14:59:59 +0000 | [diff] [blame] | 710 | |
| 711 | define = 0 |
| 712 | if function_defines.has_key(name): |
| 713 | test.write("#ifdef %s\n" % (function_defines[name])) |
| 714 | define = 1 |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 715 | |
| 716 | # Declare the memory usage counter |
| 717 | no_mem = is_skipped_memcheck(name) |
| 718 | if no_mem == 0: |
| 719 | test.write(" int mem_base;\n"); |
| 720 | |
| 721 | # Declare the return value |
| 722 | if t_ret != None: |
| 723 | test.write(" %s ret_val;\n" % (t_ret[1])) |
| 724 | |
| 725 | # Declare the arguments |
| 726 | for arg in t_args: |
William M. Brack | f13f77f | 2004-11-12 16:03:48 +0000 | [diff] [blame] | 727 | (nam, type, rtype, crtype, info) = arg; |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 728 | # add declaration |
Daniel Veillard | ce682bc | 2004-11-05 17:22:25 +0000 | [diff] [blame] | 729 | test.write(" %s %s; /* %s */\n" % (crtype, nam, info)) |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 730 | test.write(" int n_%s;\n" % (nam)) |
| 731 | test.write("\n") |
| 732 | |
| 733 | # Cascade loop on of each argument list of values |
| 734 | for arg in t_args: |
William M. Brack | f13f77f | 2004-11-12 16:03:48 +0000 | [diff] [blame] | 735 | (nam, type, rtype, crtype, info) = arg; |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 736 | # |
| 737 | test.write(" for (n_%s = 0;n_%s < gen_nb_%s;n_%s++) {\n" % ( |
| 738 | nam, nam, type, nam)) |
| 739 | |
| 740 | # log the memory usage |
| 741 | if no_mem == 0: |
| 742 | test.write(" mem_base = xmlMemBlocks();\n"); |
| 743 | |
| 744 | # prepare the call |
Daniel Veillard | 3d97e66 | 2004-11-04 10:49:00 +0000 | [diff] [blame] | 745 | i = 0; |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 746 | for arg in t_args: |
William M. Brack | f13f77f | 2004-11-12 16:03:48 +0000 | [diff] [blame] | 747 | (nam, type, rtype, crtype, info) = arg; |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 748 | # |
Daniel Veillard | 3d97e66 | 2004-11-04 10:49:00 +0000 | [diff] [blame] | 749 | test.write(" %s = gen_%s(n_%s, %d);\n" % (nam, type, nam, i)) |
| 750 | i = i + 1; |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 751 | |
| 752 | # do the call, and clanup the result |
Daniel Veillard | 34099b4 | 2004-11-04 17:34:35 +0000 | [diff] [blame] | 753 | if extra_pre_call.has_key(name): |
| 754 | test.write(" %s\n"% (extra_pre_call[name])) |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 755 | if t_ret != None: |
| 756 | test.write("\n ret_val = %s(" % (name)) |
| 757 | need = 0 |
| 758 | for arg in t_args: |
William M. Brack | f13f77f | 2004-11-12 16:03:48 +0000 | [diff] [blame] | 759 | (nam, type, rtype, crtype, info) = arg |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 760 | if need: |
| 761 | test.write(", ") |
| 762 | else: |
| 763 | need = 1 |
William M. Brack | f13f77f | 2004-11-12 16:03:48 +0000 | [diff] [blame] | 764 | if rtype != crtype: |
| 765 | test.write("(%s)" % rtype) |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 766 | test.write("%s" % nam); |
Daniel Veillard | 8a32fe4 | 2004-11-02 22:10:16 +0000 | [diff] [blame] | 767 | test.write(");\n") |
| 768 | if extra_post_call.has_key(name): |
| 769 | test.write(" %s\n"% (extra_post_call[name])) |
| 770 | test.write(" desret_%s(ret_val);\n" % t_ret[0]) |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 771 | else: |
| 772 | test.write("\n %s(" % (name)); |
| 773 | need = 0; |
| 774 | for arg in t_args: |
William M. Brack | f13f77f | 2004-11-12 16:03:48 +0000 | [diff] [blame] | 775 | (nam, type, rtype, crtype, info) = arg; |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 776 | if need: |
| 777 | test.write(", ") |
| 778 | else: |
| 779 | need = 1 |
William M. Brack | f13f77f | 2004-11-12 16:03:48 +0000 | [diff] [blame] | 780 | if rtype != crtype: |
| 781 | test.write("(%s)" % rtype) |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 782 | test.write("%s" % nam) |
| 783 | test.write(");\n") |
Daniel Veillard | 8a32fe4 | 2004-11-02 22:10:16 +0000 | [diff] [blame] | 784 | if extra_post_call.has_key(name): |
| 785 | test.write(" %s\n"% (extra_post_call[name])) |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 786 | |
Daniel Veillard | 8a32fe4 | 2004-11-02 22:10:16 +0000 | [diff] [blame] | 787 | test.write(" call_tests++;\n"); |
Daniel Veillard | a03e365 | 2004-11-02 18:45:30 +0000 | [diff] [blame] | 788 | |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 789 | # Free the arguments |
Daniel Veillard | 3d97e66 | 2004-11-04 10:49:00 +0000 | [diff] [blame] | 790 | i = 0; |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 791 | for arg in t_args: |
William M. Brack | f13f77f | 2004-11-12 16:03:48 +0000 | [diff] [blame] | 792 | (nam, type, rtype, crtype, info) = arg; |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 793 | # |
William M. Brack | f13f77f | 2004-11-12 16:03:48 +0000 | [diff] [blame] | 794 | test.write(" des_%s(n_%s, " % (type, nam)) |
| 795 | if rtype != crtype: |
| 796 | test.write("(%s)" % rtype) |
| 797 | test.write("%s, %d);\n" % (nam, i)) |
Daniel Veillard | 3d97e66 | 2004-11-04 10:49:00 +0000 | [diff] [blame] | 798 | i = i + 1; |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 799 | |
| 800 | test.write(" xmlResetLastError();\n"); |
| 801 | # Check the memory usage |
| 802 | if no_mem == 0: |
| 803 | test.write(""" if (mem_base != xmlMemBlocks()) { |
Daniel Veillard | a03e365 | 2004-11-02 18:45:30 +0000 | [diff] [blame] | 804 | printf("Leak of %%d blocks found in %s", |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 805 | xmlMemBlocks() - mem_base); |
Daniel Veillard | 4259532 | 2004-11-08 10:52:06 +0000 | [diff] [blame] | 806 | test_ret++; |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 807 | """ % (name)); |
Daniel Veillard | a03e365 | 2004-11-02 18:45:30 +0000 | [diff] [blame] | 808 | for arg in t_args: |
William M. Brack | f13f77f | 2004-11-12 16:03:48 +0000 | [diff] [blame] | 809 | (nam, type, rtype, crtype, info) = arg; |
Daniel Veillard | a03e365 | 2004-11-02 18:45:30 +0000 | [diff] [blame] | 810 | test.write(""" printf(" %%d", n_%s);\n""" % (nam)) |
| 811 | test.write(""" printf("\\n");\n""") |
| 812 | test.write(" }\n") |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 813 | |
| 814 | for arg in t_args: |
| 815 | test.write(" }\n") |
| 816 | |
Daniel Veillard | d0cf7f6 | 2004-11-09 16:17:02 +0000 | [diff] [blame] | 817 | test.write(" function_tests++;\n") |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 818 | # |
| 819 | # end of conditional |
| 820 | # |
| 821 | while nb_cond > 0: |
| 822 | test.write("#endif\n") |
| 823 | nb_cond = nb_cond -1 |
Daniel Veillard | a521d28 | 2004-11-09 14:59:59 +0000 | [diff] [blame] | 824 | if define == 1: |
| 825 | test.write("#endif\n") |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 826 | |
| 827 | nb_tests = nb_tests + 1; |
| 828 | |
| 829 | test.write(""" |
Daniel Veillard | 4259532 | 2004-11-08 10:52:06 +0000 | [diff] [blame] | 830 | return(test_ret); |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 831 | } |
| 832 | |
| 833 | """) |
| 834 | |
| 835 | # |
| 836 | # Generate all module callers |
| 837 | # |
| 838 | for module in modules: |
| 839 | # gather all the functions exported by that module |
| 840 | try: |
| 841 | functions = ctxt.xpathEval("/api/symbols/function[@file='%s']" % (module)) |
| 842 | except: |
| 843 | print "Failed to gather functions from module %s" % (module) |
| 844 | continue; |
| 845 | |
| 846 | # iterate over all functions in the module generating the test |
Daniel Veillard | 1ba06bb | 2004-11-04 12:32:18 +0000 | [diff] [blame] | 847 | i = 0 |
| 848 | nb_tests_old = nb_tests |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 849 | for function in functions: |
Daniel Veillard | 1ba06bb | 2004-11-04 12:32:18 +0000 | [diff] [blame] | 850 | i = i + 1 |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 851 | generate_test(module, function); |
| 852 | |
| 853 | # header |
| 854 | test.write("""static int |
| 855 | test_%s(void) { |
Daniel Veillard | 4259532 | 2004-11-08 10:52:06 +0000 | [diff] [blame] | 856 | int test_ret = 0; |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 857 | |
Daniel Veillard | d0cf7f6 | 2004-11-09 16:17:02 +0000 | [diff] [blame] | 858 | if (quiet == 0) printf("Testing %s : %d of %d functions ...\\n"); |
Daniel Veillard | 1ba06bb | 2004-11-04 12:32:18 +0000 | [diff] [blame] | 859 | """ % (module, module, nb_tests - nb_tests_old, i)) |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 860 | |
| 861 | # iterate over all functions in the module generating the call |
| 862 | for function in functions: |
| 863 | name = function.xpathEval('string(@name)') |
| 864 | if is_skipped_function(name): |
| 865 | continue |
Daniel Veillard | 4259532 | 2004-11-08 10:52:06 +0000 | [diff] [blame] | 866 | test.write(" test_ret += test_%s();\n" % (name)) |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 867 | |
| 868 | # footer |
| 869 | test.write(""" |
Daniel Veillard | 4259532 | 2004-11-08 10:52:06 +0000 | [diff] [blame] | 870 | if (test_ret != 0) |
| 871 | printf("Module %s: %%d errors\\n", test_ret); |
| 872 | return(test_ret); |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 873 | } |
| 874 | """ % (module)) |
| 875 | |
Daniel Veillard | ce244ad | 2004-11-05 10:03:46 +0000 | [diff] [blame] | 876 | # |
| 877 | # Generate direct module caller |
| 878 | # |
| 879 | test.write("""static int |
| 880 | test_module(const char *module) { |
| 881 | """); |
| 882 | for module in modules: |
| 883 | test.write(""" if (!strcmp(module, "%s")) return(test_%s());\n""" % ( |
| 884 | module, module)) |
| 885 | test.write(""" return(0); |
| 886 | } |
| 887 | """); |
| 888 | |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 889 | print "Generated test for %d modules and %d functions" %(len(modules), nb_tests) |
Daniel Veillard | 1ba06bb | 2004-11-04 12:32:18 +0000 | [diff] [blame] | 890 | |
Daniel Veillard | 34099b4 | 2004-11-04 17:34:35 +0000 | [diff] [blame] | 891 | compare_and_save() |
| 892 | |
Daniel Veillard | 1ba06bb | 2004-11-04 12:32:18 +0000 | [diff] [blame] | 893 | missing_list = [] |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 894 | for missing in missing_types.keys(): |
Daniel Veillard | 1ba06bb | 2004-11-04 12:32:18 +0000 | [diff] [blame] | 895 | if missing == 'va_list' or missing == '...': |
Daniel Veillard | b1b3a3e | 2004-11-03 23:25:47 +0000 | [diff] [blame] | 896 | continue; |
Daniel Veillard | 1ba06bb | 2004-11-04 12:32:18 +0000 | [diff] [blame] | 897 | |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 898 | n = len(missing_types[missing]) |
Daniel Veillard | 1ba06bb | 2004-11-04 12:32:18 +0000 | [diff] [blame] | 899 | missing_list.append((n, missing)) |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 900 | |
Daniel Veillard | 1ba06bb | 2004-11-04 12:32:18 +0000 | [diff] [blame] | 901 | def compare_missing(a, b): |
| 902 | return b[0] - a[0] |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 903 | |
Daniel Veillard | 1ba06bb | 2004-11-04 12:32:18 +0000 | [diff] [blame] | 904 | missing_list.sort(compare_missing) |
Daniel Veillard | 0ea9c9f | 2004-11-05 14:30:41 +0000 | [diff] [blame] | 905 | print "Missing support for %d functions and %d types see missing.lst" % (missing_functions_nr, len(missing_list)) |
Daniel Veillard | 1ba06bb | 2004-11-04 12:32:18 +0000 | [diff] [blame] | 906 | lst = open("missing.lst", "w") |
Daniel Veillard | 34099b4 | 2004-11-04 17:34:35 +0000 | [diff] [blame] | 907 | lst.write("Missing support for %d types" % (len(missing_list))) |
| 908 | lst.write("\n") |
Daniel Veillard | 1ba06bb | 2004-11-04 12:32:18 +0000 | [diff] [blame] | 909 | for miss in missing_list: |
| 910 | lst.write("%s: %d :" % (miss[1], miss[0])) |
| 911 | i = 0 |
| 912 | for n in missing_types[miss[1]]: |
| 913 | i = i + 1 |
| 914 | if i > 5: |
| 915 | lst.write(" ...") |
| 916 | break |
| 917 | lst.write(" %s" % (n)) |
| 918 | lst.write("\n") |
Daniel Veillard | 34099b4 | 2004-11-04 17:34:35 +0000 | [diff] [blame] | 919 | lst.write("\n") |
| 920 | lst.write("\n") |
| 921 | lst.write("Missing support per module"); |
| 922 | for module in missing_functions.keys(): |
| 923 | lst.write("module %s:\n %s\n" % (module, missing_functions[module])) |
Daniel Veillard | 1ba06bb | 2004-11-04 12:32:18 +0000 | [diff] [blame] | 924 | |
| 925 | lst.close() |
Daniel Veillard | b1b3a3e | 2004-11-03 23:25:47 +0000 | [diff] [blame] | 926 | |
Daniel Veillard | 36e5cd5 | 2004-11-02 14:52:23 +0000 | [diff] [blame] | 927 | |