1 /** 2 * Copyright 2020 Huawei Technologies Co., Ltd 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 #include <iostream> 17 #include <sstream> 18 #include <memory> 19 #include <algorithm> 20 21 #include "common/common_test.h" 22 #include "common/py_func_graph_fetcher.h" 23 24 #include "ir/anf.h" 25 #include "ir/graph_utils.h" 26 #include "utils/convert_utils.h" 27 #include "pipeline/jit/parse/parse_base.h" 28 #include "pipeline/jit/parse/parse.h" 29 30 namespace mindspore { 31 32 class TestGraphUtils : public UT::Common { 33 public: 34 TestGraphUtils() : getPyFun("gtest_input.utils.graph_utils_test", true), equiv_graph(), equiv_node() {} 35 std::shared_ptr<FuncGraph> GetPythonFunction(std::string function); 36 37 public: 38 UT::PyFuncGraphFetcher getPyFun; 39 40 FuncGraphPairMapEquiv equiv_graph; 41 NodeMapEquiv equiv_node; 42 }; 43 44 TEST_F(TestGraphUtils, Isomorphic) { 45 std::shared_ptr<FuncGraph> g1 = getPyFun("test_graph_utils_isomorphic_1"); 46 std::shared_ptr<FuncGraph> g2 = getPyFun("test_graph_utils_isomorphic_2"); 47 std::shared_ptr<FuncGraph> g3 = getPyFun("test_graph_utils_isomorphic_3"); 48 ASSERT_TRUE(nullptr != g1); 49 ASSERT_TRUE(nullptr != g2); 50 ASSERT_TRUE(Isomorphic(g1, g2, &equiv_graph, &equiv_node)); 51 52 ASSERT_TRUE(nullptr != g3); 53 ASSERT_FALSE(Isomorphic(g1, g3, &equiv_graph, &equiv_node)); 54 } 55 56 } // namespace mindspore 57