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_aicpu_parser.py 2.7 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. # Copyright 2020 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 the aicpu parser."""
  16. import os
  17. import tempfile
  18. import shutil
  19. from mindspore.profiler.parser.aicpu_data_parser import DataPreProcessParser
  20. class TestAicpuParser:
  21. """Test the class of Aicpu Parser."""
  22. def setup_class(self):
  23. """Initialization before test case execution."""
  24. self.profiling_dir = os.path.realpath(os.path.join(os.path.dirname(__file__),
  25. '../../../data/profiler_data/'
  26. 'JOB_AICPU/data'))
  27. self.expect_dir = os.path.realpath(os.path.join(os.path.dirname(__file__),
  28. '../../../data/profiler_data/'
  29. 'JOB_AICPU/expect'))
  30. self.output_path = tempfile.mkdtemp(prefix='output_data_preprocess_aicpu_')
  31. self.output_file = os.path.join(self.output_path, 'output_data_preprocess_aicpu_0.txt')
  32. self.expect_file = os.path.join(self.expect_dir, 'output_data_preprocess_aicpu_0.txt')
  33. self.op_task_dict = {
  34. "22_2": "Default/network-_VirtualDatasetCell/_backbone-WithLossCell/_backbone-AlexNet/dropout-Dropout/"
  35. "DropoutGenMask-op281",
  36. "22_4": "Default/network-_VirtualDatasetCell/_backbone-WithLossCell/_backbone-AlexNet/dropout-Dropout/"
  37. "DropoutGenMask-op280"
  38. }
  39. def teardown_method(self) -> None:
  40. """Clear output file."""
  41. if os.path.exists(self.output_path):
  42. shutil.rmtree(self.output_path)
  43. def test_aicpu_parser(self):
  44. """Test the class of Aicpu Parser."""
  45. data = DataPreProcessParser(self.profiling_dir, self.output_file, self.op_task_dict)
  46. data.execute()
  47. with open(self.expect_file, 'r') as fp:
  48. expect_result = fp.read()
  49. with open(self.output_file, 'r') as fp:
  50. result = fp.read()
  51. assert expect_result == result