|
2 | 2 | from xcvrd.xcvrd_utilities.port_mapping import *
|
3 | 3 | from xcvrd.xcvrd_utilities.sfp_status_helper import *
|
4 | 4 | from xcvrd.xcvrd import *
|
| 5 | +import pytest |
5 | 6 | import copy
|
6 | 7 | import os
|
7 | 8 | import sys
|
@@ -654,6 +655,111 @@ def test_CmisManagerTask_task_run_stop(self, mock_chassis):
|
654 | 655 | cmis_manager.join()
|
655 | 656 | assert not cmis_manager.is_alive()
|
656 | 657 |
|
| 658 | + DEFAULT_DP_STATE = { |
| 659 | + 'DP1State': 'DataPathActivated', |
| 660 | + 'DP2State': 'DataPathActivated', |
| 661 | + 'DP3State': 'DataPathActivated', |
| 662 | + 'DP4State': 'DataPathActivated', |
| 663 | + 'DP5State': 'DataPathActivated', |
| 664 | + 'DP6State': 'DataPathActivated', |
| 665 | + 'DP7State': 'DataPathActivated', |
| 666 | + 'DP8State': 'DataPathActivated' |
| 667 | + } |
| 668 | + DEFAULT_CONFIG_STATUS = { |
| 669 | + 'ConfigStatusLane1': 'ConfigSuccess', |
| 670 | + 'ConfigStatusLane2': 'ConfigSuccess', |
| 671 | + 'ConfigStatusLane3': 'ConfigSuccess', |
| 672 | + 'ConfigStatusLane4': 'ConfigSuccess', |
| 673 | + 'ConfigStatusLane5': 'ConfigSuccess', |
| 674 | + 'ConfigStatusLane6': 'ConfigSuccess', |
| 675 | + 'ConfigStatusLane7': 'ConfigSuccess', |
| 676 | + 'ConfigStatusLane8': 'ConfigSuccess' |
| 677 | + } |
| 678 | + CONFIG_LANE_8_UNDEFINED = { |
| 679 | + 'ConfigStatusLane1': 'ConfigSuccess', |
| 680 | + 'ConfigStatusLane2': 'ConfigSuccess', |
| 681 | + 'ConfigStatusLane3': 'ConfigSuccess', |
| 682 | + 'ConfigStatusLane4': 'ConfigSuccess', |
| 683 | + 'ConfigStatusLane5': 'ConfigSuccess', |
| 684 | + 'ConfigStatusLane6': 'ConfigSuccess', |
| 685 | + 'ConfigStatusLane7': 'ConfigSuccess', |
| 686 | + 'ConfigStatusLane8': 'ConfigUndefined' |
| 687 | + } |
| 688 | + @pytest.mark.parametrize("app_new, host_lanes_mask, lane_appl_code, default_dp_state, default_config_status, expected", [ |
| 689 | + (1, 0x0F, {0 : 1, 1 : 1, 2 : 1, 3 : 1}, DEFAULT_DP_STATE, DEFAULT_CONFIG_STATUS, False), |
| 690 | + (1, 0x0F, {0 : 1, 1 : 1, 2 : 1, 3 : 0}, DEFAULT_DP_STATE, DEFAULT_CONFIG_STATUS, True), |
| 691 | + (1, 0xF0, {4 : 1, 5 : 1, 6 : 1, 7 : 1}, DEFAULT_DP_STATE, DEFAULT_CONFIG_STATUS, False), |
| 692 | + (1, 0xF0, {4 : 1, 5 : 1, 6 : 1, 7 : 1}, DEFAULT_DP_STATE, CONFIG_LANE_8_UNDEFINED, True), |
| 693 | + (1, 0xF0, {4 : 1, 5 : 7, 6 : 1, 7 : 1}, DEFAULT_DP_STATE, DEFAULT_CONFIG_STATUS, True), |
| 694 | + (4, 0xF0, {4 : 1, 5 : 7, 6 : 1, 7 : 1}, DEFAULT_DP_STATE, DEFAULT_CONFIG_STATUS, True), |
| 695 | + (3, 0xC0, {7 : 3, 8 : 3}, DEFAULT_DP_STATE, DEFAULT_CONFIG_STATUS, False), |
| 696 | + (1, 0x0F, {}, DEFAULT_DP_STATE, DEFAULT_CONFIG_STATUS, True), |
| 697 | + (-1, 0x0F, {}, DEFAULT_DP_STATE, DEFAULT_CONFIG_STATUS, False) |
| 698 | + ]) |
| 699 | + def test_CmisManagerTask_is_cmis_application_update_required(self, app_new, host_lanes_mask, lane_appl_code, default_dp_state, default_config_status, expected): |
| 700 | + |
| 701 | + mock_xcvr_api = MagicMock() |
| 702 | + mock_xcvr_api.is_flat_memory = MagicMock(return_value=False) |
| 703 | + |
| 704 | + def get_application(lane): |
| 705 | + return lane_appl_code.get(lane, 0) |
| 706 | + mock_xcvr_api.get_application = MagicMock(side_effect=get_application) |
| 707 | + |
| 708 | + mock_xcvr_api.get_datapath_state = MagicMock(return_value=default_dp_state) |
| 709 | + mock_xcvr_api.get_config_datapath_hostlane_status = MagicMock(return_value=default_config_status) |
| 710 | + |
| 711 | + port_mapping = PortMapping() |
| 712 | + stop_event = threading.Event() |
| 713 | + task = CmisManagerTask(DEFAULT_NAMESPACE, port_mapping, stop_event) |
| 714 | + |
| 715 | + assert task.is_cmis_application_update_required(mock_xcvr_api, app_new, host_lanes_mask) == expected |
| 716 | + |
| 717 | + @pytest.mark.parametrize("host_lane_count, speed, subport, expected", [ |
| 718 | + (8, 400000, 0, 0xFF), |
| 719 | + (4, 100000, 1, 0xF), |
| 720 | + (4, 100000, 2, 0xF0), |
| 721 | + (4, 100000, 0, 0xF), |
| 722 | + (4, 100000, 9, 0x0), |
| 723 | + (1, 50000, 2, 0x2), |
| 724 | + (1, 200000, 2, 0x0) |
| 725 | + ]) |
| 726 | + def test_CmisManagerTask_get_cmis_host_lanes_mask(self, host_lane_count, speed, subport, expected): |
| 727 | + appl_advert_dict = { |
| 728 | + 1: { |
| 729 | + 'host_electrical_interface_id': '400GAUI-8 C2M (Annex 120E)', |
| 730 | + 'module_media_interface_id': '400GBASE-DR4 (Cl 124)', |
| 731 | + 'media_lane_count': 4, |
| 732 | + 'host_lane_count': 8, |
| 733 | + 'host_lane_assignment_options': 1 |
| 734 | + }, |
| 735 | + 2: { |
| 736 | + 'host_electrical_interface_id': 'CAUI-4 C2M (Annex 83E)', |
| 737 | + 'module_media_interface_id': 'Active Cable assembly with BER < 5x10^-5', |
| 738 | + 'media_lane_count': 4, |
| 739 | + 'host_lane_count': 4, |
| 740 | + 'host_lane_assignment_options': 17 |
| 741 | + }, |
| 742 | + 3: { |
| 743 | + 'host_electrical_interface_id': '50GAUI-1 C2M', |
| 744 | + 'module_media_interface_id': '50GBASE-SR', |
| 745 | + 'media_lane_count': 1, |
| 746 | + 'host_lane_count': 1, |
| 747 | + 'host_lane_assignment_options': 255 |
| 748 | + } |
| 749 | + } |
| 750 | + mock_xcvr_api = MagicMock() |
| 751 | + mock_xcvr_api.get_application_advertisement = MagicMock(return_value=appl_advert_dict) |
| 752 | + |
| 753 | + def get_host_lane_assignment_option_side_effect(app): |
| 754 | + return appl_advert_dict[app]['host_lane_assignment_options'] |
| 755 | + mock_xcvr_api.get_host_lane_assignment_option = MagicMock(side_effect=get_host_lane_assignment_option_side_effect) |
| 756 | + port_mapping = PortMapping() |
| 757 | + stop_event = threading.Event() |
| 758 | + task = CmisManagerTask(DEFAULT_NAMESPACE, port_mapping, stop_event) |
| 759 | + |
| 760 | + appl = task.get_cmis_application_desired(mock_xcvr_api, host_lane_count, speed) |
| 761 | + assert task.get_cmis_host_lanes_mask(mock_xcvr_api, appl, host_lane_count, subport) == expected |
| 762 | + |
657 | 763 | @patch('xcvrd.xcvrd.platform_chassis')
|
658 | 764 | @patch('xcvrd.xcvrd_utilities.port_mapping.subscribe_port_update_event', MagicMock(return_value=(None, None)))
|
659 | 765 | @patch('xcvrd.xcvrd_utilities.port_mapping.handle_port_update_event', MagicMock())
|
|
0 commit comments