• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2024 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 implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "libabckit/include/c/metadata_core.h"
17 #include "libabckit/include/c/ir_core.h"
18 #include "libabckit/include/c/isa/isa_dynamic.h"
19 #include "libabckit/include/c/abckit.h"
20 
21 #include "helpers/helpers.h"
22 #include "helpers/helpers_runtime.h"
23 
24 #include <gtest/gtest.h>
25 
26 // NOLINTBEGIN(readability-magic-numbers)
27 namespace libabckit::test {
28 
29 namespace {
30 
31 auto g_impl = AbckitGetApiImpl(ABCKIT_VERSION_RELEASE_1_0_0);
32 auto g_implI = AbckitGetInspectApiImpl(ABCKIT_VERSION_RELEASE_1_0_0);
33 auto g_implM = AbckitGetModifyApiImpl(ABCKIT_VERSION_RELEASE_1_0_0);
34 auto g_implG = AbckitGetGraphApiImpl(ABCKIT_VERSION_RELEASE_1_0_0);
35 auto g_dynG = AbckitGetIsaApiDynamicImpl(ABCKIT_VERSION_RELEASE_1_0_0);
36 
__anonca5e49df0202(AbckitFile *file, AbckitCoreFunction * , AbckitGraph *graph) 37 auto g_icreateGettemplateobject1Lambda = [](AbckitFile *file, AbckitCoreFunction * /*method*/, AbckitGraph *graph) {
38     auto *worldStr = g_implM->createString(file, "world", strlen("world"));
39     auto *loadStringWorld = g_dynG->iCreateLoadString(graph, worldStr);
40     auto *stringPrint = g_implM->createString(file, "print", strlen("print"));
41     auto *tryldglobalbyname = g_dynG->iCreateTryldglobalbyname(graph, stringPrint);
42     auto *createemptyarray1 = g_dynG->iCreateCreateemptyarray(graph);
43     auto *createemptyarray2 = g_dynG->iCreateCreateemptyarray(graph);
44     auto *helloStr = g_implM->createString(file, "Hello ", strlen("Hello "));
45     auto *loadStringHello = g_dynG->iCreateLoadString(graph, helloStr);
46     auto *const0 = g_implG->gFindOrCreateConstantU64(graph, 0);
47     auto *definefieldbyvalue1 =
48         g_dynG->iCreateCallruntimeDefinefieldbyvalue(graph, loadStringHello, const0, createemptyarray1);
49     auto *definefieldbyvalue2 =
50         g_dynG->iCreateCallruntimeDefinefieldbyvalue(graph, loadStringHello, const0, createemptyarray2);
51     auto *str2 = g_implM->createString(file, "!", strlen("!"));
52     auto *loadString2 = g_dynG->iCreateLoadString(graph, str2);
53     auto *const1 = g_implG->gFindOrCreateConstantU64(graph, 1);
54     auto *definefieldbyvalue3 =
55         g_dynG->iCreateCallruntimeDefinefieldbyvalue(graph, loadString2, const1, createemptyarray1);
56     auto *definefieldbyvalue4 =
57         g_dynG->iCreateCallruntimeDefinefieldbyvalue(graph, loadString2, const1, createemptyarray2);
58     auto *createemptyarray3 = g_dynG->iCreateCreateemptyarray(graph);
59     auto *definefieldbyvalue5 =
60         g_dynG->iCreateCallruntimeDefinefieldbyvalue(graph, createemptyarray1, const0, createemptyarray3);
61     auto *definefieldbyvalue6 =
62         g_dynG->iCreateCallruntimeDefinefieldbyvalue(graph, createemptyarray2, const1, createemptyarray3);
63     auto *gettemplateobject = g_dynG->iCreateGettemplateobject(graph, createemptyarray3);
64     ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_NO_ERROR);
65     auto *deffunc = helpers::FindFirstInst(graph, ABCKIT_ISA_API_DYNAMIC_OPCODE_DEFINEFUNC);
66     auto *callargs2 = g_dynG->iCreateCallargs2(graph, deffunc, gettemplateobject, loadStringWorld);
67     auto *callarg1 = g_dynG->iCreateCallarg1(graph, tryldglobalbyname, callargs2);
68 
69     auto *returnundef = helpers::FindFirstInst(graph, ABCKIT_ISA_API_DYNAMIC_OPCODE_RETURNUNDEFINED);
70     g_implG->iInsertBefore(loadStringWorld, returnundef);
71     g_implG->iInsertBefore(tryldglobalbyname, returnundef);
72     g_implG->iInsertBefore(createemptyarray1, returnundef);
73     g_implG->iInsertBefore(createemptyarray2, returnundef);
74     g_implG->iInsertBefore(loadStringHello, returnundef);
75     g_implG->iInsertBefore(definefieldbyvalue1, returnundef);
76     g_implG->iInsertBefore(definefieldbyvalue2, returnundef);
77     g_implG->iInsertBefore(loadString2, returnundef);
78     g_implG->iInsertBefore(definefieldbyvalue3, returnundef);
79     g_implG->iInsertBefore(definefieldbyvalue4, returnundef);
80     g_implG->iInsertBefore(createemptyarray3, returnundef);
81     g_implG->iInsertBefore(definefieldbyvalue5, returnundef);
82     g_implG->iInsertBefore(definefieldbyvalue6, returnundef);
83     g_implG->iInsertBefore(gettemplateobject, returnundef);
84     g_implG->iInsertBefore(callargs2, returnundef);
85     g_implG->iInsertBefore(callarg1, returnundef);
86 };
87 
88 }  // namespace
89 
90 class LibAbcKitCreateDynGettemplateobject : public ::testing::Test {};
91 
92 // Test: test-kind=api, api=IsaApiDynamicImpl::iCreateGettemplateobject, abc-kind=ArkTS1, category=positive, extension=c
TEST_F(LibAbcKitCreateDynGettemplateobject,IcreateGettemplateobject_1)93 TEST_F(LibAbcKitCreateDynGettemplateobject, IcreateGettemplateobject_1)
94 {
95     auto output = helpers::ExecuteDynamicAbc(
96         ABCKIT_ABC_DIR "ut/isa/isa_dynamic/get_insts/gettemplateobject_dynamic.abc", "gettemplateobject_dynamic");
97     EXPECT_TRUE(helpers::Match(output, ""));
98 
99     helpers::TransformMethod(ABCKIT_ABC_DIR "ut/isa/isa_dynamic/get_insts/gettemplateobject_dynamic.abc",
100                              ABCKIT_ABC_DIR "ut/isa/isa_dynamic/get_insts/gettemplateobject_dynamic_modified.abc",
101                              "func_main_0", g_icreateGettemplateobject1Lambda);
102 
103     output =
104         helpers::ExecuteDynamicAbc(ABCKIT_ABC_DIR "ut/isa/isa_dynamic/get_insts/gettemplateobject_dynamic_modified.abc",
105                                    "gettemplateobject_dynamic");
106     EXPECT_TRUE(helpers::Match(output, "Hello world!\n"));
107 }
108 
109 }  // namespace libabckit::test
110 // NOLINTEND(readability-magic-numbers)
111