• 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 g_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_dynamic.h"
18 #include "libabckit/include/c/statuses.h"
19 #include "libabckit/include/c/metadata_core.h"
20 #include "libabckit/include/c/ir_core.h"
21 #include "libabckit/src/include_v2/c/isa/isa_static.h"
22 
23 #include "helpers/helpers.h"
24 #include "helpers/helpers_runtime.h"
25 
26 #include <gtest/gtest.h>
27 #include <cstddef>
28 #include <cstdint>
29 
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 LibAbcKitIcreateTest : public ::testing::Test {};
39 
40 // Test: test-kind=api, api=IsaApiDynamicImpl::iCreateDebugger, abc-kind=ArkTS2, category=positive, extension=c
TEST_F(LibAbcKitIcreateTest,IcreateDebugger)41 TEST_F(LibAbcKitIcreateTest, IcreateDebugger)
42 {
43     helpers::TransformMethod(
44         ABCKIT_ABC_DIR "ut/isa/isa_dynamic/create/createdebugger_dynamic.abc",
45         ABCKIT_ABC_DIR "ut/isa/isa_dynamic/create/createdebugger_dynamic_modifyed.abc", "test",
46         [](AbckitFile *, AbckitCoreFunction *, AbckitGraph *graph) {
47             auto *start = g_implG->gGetStartBasicBlock(graph);
48             ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_NO_ERROR);
49             auto *main = helpers::BBgetSuccBlocks(start)[0];
50             ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_NO_ERROR);
51 
52             auto *deb = g_dynG->iCreateDebugger(graph);
53             ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_NO_ERROR);
54             g_implG->bbAddInstFront(main, deb);
55 
56             std::vector<helpers::BBSchema<AbckitIsaApiDynamicOpcode>> bbSchemas(
57                 {{{},
58                   {1},
59                   {{0, ABCKIT_ISA_API_DYNAMIC_OPCODE_PARAMETER, {}},
60                    {1, ABCKIT_ISA_API_DYNAMIC_OPCODE_PARAMETER, {}},
61                    {2, ABCKIT_ISA_API_DYNAMIC_OPCODE_PARAMETER, {}}}},
62                  {{0},
63                   {2},
64                   {
65                       {3, ABCKIT_ISA_API_DYNAMIC_OPCODE_DEBUGGER, {}},
66                       {4, ABCKIT_ISA_API_DYNAMIC_OPCODE_RETURNUNDEFINED, {}},
67                   }},
68                  {{1}, {}, {}}});
69             helpers::VerifyGraph(graph, bbSchemas);
70 
71             ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_NO_ERROR);
72         },
73         []([[maybe_unused]] AbckitGraph *graph) {});
74 }
75 
76 }  // namespace libabckit::test
77