• 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 #include "helpers_arithmetic.h"
24 
25 #include <gtest/gtest.h>
26 
27 // NOLINTBEGIN(readability-magic-numbers)
28 namespace libabckit::test {
29 
30 static auto g_impl = AbckitGetApiImpl(ABCKIT_VERSION_RELEASE_1_0_0);
31 static auto g_implI = AbckitGetInspectApiImpl(ABCKIT_VERSION_RELEASE_1_0_0);
32 static auto g_implM = AbckitGetModifyApiImpl(ABCKIT_VERSION_RELEASE_1_0_0);
33 static auto g_implG = AbckitGetGraphApiImpl(ABCKIT_VERSION_RELEASE_1_0_0);
34 static auto g_dynG = AbckitGetIsaApiDynamicImpl(ABCKIT_VERSION_RELEASE_1_0_0);
35 
ValidTest(AbckitInst * (* binaryInstToCheck)(AbckitGraph * graph,AbckitInst * input0,AbckitInst * input1),AbckitIsaApiDynamicOpcode expectedOpcode,const std::string & expectedOutput)36 static void ValidTest(AbckitInst *(*binaryInstToCheck)(AbckitGraph *graph, AbckitInst *input0, AbckitInst *input1),
37                       AbckitIsaApiDynamicOpcode expectedOpcode, const std::string &expectedOutput)
38 {
39     auto output = helpers::ExecuteDynamicAbc(ABCKIT_ABC_DIR "ut/isa/isa_dynamic/arithmetic/bininst_shifts_dynamic.abc",
40                                              "bininst_shifts_dynamic");
41     EXPECT_TRUE(helpers::Match(output, "60\n"));
42 
43     helpers::TransformMethod(
44         ABCKIT_ABC_DIR "ut/isa/isa_dynamic/arithmetic/bininst_shifts_dynamic.abc",
45         ABCKIT_ABC_DIR "ut/isa/isa_dynamic/arithmetic/bininst_shifts_dynamic_modified.abc", "foo",
46         [&](AbckitFile * /*file*/, AbckitCoreFunction * /*method*/, AbckitGraph *graph) {
47             helpers::arithmetic::TransformIrBinInstrValid(graph, binaryInstToCheck, 4, 3);
48         },
49         [&](AbckitGraph *graph) {
50             std::vector<helpers::BBSchema<AbckitIsaApiDynamicOpcode>> bbSchemas(
51                 helpers::arithmetic::CreateBBSchemaForDynBinary(expectedOpcode));
52             helpers::VerifyGraph(graph, bbSchemas);
53         });
54 
55     output = helpers::ExecuteDynamicAbc(
56         ABCKIT_ABC_DIR "ut/isa/isa_dynamic/arithmetic/bininst_shifts_dynamic_modified.abc", "bininst_shifts_dynamic");
57     EXPECT_TRUE(helpers::Match(output, expectedOutput));
58 }
59 
60 class LibAbcKitCreateDynBinInstShiftsTest : public ::testing::Test {};
61 
62 // Test: test-kind=api, api=IsaApiDynamicImpl::iCreateShl2, abc-kind=ArkTS1, category=positive, extension=c
TEST_F(LibAbcKitCreateDynBinInstShiftsTest,CreateDynShl2Valid)63 TEST_F(LibAbcKitCreateDynBinInstShiftsTest, CreateDynShl2Valid)
64 {
65     ValidTest(g_dynG->iCreateShl2, ABCKIT_ISA_API_DYNAMIC_OPCODE_SHL2, "40\n");
66 }
67 
68 // Test: test-kind=api, api=IsaApiDynamicImpl::iCreateAshr2, abc-kind=ArkTS1, category=positive, extension=c
TEST_F(LibAbcKitCreateDynBinInstShiftsTest,CreateDynAshr2Valid)69 TEST_F(LibAbcKitCreateDynBinInstShiftsTest, CreateDynAshr2Valid)
70 {
71     ValidTest(g_dynG->iCreateAshr2, ABCKIT_ISA_API_DYNAMIC_OPCODE_ASHR2, "2\n");
72 }
73 
74 // Test: test-kind=api, api=IsaApiDynamicImpl::iCreateShr2, abc-kind=ArkTS1, category=positive, extension=c
TEST_F(LibAbcKitCreateDynBinInstShiftsTest,CreateDynShr2Valid)75 TEST_F(LibAbcKitCreateDynBinInstShiftsTest, CreateDynShr2Valid)
76 {
77     ValidTest(g_dynG->iCreateShr2, ABCKIT_ISA_API_DYNAMIC_OPCODE_SHR2, "2\n");
78 }
79 
80 }  // namespace libabckit::test
81 // NOLINTEND(readability-magic-numbers)
82