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.

debug_info_test.cc 3.1 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /**
  2. * Copyright 2021 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 <set>
  19. #include "common/common_test.h"
  20. #include "utils/info.h"
  21. #include "utils/trace_base.h"
  22. #include "ir/anf.h"
  23. #include "ir/func_graph.h"
  24. #include "frontend/operator/ops.h"
  25. #include "base/core_ops.h"
  26. namespace mindspore {
  27. class TestDebugInfo : public UT::Common {
  28. public:
  29. TestDebugInfo() {}
  30. };
  31. // Feature: Debug info
  32. // Description: Make a location
  33. // Expectation: make a location with no error
  34. TEST_F(TestDebugInfo, test_make_location) {
  35. LocationPtr loc1 = std::make_shared<Location>("/home/workspace/a.py", 0, 4, 1, 8);
  36. std::string s = loc1->ToString(kSourceLineTipDiscard);
  37. std::string expect_str("In file /home/workspace/a.py(0)\n");
  38. ASSERT_TRUE(s == expect_str);
  39. }
  40. // Feature: Debug info
  41. // Description: Deduplicate the debug infos which have the same print
  42. // Expectation: a set of debug infos is deduplicated
  43. TEST_F(TestDebugInfo, test_location_dedup) {
  44. LocationPtr loc1 = std::make_shared<Location>("file1.py", 0, 0, 0, 0);
  45. NodeDebugInfoPtr debug_info1 = std::make_shared<NodeDebugInfo>();
  46. debug_info1->set_location(loc1);
  47. LocationPtr loc2 = std::make_shared<Location>("file1.py", 0, 0, 0, 0);
  48. NodeDebugInfoPtr debug_info2 = std::make_shared<NodeDebugInfo>();
  49. debug_info2->set_location(loc2);
  50. LocationPtr loc3 = std::make_shared<Location>("file2.py", 0, 0, 0, 0);
  51. NodeDebugInfoPtr debug_info3 = std::make_shared<NodeDebugInfo>();
  52. debug_info3->set_location(loc3);
  53. std::set<NodeDebugInfoPtr, DebugInfoCompare> fused_debug_info_set;
  54. (void)fused_debug_info_set.emplace(debug_info1);
  55. ASSERT_TRUE(fused_debug_info_set.size() == 1);
  56. (void)fused_debug_info_set.emplace(debug_info2);
  57. ASSERT_TRUE(fused_debug_info_set.size() == 1);
  58. (void)fused_debug_info_set.emplace(debug_info3);
  59. ASSERT_TRUE(fused_debug_info_set.size() == 2);
  60. (void)fused_debug_info_set.emplace(debug_info3);
  61. ASSERT_TRUE(fused_debug_info_set.size() == 2);
  62. }
  63. // Feature: Debug info
  64. // Description: Test adding a fused debug info
  65. // Expectation: success
  66. TEST_F(TestDebugInfo, test_fused_debug_info) {
  67. FuncGraphPtr fg = std::make_shared<FuncGraph>();
  68. std::vector<AnfNodePtr> inputs;
  69. CNodePtr cnode = std::make_shared<CNode>(inputs, fg);
  70. ASSERT_TRUE(cnode->fused_debug_infos().size() == 0);
  71. NodeDebugInfoPtr debug_info = std::make_shared<NodeDebugInfo>();
  72. cnode->AddFusedDebugInfo(debug_info);
  73. ASSERT_TRUE(cnode->fused_debug_infos().size() == 1);
  74. }
  75. } // namespace mindspore