• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <string>
18 #include "common/common_test.h"
19 #include "common/py_func_graph_fetcher.h"
20 
21 #include "utils/log_adapter.h"
22 #include "pipeline/jit/parse/parse.h"
23 #include "debug/draw.h"
24 
25 namespace mindspore {
26 namespace parse {
27 
28 class TestResolve : public UT::Common {
29  public:
TestResolve()30   TestResolve() {}
31   virtual void SetUp();
32   virtual void TearDown();
33 };
34 
SetUp()35 void TestResolve::SetUp() { UT::InitPythonPath(); }
36 
TearDown()37 void TestResolve::TearDown() {}
38 
TEST_F(TestResolve,TestResolveApi)39 TEST_F(TestResolve, TestResolveApi) {
40   py::function fn_ = python_adapter::GetPyFn("gtest_input.pipeline.parse.parser_test", "get_resolve_fn");
41 
42   // parse graph
43   FuncGraphPtr func_graph = ParsePythonCode(fn_);
44   ASSERT_FALSE(nullptr == func_graph);
45 
46   // save the func_graph to manager
47   std::shared_ptr<FuncGraphManager> manager = Manage(func_graph);
48 
49   // call resolve
50   bool ret_ = ResolveAll(manager);
51 
52   ASSERT_TRUE(ret_);
53 
54   ASSERT_EQ(manager->func_graphs().size(), (size_t)2);
55 }
56 
TEST_F(TestResolve,TestParseGraphTestClosureResolve)57 TEST_F(TestResolve, TestParseGraphTestClosureResolve) {
58   py::function test_fn =
59     python_adapter::CallPyFn("gtest_input.pipeline.parse.parser_test", "test_reslove_closure", 123);
60   FuncGraphPtr func_graph = ParsePythonCode(test_fn);
61   ASSERT_TRUE(func_graph != nullptr);
62   // save the func_graph to manager
63   std::shared_ptr<FuncGraphManager> manager = Manage(func_graph);
64 
65   // call resolve
66   bool ret_ = ResolveAll(manager);
67 
68   ASSERT_TRUE(ret_);
69 
70   ASSERT_EQ(manager->func_graphs().size(), (size_t)2);
71 }
72 }  // namespace parse
73 }  // namespace mindspore
74