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