Browse Source

add and modify ut case

tags/v0.5.0-beta
askmiao 5 years ago
parent
commit
f9d5fa3b59
4 changed files with 82 additions and 3 deletions
  1. +74
    -0
      tests/ut/profiler/parser/test_aicpu_parser.py
  2. +3
    -3
      tests/ut/profiler/proposer/test_proposer.py
  3. BIN
      tests/utils/resource/JOB_AICPU/data/DATA_PREPROCESS.dev.AICPU.0.slice_0
  4. +5
    -0
      tests/utils/resource/JOB_AICPU/expect/output_data_preprocess_aicpu_0.txt

+ 74
- 0
tests/ut/profiler/parser/test_aicpu_parser.py View File

@@ -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)

+ 3
- 3
tests/ut/profiler/proposer/test_proposer.py View File

@@ -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)


BIN
tests/utils/resource/JOB_AICPU/data/DATA_PREPROCESS.dev.AICPU.0.slice_0 View File


+ 5
- 0
tests/utils/resource/JOB_AICPU/expect/output_data_preprocess_aicpu_0.txt View File

@@ -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

Loading…
Cancel
Save