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 TestParserPrimitive : public UT::Common {
29 public:
TestParserPrimitive()30 TestParserPrimitive() {}
31 virtual void SetUp();
32 virtual void TearDown();
33 };
34
SetUp()35 void TestParserPrimitive::SetUp() { UT::InitPythonPath(); }
36
TearDown()37 void TestParserPrimitive::TearDown() {}
38
TEST_F(TestParserPrimitive,TestParserOpsMethod1)39 TEST_F(TestParserPrimitive, TestParserOpsMethod1) {
40 py::function fn_ = python_adapter::GetPyFn("gtest_input.pipeline.parse.parse_primitive", "test_ops_f1");
41
42 FuncGraphPtr func_graph = ParsePythonCode(fn_);
43 ASSERT_TRUE(nullptr != func_graph);
44
45 // save the func_graph to manager
46 std::shared_ptr<FuncGraphManager> manager = Manage(func_graph);
47
48 // call resolve
49 bool ret_ = ResolveAll(manager);
50
51 ASSERT_TRUE(ret_);
52 }
53
TEST_F(TestParserPrimitive,TestParserOpsMethod2)54 TEST_F(TestParserPrimitive, TestParserOpsMethod2) {
55 py::function fn_ = python_adapter::GetPyFn("gtest_input.pipeline.parse.parse_primitive", "test_ops_f2");
56
57 FuncGraphPtr func_graph = ParsePythonCode(fn_);
58 ASSERT_TRUE(nullptr != func_graph);
59
60 // save the func_graph to manager
61 std::shared_ptr<FuncGraphManager> manager = Manage(func_graph);
62
63 // call resolve
64 bool ret_ = ResolveAll(manager);
65
66 ASSERT_TRUE(ret_);
67 }
68
69 // Test primitive class obj
TEST_F(TestParserPrimitive,TestParsePrimitive)70 TEST_F(TestParserPrimitive, TestParsePrimitive) {
71 #if 0 // Segmentation fault
72 py::object obj_ = python_adapter::CallPyFn("gtest_input.pipeline.parse.parse_primitive", "test_primitive_obj");
73 Parser::InitParserEnvironment(obj_);
74 FuncGraphPtr func_graph = ParsePythonCode(obj_);
75 ASSERT_TRUE(nullptr != func_graph);
76
77 // save the func_graph to manager
78 std::shared_ptr<FuncGraphManager> manager = Manage(func_graph);
79
80 // call resolve
81 bool ret_ = ResolveAll(manager);
82
83 ASSERT_TRUE(ret_);
84 #endif
85 }
86
87 /* skip ut test case temporarily
88 TEST_F(TestParserPrimitive, TestParsePrimitiveParmeter) {
89 py::object obj_ =
90 python_adapter::CallPyFn("gtest_input.pipeline.parse.parse_primitive", "test_primitive_obj_parameter");
91 Parser::InitParserEnvironment(obj_);
92 FuncGraphPtr func_graph = ParsePythonCode(obj_);
93 ASSERT_TRUE(nullptr != func_graph);
94
95 // save the func_graph to manager
96 std::shared_ptr<FuncGraphManager> manager = Manage(func_graph);
97
98 // call resolve
99 bool ret_ = ResolveAll(manager);
100
101 ASSERT_TRUE(ret_);
102 }
103
104 TEST_F(TestParserPrimitive, TestParsePrimitiveParmeter2) {
105 py::object obj_ = python_adapter::CallPyFn("gtest_input.pipeline.parse.parse_primitive", "test_primitive_functional");
106 Parser::InitParserEnvironment(obj_);
107 FuncGraphPtr func_graph = ParsePythonCode(obj_);
108 ASSERT_TRUE(nullptr != func_graph);
109
110 // save the func_graph to manager
111 std::shared_ptr<FuncGraphManager> manager = Manage(func_graph);
112
113 // call resolve
114 bool ret_ = ResolveAll(manager);
115
116 ASSERT_TRUE(ret_);
117 }
118 */
119
120 } // namespace parse
121 } // namespace mindspore
122