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.8 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 unittest import TestCase
  20. from mindspore.profiler.parser.aicpu_data_parser import DataPreProcessParser
  21. def get_result(file_path):
  22. """
  23. Get result from the aicpu file.
  24. Args:
  25. file_path (str): The aicpu file path.
  26. Returns:
  27. list[list], the parsed aicpu information.
  28. """
  29. result = []
  30. file = None
  31. try:
  32. file = open(file_path, 'r')
  33. result.append(file.read())
  34. return result
  35. finally:
  36. if file:
  37. file.close()
  38. class TestAicpuParser(TestCase):
  39. """Test the class of Aicpu Parser."""
  40. def setUp(self) -> None:
  41. """Initialization before test case execution."""
  42. self.profiling_dir = os.path.realpath(os.path.join(os.path.dirname(__file__),
  43. '../../../data/profiler_data/'
  44. 'JOB_AICPU/data'))
  45. self.expect_dir = os.path.realpath(os.path.join(os.path.dirname(__file__),
  46. '../../../data/profiler_data/'
  47. 'JOB_AICPU/expect'))
  48. self.output_path = tempfile.mkdtemp(prefix='output_data_preprocess_aicpu_')
  49. self.output_file = os.path.join(self.output_path, 'output_data_preprocess_aicpu_0.txt')
  50. self.expect_file = os.path.join(self.expect_dir, 'output_data_preprocess_aicpu_0.txt')
  51. def test_aicpu_parser(self):
  52. """Test the class of Aicpu Parser."""
  53. data = DataPreProcessParser(self.profiling_dir, self.output_file)
  54. data.execute()
  55. expect_result = get_result(self.expect_file)
  56. result = get_result(self.output_file)
  57. shutil.rmtree(self.output_path)
  58. assert expect_result == result
  59. def test_aicpu_parser_file_not_exist(self):
  60. """Test the class of Aicpu Parser."""
  61. profiling_dir = os.path.realpath(os.path.join(self.profiling_dir, 'data'))
  62. data = DataPreProcessParser(profiling_dir, self.output_file)
  63. data.execute()
  64. shutil.rmtree(self.output_path)