From 560f53a661f08c1e8419ac054fb33dec33c71b31 Mon Sep 17 00:00:00 2001 From: Jaganathan Anbalagan Date: Fri, 29 Sep 2023 13:27:26 -0700 Subject: [PATCH 1/4] In order to collect PM stats without loss of data following vdm freeze and unfreeze request needs to be followed. VDM freeze PM stats collection VDM unfreeze --- .../sonic_xcvr/api/public/c_cmis.py | 46 +++++++++--- .../sonic_xcvr/fields/consts.py | 4 + .../sonic_xcvr/mem_maps/public/cmis.py | 4 + .../sonic_xcvr/sfp_optoe_base.py | 41 ++++++++++ tests/sonic_xcvr/test_ccmis.py | 41 ++++++++++ tests/sonic_xcvr/test_sfp_optoe_base.py | 74 +++++++++++++++++++ 6 files changed, 201 insertions(+), 9 deletions(-) create mode 100644 tests/sonic_xcvr/test_sfp_optoe_base.py diff --git a/sonic_platform_base/sonic_xcvr/api/public/c_cmis.py b/sonic_platform_base/sonic_xcvr/api/public/c_cmis.py index bb7e3a703..3b6479838 100644 --- a/sonic_platform_base/sonic_xcvr/api/public/c_cmis.py +++ b/sonic_platform_base/sonic_xcvr/api/public/c_cmis.py @@ -147,6 +147,43 @@ def set_tx_power(self, tx_power): time.sleep(1) return status + def freeze_vdm_stats(self): + ''' + This function freeze all the vdm statistics reporting registers. + When raised by the host, causes the module to freeze and hold all + reported statistics reporting registers (minimum, maximum and + average values)in Pages 24h-27h. + + Returns True if the provision succeeds and False incase of failure. + ''' + return self.xcvr_eeprom.write(consts.VDM_CONTROL, VDM_FREEZE) + + def get_freeze_vdm_stats(self): + ''' + This function reads and returns the vdm Freeze done status. + + Returns True if the vdm stats freeze is successful and False if not freeze. + ''' + return self.xcvr_eeprom.read(consts.VDM_FREEZE_DONE) + + def unfreeze_vdm_stats(self): + ''' + This function unfreeze all the vdm statistics reporting registers. + When freeze is ceased by the host, releases the freeze request, allowing the + reported minimum, maximum and average values to update again. + + Returns True if the provision succeeds and False incase of failure. + ''' + return self.xcvr_eeprom.write(consts.VDM_CONTROL, VDM_UNFREEZE) + + def get_unfreeze_vdm_stats(self): + ''' + This function reads and returns the vdm unfreeze status. + + Returns True if the vdm stats unfreeze is successful and False if not unfreeze. + ''' + return self.xcvr_eeprom.read(consts.VDM_UNFREEZE_DONE) + def get_pm_all(self): ''' This function returns the PMs reported in Page 34h and 35h in OIF C-CMIS document @@ -163,14 +200,6 @@ def get_pm_all(self): SOPROC: unit in krad/s MER: unit in dB ''' - # When raised by the host, causes the module to freeze and hold all - # reported statistics reporting registers (minimum, maximum and - # average values)in Pages 24h-27h. - # When ceased by the host, releases the freeze request, allowing the - # reported minimum, maximum and average values to update again. - self.xcvr_eeprom.write(consts.VDM_CONTROL, VDM_FREEZE) - time.sleep(1) - self.xcvr_eeprom.write(consts.VDM_CONTROL, VDM_UNFREEZE) PM_dict = dict() rx_bits_pm = self.xcvr_eeprom.read(consts.RX_BITS_PM) @@ -256,7 +285,6 @@ def get_pm_all(self): PM_dict['rx_mer_max'] = self.xcvr_eeprom.read(consts.RX_MAX_MER_PM) return PM_dict - def get_transceiver_info(self): """ Retrieves transceiver info of this SFP diff --git a/sonic_platform_base/sonic_xcvr/fields/consts.py b/sonic_platform_base/sonic_xcvr/fields/consts.py index c36e46601..68ff4b2da 100644 --- a/sonic_platform_base/sonic_xcvr/fields/consts.py +++ b/sonic_platform_base/sonic_xcvr/fields/consts.py @@ -413,6 +413,10 @@ VDM_SUPPORTED = "VdmSupported" VDM_SUPPORTED_PAGE = "VdmSupportedPage" VDM_CONTROL = "VdmControl" +VDM_STATUS = "VdmStatus" +VDM_FREEZE_DONE = "VdmFreezeDone" +VDM_UNFREEZE_DONE = "VdmUnfreezeDone" + MEDIA_LANE_FEC_PM = "Media Lane FEC Performance Monitoring" MEDIA_LANE_LINK_PM = "Media Lane Link Performance Monitoring" RX_BITS_PM = "rxBitsPm" diff --git a/sonic_platform_base/sonic_xcvr/mem_maps/public/cmis.py b/sonic_platform_base/sonic_xcvr/mem_maps/public/cmis.py index 140faeafd..8702e76f3 100644 --- a/sonic_platform_base/sonic_xcvr/mem_maps/public/cmis.py +++ b/sonic_platform_base/sonic_xcvr/mem_maps/public/cmis.py @@ -449,6 +449,10 @@ def __init__(self, codes): *(RegBitField("Bit%d" % (bit), bit) for bit in range (0, 2)) ), NumberRegField(consts.VDM_CONTROL, self.getaddr(0x2f, 144), size=1, ro=False), + NumberRegField(consts.VDM_STATUS, self.getaddr(0x2f, 145), + RegBitField(consts.VDM_UNFREEZE_DONE, 6), + RegBitField(consts.VDM_FREEZE_DONE, 7), + ), ) self.TRANS_CONFIG = RegGroupField(consts.TRANS_CONFIG_FIELD, diff --git a/sonic_platform_base/sonic_xcvr/sfp_optoe_base.py b/sonic_platform_base/sonic_xcvr/sfp_optoe_base.py index 668389e14..8012212f4 100644 --- a/sonic_platform_base/sonic_xcvr/sfp_optoe_base.py +++ b/sonic_platform_base/sonic_xcvr/sfp_optoe_base.py @@ -51,6 +51,47 @@ def get_transceiver_pm(self): api = self.get_xcvr_api() return api.get_transceiver_pm() if api is not None else None + def freeze_vdm_stats(self): + ''' + This function freeze all the vdm statistics reporting registers. + When raised by the host, causes the module to freeze and hold all + reported statistics reporting registers (minimum, maximum and + average values)in Pages 24h-27h. + + Returns True if the provision succeeds and False incase of failure. + ''' + api = self.get_xcvr_api() + return api.freeze_vdm_stats() if api is not None else None + + def unfreeze_vdm_stats(self): + ''' + This function unfreeze all the vdm statistics reporting registers. + When freeze is ceased by the host, releases the freeze request, allowing the + reported minimum, maximum and average values to update again. + + Returns True if the provision succeeds and False incase of failure. + ''' + api = self.get_xcvr_api() + return api.unfreeze_vdm_stats() if api is not None else None + + def get_freeze_vdm_stats(self): + ''' + This function reads and returns the vdm Freeze done status. + + Returns True if the vdm stats freeze is successful and False if not freeze. + ''' + api = self.get_xcvr_api() + return api.get_freeze_vdm_stats() if api is not None else None + + def get_unfreeze_vdm_stats(self): + ''' + This function reads and returns the vdm unfreeze status. + + Returns True if the vdm stats unfreeze is successful and False if not unfreeze. + ''' + api = self.get_xcvr_api() + return api.get_unfreeze_vdm_stats() if api is not None else None + def get_rx_los(self): api = self.get_xcvr_api() if api is not None: diff --git a/tests/sonic_xcvr/test_ccmis.py b/tests/sonic_xcvr/test_ccmis.py index 8b2eb7b7e..fdb31368b 100644 --- a/tests/sonic_xcvr/test_ccmis.py +++ b/tests/sonic_xcvr/test_ccmis.py @@ -624,3 +624,44 @@ def test_get_transceiver_pm(self, mock_response, expected): self.api.get_pm_all.return_value = mock_response result = self.api.get_transceiver_pm() assert result == expected + + @pytest.mark.parametrize("mock_response, expected", [ + (0, 0), + (1, 1), + ]) + def test_get_freeze_vdm_stats(self, mock_response, expected): + self.api.xcvr_eeprom.read = MagicMock() + self.api.xcvr_eeprom.read.return_value = mock_response + result = self.api.get_freeze_vdm_stats() + assert result == expected + + @pytest.mark.parametrize("mock_response, expected", [ + (0, 0), + (1, 1), + ]) + def test_get_unfreeze_vdm_stats(self, mock_response, expected): + self.api.xcvr_eeprom.read = MagicMock() + self.api.xcvr_eeprom.read.return_value = mock_response + result = self.api.get_unfreeze_vdm_stats() + assert result == expected + + @pytest.mark.parametrize("mock_response, expected", [ + (0, 0), + (1, 1), + ]) + def test_freeze_vdm_stats(self, mock_response, expected): + self.api.xcvr_eeprom.write = MagicMock() + self.api.xcvr_eeprom.write.return_value = mock_response + result = self.api.freeze_vdm_stats() + assert result == expected + + @pytest.mark.parametrize("mock_response, expected", [ + (0, 0), + (1, 1), + ]) + def test_unfreeze_vdm_stats(self, mock_response, expected): + self.api.xcvr_eeprom.write = MagicMock() + self.api.xcvr_eeprom.write.return_value = mock_response + result = self.api.unfreeze_vdm_stats() + assert result == expected + diff --git a/tests/sonic_xcvr/test_sfp_optoe_base.py b/tests/sonic_xcvr/test_sfp_optoe_base.py new file mode 100644 index 000000000..f5c53c1bf --- /dev/null +++ b/tests/sonic_xcvr/test_sfp_optoe_base.py @@ -0,0 +1,74 @@ +from mock import MagicMock +from mock import patch +import pytest +from sonic_platform_base.sonic_xcvr.sfp_optoe_base import SfpOptoeBase +from sonic_platform_base.sonic_xcvr.api.public.c_cmis import CCmisApi +from sonic_platform_base.sonic_xcvr.mem_maps.public.c_cmis import CCmisMemMap +from sonic_platform_base.sonic_xcvr.xcvr_eeprom import XcvrEeprom +from sonic_platform_base.sonic_xcvr.codes.public.cmis import CmisCodes + +class TestSfpOptoeBase(object): + + codes = CmisCodes + mem_map = CCmisMemMap(codes) + reader = MagicMock(return_value=None) + writer = MagicMock() + eeprom = XcvrEeprom(reader, writer, mem_map) + sfp_optoe_api = SfpOptoeBase() + ccmis_api = CCmisApi(eeprom) + + @pytest.mark.parametrize("mock_response1, mock_response2, expected", [ + (0, ccmis_api, 0), + (1, ccmis_api, 1), + ]) + def test_freeze_vdm_stats(self, mock_response1, mock_response2, expected): + self.sfp_optoe_api.get_xcvr_api = MagicMock() + self.sfp_optoe_api.get_xcvr_api.return_value = mock_response2 + self.ccmis_api.freeze_vdm_stats = MagicMock() + self.ccmis_api.freeze_vdm_stats.return_value = mock_response1 + + result = self.sfp_optoe_api.freeze_vdm_stats() + assert result == expected + + @pytest.mark.parametrize("mock_response1, mock_response2, expected", [ + (0, ccmis_api, 0), + (1, ccmis_api, 1), + (None, None, None), + ]) + def test_unfreeze_vdm_stats(self, mock_response1, mock_response2, expected): + self.sfp_optoe_api.get_xcvr_api = MagicMock() + self.sfp_optoe_api.get_xcvr_api.return_value = mock_response2 + self.ccmis_api.unfreeze_vdm_stats = MagicMock() + self.ccmis_api.unfreeze_vdm_stats.return_value = mock_response1 + + result = self.sfp_optoe_api.unfreeze_vdm_stats() + assert result == expected + + @pytest.mark.parametrize("mock_response1, mock_response2, expected", [ + (0, ccmis_api, 0), + (1, ccmis_api, 1), + (None, None, None), + ]) + def test_get_freeze_vdm_stats(self, mock_response1, mock_response2, expected): + self.sfp_optoe_api.get_xcvr_api = MagicMock() + self.sfp_optoe_api.get_xcvr_api.return_value = mock_response2 + self.ccmis_api.get_freeze_vdm_stats = MagicMock() + self.ccmis_api.get_freeze_vdm_stats.return_value = mock_response1 + + result = self.sfp_optoe_api.get_freeze_vdm_stats() + assert result == expected + + @pytest.mark.parametrize("mock_response1, mock_response2, expected", [ + (0, ccmis_api, 0), + (1, ccmis_api, 1), + (None, None, None), + ]) + def test_get_unfreeze_vdm_stats(self, mock_response1, mock_response2, expected): + self.sfp_optoe_api.get_xcvr_api = MagicMock() + self.sfp_optoe_api.get_xcvr_api.return_value = mock_response2 + self.ccmis_api.get_unfreeze_vdm_stats = MagicMock() + self.ccmis_api.get_unfreeze_vdm_stats.return_value = mock_response1 + + result = self.sfp_optoe_api.get_unfreeze_vdm_stats() + assert result == expected + From fbf8c831626bcd57f0a36f25f631539e68c726b8 Mon Sep 17 00:00:00 2001 From: Jaganathan Anbalagan Date: Thu, 26 Oct 2023 14:46:12 -0700 Subject: [PATCH 2/4] Signed-off-by: Jaganathan Anbalagan Addressing PR comments. Removed VDM statistics freeze/unfreeze performed inside standard APIs. It should be performed by xcvrd explicitly. --- .../sonic_xcvr/api/public/c_cmis.py | 4 +-- .../sonic_xcvr/api/public/cmisVDM.py | 8 ------ .../sonic_xcvr/sfp_optoe_base.py | 26 ++++++++++++++----- tests/sonic_xcvr/test_ccmis.py | 8 +++--- tests/sonic_xcvr/test_sfp_optoe_base.py | 16 ++++++------ 5 files changed, 34 insertions(+), 28 deletions(-) diff --git a/sonic_platform_base/sonic_xcvr/api/public/c_cmis.py b/sonic_platform_base/sonic_xcvr/api/public/c_cmis.py index 3b6479838..92a4a50fb 100644 --- a/sonic_platform_base/sonic_xcvr/api/public/c_cmis.py +++ b/sonic_platform_base/sonic_xcvr/api/public/c_cmis.py @@ -158,7 +158,7 @@ def freeze_vdm_stats(self): ''' return self.xcvr_eeprom.write(consts.VDM_CONTROL, VDM_FREEZE) - def get_freeze_vdm_stats(self): + def get_vdm_freeze_status(self): ''' This function reads and returns the vdm Freeze done status. @@ -176,7 +176,7 @@ def unfreeze_vdm_stats(self): ''' return self.xcvr_eeprom.write(consts.VDM_CONTROL, VDM_UNFREEZE) - def get_unfreeze_vdm_stats(self): + def get_vdm_unfreeze_status(self): ''' This function reads and returns the vdm unfreeze status. diff --git a/sonic_platform_base/sonic_xcvr/api/public/cmisVDM.py b/sonic_platform_base/sonic_xcvr/api/public/cmisVDM.py index a76c7a39e..dba2a7350 100644 --- a/sonic_platform_base/sonic_xcvr/api/public/cmisVDM.py +++ b/sonic_platform_base/sonic_xcvr/api/public/cmisVDM.py @@ -170,14 +170,6 @@ def get_vdm_allpage(self): return None VDM_START_PAGE = 0x20 vdm = dict() - # When raised by the host, causes the module to freeze and hold all - # reported statistics reporting registers (minimum, maximum and - # average values)in Pages 24h-27h. - # When ceased by the host, releases the freeze request, allowing the - # reported minimum, maximum and average values to update again. - self.xcvr_eeprom.write(consts.VDM_CONTROL, VDM_FREEZE) - time.sleep(1) - self.xcvr_eeprom.write(consts.VDM_CONTROL, VDM_UNFREEZE) vdm_flag_page = self.xcvr_eeprom.read_raw(VDM_FLAG_PAGE * PAGE_SIZE + PAGE_OFFSET, PAGE_SIZE) for page in range(VDM_START_PAGE, VDM_START_PAGE + vdm_page_supported_raw + 1): vdm_current_page = self.get_vdm_page(page, vdm_flag_page) diff --git a/sonic_platform_base/sonic_xcvr/sfp_optoe_base.py b/sonic_platform_base/sonic_xcvr/sfp_optoe_base.py index 8012212f4..54e5ebf44 100644 --- a/sonic_platform_base/sonic_xcvr/sfp_optoe_base.py +++ b/sonic_platform_base/sonic_xcvr/sfp_optoe_base.py @@ -61,7 +61,10 @@ def freeze_vdm_stats(self): Returns True if the provision succeeds and False incase of failure. ''' api = self.get_xcvr_api() - return api.freeze_vdm_stats() if api is not None else None + try: + return api.freeze_vdm_stats() if api is not None else False + except (NotImplementedError, AttributeError): + return False def unfreeze_vdm_stats(self): ''' @@ -72,25 +75,36 @@ def unfreeze_vdm_stats(self): Returns True if the provision succeeds and False incase of failure. ''' api = self.get_xcvr_api() - return api.unfreeze_vdm_stats() if api is not None else None + try: + return api.unfreeze_vdm_stats() if api is not None else False + except (NotImplementedError, AttributeError): + return False + - def get_freeze_vdm_stats(self): + def get_vdm_freeze_status(self): ''' This function reads and returns the vdm Freeze done status. Returns True if the vdm stats freeze is successful and False if not freeze. ''' api = self.get_xcvr_api() - return api.get_freeze_vdm_stats() if api is not None else None + try: + return api.get_vdm_freeze_status() if api is not None else False + except (NotImplementedError, AttributeError): + return False - def get_unfreeze_vdm_stats(self): + def get_vdm_unfreeze_status(self): ''' This function reads and returns the vdm unfreeze status. Returns True if the vdm stats unfreeze is successful and False if not unfreeze. ''' api = self.get_xcvr_api() - return api.get_unfreeze_vdm_stats() if api is not None else None + try: + return api.get_vdm_unfreeze_status() if api is not None else False + except (NotImplementedError, AttributeError): + return False + def get_rx_los(self): api = self.get_xcvr_api() diff --git a/tests/sonic_xcvr/test_ccmis.py b/tests/sonic_xcvr/test_ccmis.py index fdb31368b..e81d3bdb2 100644 --- a/tests/sonic_xcvr/test_ccmis.py +++ b/tests/sonic_xcvr/test_ccmis.py @@ -629,20 +629,20 @@ def test_get_transceiver_pm(self, mock_response, expected): (0, 0), (1, 1), ]) - def test_get_freeze_vdm_stats(self, mock_response, expected): + def test_get_vdm_freeze_status(self, mock_response, expected): self.api.xcvr_eeprom.read = MagicMock() self.api.xcvr_eeprom.read.return_value = mock_response - result = self.api.get_freeze_vdm_stats() + result = self.api.get_vdm_freeze_status() assert result == expected @pytest.mark.parametrize("mock_response, expected", [ (0, 0), (1, 1), ]) - def test_get_unfreeze_vdm_stats(self, mock_response, expected): + def test_get_vdm_unfreeze_status(self, mock_response, expected): self.api.xcvr_eeprom.read = MagicMock() self.api.xcvr_eeprom.read.return_value = mock_response - result = self.api.get_unfreeze_vdm_stats() + result = self.api.get_vdm_unfreeze_stats() assert result == expected @pytest.mark.parametrize("mock_response, expected", [ diff --git a/tests/sonic_xcvr/test_sfp_optoe_base.py b/tests/sonic_xcvr/test_sfp_optoe_base.py index f5c53c1bf..54237e71b 100644 --- a/tests/sonic_xcvr/test_sfp_optoe_base.py +++ b/tests/sonic_xcvr/test_sfp_optoe_base.py @@ -49,13 +49,13 @@ def test_unfreeze_vdm_stats(self, mock_response1, mock_response2, expected): (1, ccmis_api, 1), (None, None, None), ]) - def test_get_freeze_vdm_stats(self, mock_response1, mock_response2, expected): + def test_get_vdm_freeze_status(self, mock_response1, mock_response2, expected): self.sfp_optoe_api.get_xcvr_api = MagicMock() self.sfp_optoe_api.get_xcvr_api.return_value = mock_response2 - self.ccmis_api.get_freeze_vdm_stats = MagicMock() - self.ccmis_api.get_freeze_vdm_stats.return_value = mock_response1 + self.ccmis_api.get_vdm_freeze_status = MagicMock() + self.ccmis_api.get_vdm_freeze_status.return_value = mock_response1 - result = self.sfp_optoe_api.get_freeze_vdm_stats() + result = self.sfp_optoe_api.get_vdm_freeze_status() assert result == expected @pytest.mark.parametrize("mock_response1, mock_response2, expected", [ @@ -63,12 +63,12 @@ def test_get_freeze_vdm_stats(self, mock_response1, mock_response2, expected): (1, ccmis_api, 1), (None, None, None), ]) - def test_get_unfreeze_vdm_stats(self, mock_response1, mock_response2, expected): + def test_get_vdm_unfreeze_status(self, mock_response1, mock_response2, expected): self.sfp_optoe_api.get_xcvr_api = MagicMock() self.sfp_optoe_api.get_xcvr_api.return_value = mock_response2 - self.ccmis_api.get_unfreeze_vdm_stats = MagicMock() - self.ccmis_api.get_unfreeze_vdm_stats.return_value = mock_response1 + self.ccmis_api.get_vdm_unfreeze_status = MagicMock() + self.ccmis_api.get_vdm_unfreeze_status.return_value = mock_response1 - result = self.sfp_optoe_api.get_unfreeze_vdm_stats() + result = self.sfp_optoe_api.get_vdm_unfreeze_status() assert result == expected From 79d89b058ea1887cb3d6babb9b7199fa8425199a Mon Sep 17 00:00:00 2001 From: Jaganathan Anbalagan Date: Mon, 27 Nov 2023 18:05:54 -0800 Subject: [PATCH 3/4] test code correction --- tests/sonic_xcvr/test_ccmis.py | 2 +- tests/sonic_xcvr/test_sfp_optoe_base.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/sonic_xcvr/test_ccmis.py b/tests/sonic_xcvr/test_ccmis.py index e81d3bdb2..75fa2c146 100644 --- a/tests/sonic_xcvr/test_ccmis.py +++ b/tests/sonic_xcvr/test_ccmis.py @@ -642,7 +642,7 @@ def test_get_vdm_freeze_status(self, mock_response, expected): def test_get_vdm_unfreeze_status(self, mock_response, expected): self.api.xcvr_eeprom.read = MagicMock() self.api.xcvr_eeprom.read.return_value = mock_response - result = self.api.get_vdm_unfreeze_stats() + result = self.api.get_vdm_unfreeze_status() assert result == expected @pytest.mark.parametrize("mock_response, expected", [ diff --git a/tests/sonic_xcvr/test_sfp_optoe_base.py b/tests/sonic_xcvr/test_sfp_optoe_base.py index 54237e71b..47c22ec8c 100644 --- a/tests/sonic_xcvr/test_sfp_optoe_base.py +++ b/tests/sonic_xcvr/test_sfp_optoe_base.py @@ -33,7 +33,7 @@ def test_freeze_vdm_stats(self, mock_response1, mock_response2, expected): @pytest.mark.parametrize("mock_response1, mock_response2, expected", [ (0, ccmis_api, 0), (1, ccmis_api, 1), - (None, None, None), + (None, None, False), ]) def test_unfreeze_vdm_stats(self, mock_response1, mock_response2, expected): self.sfp_optoe_api.get_xcvr_api = MagicMock() @@ -47,7 +47,7 @@ def test_unfreeze_vdm_stats(self, mock_response1, mock_response2, expected): @pytest.mark.parametrize("mock_response1, mock_response2, expected", [ (0, ccmis_api, 0), (1, ccmis_api, 1), - (None, None, None), + (None, None, False), ]) def test_get_vdm_freeze_status(self, mock_response1, mock_response2, expected): self.sfp_optoe_api.get_xcvr_api = MagicMock() @@ -61,7 +61,7 @@ def test_get_vdm_freeze_status(self, mock_response1, mock_response2, expected): @pytest.mark.parametrize("mock_response1, mock_response2, expected", [ (0, ccmis_api, 0), (1, ccmis_api, 1), - (None, None, None), + (None, None, False), ]) def test_get_vdm_unfreeze_status(self, mock_response1, mock_response2, expected): self.sfp_optoe_api.get_xcvr_api = MagicMock() From d01bf3675e3d23a5dca1db8393147f94f134f854 Mon Sep 17 00:00:00 2001 From: Jaganathan Anbalagan Date: Tue, 28 Nov 2023 06:50:07 -0800 Subject: [PATCH 4/4] code coverage --- tests/sonic_xcvr/test_sfp_optoe_base.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/tests/sonic_xcvr/test_sfp_optoe_base.py b/tests/sonic_xcvr/test_sfp_optoe_base.py index 47c22ec8c..5b18beb0e 100644 --- a/tests/sonic_xcvr/test_sfp_optoe_base.py +++ b/tests/sonic_xcvr/test_sfp_optoe_base.py @@ -2,11 +2,12 @@ from mock import patch import pytest from sonic_platform_base.sonic_xcvr.sfp_optoe_base import SfpOptoeBase -from sonic_platform_base.sonic_xcvr.api.public.c_cmis import CCmisApi +from sonic_platform_base.sonic_xcvr.api.public.c_cmis import CCmisApi +from sonic_platform_base.sonic_xcvr.api.public.cmis import CmisApi from sonic_platform_base.sonic_xcvr.mem_maps.public.c_cmis import CCmisMemMap from sonic_platform_base.sonic_xcvr.xcvr_eeprom import XcvrEeprom from sonic_platform_base.sonic_xcvr.codes.public.cmis import CmisCodes - + class TestSfpOptoeBase(object): codes = CmisCodes @@ -16,10 +17,13 @@ class TestSfpOptoeBase(object): eeprom = XcvrEeprom(reader, writer, mem_map) sfp_optoe_api = SfpOptoeBase() ccmis_api = CCmisApi(eeprom) + cmis_api = CmisApi(eeprom) @pytest.mark.parametrize("mock_response1, mock_response2, expected", [ (0, ccmis_api, 0), - (1, ccmis_api, 1), + (1, ccmis_api, 1), + (None, None, False), + (None, cmis_api, False), ]) def test_freeze_vdm_stats(self, mock_response1, mock_response2, expected): self.sfp_optoe_api.get_xcvr_api = MagicMock() @@ -34,6 +38,7 @@ def test_freeze_vdm_stats(self, mock_response1, mock_response2, expected): (0, ccmis_api, 0), (1, ccmis_api, 1), (None, None, False), + (None, cmis_api, False), ]) def test_unfreeze_vdm_stats(self, mock_response1, mock_response2, expected): self.sfp_optoe_api.get_xcvr_api = MagicMock() @@ -48,6 +53,7 @@ def test_unfreeze_vdm_stats(self, mock_response1, mock_response2, expected): (0, ccmis_api, 0), (1, ccmis_api, 1), (None, None, False), + (None, cmis_api, False), ]) def test_get_vdm_freeze_status(self, mock_response1, mock_response2, expected): self.sfp_optoe_api.get_xcvr_api = MagicMock() @@ -62,6 +68,7 @@ def test_get_vdm_freeze_status(self, mock_response1, mock_response2, expected): (0, ccmis_api, 0), (1, ccmis_api, 1), (None, None, False), + (None, cmis_api, False), ]) def test_get_vdm_unfreeze_status(self, mock_response1, mock_response2, expected): self.sfp_optoe_api.get_xcvr_api = MagicMock()