• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "libabckit/include/c/abckit.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 
21 #include "helpers/helpers_runtime.h"
22 #include "helpers/helpers.h"
23 
24 #include <gtest/gtest.h>
25 
26 namespace libabckit::test {
27 
28 namespace {
29 auto g_impl = AbckitGetApiImpl(ABCKIT_VERSION_RELEASE_1_0_0);
30 auto g_implI = AbckitGetInspectApiImpl(ABCKIT_VERSION_RELEASE_1_0_0);
31 auto g_implM = AbckitGetModifyApiImpl(ABCKIT_VERSION_RELEASE_1_0_0);
32 auto g_implG = AbckitGetGraphApiImpl(ABCKIT_VERSION_RELEASE_1_0_0);
33 auto g_statG = AbckitGetIsaApiStaticImpl(ABCKIT_VERSION_RELEASE_1_0_0);
34 
TransformSetSetCallMethod(AbckitGraph * graph,AbckitCoreFunction * bar)35 void TransformSetSetCallMethod(AbckitGraph *graph, AbckitCoreFunction *bar)
36 {
37     auto *call = helpers::FindFirstInst(graph, ABCKIT_ISA_API_STATIC_OPCODE_CALL_STATIC);
38     ASSERT_NE(call, nullptr);
39     ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_NO_ERROR);
40 
41     g_implG->iSetFunction(call, bar);
42     ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_NO_ERROR);
43 }
44 }  // namespace
45 
46 class LibAbcKitMethodStaticTest : public ::testing::Test {};
47 
48 // Test: test-kind=api, api=GraphApiImpl::iSetFunction, abc-kind=ArkTS2, category=positive, extension=c
TEST_F(LibAbcKitMethodStaticTest,LibAbcKitTestSetCallMethod)49 TEST_F(LibAbcKitMethodStaticTest, LibAbcKitTestSetCallMethod)
50 {
51     auto output = helpers::ExecuteStaticAbc(ABCKIT_ABC_DIR "ut/ir_core/method/method_static.abc",
52                                             "method_static/ETSGLOBAL", "main");
53     EXPECT_TRUE(helpers::Match(output, "foo\n"));
54 
55     helpers::TransformMethod(ABCKIT_ABC_DIR "ut/ir_core/method/method_static.abc",
56                              ABCKIT_ABC_DIR "ut/ir_core/method/method_static_modified.abc", "main",
57                              [](AbckitFile * /*file*/, AbckitCoreFunction *method, AbckitGraph *graph) {
58                                  auto *bar = helpers::FindMethodByName(g_implI->functionGetFile(method), "bar");
59                                  ASSERT_NE(bar, nullptr);
60                                  TransformSetSetCallMethod(graph, bar);
61                              });
62 
63     output = helpers::ExecuteStaticAbc(ABCKIT_ABC_DIR "ut/ir_core/method/method_static_modified.abc",
64                                        "method_static/ETSGLOBAL", "main");
65     EXPECT_TRUE(helpers::Match(output, "bar\n"));
66 }
67 
68 }  // namespace libabckit::test
69