1 /**
2 * Copyright (c) 2024-2025 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or g_implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "ir_impl.h"
17 #include "libabckit/include/c/isa/isa_static.h"
18 #include "libabckit/include/c/metadata_core.h"
19 #include "libabckit/include/c/ir_core.h"
20 #include "libabckit/include/c/isa/isa_dynamic.h"
21 #include "libabckit/include/c/abckit.h"
22
23 #include "helpers/helpers.h"
24 #include "helpers/helpers_runtime.h"
25 #include "metadata_inspect_impl.h"
26
27 #include <gtest/gtest.h>
28
29 // NOLINTBEGIN(readability-magic-numbers)
30 namespace libabckit::test {
31
32 static auto g_impl = AbckitGetApiImpl(ABCKIT_VERSION_RELEASE_1_0_0);
33 static auto g_implI = AbckitGetInspectApiImpl(ABCKIT_VERSION_RELEASE_1_0_0);
34 static auto g_implM = AbckitGetModifyApiImpl(ABCKIT_VERSION_RELEASE_1_0_0);
35 static auto g_implG = AbckitGetGraphApiImpl(ABCKIT_VERSION_RELEASE_1_0_0);
36 static auto g_dynG = AbckitGetIsaApiDynamicImpl(ABCKIT_VERSION_RELEASE_1_0_0);
37
38 class LibAbcKitCreateDynSendable : public ::testing::Test {};
39
CreateSendableClass(AbckitInst * klass,AbckitFile * file,AbckitGraph * graph)40 static AbckitInst *CreateSendableClass(AbckitInst *klass, AbckitFile *file, AbckitGraph *graph)
41 {
42 auto *m = g_implG->iGetFunction(klass);
43 EXPECT_EQ(g_impl->getLastError(), ABCKIT_STATUS_NO_ERROR);
44 auto *litarr = g_implG->iGetLiteralArray(klass);
45 EXPECT_EQ(g_impl->getLastError(), ABCKIT_STATUS_NO_ERROR);
46 auto immClass = g_implG->iGetImmediate(klass, 0);
47 EXPECT_EQ(g_impl->getLastError(), ABCKIT_STATUS_NO_ERROR);
48 auto *input = g_implG->iGetInput(klass, 0);
49 EXPECT_EQ(g_impl->getLastError(), ABCKIT_STATUS_NO_ERROR);
50
51 std::array<AbckitLiteral *, 2U> statlitarr = {g_implM->createLiteralU32(file, 0),
52 g_implM->createLiteralLiteralArray(file, litarr)};
53
54 auto *newlitarr = g_implM->createLiteralArray(file, statlitarr.data(), 2U);
55 EXPECT_EQ(g_impl->getLastError(), ABCKIT_STATUS_NO_ERROR);
56
57 // creating new inst
58 auto *sendableKlass = g_dynG->iCreateCallruntimeDefinesendableclass(graph, m, newlitarr, immClass, input);
59 EXPECT_NE(sendableKlass, nullptr);
60 EXPECT_EQ(g_impl->getLastError(), ABCKIT_STATUS_NO_ERROR);
61 return sendableKlass;
62 }
63
TransformIrSendableClass(AbckitFile * file,AbckitGraph * graph,bool isWideMode,uint64_t imm=0x0)64 static void TransformIrSendableClass(AbckitFile *file, AbckitGraph *graph, bool isWideMode, uint64_t imm = 0x0)
65 {
66 auto *klass = helpers::FindFirstInst(graph, ABCKIT_ISA_API_DYNAMIC_OPCODE_DEFINECLASSWITHBUFFER);
67 ASSERT_NE(klass, nullptr);
68 ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_NO_ERROR);
69
70 auto *sendableKlass = CreateSendableClass(klass, file, graph);
71 ASSERT_NE(sendableKlass, nullptr);
72
73 // Slot number passed to create newsendableenv allows [0, slot number - 1] slots to be used by other instructions in
74 // this env. Slot index imm used in stsendablevar and ldsendablevar must be less than the slot number.
75 AbckitInst *newsendableenv = isWideMode ? g_dynG->iCreateCallruntimeWidenewsendableenv(graph, imm + 1)
76 : g_dynG->iCreateCallruntimeNewsendableenv(graph, imm + 1);
77 ASSERT_NE(newsendableenv, nullptr);
78 ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_NO_ERROR);
79
80 AbckitInst *stsendablevar = isWideMode ? g_dynG->iCreateCallruntimeWidestsendablevar(graph, sendableKlass, 0x0, imm)
81 : g_dynG->iCreateCallruntimeStsendablevar(graph, sendableKlass, 0x0, imm);
82 ASSERT_NE(stsendablevar, nullptr);
83 ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_NO_ERROR);
84
85 // getting other insts
86 auto *ldhole = g_implG->iGetPrev(klass);
87 ASSERT_NE(ldhole, nullptr);
88 ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_NO_ERROR);
89 auto *definefunc = g_implG->iGetPrev(ldhole);
90 ASSERT_NE(definefunc, nullptr);
91 ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_NO_ERROR);
92 auto *newlexenv = g_implG->iGetPrev(definefunc);
93 ASSERT_NE(newlexenv, nullptr);
94 ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_NO_ERROR);
95 auto *ldobjbyname = g_implG->iGetNext(klass);
96 ASSERT_NE(ldobjbyname, nullptr);
97 ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_NO_ERROR);
98 auto *stlexvar = g_implG->iGetNext(ldobjbyname);
99 ASSERT_NE(stlexvar, nullptr);
100 ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_NO_ERROR);
101
102 // removing old insts
103 g_implG->iRemove(klass);
104 ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_NO_ERROR);
105 g_implG->iRemove(ldobjbyname);
106 ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_NO_ERROR);
107
108 g_implG->iInsertAfter(newsendableenv, newlexenv);
109 ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_NO_ERROR);
110 g_implG->iRemove(newlexenv);
111 ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_NO_ERROR);
112
113 g_implG->iInsertAfter(sendableKlass, ldhole);
114 ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_NO_ERROR);
115
116 g_implG->iInsertAfter(stsendablevar, stlexvar);
117 ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_NO_ERROR);
118 g_implG->iRemove(stlexvar);
119 ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_NO_ERROR);
120
121 // setting up insts' inputs
122 g_implG->iSetInput(sendableKlass, ldhole, 0);
123 ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_NO_ERROR);
124 }
125
TransformIrSendableClassFoo(AbckitGraph * graph,bool isWideMode,uint64_t imm)126 static void TransformIrSendableClassFoo(AbckitGraph *graph, bool isWideMode, uint64_t imm)
127 {
128 auto *ldlexvar = helpers::FindFirstInst(graph, ABCKIT_ISA_API_DYNAMIC_OPCODE_LDLEXVAR);
129 ASSERT_NE(ldlexvar, nullptr);
130 ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_NO_ERROR);
131 auto *throwundef = g_implG->iGetNext(ldlexvar);
132 ASSERT_NE(throwundef, nullptr);
133 ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_NO_ERROR);
134 auto *newobjrange = g_implG->iGetNext(throwundef);
135 ASSERT_NE(newobjrange, nullptr);
136 ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_NO_ERROR);
137 auto *ret = g_implG->iGetNext(newobjrange);
138 ASSERT_NE(ret, nullptr);
139 ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_NO_ERROR);
140
141 AbckitInst *ldsendablevar = nullptr;
142 if (isWideMode) {
143 ldsendablevar = g_dynG->iCreateCallruntimeWideldsendablevar(graph, 0x0, imm);
144 } else {
145 ldsendablevar = g_dynG->iCreateCallruntimeLdsendablevar(graph, 0x0, imm);
146 }
147 ASSERT_NE(ldsendablevar, nullptr);
148 ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_NO_ERROR);
149
150 g_implG->iInsertAfter(ldsendablevar, ldlexvar);
151 ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_NO_ERROR);
152 g_implG->iRemove(ldlexvar);
153 ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_NO_ERROR);
154
155 g_implG->iSetInput(throwundef, ldsendablevar, 0);
156 ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_NO_ERROR);
157 g_implG->iSetInput(newobjrange, ldsendablevar, 0);
158 ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_NO_ERROR);
159 }
160
TransformIrLdSendableClass(AbckitFile * file,AbckitGraph * graph)161 static void TransformIrLdSendableClass(AbckitFile *file, AbckitGraph *graph)
162 {
163 auto *ret = helpers::FindFirstInst(graph, ABCKIT_ISA_API_DYNAMIC_OPCODE_RETURN);
164 ASSERT_NE(ret, nullptr);
165 ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_NO_ERROR);
166
167 auto *str = g_implM->createString(file, "foo", strlen("foo"));
168 ASSERT_NE(str, nullptr);
169 ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_NO_ERROR);
170
171 // creating new inst
172 auto *ldsendableclass = g_dynG->iCreateCallruntimeLdsendableclass(graph, 0x0);
173 ASSERT_NE(ldsendableclass, nullptr);
174 ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_NO_ERROR);
175
176 auto *ldobjbyname = g_dynG->iCreateLdobjbyname(graph, ldsendableclass, str);
177 ASSERT_NE(ldobjbyname, nullptr);
178 ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_NO_ERROR);
179
180 auto *callthis0 = g_dynG->iCreateCallthis0(graph, ldobjbyname, ldsendableclass);
181 ASSERT_NE(callthis0, nullptr);
182 ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_NO_ERROR);
183
184 g_implG->iInsertBefore(callthis0, ret);
185 ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_NO_ERROR);
186 g_implG->iInsertBefore(ldobjbyname, callthis0);
187 ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_NO_ERROR);
188 g_implG->iInsertBefore(ldsendableclass, ldobjbyname);
189 ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_NO_ERROR);
190 }
191
TransformIrSendableClassCtor(AbckitGraph * graph,bool isWideMode)192 static void TransformIrSendableClassCtor(AbckitGraph *graph, bool isWideMode)
193 {
194 auto *ldexternalmodulevar = helpers::FindFirstInst(graph, ABCKIT_ISA_API_DYNAMIC_OPCODE_LDEXTERNALMODULEVAR);
195 ASSERT_NE(ldexternalmodulevar, nullptr);
196 ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_NO_ERROR);
197
198 auto *throwundefined = g_implG->iGetNext(ldexternalmodulevar);
199 ASSERT_NE(throwundefined, nullptr);
200 ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_NO_ERROR);
201
202 auto *callarg1 = g_implG->iGetNext(throwundefined);
203 ASSERT_NE(callarg1, nullptr);
204 ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_NO_ERROR);
205
206 // creating new inst
207 AbckitInst *ldsendableexternalmodulevar = nullptr;
208 if (isWideMode) {
209 ldsendableexternalmodulevar = g_dynG->iCreateCallruntimeWideldsendableexternalmodulevar(graph, 0x0);
210 } else {
211 ldsendableexternalmodulevar = g_dynG->iCreateCallruntimeLdsendableexternalmodulevar(graph, 0x0);
212 }
213 ASSERT_NE(ldsendableexternalmodulevar, nullptr);
214 ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_NO_ERROR);
215
216 g_implG->iInsertBefore(ldsendableexternalmodulevar, ldexternalmodulevar);
217 ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_NO_ERROR);
218
219 g_implG->iSetInput(throwundefined, ldsendableexternalmodulevar, 0);
220 ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_NO_ERROR);
221 g_implG->iSetInput(callarg1, ldsendableexternalmodulevar, 1);
222 ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_NO_ERROR);
223
224 g_implG->iRemove(ldexternalmodulevar);
225 ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_NO_ERROR);
226 g_implG->gGetStartBasicBlock(graph);
227 }
228
VerifyIrSendableClass(AbckitGraph * graph,bool isWideMode)229 static void VerifyIrSendableClass(AbckitGraph *graph, bool isWideMode)
230 {
231 AbckitIsaApiDynamicOpcode newsendableenv = isWideMode ? ABCKIT_ISA_API_DYNAMIC_OPCODE_CALLRUNTIME_WIDENEWSENDABLEENV
232 : ABCKIT_ISA_API_DYNAMIC_OPCODE_CALLRUNTIME_NEWSENDABLEENV;
233 AbckitIsaApiDynamicOpcode stsendablevar = isWideMode ? ABCKIT_ISA_API_DYNAMIC_OPCODE_CALLRUNTIME_WIDESTSENDABLEVAR
234 : ABCKIT_ISA_API_DYNAMIC_OPCODE_CALLRUNTIME_STSENDABLEVAR;
235 std::vector<helpers::BBSchema<AbckitIsaApiDynamicOpcode>> bbSchema = {
236 {{},
237 {1},
238 {{8, ABCKIT_ISA_API_DYNAMIC_OPCODE_PARAMETER, {}},
239 {9, ABCKIT_ISA_API_DYNAMIC_OPCODE_PARAMETER, {}},
240 {10, ABCKIT_ISA_API_DYNAMIC_OPCODE_PARAMETER, {}}}},
241 {{0},
242 {2},
243 {
244 {0, newsendableenv, {}},
245 {1, ABCKIT_ISA_API_DYNAMIC_OPCODE_DEFINEFUNC, {}},
246 {2, ABCKIT_ISA_API_DYNAMIC_OPCODE_LDHOLE, {}},
247 {3, ABCKIT_ISA_API_DYNAMIC_OPCODE_CALLRUNTIME_DEFINESENDABLECLASS, {2}},
248 {4, stsendablevar, {3}},
249 {5, ABCKIT_ISA_API_DYNAMIC_OPCODE_CALLARG0, {1}},
250 {6, ABCKIT_ISA_API_DYNAMIC_OPCODE_RETURNUNDEFINED, {}},
251 }},
252 {{1}, {}, {}}};
253
254 helpers::VerifyGraph(graph, bbSchema);
255 }
256
VerifyIrSendableClassFoo(AbckitGraph * graph,bool isWideMode)257 static void VerifyIrSendableClassFoo(AbckitGraph *graph, bool isWideMode)
258 {
259 AbckitIsaApiDynamicOpcode ldsendable = isWideMode ? ABCKIT_ISA_API_DYNAMIC_OPCODE_CALLRUNTIME_WIDELDSENDABLEVAR
260 : ABCKIT_ISA_API_DYNAMIC_OPCODE_CALLRUNTIME_LDSENDABLEVAR;
261 std::vector<helpers::BBSchema<AbckitIsaApiDynamicOpcode>> bbSchema = {
262 {{},
263 {1},
264 {{4, ABCKIT_ISA_API_DYNAMIC_OPCODE_PARAMETER, {}},
265 {5, ABCKIT_ISA_API_DYNAMIC_OPCODE_PARAMETER, {}},
266 {6, ABCKIT_ISA_API_DYNAMIC_OPCODE_PARAMETER, {}}}},
267 {{0},
268 {2},
269 {
270 {0, ldsendable, {}},
271 {1, ABCKIT_ISA_API_DYNAMIC_OPCODE_THROW_UNDEFINEDIFHOLEWITHNAME, {0}},
272 {2, ABCKIT_ISA_API_DYNAMIC_OPCODE_NEWOBJRANGE, {0}},
273 {3, ABCKIT_ISA_API_DYNAMIC_OPCODE_RETURN, {2}},
274 }},
275 {{1}, {}, {}}};
276
277 helpers::VerifyGraph(graph, bbSchema);
278 }
279
VerifyIrSendableClassCtor(AbckitGraph * graph,bool isWideMode)280 static void VerifyIrSendableClassCtor(AbckitGraph *graph, bool isWideMode)
281 {
282 AbckitIsaApiDynamicOpcode ldsendableexternal =
283 isWideMode ? ABCKIT_ISA_API_DYNAMIC_OPCODE_CALLRUNTIME_WIDELDSENDABLEEXTERNALMODULEVAR
284 : ABCKIT_ISA_API_DYNAMIC_OPCODE_CALLRUNTIME_LDSENDABLEEXTERNALMODULEVAR;
285 std::vector<helpers::BBSchema<AbckitIsaApiDynamicOpcode>> bbSchema = {
286 {{},
287 {1},
288 {{0, ABCKIT_ISA_API_DYNAMIC_OPCODE_PARAMETER, {}},
289 {1, ABCKIT_ISA_API_DYNAMIC_OPCODE_PARAMETER, {}},
290 {2, ABCKIT_ISA_API_DYNAMIC_OPCODE_PARAMETER, {}}}},
291 {{0},
292 {2},
293 {
294 {3, ABCKIT_ISA_API_DYNAMIC_OPCODE_TRYLDGLOBALBYNAME, {}},
295 {4, ldsendableexternal, {}},
296 {5, ABCKIT_ISA_API_DYNAMIC_OPCODE_THROW_UNDEFINEDIFHOLEWITHNAME, {4}},
297 {6, ABCKIT_ISA_API_DYNAMIC_OPCODE_CALLARG1, {3, 4}},
298 {7, ABCKIT_ISA_API_DYNAMIC_OPCODE_TRYLDGLOBALBYNAME, {}},
299 {8, ABCKIT_ISA_API_DYNAMIC_OPCODE_LOADSTRING, {}},
300 {9, ABCKIT_ISA_API_DYNAMIC_OPCODE_CALLARG1, {7, 8}},
301 {10, ABCKIT_ISA_API_DYNAMIC_OPCODE_RETURN, {2}},
302 }},
303 {{1}, {}, {}}};
304
305 helpers::VerifyGraph(graph, bbSchema);
306 }
307
VerifyIrLdSendableClass(AbckitGraph * graph)308 static void VerifyIrLdSendableClass(AbckitGraph *graph)
309 {
310 std::vector<helpers::BBSchema<AbckitIsaApiDynamicOpcode>> bbSchema = {
311 {{},
312 {1},
313 {
314 {0, ABCKIT_ISA_API_DYNAMIC_OPCODE_PARAMETER, {}},
315 {1, ABCKIT_ISA_API_DYNAMIC_OPCODE_PARAMETER, {}},
316 {2, ABCKIT_ISA_API_DYNAMIC_OPCODE_PARAMETER, {}},
317 }},
318 {{0},
319 {2},
320 {
321 {3, ABCKIT_ISA_API_DYNAMIC_OPCODE_CALLRUNTIME_LDSENDABLECLASS, {}},
322 {4, ABCKIT_ISA_API_DYNAMIC_OPCODE_LDOBJBYNAME, {3}},
323 {5, ABCKIT_ISA_API_DYNAMIC_OPCODE_CALLTHIS0, {4, 3}},
324 {6, ABCKIT_ISA_API_DYNAMIC_OPCODE_RETURN, {2}},
325 }},
326 {{1}, {}, {}}};
327
328 helpers::VerifyGraph(graph, bbSchema);
329 }
330
ModifySendableClass(bool isWideMode,uint64_t imm=0x0)331 static void ModifySendableClass(bool isWideMode, uint64_t imm = 0x0)
332 {
333 auto output = helpers::ExecuteDynamicAbc(ABCKIT_ABC_DIR "ut/isa/isa_dynamic/sendable/makesendableclass_dynamic.abc",
334 "makesendableclass_dynamic");
335 EXPECT_TRUE(helpers::Match(output, "0\nHello\n"));
336
337 helpers::TransformMethod(
338 ABCKIT_ABC_DIR "ut/isa/isa_dynamic/sendable/makesendableclass_dynamic.abc",
339 ABCKIT_ABC_DIR "ut/isa/isa_dynamic/sendable/makesendableclass_dynamic_modified.abc",
340 "makesendableclass_dynamic.func_main_0",
341 [&](AbckitFile *file, AbckitCoreFunction *, AbckitGraph *graph) {
342 TransformIrSendableClass(file, graph, isWideMode, imm);
343 },
344 [&](AbckitGraph *graph) { VerifyIrSendableClass(graph, isWideMode); });
345
346 helpers::TransformMethod(
347 ABCKIT_ABC_DIR "ut/isa/isa_dynamic/sendable/makesendableclass_dynamic_modified.abc",
348 ABCKIT_ABC_DIR "ut/isa/isa_dynamic/sendable/makesendableclass_dynamic_modified.abc",
349 "makesendableclass_dynamic.foo",
350 [&](AbckitFile *, AbckitCoreFunction *, AbckitGraph *graph) {
351 TransformIrSendableClassFoo(graph, isWideMode, imm);
352 },
353 [&](AbckitGraph *graph) { VerifyIrSendableClassFoo(graph, isWideMode); });
354
355 helpers::TransformMethod(
356 ABCKIT_ABC_DIR "ut/isa/isa_dynamic/sendable/makesendableclass_dynamic_modified.abc",
357 ABCKIT_ABC_DIR "ut/isa/isa_dynamic/sendable/makesendableclass_dynamic_modified.abc",
358 "makesendableclass_dynamic.A",
359 [&](AbckitFile * /*file*/, AbckitCoreFunction * /*method*/, AbckitGraph *graph) {
360 TransformIrSendableClassCtor(graph, isWideMode);
361 },
362 [&](AbckitGraph *graph) { VerifyIrSendableClassCtor(graph, isWideMode); });
363
364 output =
365 helpers::ExecuteDynamicAbc(ABCKIT_ABC_DIR "ut/isa/isa_dynamic/sendable/makesendableclass_dynamic_modified.abc",
366 "makesendableclass_dynamic");
367 EXPECT_TRUE(helpers::Match(output, "0\nHello\n"));
368 }
369
370 // Test: test-kind=api, api=IsaApiDynamicImpl::iCreateCallruntimeDefinesendableclass, abc-kind=ArkTS1,
371 // category=positive, extension=c
TEST_F(LibAbcKitCreateDynSendable,DefineSendableClass)372 TEST_F(LibAbcKitCreateDynSendable, DefineSendableClass)
373 {
374 ModifySendableClass(false);
375 }
376
377 // Test: test-kind=api, api=IsaApiDynamicImpl::iCreateCallruntimeLdsendablevar, abc-kind=ArkTS1, category=positive,
378 // extension=c
TEST_F(LibAbcKitCreateDynSendable,LdSendableVar_imm4)379 TEST_F(LibAbcKitCreateDynSendable, LdSendableVar_imm4)
380 {
381 ModifySendableClass(false, 0x0);
382 }
383
384 // Test: test-kind=api, api=IsaApiDynamicImpl::iCreateCallruntimeLdsendablevar, abc-kind=ArkTS1, category=positive,
385 // extension=c
TEST_F(LibAbcKitCreateDynSendable,LdSendableVar_imm8)386 TEST_F(LibAbcKitCreateDynSendable, LdSendableVar_imm8)
387 {
388 ModifySendableClass(false, 0x10);
389 }
390
391 // Test: test-kind=api, api=IsaApiDynamicImpl::iCreateCallruntimeNewsendableenv, abc-kind=ArkTS1, category=positive,
392 // extension=c
TEST_F(LibAbcKitCreateDynSendable,NewSendableEnv)393 TEST_F(LibAbcKitCreateDynSendable, NewSendableEnv)
394 {
395 ModifySendableClass(false);
396 }
397
398 // Test: test-kind=api, api=IsaApiDynamicImpl::iCreateCallruntimeStsendablevar, abc-kind=ArkTS1, category=positive,
399 // extension=c
TEST_F(LibAbcKitCreateDynSendable,StSendableVar_imm4)400 TEST_F(LibAbcKitCreateDynSendable, StSendableVar_imm4)
401 {
402 ModifySendableClass(false, 0x0);
403 }
404
405 // Test: test-kind=api, api=IsaApiDynamicImpl::iCreateCallruntimeStsendablevar, abc-kind=ArkTS1, category=positive,
406 // extension=c
TEST_F(LibAbcKitCreateDynSendable,StSendableVar_imm8)407 TEST_F(LibAbcKitCreateDynSendable, StSendableVar_imm8)
408 {
409 ModifySendableClass(false, 0x10);
410 }
411
412 // Test: test-kind=api, api=IsaApiDynamicImpl::iCreateCallruntimeLdsendableexternalmodulevar, abc-kind=ArkTS1,
413 // category=positive
TEST_F(LibAbcKitCreateDynSendable,LdExternalModuleVar)414 TEST_F(LibAbcKitCreateDynSendable, LdExternalModuleVar)
415 {
416 ModifySendableClass(false);
417 }
418
419 // Test: test-kind=api, api=IsaApiDynamicImpl::iCreateCallruntimeLdsendableclass, abc-kind=ArkTS1, category=positive,
420 // extension=c
TEST_F(LibAbcKitCreateDynSendable,LdSendableClass)421 TEST_F(LibAbcKitCreateDynSendable, LdSendableClass)
422 {
423 auto output = helpers::ExecuteDynamicAbc(ABCKIT_ABC_DIR "ut/isa/isa_dynamic/sendable/ldsendableclass_dynamic.abc",
424 "ldsendableclass_dynamic");
425 EXPECT_TRUE(helpers::Match(output, ""));
426
427 helpers::TransformMethod(
428 ABCKIT_ABC_DIR "ut/isa/isa_dynamic/sendable/ldsendableclass_dynamic.abc",
429 ABCKIT_ABC_DIR "ut/isa/isa_dynamic/sendable/ldsendableclass_dynamic_modified.abc", "ldsendableclass_dynamic.B",
430 [&](AbckitFile *file, AbckitCoreFunction * /*method*/, AbckitGraph *graph) {
431 TransformIrLdSendableClass(file, graph);
432 },
433 [&](AbckitGraph *graph) { VerifyIrLdSendableClass(graph); });
434
435 output = helpers::ExecuteDynamicAbc(
436 ABCKIT_ABC_DIR "ut/isa/isa_dynamic/sendable/ldsendableclass_dynamic_modified.abc", "ldsendableclass_dynamic");
437 EXPECT_TRUE(helpers::Match(output, "Hello\n"));
438 }
439
440 // Test: test-kind=api, api=IsaApiDynamicImpl::iCreateCallruntimeWideldsendablevar, abc-kind=ArkTS1, category=positive,
441 // extension=c
TEST_F(LibAbcKitCreateDynSendable,WideLdSendableVar)442 TEST_F(LibAbcKitCreateDynSendable, WideLdSendableVar)
443 {
444 ModifySendableClass(true);
445 }
446
447 // Test: test-kind=api, api=IsaApiDynamicImpl::iCreateCallruntimeWidenewsendableenv, abc-kind=ArkTS1, category=positive,
448 // extension=c
TEST_F(LibAbcKitCreateDynSendable,WideNewSendableEnv)449 TEST_F(LibAbcKitCreateDynSendable, WideNewSendableEnv)
450 {
451 ModifySendableClass(true);
452 }
453
454 // Test: test-kind=api, api=IsaApiDynamicImpl::iCreateCallruntimeWidestsendablevar, abc-kind=ArkTS1, category=positive,
455 // extension=c
TEST_F(LibAbcKitCreateDynSendable,WideStSendableVar)456 TEST_F(LibAbcKitCreateDynSendable, WideStSendableVar)
457 {
458 ModifySendableClass(true);
459 }
460
461 // Test: test-kind=api, api=IsaApiDynamicImpl::iCreateCallruntimeWideldsendableexternalmodulevar, abc-kind=ArkTS1,
462 // category=positive
TEST_F(LibAbcKitCreateDynSendable,WideLdExternalModuleVar)463 TEST_F(LibAbcKitCreateDynSendable, WideLdExternalModuleVar)
464 {
465 ModifySendableClass(true);
466 }
467
468 } // namespace libabckit::test
469 // NOLINTEND(readability-magic-numbers)
470