Skip to content

Commit

Permalink
[xrcvd]: Added unit test for sfp oir events (#205)
Browse files Browse the repository at this point in the history
Signed-off-by: Prince George <prgeor@microsoft.com>
  • Loading branch information
prgeor committed Jul 31, 2021
1 parent 4a32b5a commit b880c48
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion sonic-xcvrd/tests/test_xcvrd.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import sys
import time

import unittest
if sys.version_info >= (3, 3):
Expand Down Expand Up @@ -29,7 +30,6 @@
from xcvrd.xcvrd_utilities.y_cable_helper import *
from xcvrd.xcvrd_utilities.sfp_status_helper import *


class TestXcvrdScript(object):

def test_xcvrd_helper_class_run(self):
Expand Down Expand Up @@ -335,3 +335,28 @@ def test_is_error_sfp_status(self):

assert not is_error_block_eeprom_reading(int(SFP_STATUS_INSERTED))
assert not is_error_block_eeprom_reading(int(SFP_STATUS_REMOVED))

def test_sfp_insert_events(self):
from xcvrd.xcvrd import _wrapper_soak_sfp_insert_event
sfp_insert_events = {}
insert = port_dict = {1:'1', 2:'1', 3:'1', 4:'1', 5:'1'}
start = time.time()
while True:
_wrapper_soak_sfp_insert_event(sfp_insert_events, insert)
assert not bool(insert)
if time.time() - start > MGMT_INIT_TIME_DELAY_SECS:
break
assert insert == port_dict

def test_sfp_remove_events(self):
from xcvrd.xcvrd import _wrapper_soak_sfp_insert_event
sfp_insert_events = {}
insert = {1:'1', 2:'1', 3:'1', 4:'1', 5:'1'}
removal = {1:'0', 2:'0', 3:'0', 4:'0', 5:'0'}
port_dict = {1:'0', 2:'0', 3:'0', 4:'0', 5:'0'}
for x in range(5):
_wrapper_soak_sfp_insert_event(sfp_insert_events, insert)
time.sleep(1)
_wrapper_soak_sfp_insert_event(sfp_insert_events, removal)

assert port_dict == removal

0 comments on commit b880c48

Please sign in to comment.