• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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'
15
16abckit_scripts = File.dirname(__FILE__)
17abckit_root = File.expand_path("../", abckit_scripts)
18abckit_test = File.join(abckit_root, "/tests/wrong_imm_tests/")
19
20funcs_with_imm_bitsize_8 = [
21  "iCreateCreateobjectwithexcludedkeys",
22  "iCreateNewlexenv",
23  "iCreateNewlexenvwithname",
24  "iCreateCallruntimeLdsendableexternalmodulevar",
25  "iCreateCallruntimeNewsendableenv",
26  "iCreateCallruntimeStsendablevar",
27  "iCreateCallruntimeLdsendablevar",
28  "iCreateDefinefunc",
29  "iCreateDefinemethod",
30  "iCreateCopyrestargs",
31  "iCreateLdlexvar",
32  "iCreateStlexvar",
33  "iCreateSetgeneratorstate",
34  "iCreateNewobjrange",
35  "iCreateCallrange",
36  "iCreateCallthisrange",
37  "iCreateSupercallarrowrange"
38]
39
40funcs_with_imm_bitsize_16 = [
41  "iCreateLdprivateproperty",
42  "iCreateStprivateproperty",
43  "iCreateTestin",
44  "iCreateWideCreateobjectwithexcludedkeys",
45  "iCreateWideNewlexenv",
46  "iCreateWideNewlexenvwithname",
47  "iCreateCallruntimeCreateprivateproperty",
48  "iCreateCallruntimeDefineprivateproperty",
49  "iCreateCallruntimeDefinesendableclass",
50  "iCreateCallruntimeLdsendableclass",
51  "iCreateCallruntimeWideldsendableexternalmodulevar",
52  "iCreateCallruntimeWidenewsendableenv",
53  "iCreateCallruntimeWidestsendablevar",
54  "iCreateCallruntimeWideldsendablevar",
55  "iCreateThrowIfsupernotcorrectcall",
56  "iCreateDefineclasswithbuffer",
57  "iCreateLdobjbyindex",
58  "iCreateStobjbyindex",
59  "iCreateStownbyindex",
60  "iCreateWideCopyrestargs",
61  "iCreateWideLdlexvar",
62  "iCreateWideStlexvar",
63  "iCreateWideLdpatchvar",
64  "iCreateWideStpatchvar",
65  "iCreateWideNewobjrange",
66  "iCreateWideCallrange",
67  "iCreateWideCallthisrange",
68  "iCreateSupercallarrowrange"
69]
70
71funcs_with_imm_bitsize_32 = [
72  "iCreateCallruntimeDefinefieldbyindex",
73  "iCreateWideStownbyindex",
74  "iCreateWideStobjbyindex",
75  "iCreateWideLdobjbyindex"
76]
77
78implemented_api_raw = nil
79Dir.chdir(abckit_scripts) do
80  implemented_api_raw = `python abckit_status.py --capi --print-implemented 2>&1`.split(/\n/).sort
81end
82
83implemented_api_map = {}
84included_funcs = funcs_with_imm_bitsize_8 + funcs_with_imm_bitsize_16 + funcs_with_imm_bitsize_32
85
86implemented_api_raw.each do |api_func_raw|
87  domain, api_func = *api_func_raw.split(/::/)
88
89  if api_func.include? "iCreate" and domain.include? "IsaApiDynamicImpl" and included_funcs.include?(api_func)
90    if implemented_api_map[domain].nil?
91      implemented_api_map[domain] = [api_func]
92    else
93      implemented_api_map[domain].append(api_func)
94    end
95    next
96  end
97end
98
99wrong_imm_tests_erb = File.join(abckit_test, "wrong_imm_tests.cpp.erb")
100implemented_api_map.each_key do |domain|
101  iteration = 0
102  index = 0
103  slice_size = 100
104  api_funcs_arr = implemented_api_map[domain]
105  total_domain_api_funcs = api_funcs_arr.length
106
107  puts "#{domain}: #{total_domain_api_funcs}"
108
109  while index < total_domain_api_funcs do
110    testfile_fullpath = File.join(abckit_test, "wrong_imm_tests_#{domain}_#{iteration}.cpp")
111    res = ERB.new(File.read(wrong_imm_tests_erb), nil, "%").result(binding)
112    File.write(testfile_fullpath, res)
113    iteration += 1
114    index += slice_size
115  end
116end
117