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