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.

test_data_loader.py 6.2 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. # Copyright 2021 Huawei Technologies Co., Ltd
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. # ============================================================================
  15. """Test DataLoader of offline debugger."""
  16. import os
  17. import shutil
  18. import pytest
  19. from mindinsight.debugger.stream_cache.data_loader import DataLoader
  20. from tests.st.func.debugger.conftest import GRAPH_PROTO_FILE
  21. from tests.st.func.debugger.utils import build_dump_file_structure
  22. from tests.utils.tools import compare_result_with_file, compare_result_with_binary_file
  23. class TestDataLoader:
  24. """Test DataLoader."""
  25. @classmethod
  26. def setup_class(cls):
  27. """Init TestDataLoader for DataLoader unittest."""
  28. cls.debugger_tmp_dir, cls.dump_files_dir = build_dump_file_structure()
  29. cls.expected_results_dir = os.path.join(os.path.dirname(__file__),
  30. 'expect_results/offline_debugger')
  31. cls.dump_files_dir_ascend = os.path.join(cls.dump_files_dir,
  32. 'Ascend/sync')
  33. cls.data_loader_ascend = DataLoader(cls.dump_files_dir_ascend)
  34. cls.data_loader_ascend.initialize()
  35. cls.dump_files_dir_gpu = os.path.join(cls.dump_files_dir,
  36. 'GPU/sync')
  37. cls.data_loader_gpu = DataLoader(cls.dump_files_dir_gpu)
  38. cls.data_loader_gpu.initialize()
  39. cls.dump_files_dir_ascend_async = os.path.join(cls.dump_files_dir,
  40. 'Ascend/async')
  41. cls.data_loader_ascend_async = DataLoader(cls.dump_files_dir_ascend_async)
  42. cls.data_loader_ascend_async.initialize()
  43. @classmethod
  44. def teardown_class(cls):
  45. """Run after test this class."""
  46. if os.path.exists(cls.debugger_tmp_dir):
  47. shutil.rmtree(cls.debugger_tmp_dir)
  48. @pytest.mark.level
  49. @pytest.mark.env_single
  50. @pytest.mark.platform_x86_cpu
  51. @pytest.mark.platform_arm_ascend_training
  52. @pytest.mark.platform_x86_gpu_training
  53. @pytest.mark.platform_x86_ascend_training
  54. def test_load_graphs_ascend(self):
  55. """Test load_graphs function of offline-debugger."""
  56. res = self.data_loader_ascend.load_graphs()
  57. expected_result0 = GRAPH_PROTO_FILE
  58. res0 = res[0]['graph_protos'][0].SerializeToString()
  59. compare_result_with_binary_file(res0, expected_result0)
  60. @pytest.mark.level0
  61. @pytest.mark.env_single
  62. @pytest.mark.platform_x86_cpu
  63. @pytest.mark.platform_arm_ascend_training
  64. @pytest.mark.platform_x86_gpu_training
  65. @pytest.mark.platform_x86_ascend_training
  66. def test_load_device_info_ascend(self):
  67. """Test load_device_info of ascend chip for offline-debugger."""
  68. res = self.data_loader_ascend.load_device_info()
  69. expected_result = os.path.join(self.expected_results_dir, 'load_device_info_ascend.json')
  70. compare_result_with_file(res, expected_result)
  71. @pytest.mark.level0
  72. @pytest.mark.env_single
  73. @pytest.mark.platform_x86_cpu
  74. @pytest.mark.platform_arm_ascend_training
  75. @pytest.mark.platform_x86_gpu_training
  76. @pytest.mark.platform_x86_ascend_training
  77. def test_load_step_num_ascend(self):
  78. """Test load_step_num of ascend chip for offline-debugger."""
  79. res = self.data_loader_ascend.load_step_number()
  80. expected_result = {"0": 4, "1": 4}
  81. assert res == expected_result
  82. @pytest.mark.level0
  83. @pytest.mark.env_single
  84. @pytest.mark.platform_x86_cpu
  85. @pytest.mark.platform_arm_ascend_training
  86. @pytest.mark.platform_x86_gpu_training
  87. @pytest.mark.platform_x86_ascend_training
  88. def test_get_net_name_ascend(self):
  89. """Test get_net_name of ascend chip for offline-debugger."""
  90. res = self.data_loader_ascend.get_net_name()
  91. assert res == 'Lenet'
  92. @pytest.mark.level0
  93. @pytest.mark.env_single
  94. @pytest.mark.platform_x86_cpu
  95. @pytest.mark.platform_arm_ascend_training
  96. @pytest.mark.platform_x86_gpu_training
  97. @pytest.mark.platform_x86_ascend_training
  98. def test_get_sync_flag(self):
  99. """Test get_sync_flag of ascend chip for offline-debugger."""
  100. res = self.data_loader_ascend.get_sync_flag()
  101. assert res
  102. @pytest.mark.level0
  103. @pytest.mark.env_single
  104. @pytest.mark.platform_x86_cpu
  105. @pytest.mark.platform_arm_ascend_training
  106. @pytest.mark.platform_x86_gpu_training
  107. @pytest.mark.platform_x86_ascend_training
  108. def test_load_graphs_gpu(self):
  109. """Test load_graphs function of offline-debugger."""
  110. res = self.data_loader_gpu.load_graphs()
  111. expected_result0 = GRAPH_PROTO_FILE
  112. res0 = res[0]['graph_protos'][0].SerializeToString()
  113. compare_result_with_binary_file(res0, expected_result0)
  114. @pytest.mark.level0
  115. @pytest.mark.env_single
  116. @pytest.mark.platform_x86_cpu
  117. @pytest.mark.platform_arm_ascend_training
  118. @pytest.mark.platform_x86_gpu_training
  119. @pytest.mark.platform_x86_ascend_training
  120. def test_load_step_num_gpu(self):
  121. """Test load_step_num of ascend chip for offline-debugger."""
  122. res = self.data_loader_gpu.load_step_number()
  123. expected_result = {"0": 3, "1": 3}
  124. assert res == expected_result
  125. @pytest.mark.level0
  126. @pytest.mark.env_single
  127. @pytest.mark.platform_x86_cpu
  128. @pytest.mark.platform_arm_ascend_training
  129. @pytest.mark.platform_x86_gpu_training
  130. @pytest.mark.platform_x86_ascend_training
  131. def test_load_step_num_ascend_async(self):
  132. """Test load_step_num of ascend chip for offline-debugger."""
  133. res = self.data_loader_ascend_async.load_step_number()
  134. expected_result = {"0": 3, "1": 3}
  135. assert res == expected_result