• 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/ir_core.h"
18 #include "libabckit/include/c/isa/isa_static.h"
19 #include "libabckit/include/c/metadata_core.h"
20 
21 #include "helpers/helpers_runtime.h"
22 #include "helpers/helpers.h"
23 #include "libabckit/include/c/statuses.h"
24 
25 #include <gtest/gtest.h>
26 
27 // NOLINTBEGIN(readability-magic-numbers)
28 namespace libabckit::test {
29 
30 namespace {
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_statG = AbckitGetIsaApiStaticImpl(ABCKIT_VERSION_RELEASE_1_0_0);
36 
CheckInstAndGetNext(AbckitInst * inst,AbckitIsaApiStaticOpcode opcode)37 AbckitInst *CheckInstAndGetNext(AbckitInst *inst, AbckitIsaApiStaticOpcode opcode)
38 {
39     EXPECT_EQ(g_statG->iGetOpcode(inst), opcode);
40     EXPECT_EQ(g_impl->getLastError(), ABCKIT_STATUS_NO_ERROR);
41     inst = g_implG->iGetNext(inst);
42     EXPECT_EQ(g_impl->getLastError(), ABCKIT_STATUS_NO_ERROR);
43     return inst;
44 }
45 
InspectIr(AbckitGraph * graph)46 void InspectIr(AbckitGraph *graph)
47 {
48     auto *bb = g_implG->gGetBasicBlock(graph, 0);
49     ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_NO_ERROR);
50 
51     auto *inst = g_implG->bbGetFirstInst(bb);
52     ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_NO_ERROR);
53 
54     inst = CheckInstAndGetNext(inst, ABCKIT_ISA_API_STATIC_OPCODE_INITOBJECT);
55     inst = CheckInstAndGetNext(inst, ABCKIT_ISA_API_STATIC_OPCODE_NEWARRAY);
56     inst = CheckInstAndGetNext(inst, ABCKIT_ISA_API_STATIC_OPCODE_STOREARRAY);
57     inst = CheckInstAndGetNext(inst, ABCKIT_ISA_API_STATIC_OPCODE_INITOBJECT);
58     inst = CheckInstAndGetNext(inst, ABCKIT_ISA_API_STATIC_OPCODE_STOREARRAY);
59     inst = CheckInstAndGetNext(inst, ABCKIT_ISA_API_STATIC_OPCODE_LOADARRAY);
60     inst = CheckInstAndGetNext(inst, ABCKIT_ISA_API_STATIC_OPCODE_LOADOBJECT);
61     inst = CheckInstAndGetNext(inst, ABCKIT_ISA_API_STATIC_OPCODE_CAST);
62     CheckInstAndGetNext(inst, ABCKIT_ISA_API_STATIC_OPCODE_RETURN);
63 }
64 }  // namespace
65 
66 class LibAbcKitIgetOpcodeStaticTest : public ::testing::Test {};
67 
68 // Test: test-kind=api, api=IsaApiStaticImpl::iGetOpcode, abc-kind=ArkTS2, category=positive, extension=c
TEST_F(LibAbcKitIgetOpcodeStaticTest,LibAbcKitTestIgetOpcode)69 TEST_F(LibAbcKitIgetOpcodeStaticTest, LibAbcKitTestIgetOpcode)
70 {
71     helpers::InspectMethod(
72         ABCKIT_ABC_DIR "ut/isa/isa_static/get_opcode/get_opcode_static.abc", "foo",
73         [](AbckitFile * /*file*/, AbckitCoreFunction * /*method*/, AbckitGraph *graph) { InspectIr(graph); });
74 }
75 
76 }  // namespace libabckit::test
77 // NOLINTEND(readability-magic-numbers)
78