diff --git a/profiler/test/resource/advisor/cluster_analysis_output/cluster_communication.json b/profiler/test/resource/advisor/cluster_analysis_output/cluster_communication.json new file mode 100644 index 0000000000000000000000000000000000000000..bb47a7c19807ffb70f9ac5e7bf7561fb6eecbc75 --- /dev/null +++ b/profiler/test/resource/advisor/cluster_analysis_output/cluster_communication.json @@ -0,0 +1 @@ +{"(0, 1)": {"step": {"hcom_broadcast__501_0@6297232067196334501": {"0": {"Communication Time Info": {"Start Timestamp(us)": 1695054582608213.0,"Elapse Time(ms)": 121.73694384375,"Transit Time(ms)": 0.0080599375,"Wait Time(ms)": 115.96064153125,"Synchronization Time(ms)": 102.699834,"Idle Time(ms)": 5.768242375,"Wait Time Ratio": 0.9999,"Synchronization Time Ratio": 0.9999},"Communication Bandwidth Info": {"RDMA": {"Transit Size(MB)": 0,"Transit Time(ms)": 0,"Bandwidth(GB/s)": 0,"Large Packet Ratio": 0,"Size Distribution": {}},"HCCS": {"Transit Size(MB)": 0.06393599999999998,"Transit Time(ms)": 0.02366978125,"Bandwidth(GB/s)": 2.7012,"Large Packet Ratio": 0.0,"Size Distribution": {"0.003072": [18,0.0202498125],"0.002944": [2,0.00230996875],"0.002752": [1,0.00111]}},"PCIE": {"Transit Size(MB)": 0.021376,"Transit Time(ms)": 0.011499890625,"Bandwidth(GB/s)": 1.8588,"Large Packet Ratio": 0.0,"Size Distribution": {"0.003072": [6,0.009869906250000001],"0.002944": [1,0.001629984375]}},"SDMA": {"Transit Size(MB)": 0.08531199999999997,"Transit Time(ms)": 0.035169671875,"Bandwidth(GB/s)": 2.4257,"Large Packet Ratio": 0,"Size Distribution": {}}}},"1": {"Communication Time Info": {"Start Timestamp(us)": 1695054582707330.2,"Elapse Time(ms)": 20.798642234375,"Transit Time(ms)": 0.01630984375,"Wait Time(ms)": 0.00015000000000000001,"Synchronization Time(ms)": 1e-05,"Idle Time(ms)": 20.782182390624996,"Wait Time Ratio": 0.0091,"Synchronization Time Ratio": 0.0006},"Communication Bandwidth Info": {"RDMA": {"Transit Size(MB)": 0,"Transit Time(ms)": 0,"Bandwidth(GB/s)": 0,"Large Packet Ratio": 0,"Size Distribution": {}},"HCCS": {"Transit Size(MB)": 0.10380800000000005,"Transit Time(ms)": 0.03860956250000001,"Bandwidth(GB/s)": 2.6887,"Large Packet Ratio": 0.0,"Size Distribution": {"0.003072": [29,0.033139625000000006],"0.002944": [5,0.005469937500000001]}},"PCIE": {"Transit Size(MB)": 0.030399999999999996,"Transit Time(ms)": 0.01630984375,"Bandwidth(GB/s)": 1.8639,"Large Packet Ratio": 0.0,"Size Distribution": {"0.003072": [9,0.014699859374999999],"0.002752": [1,0.001609984375]}},"SDMA": {"Transit Size(MB)": 0.13420800000000005,"Transit Time(ms)": 0.05491940625000001,"Bandwidth(GB/s)": 2.4437,"Large Packet Ratio": 0,"Size Distribution": {}}}}},"hcom_broadcast__501_1@6297232067196334501": {"0": {"Communication Time Info": {"Start Timestamp(us)": 1695054582728707.2,"Elapse Time(ms)": 27.107999203125,"Transit Time(ms)": 0,"Wait Time(ms)": 27.096639281249992,"Synchronization Time(ms)": 27.096639281249992,"Idle Time(ms)": 0.011359921875008894,"Wait Time Ratio": 1.0,"Synchronization Time Ratio": 1.0},"Communication Bandwidth Info": {"RDMA": {"Transit Size(MB)": 0,"Transit Time(ms)": 0,"Bandwidth(GB/s)": 0,"Large Packet Ratio": 0,"Size Distribution": {}},"HCCS": {"Transit Size(MB)": 5.6e-05,"Transit Time(ms)": 0.001129984375,"Bandwidth(GB/s)": 0.0496,"Large Packet Ratio": 0.0,"Size Distribution": {"5.6e-05": [1,0.001129984375]}},"PCIE": {"Transit Size(MB)": 0,"Transit Time(ms)": 0,"Bandwidth(GB/s)": 0,"Large Packet Ratio": 0,"Size Distribution": {}},"SDMA": {"Transit Size(MB)": 5.6e-05,"Transit Time(ms)": 0.001129984375,"Bandwidth(GB/s)": 0.0496,"Large Packet Ratio": 0,"Size Distribution": {}}}},"1": {"Communication Time Info": {"Start Timestamp(us)": 1695054582738906.0,"Elapse Time(ms)": 17.367596484375,"Transit Time(ms)": 0,"Wait Time(ms)": 0.0002,"Synchronization Time(ms)": 0.0002,"Idle Time(ms)": 17.367396484375,"Wait Time Ratio": 1.0,"Synchronization Time Ratio": 1.0},"Communication Bandwidth Info": {"RDMA": {"Transit Size(MB)": 0,"Transit Time(ms)": 0,"Bandwidth(GB/s)": 0,"Large Packet Ratio": 0,"Size Distribution": {}},"HCCS": {"Transit Size(MB)": 0.000184,"Transit Time(ms)": 0.0020599843749999997,"Bandwidth(GB/s)": 0.0893,"Large Packet Ratio": 0.0,"Size Distribution": {"5.6e-05": [1,0.00114],"0.000128": [1,0.000919984375]}},"PCIE": {"Transit Size(MB)": 0,"Transit Time(ms)": 0,"Bandwidth(GB/s)": 0,"Large Packet Ratio": 0,"Size Distribution": {}},"SDMA": {"Transit Size(MB)": 0.000184,"Transit Time(ms)": 0.0020599843749999997,"Bandwidth(GB/s)": 0.0893,"Large Packet Ratio": 0,"Size Distribution": {}}}}}}}} \ No newline at end of file diff --git a/profiler/test/resource/advisor/cluster_analysis_output/cluster_step_trace_time.csv b/profiler/test/resource/advisor/cluster_analysis_output/cluster_step_trace_time.csv new file mode 100644 index 0000000000000000000000000000000000000000..964f26b3c08d941814d81253c334d5a56bc3f559 --- /dev/null +++ b/profiler/test/resource/advisor/cluster_analysis_output/cluster_step_trace_time.csv @@ -0,0 +1,10 @@ +Step,Type,Index,Computing,Communication(Not Overlapped),Overlapped,Communication,Free,Stage,Bubble,Communication(Not Overlapped and Exclude Receive) +,rank,0,80309.68717187493,683731.2897031249,5524.544625000097,689255.834328125,990605.1042031233,1754645.75,0.0,683731.2897031249 +,rank,1,80435.74650000008,133385.97745312497,76.47925000000396,133462.45670312498,1488610.0587500026,1702431.75,0.0,133385.97745312497 +,rank,2,80335.81743750002,530279.2325156251,2056.8394374999916,532336.0719531251,1110332.1177812554,1720947.0,0.0,530279.2325156251 +,rank,3,80077.26998437475,265574.66,1775.3800000000629,267350.04000000004,1366552.5200156313,1712204.5,0.0,265574.66 +,rank,4,81662.19999999994,478477.3900000001,2224.999999999942,480702.39,1130793.2500000068,1690932.75,0.0,478477.3900000001 +,rank,5,81367.62001562494,756374.86,7225.910000000033,763600.77,892836.8999843737,1730579.25,0.0,756374.86 +,rank,6,81359.02999999997,244123.84000000003,1568.109999999986,245691.95,1390633.03,1716115.75,0.0,244123.84000000003 +,rank,7,81416.40999999992,539037.92,2378.3699999999953,541416.29,1061577.0900000043,1682031.25,0.0,539037.92 +,stage,"(0, 1, 2, 3, 4, 5, 6, 7)",81662.19999999994,756374.86,7225.910000000033,763600.77,1488610.0587500026,1754645.75,0,756374.86 diff --git a/profiler/test/run_ut.py b/profiler/test/run_ut.py index f1a0b4f169613deb36560f2c2c633120d71765d9..ee27abaace177c7eab9021bcd3fcf51f0368c832 100644 --- a/profiler/test/run_ut.py +++ b/profiler/test/run_ut.py @@ -5,9 +5,15 @@ import sys def set_python_path(): - cluster_analyse_root = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "cluster_analyse") - compare_tools_root = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "compare_tools") - advisor_root = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "advisor") + cluster_analyse_root = os.path.join( + os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "cluster_analyse") + compare_tools_root = os.path.join( + os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "compare_tools") + advisor_root = os.path.join( + os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "advisor") + advisor_backend_root = os.path.join( + os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "advisor", "advisor_backend") + # Update PYTHONPATH python_path = os.environ.get("PYTHONPATH", "") if not python_path: python_path += cluster_analyse_root @@ -15,6 +21,7 @@ def set_python_path(): python_path += f":{cluster_analyse_root}" python_path += f":{compare_tools_root}" python_path += f":{advisor_root}" + python_path += f":{advisor_backend_root}" os.environ["PYTHONPATH"] = python_path diff --git a/profiler/test/ut/advisor/advisor_backend/cluster_advice/test_cluster_advice_base.py b/profiler/test/ut/advisor/advisor_backend/cluster_advice/test_cluster_advice_base.py new file mode 100644 index 0000000000000000000000000000000000000000..6235c06efb37a553ddb61a60a7a705fdb603edea --- /dev/null +++ b/profiler/test/ut/advisor/advisor_backend/cluster_advice/test_cluster_advice_base.py @@ -0,0 +1,72 @@ +import os +import shutil +import unittest +from unittest import mock +from unittest.mock import MagicMock + +from advisor_backend.cluster_advice.cluster_advice_base import ClusterAdviceBase + + +class MockChildClusterAdvice(ClusterAdviceBase): + + def __init__(self, collection_path: str): + super().__init__(collection_path) + + def run(self): + return True + + def output(self): + return True + + +class TestClusterAdviceBase(unittest.TestCase): + + def setUp(self): + self.tmp_dir = "./tmp_dir" + os.makedirs(self.tmp_dir) + + def tearDown(self): + shutil.rmtree(self.tmp_dir) + + def test_compute_max_gap_ratio_with_zero_mean(self): + result = ClusterAdviceBase.compute_max_gap_ratio([1, 2], 0) + self.assertEqual(0, result) + + def test_compute_max_gap_ratio_with_normal_input(self): + result = ClusterAdviceBase.compute_max_gap_ratio([3, 1], 2.0) + self.assertEqual(1.0, result) + + def test_compute_max_gap_ratio_with_abnormal_input(self): + with self.assertRaises(TypeError): + ClusterAdviceBase.compute_max_gap_ratio(["name", "age"], 2.0) + + def test_path_check_with_output_path(self): + analysis_output = os.path.join(self.tmp_dir, "cluster_analysis_output") + os.makedirs(analysis_output) + mock_inst = MockChildClusterAdvice(self.tmp_dir) + mock_inst.cluster_analyze = MagicMock(name="cluster_analyze") + mock_inst.path_check() + mock_inst.cluster_analyze.assert_not_called() + + def test_path_check_without_output_path(self): + mock_inst = MockChildClusterAdvice(self.tmp_dir) + mock_inst.cluster_analyze = MagicMock(name="cluster_analyze") + mock_inst.path_check() + mock_inst.cluster_analyze.assert_called_once() + + def test_cluster_analyze_normal(self): + mock_inst = MockChildClusterAdvice(self.tmp_dir) + with mock.patch("advisor_backend.cluster_advice.cluster_advice_base.Interface") as mock_if: + mock_if_inst = mock_if.return_value + mock_if_inst.run = MagicMock(name="run") + mock_inst.cluster_analyze() + mock_if_inst.run.assert_called_once() + + def test_cluster_analyze_abnormal(self): + mock_inst = MockChildClusterAdvice(self.tmp_dir) + with self.assertRaises(ValueError): + with mock.patch("advisor_backend.cluster_advice.cluster_advice_base.Interface") as mock_if: + mock_if_inst = mock_if.return_value + mock_if_inst.run = mock.Mock(name="run", side_effect=Exception('Error!')) + mock_inst.cluster_analyze() + mock_if_inst.run.assert_called_once() diff --git a/profiler/test/ut/advisor/advisor_backend/cluster_advice/test_kernel_cluster_advice.py b/profiler/test/ut/advisor/advisor_backend/cluster_advice/test_kernel_cluster_advice.py new file mode 100644 index 0000000000000000000000000000000000000000..0509b197cafae23e4f53ed0b300c1934a66b1197 --- /dev/null +++ b/profiler/test/ut/advisor/advisor_backend/cluster_advice/test_kernel_cluster_advice.py @@ -0,0 +1,104 @@ +import os +import stat +import shutil +import unittest +from unittest import mock +from unittest.mock import MagicMock + +from common_func.constant import Constant +from advisor_backend.cluster_advice.kernel_cluster_advice import KernelClusterAdvice + + +class TestClusterAdviceBase(unittest.TestCase): + + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.tmp_dir = './tmp_dir' + cls.data_map_normal = { + 0: os.path.join(cls.tmp_dir, 'rank_0'), + 1: os.path.join(cls.tmp_dir, 'rank_1') + } + cls.data_map_abnormal = { + 2: os.path.join(cls.tmp_dir, 'rank_2') + } + ascend_output_0 = os.path.join(cls.tmp_dir, 'rank_0', Constant.SINGLE_OUTPUT) + os.makedirs(ascend_output_0) + ascend_output_1 = os.path.join(cls.tmp_dir, 'rank_1', Constant.SINGLE_OUTPUT) + os.makedirs(ascend_output_1) + ascend_output_2 = os.path.join(cls.tmp_dir, 'rank_2', Constant.SINGLE_OUTPUT) + os.makedirs(ascend_output_2) + # write data to csv file + flags = os.O_WRONLY | os.O_CREAT + mode = stat.S_IWUSR | stat.S_IRUSR + with os.fdopen(os.open( + os.path.join(ascend_output_0, Constant.KERNEL_DETAILS_CSV), flags, mode), 'w') as fp: + fp.write('Step Id,Name,Input Shapes,Input Data Types,Output Shapes,Duration(us)\n') + fp.write('0,ZerosLike46,"""544404480""",FLOAT16,"""544404480""",10.0\n') + fp.write('0,ZerosLike46,"""544404480""",FLOAT16,"""544404480""",20.0\n') + with os.fdopen(os.open( + os.path.join(ascend_output_1, Constant.KERNEL_DETAILS_CSV), flags, mode), 'w') as fp: + fp.write('Step Id,Name,Input Shapes,Input Data Types,Output Shapes,Duration(us)\n') + fp.write('0,Mul85,"""4,1024,12288;4,1024,1""",FLOAT16,"""4,1024,12288""",30.0\n') + fp.write('0,Mul85,"""4,1024,12288;4,1024,1""",FLOAT16,"""4,1024,12288""",40.0\n') + cls.all_kernel_data = { + 'rank id': {0: 0, 1: 0, 2: 1, 3: 1}, + 'Name': {0: 'ZerosLike46', 1: 'ZerosLike46', 2: 'Mul85', 3: 'Mul85'}, + 'Input Shapes': {0: '"544404480"', 1: '"544404480"', 2: '"4,1024,12288;4,1024,1"', 3: '"4,1024,12288;4,1024,1"'}, + 'Input Data Types': {0: 'FLOAT16', 1: 'FLOAT16', 2: 'FLOAT16', 3: 'FLOAT16'}, + 'Output Shapes': {0: '"544404480"', 1: '"544404480"', 2: '"4,1024,12288"', 3: '"4,1024,12288"'}, + 'Duration(us)': {0: 10.0, 1: 20.0, 2: 30.0, 3: 40.0} + } + cls.expect_result = { + 'rank id': {0: 0, 1: 1}, + 'Name': {0: 'ZerosLike46', 1: 'Mul85'}, + 'Input Shapes': {0: '"544404480"', 1: '"4,1024,12288;4,1024,1"'}, + 'Input Data Types': {0: 'FLOAT16', 1: 'FLOAT16'}, + 'Output Shapes': {0: '"544404480"', 1: '"4,1024,12288"'}, + 'Duration(us)_mean': {0: 15.0, 1: 35.0}, + 'Duration(us)_var': {0: 50.0, 1: 50.0}, + 'Duration(us)_max': {0: 20.0, 1: 40.0}, + 'Duration(us)_min': {0: 10.0, 1: 30.0}, + 'Duration(us)_count': {0: 2, 1: 2}, + 'Duration(us)_sum': {0: 30.0, 1: 70.0} + } + with os.fdopen(os.open( + os.path.join(ascend_output_2, Constant.KERNEL_DETAILS_CSV), flags, mode), 'w') as fp: + fp.write('Worng Title\n') + fp.write('0\n') + + @classmethod + def tearDownClass(cls): + shutil.rmtree(cls.tmp_dir) + + def test_run(self): + advice_inst = KernelClusterAdvice(self.tmp_dir) + advice_inst.load_kernel_details_data = MagicMock(name="load_kernel_details_data") + advice_inst.calculate_data = MagicMock(name="calculate_data") + advice_inst.run() + advice_inst.load_kernel_details_data.assert_called_once() + advice_inst.calculate_data.assert_called_once() + + def load_kernel_details_data_with_normal_data(self): + advice_inst = KernelClusterAdvice(self.tmp_dir) + with mock.patch("cluster_data_preprocess.pytorch_data_preprocessor.PytorchDataPreprocessor") as py_mock, \ + mock.patch("common_func.path_manager.PathManager.check_path_readable"): + py_mock_inst = py_mock.return_valuee + py_mock_inst.get_data_map.return_value = self.data_map_normal + advice_inst.load_kernel_details_data() + self.assertEqual(self.all_kernel_data, advice_inst.all_kernel_data.to_dict()) + + def load_kernel_details_data_with_abnormal_data(self): + advice_inst = KernelClusterAdvice(self.tmp_dir) + with self.assertRaises(RuntimeError): + with mock.patch("cluster_data_preprocess.pytorch_data_preprocessor.PytorchDataPreprocessor") as py_mock, \ + mock.patch("common_func.path_manager.PathManager.check_path_readable"): + py_mock_inst = py_mock.return_valuee + py_mock_inst.get_data_map.return_value = self.data_map_abnormal + advice_inst.load_kernel_details_data() + + def calculate_data(self): + advice_inst = KernelClusterAdvice(self.tmp_dir) + advice_inst.all_kernel_data = self.all_kernel_data + result = advice_inst.calculate_data() + self.assertEqual(self.expect_result, result.to_dict()) diff --git a/profiler/test/ut/advisor/advisor_backend/cluster_advice/test_slow_link_advice.py b/profiler/test/ut/advisor/advisor_backend/cluster_advice/test_slow_link_advice.py new file mode 100644 index 0000000000000000000000000000000000000000..79307813f5b2d9b272148a8b29e79f571cf9db1b --- /dev/null +++ b/profiler/test/ut/advisor/advisor_backend/cluster_advice/test_slow_link_advice.py @@ -0,0 +1,61 @@ +import unittest + +from advisor_backend.cluster_advice.slow_link_advice import SlowLinkAdvice + + +class TestSlowLinkAdvice(unittest.TestCase): + + DATA = 'data' + BOTTLENECK = 'bottleneck' + ADVICE = 'advice' + + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.prof_dir = './resource/advisor' + cls.expect_data = { + 0: { + 'RDMA time(ms)': 0, + 'RDMA size(mb)': 0, + 'SDMA time(ms)': 0.08536799999999997, + 'SDMA size(mb)': 0.03629965625, + 'RDMA bandwidth(GB/s)': 0, + 'SDMA bandwidth(GB/s)': 0.4252 + }, + 1: { + 'RDMA time(ms)': 0, + 'RDMA size(mb)': 0, + 'SDMA time(ms)': 0.13439200000000004, + 'SDMA size(mb)': 0.05697939062500001, + 'RDMA bandwidth(GB/s)': 0, + 'SDMA bandwidth(GB/s)': 0.424 + } + } + cls.expect_bottleneck = 'SDMA bandwidth(GB/s): \n' \ + 'The average is 0.425, ' \ + 'while the maximum is 0.425GB/s and ' \ + 'the minimum is 0.424GB/s. ' \ + 'the difference is 0.001GB/s. \n' + + def test_compute_ratio_abnormal(self): + result = SlowLinkAdvice.compute_ratio(19.0, 0) + self.assertEqual(0, result) + + def test_load_communication_json_abnormal(self): + slow_link_inst = SlowLinkAdvice("./tmp_dir") + with self.assertRaises(RuntimeError): + result = slow_link_inst.load_communication_json() + + def test_compute_bandwidth_abnormal(self): + slow_link_inst = SlowLinkAdvice("./tmp_dir") + op_dict = {"Name": "ZhangSan"} + with self.assertRaises(ValueError): + slow_link_inst.compute_bandwidth(op_dict) + + def test_run(self): + slow_link_inst = SlowLinkAdvice(self.prof_dir) + result = slow_link_inst.run() + data = dict(result[self.DATA]) + bottleneck = result[self.BOTTLENECK] + self.assertEqual(self.expect_data, data) + self.assertEqual(self.expect_bottleneck, bottleneck) diff --git a/profiler/test/ut/advisor/advisor_backend/cluster_advice/test_slow_rank_advice.py b/profiler/test/ut/advisor/advisor_backend/cluster_advice/test_slow_rank_advice.py new file mode 100644 index 0000000000000000000000000000000000000000..6a45553e1eb9522acc778575e104eb8903b0f7be --- /dev/null +++ b/profiler/test/ut/advisor/advisor_backend/cluster_advice/test_slow_rank_advice.py @@ -0,0 +1,42 @@ +import unittest + +from advisor_backend.cluster_advice.slow_rank_advice import SlowRankAdvice + + +class TestSlowRankAdvice(unittest.TestCase): + + DATA = 'data' + BOTTLENECK = 'bottleneck' + ADVICE = 'advice' + + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.prof_dir = './resource/advisor' + cls.expect_data = { + 0: [80309.68717187493, 683731.2897031249, 990605.1042031233, 0], + 1: [80435.74650000008, 133385.97745312497, 1488610.0587500026, 0], + 2: [80335.81743750002, 530279.2325156251, 1110332.1177812554, 0], + 3: [80077.26998437475, 265574.66, 1366552.5200156313, 0], + 4: [81662.19999999994, 478477.3900000001, 1130793.2500000068, 0], + 5: [81367.62001562494, 756374.86, 892836.8999843737, 0], + 6: [81359.02999999997, 244123.84000000003, 1390633.03, 0], + 7: [81416.40999999992, 539037.92, 1061577.0900000043, 0] + } + cls.expect_bottleneck = 'Communication has some issues in the cluster, ' \ + 'because the max difference of Communication time has reached 622.989ms. \n' \ + 'Free has some issues in the cluster, ' \ + 'because the max difference of Free time has reached 595.773ms. \n' + + def test_run(self): + slow_rank_inst = SlowRankAdvice(self.prof_dir) + result = slow_rank_inst.run() + data = dict(result[self.DATA]) + bottleneck = result[self.BOTTLENECK] + self.assertEqual(self.expect_data, data) + self.assertEqual(self.expect_bottleneck, bottleneck) + + def test_load_step_time_abnormal(self): + slow_rank_inst = SlowRankAdvice("./tmp_dir") + with self.assertRaises(RuntimeError): + slow_rank_inst.load_step_time() diff --git a/profiler/test/ut/advisor/advisor_backend/prof_bean_advisor/test_cluster_step_trace_time_bean.py b/profiler/test/ut/advisor/advisor_backend/prof_bean_advisor/test_cluster_step_trace_time_bean.py new file mode 100644 index 0000000000000000000000000000000000000000..7b141ae08865c36af83ae65afd2dd713c9e473a6 --- /dev/null +++ b/profiler/test/ut/advisor/advisor_backend/prof_bean_advisor/test_cluster_step_trace_time_bean.py @@ -0,0 +1,44 @@ +import os +import stat +import shutil +import unittest +from unittest import mock +from unittest.mock import MagicMock + +from common_func.constant import Constant +from advisor_backend.prof_bean_advisor.cluster_step_trace_time_bean import ClusterStepTraceTimeBean + + +class TestClusterStepTraceTimeBean(unittest.TestCase): + + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.normal_data = { + "Step": "0", "Type": "MockType", "Index": 9, "Computing": 123.6, + "Communication(Not Overlapped)": 12.3, "Free": 45.6 + } + cls.abnormal_data = { + "Step": "0", "Type": "MockType", "Index": "idx0", "Computing": "MockCommpute", + "Communication(Not Overlapped)": "MockCommunication", "Free": "MockFree" + } + + def test_property_normal(self): + bean_inst = ClusterStepTraceTimeBean(self.normal_data) + self.assertEqual(self.normal_data.get("Step"), bean_inst.step) + self.assertEqual(self.normal_data.get("Type"), bean_inst.type) + self.assertEqual(self.normal_data.get("Index"), bean_inst.index) + self.assertEqual(self.normal_data.get("Computing"), bean_inst.compute) + self.assertEqual(self.normal_data.get("Communication(Not Overlapped)"), bean_inst.communication) + self.assertEqual(self.normal_data.get("Free"), bean_inst.free) + + def test_property_abnormal(self): + bean_inst = ClusterStepTraceTimeBean(self.abnormal_data) + with self.assertRaises(ValueError): + _ = bean_inst.index + with self.assertRaises(ValueError): + _ = bean_inst.compute + with self.assertRaises(ValueError): + _ = bean_inst.communication + with self.assertRaises(ValueError): + _ = bean_inst.free diff --git a/profiler/test/ut/compare_tools/utils/test_file_reader.py b/profiler/test/ut/compare_tools/utils/test_file_reader.py index 7e755a69cef58a3d595eeaf3ff6889e4749f5ccc..dbf062a8f9d05ef5d661b26e439e9970fd104c8f 100644 --- a/profiler/test/ut/compare_tools/utils/test_file_reader.py +++ b/profiler/test/ut/compare_tools/utils/test_file_reader.py @@ -1,6 +1,7 @@ import unittest from utils.file_reader import FileReader +from utils.constant import Constant class TestFileReader(unittest.TestCase): @@ -15,4 +16,4 @@ class TestFileReader(unittest.TestCase): def test_check_json_type(self): t = FileReader.check_json_type("resource/event_list.json") - self.assertEqual(t, 1) + self.assertEqual(t, Constant.NPU)