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.

graph_manager_test.cc 2.0 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 <memory>
  18. #include "common/common_test.h"
  19. #ifdef OPEN_SOURCE
  20. #include "ge/client/ge_api.h"
  21. #else
  22. #include "external/ge/ge_api.h"
  23. #endif
  24. #define private public
  25. #include "transform/df_graph_manager.h"
  26. using UT::Common;
  27. namespace mindspore {
  28. namespace transform {
  29. class TestDfGraphManager : public UT::Common {
  30. public:
  31. TestDfGraphManager() {}
  32. };
  33. TEST_F(TestDfGraphManager, TestAPI) {
  34. // test public interface:
  35. DfGraphManager& graph_manager = DfGraphManager::GetInstance();
  36. ASSERT_EQ(0, graph_manager.GetAllGraphs().size());
  37. // test public interface:
  38. std::shared_ptr<ge::Graph> ge_graph = std::make_shared<ge::Graph>();
  39. ASSERT_TRUE(graph_manager.AddGraph("test_graph", nullptr) != Status::SUCCESS);
  40. graph_manager.AddGraph("test_graph", ge_graph);
  41. ASSERT_EQ(1, graph_manager.GetAllGraphs().size());
  42. std::vector<DfGraphWrapperPtr> wrappers = graph_manager.GetAllGraphs();
  43. ASSERT_EQ("test_graph", wrappers.back()->name_);
  44. ASSERT_EQ(ge_graph, wrappers.back()->graph_ptr_);
  45. // test public interface:
  46. DfGraphWrapperPtr wrappers2 = graph_manager.GetGraphByName("test_graph");
  47. ASSERT_EQ(ge_graph, wrappers2->graph_ptr_);
  48. // test public interface:
  49. graph_manager.ClearGraph();
  50. ASSERT_EQ(0, graph_manager.GetAllGraphs().size());
  51. // test public interface:
  52. int id = graph_manager.GenerateId();
  53. assert(id > 0);
  54. }
  55. } // namespace transform
  56. } // namespace mindspore