1# Copyright (c) 2024 Huawei Device Co., Ltd. 2# Licensed under the Apache License, Version 2.0 (the "License"); 3# you may not use this file except in compliance with the License. 4# You may obtain a copy of the License at 5# 6# http://www.apache.org/licenses/LICENSE-2.0 7# 8# Unless required by applicable law or agreed to in writing, software 9# distributed under the License is distributed on an "AS IS" BASIS, 10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11# See the License for the specific language governing permissions and 12# limitations under the License. 13 14require 'erb' 15require_relative 'common_gen_tests_api' 16 17abckit_scripts = File.dirname(__FILE__) 18abckit_root = File.expand_path("../", abckit_scripts) 19abckit_test = File.join(abckit_root, "/tests/wrong_ctx_tests/") 20 21excluded_funcs = [ 22 "getLastError", 23] 24 25 26funcs_without_two_abckit_entites = [ 27 "destroyGraph", 28 "closeFile", 29 "openAbc", 30 "writeAbc", 31 "fileGetVersion", 32 "fileEnumerateModules", 33 "fileEnumerateExternalModules", 34 "moduleGetFile", 35 "moduleGetName", 36 "moduleIsExternal", 37 "moduleEnumerateImports", 38 "moduleEnumerateExports", 39 "moduleEnumerateClasses", 40 "moduleEnumerateTopLevelFunctions", 41 "importDescriptorGetFile", 42 "importDescriptorGetImportedModule", 43 "importDescriptorGetImportingModule", 44 "importDescriptorGetName", 45 "importDescriptorGetAlias", 46 "exportDescriptorGetFile", 47 "exportDescriptorGetExportingModule", 48 "exportDescriptorGetExportedModule", 49 "exportDescriptorGetName", 50 "exportDescriptorGetAlias", 51 "classGetFile", 52 "classGetModule", 53 "classGetName", 54 "classEnumerateMethods", 55 "functionGetFile", 56 "functionGetModule", 57 "functionGetName", 58 "functionGetParentFunction", 59 "functionGetParentClass", 60 "functionEnumerateAnnotations", 61 "functionIsStatic", 62 "functionIsNative", 63 "functionIsCtor", 64 "functionIsAnonymous", 65 "annotationGetFile", 66 "annotationEnumerateElements", 67 "typeGetTypeId", 68 "typeGetReferenceClass", 69 "literalArrayEnumerateElements", 70 "arrayValueGetLiteralArray", 71 "literalGetBool", 72 "literalGetDouble", 73 "literalGetFloat", 74 "literalGetString", 75 "literalGetMethodAffiliate", 76 "literalGetTag", 77 "literalGetU16", 78 "literalGetMethodAffiliate", 79 "literalGetU32", 80 "literalGetU64", 81 "literalGetU8", 82 "valueGetDouble", 83 "valueGetString", 84 "valueGetType", 85 "valueGetU1", 86 "createLiteralArrayValue", 87 "createLiteralArrayValue", 88 "createLiteralBool", 89 "createLiteralDouble", 90 "createLiteralFloat", 91 "createLiteralString", 92 "createLiteralMethodAffiliate", 93 "createLiteralU16", 94 "createLiteralMethodAffiliate", 95 "createLiteralU32", 96 "createLiteralU64", 97 "createLiteralU8", 98 "createReferenceType", 99 "createString", 100 "iCreateTypeof", 101 "createValueDouble", 102 "createValueString", 103 "createValueU1", 104 "moduleRemoveExport", 105 "moduleRemoveImport", 106 "iSetConditionCode", 107 "iSetExportDescriptor", 108 "iSetInput", 109 "iSetInputs", 110 "iSetLiteralArray", 111 "iSetModule", 112 "iSetTargetType", 113 "iVisitInputs", 114 "iVisitUsers", 115 "iSetImportDescriptor", 116 "bbRemoveAllInsts", 117 "bbCreateEmpty", 118 "bbDump", 119 "bbGetFalseBranch", 120 "bbGetTrueBranch", 121 "bbGetFirstInst", 122 "bbGetGraph", 123 "bbGetId", 124 "bbGetImmediateDominator", 125 "bbGetLastInst", 126 "bbGetNumberOfInstructions", 127 "bbGetPredBlockCount", 128 "bbGetPredBlockCount", 129 "bbGetSuccBlockCount", 130 "bbGetSuccBlockCount", 131 "bbGetTrueBranch", 132 "bbIsCatchBegin", 133 "bbIsCatchBegin", 134 "bbIsEnd", 135 "bbIsLoopHead", 136 "bbIsLoopPrehead", 137 "bbIsStart", 138 "bbIsTryBegin", 139 "bbIsTryBegin", 140 "bbIsTryEnd", 141 "bbSplitBlockAfterInstruction", 142 "bbVisitDominatedBlocks", 143 "bbVisitPredBlocks", 144 "bbVisitSuccBlocks", 145 "bbCreatePhi", 146 "gFindOrCreateConstantF64", 147 "gFindOrCreateConstantI32", 148 "gFindOrCreateConstantI64", 149 "gFindOrCreateConstantU64", 150 "gCreateNullPtr", 151 "gDump", 152 "gGetBasicBlock", 153 "gGetEndBasicBlock", 154 "gGetNumberOfBasicBlocks", 155 "gGetParameter", 156 "gGetNumberOfParameters", 157 "gGetStartBasicBlock", 158 "gRunPassRemoveUnreachableBlocks", 159 "gVisitBlocksRpo", 160 "iCheckIsCall", 161 "iCreateAsyncfunctionenter", 162 "iCreateCallruntimeCreateprivateproperty", 163 "iCreateCallruntimeLdsendableclass", 164 "iCreateCallruntimeLdsendableexternalmodulevar", 165 "iCreateCallruntimeLdsendablevar", 166 "iCreateCallruntimeNewsendableenv", 167 "iCreateCallruntimeWideldsendableexternalmodulevar", 168 "iCreateCallruntimeWideldsendablevar", 169 "iCreateCallruntimeWidenewsendableenv", 170 "iCreateCopyrestargs", 171 "iCreateCreatearraywithbuffer", 172 "iCreateCreateemptyarray", 173 "iCreateCreateemptyobject", 174 "iCreateCreateobjectwithbuffer", 175 "iCreateDebugger", 176 "iCreateGetunmappedargs", 177 "iCreateLdbigint", 178 "iCreateLdexternalmodulevar", 179 "iCreateLdfalse", 180 "iCreateLdfunction", 181 "iCreateLdglobal", 182 "iCreateLdglobalvar", 183 "iCreateLdhole", 184 "iCreateLdinfinity", 185 "iCreateLdlexvar", 186 "iCreateLdlocalmodulevar", 187 "iCreateLdnan", 188 "iCreateLdnewtarget", 189 "iCreateLdnull", 190 "iCreateLdsymbol", 191 "iCreateLdthis", 192 "iCreateLdthisbyname", 193 "iCreateLdtrue", 194 "iCreateLdundefined", 195 "iCreateNewlexenv", 196 "iCreateNewlexenvwithname", 197 "iCreatePoplexenv", 198 "iCreateReturnundefined", 199 "iCreateThrowDeletesuperproperty", 200 "iCreateThrowNotexists", 201 "iCreateThrowPatternnoncoercible", 202 "iCreateTryldglobalbyname", 203 "iCreateWideCopyrestargs", 204 "iCreateWideLdexternalmodulevar", 205 "iCreateWideLdlexvar", 206 "iCreateWideLdlocalmodulevar", 207 "iCreateWideLdpatchvar", 208 "iCreateWideNewlexenv", 209 "iCreateWideNewlexenvwithname", 210 "iCreateLoadString", 211 "iCreateReturnVoid", 212 "iDump", 213 "iGetBasicBlock", 214 "iGetConditionCode", 215 "iGetConstantValueF64", 216 "iGetConstantValueI64", 217 "iGetConstantValueU64", 218 "iGetExportDescriptor", 219 "iGetId", 220 "iGetImmediate", 221 "iGetImmediateCount", 222 "iGetImportDescriptor", 223 "iGetInputCount", 224 "iGetInputCount", 225 "iGetLiteralArray", 226 "iGetFunction", 227 "iGetModule", 228 "iGetNext", 229 "iGetOpcode", 230 "iGetPrev", 231 "iGetTargetType", 232 "iGetType", 233 "iGetUserCount", 234 "iRemove", 235 "iSetImmediate", 236 "iCreateLoadConstArray", 237 "iCreateLoadUndefined", 238 "iGetString", 239 "iSetString" 240] 241 242funcs_without_helper = [ 243 "coreAnnotationElementToArkTsAnnotationElement", 244 "coreNamespaceToArkTsNamespace", 245 "annotationElementGetAnnotation", 246 "moduleEnumerateAnonymousFunctions", 247 "annotationInterfaceFieldGetName", 248 "classEnumerateAnnotations", 249 "functionEnumerateNestedFunctions", 250 "functionEnumerateNestedClasses", 251 "literalGetMethod", 252 "namespaceGetName", 253 "functionGetParentNamespace", 254 "moduleEnumerateNamespaces", 255 "annotationInterfaceGetFile", 256 "annotationInterfaceGetName", 257 "moduleEnumerateAnnotationInterfaces", 258 "annotationElementGetFile", 259 "namespaceGetParentNamespace", 260 "coreFunctionToArkTsFunction", 261 "coreAnnotationInterfaceFieldToArkTsAnnotationInterfaceField", 262 "arkTsAnnotationInterfaceFieldToCoreAnnotationInterfaceField", 263 "coreImportDescriptorToArkTsImportDescriptor", 264 "arkTsImportDescriptorToCoreImportDescriptor", 265 "coreClassToArkTsClass", 266 "arkTsClassToCoreClass", 267 "arkTsModuleToCoreModule", 268 "coreAnnotationToArkTsAnnotation", 269 "arkTsAnnotationElementToCoreAnnotationElement", 270 "arkTsFunctionToCoreFunction", 271 "arkTsExportDescriptorToCoreExportDescriptor", 272 "arkTsAnnotationToCoreAnnotation", 273 "arkTsV1NamespaceGetConstructor", 274 "arkTsNamespaceToCoreNamespace", 275 "arkTsAnnotationInterfaceToCoreAnnotationInterface", 276 "coreExportDescriptorToArkTsExportDescriptor", 277 "coreModuleToArkTsModule", 278 "coreAnnotationInterfaceToArkTsAnnotationInterface", 279 "annotationInterfaceRemoveField", 280 "annotationRemoveAnnotationElement", 281 "classRemoveAnnotation", 282 "functionAddAnnotation", 283 "functionRemoveAnnotation", 284 "annotationAddAnnotationElement", 285 "moduleAddImportFromArkTsV1ToArkTsV1", 286 "classAddAnnotation", 287 "moduleAddExportFromArkTsV2ToArkTsV2", 288 "moduleAddImportFromArkTsV2ToArkTsV2", 289 "moduleAddAnnotationInterface", 290 "fileAddExternalModuleArktsV1", 291 "annotationInterfaceAddField", 292 "moduleAddExportFromArkTsV1ToArkTsV1", 293 "bbGetPredBlock", 294 "bbGetSuccBlock", 295 "gInsertTryCatch", 296 "iGetConstantValueI32", 297 "bbDisconnectSuccBlock", 298 "bbIsTry", 299 "gGetIsa", 300 "bbIsCatch", 301 "iGetInput", 302 "gGetFile", 303 "annotationInterfaceFieldGetFile", 304 "annotationInterfaceFieldGetDefaultValue", 305 "literalGetLiteralArray", 306 "annotationInterfaceGetModule", 307 "namespaceEnumerateTopLevelFunctions", 308 "annotationInterfaceFieldGetInterface", 309 "literalGetFile", 310 "annotationElementGetValue", 311 "classGetParentFunction", 312 "classGetParentNamespace", 313 "annotationGetInterface", 314 "annotationInterfaceFieldGetType", 315 "annotationInterfaceEnumerateFields", 316 "moduleGetTarget", 317 "namespaceEnumerateNamespaces", 318 "annotationElementGetName", 319 "createGraphFromFunction", 320 "namespaceEnumerateClasses", 321 "valueGetFile", 322 "abckitStringToString", 323 "bbCreateCatchPhi", 324 "iGetClass", 325 "iSetClass", 326 "jsImportDescriptorToCoreImportDescriptor", 327 "jsFunctionToCoreFunction", 328 "jsClassToCoreClass", 329 "coreClassToJsClass", 330 "jsExportDescriptorToCoreExportDescriptor", 331 "coreImportDescriptorToJsImportDescriptor", 332 "coreModuleToJsModule", 333 "coreFunctionToJsFunction", 334 "coreExportDescriptorToJsExportDescriptor", 335 "jsModuleToCoreModule", 336 "fileAddExternalModule", 337 "moduleAddExportFromJsToJs", 338 "moduleAddImportFromJsToJs", 339 "createLiteralMethod", 340 "createLiteralLiteralArray", 341 "createLiteralArray", 342 "createType", 343] 344 345funcs_varargs = [ 346 "iCreateNewobjrange", 347 "iCreateWideSupercallthisrange", 348 "iCreateSupercallthisrange", 349 "iCreateWideNewobjrange", 350] 351 352excluded_funcs += funcs_without_two_abckit_entites 353excluded_funcs += funcs_varargs 354excluded_funcs += funcs_without_helper 355 356implemented_api_map = collect_implemented_api_map(excluded_funcs) 357wrong_ctx_tests_erb = File.join(abckit_test, "wrong_ctx_tests.cpp.erb") 358implemented_api_map.each_key do |domain| 359 iteration = 0 360 index = 0 361 slice_size = 100 362 api_funcs_arr = implemented_api_map[domain] 363 total_domain_api_funcs = api_funcs_arr.length 364 365 puts "#{domain}: #{total_domain_api_funcs}" 366 367 while index < total_domain_api_funcs do 368 testfile_fullpath = File.join(abckit_test, "wrong_ctx_tests_#{domain}_#{iteration}.cpp") 369 res = ERB.new(File.read(wrong_ctx_tests_erb), nil, "%").result(binding) 370 File.write(testfile_fullpath, res) 371 iteration += 1 372 index += slice_size 373 end 374end