diff --git a/tests/ut/profiler/parser/test_aicpu_parser.py b/tests/ut/profiler/parser/test_aicpu_parser.py new file mode 100644 index 0000000000000000000000000000000000000000..340f3ed6f727416b98d2f076b8bde5f9610fcd08 --- /dev/null +++ b/tests/ut/profiler/parser/test_aicpu_parser.py @@ -0,0 +1,74 @@ +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +"""Test the aicpu parser.""" +import os +import tempfile +import shutil + +from unittest import TestCase + +from mindinsight.profiler.parser.aicpu_data_parser import DataPreProcessParser + + +def get_result(file_path): + """ + Get result from the aicpu file. + + Args: + file_path (str): The aicpu file path. + + Returns: + list[list], the parsed aicpu information. + """ + result = [] + try: + file = open(file_path, 'r') + result.append(file.read()) + return result + finally: + if file: + file.close() + + +class TestAicpuParser(TestCase): + """Test the class of Aicpu Parser.""" + + def setUp(self) -> None: + """Initialization before test case execution.""" + self.profiling_dir = os.path.realpath(os.path.join(os.path.dirname(__file__), + '../../../utils/resource/' + 'JOB_AICPU/data')) + self.expect_dir = os.path.realpath(os.path.join(os.path.dirname(__file__), + '../../../utils/resource/' + 'JOB_AICPU/data')) + self.output_path = tempfile.mkdtemp(prefix='output_data_preprocess_aicpu_') + self.output_file = os.path.join(self.output_path, 'output_data_preprocess_aicpu_0.txt') + self.expect_file = os.path.join(self.output_path, 'output_data_preprocess_aicpu_0.txt') + + def test_aicpu_parser(self): + """Test the class of Aicpu Parser.""" + data = DataPreProcessParser(self.profiling_dir, self.output_file) + data.execute() + expect_result = get_result(self.expect_file) + result = get_result(self.output_file) + shutil.rmtree(self.output_path) + assert expect_result == result + + def test_aicpu_parser_file_not_exist(self): + """Test the class of Aicpu Parser.""" + profiling_dir = os.path.realpath(os.path.join(self.profiling_dir, 'data')) + data = DataPreProcessParser(profiling_dir, self.output_file) + data.execute() + shutil.rmtree(self.output_path) diff --git a/tests/ut/profiler/proposer/test_proposer.py b/tests/ut/profiler/proposer/test_proposer.py index e31681d8ce331cf52a07374403ce40888dd59b7b..9bbd93e717ddd612980a6a4680e09f3ad8c523c1 100644 --- a/tests/ut/profiler/proposer/test_proposer.py +++ b/tests/ut/profiler/proposer/test_proposer.py @@ -28,7 +28,7 @@ class TestPropose(TestCase): """Initialization before test case execution.""" self.profiling_dir = os.path.realpath(os.path.join(os.path.dirname(__file__), '../../../utils/resource/profiler')) - self.device_id = 0 + self.device_id = "0" self.common_proposal_dict = OrderedDict() self.common_proposal_dict["common-profiler_tutorial"] = None self.step_trace_proposal_dict = OrderedDict() @@ -41,7 +41,7 @@ class TestPropose(TestCase): proposal_dict.update(self.step_trace_proposal_dict) proposal_dict["common-proposer_type_label"] = None proposal_dict.update(self.common_proposal_dict) - type_list = ['step_trace', 'common'] + type_list = ['step_trace', 'minddata', 'minddata_pipeline', 'common'] condition = {"filter_condition": {'mode': "proc", "proc_name": "iteration_interval", "step_id": 0}} @@ -53,7 +53,7 @@ class TestPropose(TestCase): def test_propose_compose_exception(self): """Test the class of ComposeProposal.""" profiling_dir = os.path.realpath(os.path.join(os.path.dirname(__file__), - '../../../utils/resource/test')) + '../../../utils/resource/')) proposal_dict = OrderedDict() proposal_dict["common-proposer_type_label"] = None proposal_dict.update(self.common_proposal_dict) diff --git a/tests/utils/resource/JOB_AICPU/data/DATA_PREPROCESS.dev.AICPU.0.slice_0 b/tests/utils/resource/JOB_AICPU/data/DATA_PREPROCESS.dev.AICPU.0.slice_0 new file mode 100644 index 0000000000000000000000000000000000000000..ea5e36177e236fe9adbc82925686f4449f50d397 Binary files /dev/null and b/tests/utils/resource/JOB_AICPU/data/DATA_PREPROCESS.dev.AICPU.0.slice_0 differ diff --git a/tests/utils/resource/JOB_AICPU/expect/output_data_preprocess_aicpu_0.txt b/tests/utils/resource/JOB_AICPU/expect/output_data_preprocess_aicpu_0.txt new file mode 100644 index 0000000000000000000000000000000000000000..7f3d739bac7bae23fb3f20486ac360f62bbeebd2 --- /dev/null +++ b/tests/utils/resource/JOB_AICPU/expect/output_data_preprocess_aicpu_0.txt @@ -0,0 +1,5 @@ +serial_number node_type_name total_time(us) dispatch_time(us) run_start run_end +---------------------- ---------------- ---------------- ------------------- ----------- ---------- +1 InitData 1567 100 2298200409 2298200538 +2 GetNext 989 87 2302769932 2302769980 +AI CPU Total Time(us): 2556