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 <cstring> 17 #include <gtest/gtest.h> 18 #include <iomanip> 19 #include <iostream> 20 #include <sstream> 21 #include <string> 22 #include <memory> 23 24 #include "compiler_options.h" 25 #include "constants.h" 26 #include "graph_checker.h" 27 #include "graph_visitor.h" 28 #include "graph_test.h" 29 #include "inst.h" 30 #include "locations.h" 31 #include "mem/pool_manager.h" 32 #include "optimizer/analysis/linear_order.h" 33 #include "optimizer/optimizations/cleanup.h" 34 #include "optimizer/optimizations/move_constants.h" 35 #include "optimizer/optimizations/regalloc/reg_alloc.h" 36 #include "reg_acc_alloc.h" 37 38 using namespace testing::ext; 39 40 namespace panda::compiler { 41 42 class GraphCheckerTest : public testing::Test { 43 public: SetUpTestCase(void)44 static void SetUpTestCase(void) {}; TearDownTestCase(void)45 static void TearDownTestCase(void) {}; SetUp()46 void SetUp() {}; TearDown()47 void TearDown() {}; 48 49 GraphTest graphTest_; 50 }; 51 52 /** 53 * @tc.name: graph_checker_test_001 54 * @tc.desc: Verify the Check function. 55 * @tc.type: FUNC 56 * @tc.require: issueNumber 57 */ 58 HWTEST_F(GraphCheckerTest, graph_checker_test_001, TestSize.Level1) 59 { 60 std::string pfile = GRAPH_TEST_ABC_DIR "styleTryCatch.abc"; 61 const char *test_method_name = "func6"; 62 bool status = false; __anon499f752e0102(Graph* graph, std::string &method_name) 63 graphTest_.TestBuildGraphFromFile(pfile, [&test_method_name, &status](Graph* graph, std::string &method_name) { 64 if (test_method_name != method_name) { 65 return; 66 } 67 status = true; 68 EXPECT_NE(graph, nullptr); 69 70 graph->InvalidateAnalysis<LoopAnalyzer>(); 71 EXPECT_TRUE(graph->RunPass<LoopAnalyzer>()); 72 GraphChecker gChecker(graph); 73 gChecker.Check(); 74 }); 75 EXPECT_TRUE(status); 76 } 77 78 /** 79 * @tc.name: graph_checker_test_002 80 * @tc.desc: Verify the IsTryCatchDomination function. 81 * @tc.type: FUNC 82 * @tc.require: 83 */ 84 HWTEST_F(GraphCheckerTest, graph_checker_test_002, TestSize.Level1) 85 { 86 std::string pfile = GRAPH_TEST_ABC_DIR "testTryCatch.abc"; 87 const char *test_method_name = "func6"; 88 bool status = false; __anon499f752e0202(Graph* graph, std::string &method_name) 89 graphTest_.TestBuildGraphFromFile(pfile, [&test_method_name, &status](Graph* graph, std::string &method_name) { 90 if (test_method_name != method_name) { 91 return; 92 } 93 94 EXPECT_TRUE(graph->RunPass<MoveConstants>()); 95 EXPECT_TRUE(graph->RunPass<bytecodeopt::RegAccAlloc>()); 96 EXPECT_TRUE(RegAlloc(graph)); 97 98 GraphChecker gChecker(graph); 99 gChecker.Check(); 100 101 status = true; 102 }); 103 EXPECT_TRUE(status); 104 } 105 106 /** 107 * @tc.name: graph_checker_test_003 108 * @tc.desc: Verify the Check function with infinite loop. 109 * @tc.type: FUNC 110 * @tc.require: 111 */ 112 HWTEST_F(GraphCheckerTest, graph_checker_test_003, TestSize.Level1) 113 { 114 std::string pfile = GRAPH_TEST_ABC_DIR "graphTest.abc"; 115 const char *test_method_name = "loop2"; 116 bool status = false; __anon499f752e0302(Graph* graph, std::string &method_name) 117 graphTest_.TestBuildGraphFromFile(pfile, [&test_method_name, &status](Graph* graph, std::string &method_name) { 118 if (test_method_name != method_name) { 119 return; 120 } 121 122 GraphChecker gChecker(graph); 123 gChecker.Check(); 124 status = true; 125 }); 126 EXPECT_TRUE(status); 127 } 128 }