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