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 "graph.h" 20 #include "graph_test.h" 21 #include "mem/pool_manager.h" 22 #include "optimizer/analysis/linear_order.h" 23 #include "optimizer/analysis/rpo.h" 24 25 using namespace testing::ext; 26 27 namespace panda::compiler { 28 class LinearOrderTest : public testing::Test { 29 public: SetUpTestCase(void)30 static void SetUpTestCase(void) {} TearDownTestCase(void)31 static void TearDownTestCase(void) {} SetUp()32 void SetUp() {} TearDown()33 void TearDown() {} 34 35 GraphTest graph_test_; 36 }; 37 38 /** 39 * @tc.name: linear_order_test_001 40 * @tc.desc: Verify the RunImpl function. 41 * @tc.type: FUNC 42 * @tc.require: issueNumber 43 */ 44 HWTEST_F(LinearOrderTest, linear_order_test_001, TestSize.Level1) 45 { 46 std::string pfile = GRAPH_TEST_ABC_DIR "dominatorsTryCatch.abc"; 47 const char *test_method_name = "func_main_0"; 48 bool status = false; 49 __anond3b8c4a70102(Graph* graph, std::string &method_name) 50 graph_test_.TestBuildGraphFromFile(pfile, [test_method_name, &status](Graph* graph, std::string &method_name) { 51 if (test_method_name != method_name) { 52 return; 53 } 54 status = true; 55 EXPECT_NE(graph, nullptr); 56 EXPECT_TRUE(graph->RunPass<LinearOrder>()); 57 }); 58 EXPECT_TRUE(status); 59 } 60 61 /** 62 * @tc.name: linear_order_test_002 63 * @tc.desc: Verify the RunImpl function. 64 * @tc.type: FUNC 65 * @tc.require: issueNumber 66 */ 67 HWTEST_F(LinearOrderTest, linear_order_test_002, TestSize.Level1) 68 { 69 std::string pfile = GRAPH_TEST_ABC_DIR "dominatorsTryCatch.abc"; 70 const char *test_method_name = "func_main_0"; 71 bool status = false; 72 __anond3b8c4a70202(Graph* graph, std::string &method_name) 73 graph_test_.TestBuildGraphFromFile(pfile, [test_method_name, &status](Graph* graph, std::string &method_name) { 74 if (test_method_name != method_name) { 75 return; 76 } 77 status = true; 78 EXPECT_NE(graph, nullptr); 79 80 for (auto bb : graph->GetBlocksRPO()) { 81 if (bb->IsTryBegin()) { 82 graph->SetStartBlock(bb->GetSuccessor(1)); 83 } 84 } 85 EXPECT_TRUE(graph->RunPass<LinearOrder>()); 86 }); 87 EXPECT_TRUE(status); 88 } 89 90 /** 91 * @tc.name: linear_order_test_003 92 * @tc.desc: Verify the GetBlocks function. 93 * @tc.type: FUNC 94 * @tc.require: issueNumber 95 */ 96 HWTEST_F(LinearOrderTest, linear_order_test_003, TestSize.Level1) 97 { 98 std::string pfile = GRAPH_TEST_ABC_DIR "dominatorsTryCatch.abc"; 99 const char *test_method_name = "func_main_0"; 100 bool status = false; 101 __anond3b8c4a70302(Graph* graph, std::string &method_name) 102 graph_test_.TestBuildGraphFromFile(pfile, [test_method_name, &status](Graph* graph, std::string &method_name) { 103 if (test_method_name != method_name) { 104 return; 105 } 106 status = true; 107 EXPECT_NE(graph, nullptr); 108 LinearOrder linear_order(graph); 109 EXPECT_EQ(linear_order.GetBlocks().size(), 0); 110 }); 111 EXPECT_TRUE(status); 112 } 113 } // namespace panda::compiler 114