• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 <gtest/gtest.h>
17 
18 #include "compiler/optimizer/ir/basicblock.h"
19 #include "compiler/optimizer/optimizations/regalloc/reg_alloc.h"
20 #include "graph_test.h"
21 #include "mem/pool_manager.h"
22 #include "reg_acc_alloc.h"
23 #include "reg_encoder.h"
24 
25 using namespace testing::ext;
26 
27 namespace panda::bytecodeopt {
28 using namespace compiler;
29 using namespace panda;
30 class RegEncoderTest : public testing::Test {
31 public:
SetUpTestCase(void)32     static void SetUpTestCase(void) {}
TearDownTestCase(void)33     static void TearDownTestCase(void) {}
SetUp()34     void SetUp() {}
TearDown()35     void TearDown() {}
36 
37     GraphTest graph_test_;
38 };
39 
40 /**
41  * @tc.name: reg_encoder_test_001
42  * @tc.desc: Verify the RunImpl function.
43  * @tc.type: FUNC
44  * @tc.require: issueNumber
45  */
46 HWTEST_F(RegEncoderTest, reg_encoder_test_001, TestSize.Level1)
47 {
48     std::string pFile = GRAPH_TEST_ABC_DIR "codegenTryCatch.abc";
49     const char *test_method_name = "func4";
50     bool status = false;
51 
__anonc9e90bdd0102(Graph* graph, std::string &method_name) 52     graph_test_.TestBuildGraphFromFile(pFile, [test_method_name, &status](Graph* graph, std::string &method_name) {
53         if (test_method_name != method_name) {
54             return;
55         }
56         status = true;
57         EXPECT_NE(graph, nullptr);
58         EXPECT_TRUE(RegAlloc(graph));
59         EXPECT_TRUE(graph->RunPass<RegEncoder>());
60     });
61     EXPECT_TRUE(status);
62 }
63 
64 /**
65  * @tc.name: reg_encoder_test_002
66  * @tc.desc: Verify the RunImpl function.
67  * @tc.type: FUNC
68  * @tc.require: issueNumber
69  */
70 HWTEST_F(RegEncoderTest, reg_encoder_test_002, TestSize.Level1)
71 {
72     std::string pFile = GRAPH_TEST_ABC_DIR "optimizeTryCatch.abc";
73     const char *test_method_name = "func_main_0";
74     bool status = false;
75 
__anonc9e90bdd0202(Graph* graph, std::string &method_name) 76     graph_test_.TestBuildGraphFromFile(pFile, [test_method_name, &status](Graph* graph, std::string &method_name) {
77         if (test_method_name != method_name) {
78             return;
79         }
80         status = true;
81         EXPECT_NE(graph, nullptr);
82         EXPECT_TRUE(graph->RunPass<RegAccAlloc>());
83     });
84     EXPECT_TRUE(status);
85 }
86 }  // namespace panda::bytecodeopt