From 4b2e0305521f7b81c27bdf849a7b5b50cf6176a2 Mon Sep 17 00:00:00 2001 From: wangchao Date: Thu, 5 Dec 2024 20:22:50 +0800 Subject: [PATCH 1/5] add file_utils ut --- .../test/core_ut/common/test_file_utils.py | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 debug/accuracy_tools/msprobe/test/core_ut/common/test_file_utils.py diff --git a/debug/accuracy_tools/msprobe/test/core_ut/common/test_file_utils.py b/debug/accuracy_tools/msprobe/test/core_ut/common/test_file_utils.py new file mode 100644 index 0000000000..1e28e07cd1 --- /dev/null +++ b/debug/accuracy_tools/msprobe/test/core_ut/common/test_file_utils.py @@ -0,0 +1,46 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +# Copyright (C) 2024-2024. Huawei Technologies Co., Ltd. All rights reserved. +# 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. +""" +from unittest import TestCase +from msprobe.core.common.file_utils import FileChecker +from msprobe.core.common.file_utils import check_file_size +from msprobe.core.common.file_utils import check_path_before_create +from msprobe.core.common.exceptions import FileCheckException + +class TestFileUtils(TestCase): + + def test_check_path_type(self): + with self.assertRaises(FileCheckException) as context: + FileChecker._check_path_type("err_file") + self.assertEqual(context.exception.code, FileCheckException.ILLEGAL_PARAM_ERROR) + + def test_check_file_size(self): + with self.assertRaises(FileCheckException) as context: + check_file_size("xxx.txt", 100) + self.assertEqual(context.exception.code, FileCheckException.INVALID_FILE_ERROR) + + def test_check_path_before_create_long_path(self): + with self.assertRaises(FileCheckException) as context: + long_file_path = "xxx"*4094+".txt" + check_path_before_create(long_file_path) + self.assertEqual(context.exception.code, FileCheckException.ILLEGAL_PATH_ERROR) + + def test_check_path_before_create_invalid_char(self): + with self.assertRaises(FileCheckException) as context: + invalid_file_path = "***.txt" + check_path_before_create(invalid_file_path) + self.assertEqual(context.exception.code, FileCheckException.ILLEGAL_PATH_ERROR) + -- Gitee From 6fff5719a2577716724a5e2eb4ef03d7bf5a04e6 Mon Sep 17 00:00:00 2001 From: wangchao Date: Thu, 5 Dec 2024 20:50:10 +0800 Subject: [PATCH 2/5] add file_utils ut --- .../core_ut/compare/test_postprocess_pass.py | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 debug/accuracy_tools/msprobe/test/core_ut/compare/test_postprocess_pass.py diff --git a/debug/accuracy_tools/msprobe/test/core_ut/compare/test_postprocess_pass.py b/debug/accuracy_tools/msprobe/test/core_ut/compare/test_postprocess_pass.py new file mode 100644 index 0000000000..46d5415b79 --- /dev/null +++ b/debug/accuracy_tools/msprobe/test/core_ut/compare/test_postprocess_pass.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +# Copyright (C) 2024-2024. Huawei Technologies Co., Ltd. All rights reserved. +# 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. +""" +from unittest import TestCase +from msprobe.core.compare.layer_mapping.postprocess_pass import extract_next_item_last_number + +class TestFileUtils(TestCase): + + def test_check_path_type_None(self): + input_data = "conv1.Conv2d.forward.input" + prefix = "Conv2d" + none_result = extract_next_item_last_number(input_data, prefix) + self.assertEqual(none_result, None) + + def test_check_path_type_find_result(self): + input_data = "conv1.Conv2d.forward.input.conv1" + prefix = "conv1" + result_2 = extract_next_item_last_number(input_data, prefix) + self.assertEqual(result_2, 2) + + + + +input_data = "conv1.Conv2d.forward.input.conv1" +prefix = "conv1" +result = extract_next_item_last_number(input_data, prefix) +print(result) \ No newline at end of file -- Gitee From df71750c19bfc49269aeb21828b8f19696805eb3 Mon Sep 17 00:00:00 2001 From: wangchao Date: Fri, 6 Dec 2024 10:18:31 +0800 Subject: [PATCH 3/5] add file_utils ut --- .../core_ut/compare/test_postprocess_pass.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/debug/accuracy_tools/msprobe/test/core_ut/compare/test_postprocess_pass.py b/debug/accuracy_tools/msprobe/test/core_ut/compare/test_postprocess_pass.py index 46d5415b79..e1c9fed41a 100644 --- a/debug/accuracy_tools/msprobe/test/core_ut/compare/test_postprocess_pass.py +++ b/debug/accuracy_tools/msprobe/test/core_ut/compare/test_postprocess_pass.py @@ -16,6 +16,7 @@ """ from unittest import TestCase from msprobe.core.compare.layer_mapping.postprocess_pass import extract_next_item_last_number +from msprobe.core.compare.layer_mapping.postprocess_pass import replace_next_item_index class TestFileUtils(TestCase): @@ -31,10 +32,16 @@ class TestFileUtils(TestCase): result_2 = extract_next_item_last_number(input_data, prefix) self.assertEqual(result_2, 2) + def test_replace_next_item_index(self): + input_data = "conv1.Conv2d.forward.input.conv1" + prefix = "conv1" + replace_result = replace_next_item_index(input_data, prefix, 1) + self.assertEqual(replace_result, "conv1.1.forward.input.conv1") + def test_replace_next_item_index_with_inf(self): + input_data = "conv1.Conv2d.forward.input.conv1" + prefix = "conv1" + inf_value = float("inf") + replace_result = replace_next_item_index(input_data, prefix, inf_value) + self.assertEqual(replace_result, input_data) - -input_data = "conv1.Conv2d.forward.input.conv1" -prefix = "conv1" -result = extract_next_item_last_number(input_data, prefix) -print(result) \ No newline at end of file -- Gitee From 1d82ac79e00beea184cb90738aea03e2c4bbb3cd Mon Sep 17 00:00:00 2001 From: wangchao Date: Fri, 6 Dec 2024 10:38:41 +0800 Subject: [PATCH 4/5] add file_utils ut --- .../core_ut/compare/test_data_scope_parser.py | 34 +++++++++++++++++++ .../core_ut/compare/test_postprocess_pass.py | 3 +- 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 debug/accuracy_tools/msprobe/test/core_ut/compare/test_data_scope_parser.py diff --git a/debug/accuracy_tools/msprobe/test/core_ut/compare/test_data_scope_parser.py b/debug/accuracy_tools/msprobe/test/core_ut/compare/test_data_scope_parser.py new file mode 100644 index 0000000000..ee9c7ac866 --- /dev/null +++ b/debug/accuracy_tools/msprobe/test/core_ut/compare/test_data_scope_parser.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +# Copyright (C) 2024-2024. Huawei Technologies Co., Ltd. All rights reserved. +# 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. +""" +from unittest import TestCase +from msprobe.core.compare.layer_mapping.data_scope_parser import DumpDataItem +from msprobe.core.common.utils import CompareException + + +class TestDataScopeParser(TestCase): + + def test_check_stack_valid_invalid_stack_type(self): + stack_info_string = "conv1.Conv2d.forward.input" + with self.assertRaises(CompareException) as context: + DumpDataItem.check_stack_valid(stack_info_string) + self.assertEqual(context.exception.code, CompareException.INVALID_DATA_ERROR) + + def test_check_stack_valid_invalid_stack_info(self): + stack_info_list = ["conv1.Conv2d.forward.input", 1] + with self.assertRaises(CompareException) as context: + DumpDataItem.check_stack_valid(stack_info_list) + self.assertEqual(context.exception.code, CompareException.INVALID_DATA_ERROR) diff --git a/debug/accuracy_tools/msprobe/test/core_ut/compare/test_postprocess_pass.py b/debug/accuracy_tools/msprobe/test/core_ut/compare/test_postprocess_pass.py index e1c9fed41a..9cb33eb277 100644 --- a/debug/accuracy_tools/msprobe/test/core_ut/compare/test_postprocess_pass.py +++ b/debug/accuracy_tools/msprobe/test/core_ut/compare/test_postprocess_pass.py @@ -18,7 +18,8 @@ from unittest import TestCase from msprobe.core.compare.layer_mapping.postprocess_pass import extract_next_item_last_number from msprobe.core.compare.layer_mapping.postprocess_pass import replace_next_item_index -class TestFileUtils(TestCase): + +class TestPostProcessPass(TestCase): def test_check_path_type_None(self): input_data = "conv1.Conv2d.forward.input" -- Gitee From 9fd6186964a79a468b7c8b71973fcfaf44e6482d Mon Sep 17 00:00:00 2001 From: wangchao Date: Fri, 6 Dec 2024 11:18:54 +0800 Subject: [PATCH 5/5] add file_utils ut --- ...test_data_scope_parser.py => test_common_data_scope_parser.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename debug/accuracy_tools/msprobe/test/core_ut/compare/{test_data_scope_parser.py => test_common_data_scope_parser.py} (100%) diff --git a/debug/accuracy_tools/msprobe/test/core_ut/compare/test_data_scope_parser.py b/debug/accuracy_tools/msprobe/test/core_ut/compare/test_common_data_scope_parser.py similarity index 100% rename from debug/accuracy_tools/msprobe/test/core_ut/compare/test_data_scope_parser.py rename to debug/accuracy_tools/msprobe/test/core_ut/compare/test_common_data_scope_parser.py -- Gitee