• 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 
20 #include "helpers/helpers_runtime.h"
21 #include "helpers/helpers.h"
22 #include "libabckit/src/logger.h"
23 #include <gtest/gtest.h>
24 
25 // NOLINTBEGIN(readability-magic-numbers)
26 namespace libabckit::test {
27 
28 namespace {
29 
30 auto g_impl = AbckitGetApiImpl(ABCKIT_VERSION_RELEASE_1_0_0);
31 auto g_implI = AbckitGetInspectApiImpl(ABCKIT_VERSION_RELEASE_1_0_0);
32 auto g_implM = AbckitGetModifyApiImpl(ABCKIT_VERSION_RELEASE_1_0_0);
33 auto g_implG = AbckitGetGraphApiImpl(ABCKIT_VERSION_RELEASE_1_0_0);
34 auto g_statG = AbckitGetIsaApiStaticImpl(ABCKIT_VERSION_RELEASE_1_0_0);
35 }  // namespace
36 
37 class LibAbcKitThrowStaticTest : public ::testing::Test {};
38 
39 // Test: test-kind=api, api=IsaApiStaticImpl::iCreateThrow, abc-kind=ArkTS2, category=positive, extension=c
TEST_F(LibAbcKitThrowStaticTest,LibAbcKitTestThrow)40 TEST_F(LibAbcKitThrowStaticTest, LibAbcKitTestThrow)
41 {
42     auto output = helpers::ExecuteStaticAbc(ABCKIT_ABC_DIR "ut/isa/isa_static/throw/throw_static.abc",
43                                             "throw_static/ETSGLOBAL", "main");
44     EXPECT_TRUE(helpers::Match(output, ""));
45     helpers::TransformMethod(
46         ABCKIT_ABC_DIR "ut/isa/isa_static/throw/throw_static.abc",
47         ABCKIT_ABC_DIR "ut/isa/isa_static/throw/throw_static_modified.abc", "bar",
48         [](AbckitFile * /*file*/, AbckitCoreFunction * /*method*/, AbckitGraph *graph) {
49             auto ret = helpers::FindFirstInst(graph, ABCKIT_ISA_API_STATIC_OPCODE_RETURN);
50             ASSERT_NE(ret, nullptr);
51 
52             auto input = g_implG->iGetInput(ret, 0);
53             ASSERT_NE(ret, nullptr);
54             ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_NO_ERROR);
55 
56             AbckitInst *thr = g_statG->iCreateThrow(graph, input);
57             ASSERT_NE(thr, nullptr);
58             ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_NO_ERROR);
59 
60             g_implG->iInsertBefore(thr, ret);
61             ASSERT_EQ(g_impl->getLastError(), ABCKIT_STATUS_NO_ERROR);
62         },
63         []([[maybe_unused]] AbckitGraph *graph) {});
64     output = helpers::ExecuteStaticAbc(ABCKIT_ABC_DIR "ut/isa/isa_static/throw/throw_static_modified.abc",
65                                        "throw_static/ETSGLOBAL", "main");
66     EXPECT_TRUE(helpers::Match(output, "THROW\n"));
67 }
68 
69 }  // namespace libabckit::test
70    // NOLINTEND(readability-magic-numbers)
71