You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

parser_primitive_test.cc 3.6 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. #include "utils/log_adapter.h"
  21. #include "pipeline/jit/parse/parse.h"
  22. #include "include/common/debug/draw.h"
  23. namespace mindspore {
  24. namespace parse {
  25. class TestParserPrimitive : public UT::Common {
  26. public:
  27. TestParserPrimitive() {}
  28. virtual void SetUp();
  29. virtual void TearDown();
  30. };
  31. void TestParserPrimitive::SetUp() { UT::InitPythonPath(); }
  32. void TestParserPrimitive::TearDown() {}
  33. TEST_F(TestParserPrimitive, TestParserOpsMethod1) {
  34. py::function fn_ = python_adapter::GetPyFn("gtest_input.pipeline.parse.parse_primitive", "test_ops_f1");
  35. FuncGraphPtr func_graph = ParsePythonCode(fn_);
  36. ASSERT_TRUE(nullptr != func_graph);
  37. // save the func_graph to manager
  38. std::shared_ptr<FuncGraphManager> manager = Manage(func_graph);
  39. // call resolve
  40. bool ret_ = ResolveAll(manager);
  41. ASSERT_TRUE(ret_);
  42. }
  43. TEST_F(TestParserPrimitive, TestParserOpsMethod2) {
  44. py::function fn_ = python_adapter::GetPyFn("gtest_input.pipeline.parse.parse_primitive", "test_ops_f2");
  45. FuncGraphPtr func_graph = ParsePythonCode(fn_);
  46. ASSERT_TRUE(nullptr != func_graph);
  47. // save the func_graph to manager
  48. std::shared_ptr<FuncGraphManager> manager = Manage(func_graph);
  49. // call resolve
  50. bool ret_ = ResolveAll(manager);
  51. ASSERT_TRUE(ret_);
  52. }
  53. // Test primitive class obj
  54. TEST_F(TestParserPrimitive, TestParsePrimitive) {
  55. #if 0 // Segmentation fault
  56. py::object obj_ = python_adapter::CallPyFn("gtest_input.pipeline.parse.parse_primitive", "test_primitive_obj");
  57. Parser::InitParserEnvironment(obj_);
  58. FuncGraphPtr func_graph = ParsePythonCode(obj_);
  59. ASSERT_TRUE(nullptr != func_graph);
  60. // save the func_graph to manager
  61. std::shared_ptr<FuncGraphManager> manager = Manage(func_graph);
  62. // call resolve
  63. bool ret_ = ResolveAll(manager);
  64. ASSERT_TRUE(ret_);
  65. #endif
  66. }
  67. /* skip ut test case temporarily
  68. TEST_F(TestParserPrimitive, TestParsePrimitiveParmeter) {
  69. py::object obj_ =
  70. python_adapter::CallPyFn("gtest_input.pipeline.parse.parse_primitive", "test_primitive_obj_parameter");
  71. Parser::InitParserEnvironment(obj_);
  72. FuncGraphPtr func_graph = ParsePythonCode(obj_);
  73. ASSERT_TRUE(nullptr != func_graph);
  74. // save the func_graph to manager
  75. std::shared_ptr<FuncGraphManager> manager = Manage(func_graph);
  76. // call resolve
  77. bool ret_ = ResolveAll(manager);
  78. ASSERT_TRUE(ret_);
  79. }
  80. TEST_F(TestParserPrimitive, TestParsePrimitiveParmeter2) {
  81. py::object obj_ = python_adapter::CallPyFn("gtest_input.pipeline.parse.parse_primitive", "test_primitive_functional");
  82. Parser::InitParserEnvironment(obj_);
  83. FuncGraphPtr func_graph = ParsePythonCode(obj_);
  84. ASSERT_TRUE(nullptr != func_graph);
  85. // save the func_graph to manager
  86. std::shared_ptr<FuncGraphManager> manager = Manage(func_graph);
  87. // call resolve
  88. bool ret_ = ResolveAll(manager);
  89. ASSERT_TRUE(ret_);
  90. }
  91. */
  92. } // namespace parse
  93. } // namespace mindspore