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_hccl_parser.py 2.3 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 the hccl parser module."""
  16. import csv
  17. import os
  18. import shutil
  19. import tempfile
  20. from mindspore.profiler.parser.hccl_parser import HcclParser
  21. from tests.ut.python.profiler import PROFILER_DIR
  22. def get_hccl_result(file_path):
  23. """
  24. Get hccl result from the hccl file.
  25. Args:
  26. file_path (str): The hccl file path.
  27. Returns:
  28. list[list], the parsed hccl information.
  29. """
  30. result = []
  31. with open(file_path, 'r') as file:
  32. csv_reader = csv.reader(file)
  33. for row in csv_reader:
  34. result.append(row)
  35. return result
  36. class TestHcclParser:
  37. """Test the class of `HcclParser`."""
  38. def setup_method(self):
  39. """Initialization before test case execution."""
  40. self._output_path = tempfile.mkdtemp(
  41. prefix='test_hccl_parser_'
  42. )
  43. shutil.copyfile(os.path.join(PROFILER_DIR, 'step_trace_raw_6_detail_time.csv'),
  44. os.path.join(self._output_path, 'step_trace_raw_6_detail_time.csv'))
  45. self._parser = HcclParser(os.path.join(PROFILER_DIR, 'hccl_info'), '6', '6', self._output_path)
  46. def teardown_method(self) -> None:
  47. """Clear up after test case execution."""
  48. shutil.rmtree(self._output_path)
  49. def test_parse(self):
  50. """Test the parse function."""
  51. expect_hccl_file = os.path.join(
  52. PROFILER_DIR, 'hccl_raw_6.csv'
  53. )
  54. expect_result = get_hccl_result(expect_hccl_file)
  55. self._parser.parse()
  56. hccl_file = os.path.join(
  57. self._output_path, 'hccl_raw_6.csv'
  58. )
  59. result = get_hccl_result(hccl_file)
  60. assert expect_result == result