Skip to content

Commit b880c48

Browse files
authored
[xrcvd]: Added unit test for sfp oir events (#205)
Signed-off-by: Prince George <[email protected]>
1 parent 4a32b5a commit b880c48

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

sonic-xcvrd/tests/test_xcvrd.py

+26-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
import sys
3+
import time
34

45
import unittest
56
if sys.version_info >= (3, 3):
@@ -29,7 +30,6 @@
2930
from xcvrd.xcvrd_utilities.y_cable_helper import *
3031
from xcvrd.xcvrd_utilities.sfp_status_helper import *
3132

32-
3333
class TestXcvrdScript(object):
3434

3535
def test_xcvrd_helper_class_run(self):
@@ -335,3 +335,28 @@ def test_is_error_sfp_status(self):
335335

336336
assert not is_error_block_eeprom_reading(int(SFP_STATUS_INSERTED))
337337
assert not is_error_block_eeprom_reading(int(SFP_STATUS_REMOVED))
338+
339+
def test_sfp_insert_events(self):
340+
from xcvrd.xcvrd import _wrapper_soak_sfp_insert_event
341+
sfp_insert_events = {}
342+
insert = port_dict = {1:'1', 2:'1', 3:'1', 4:'1', 5:'1'}
343+
start = time.time()
344+
while True:
345+
_wrapper_soak_sfp_insert_event(sfp_insert_events, insert)
346+
assert not bool(insert)
347+
if time.time() - start > MGMT_INIT_TIME_DELAY_SECS:
348+
break
349+
assert insert == port_dict
350+
351+
def test_sfp_remove_events(self):
352+
from xcvrd.xcvrd import _wrapper_soak_sfp_insert_event
353+
sfp_insert_events = {}
354+
insert = {1:'1', 2:'1', 3:'1', 4:'1', 5:'1'}
355+
removal = {1:'0', 2:'0', 3:'0', 4:'0', 5:'0'}
356+
port_dict = {1:'0', 2:'0', 3:'0', 4:'0', 5:'0'}
357+
for x in range(5):
358+
_wrapper_soak_sfp_insert_event(sfp_insert_events, insert)
359+
time.sleep(1)
360+
_wrapper_soak_sfp_insert_event(sfp_insert_events, removal)
361+
362+
assert port_dict == removal

0 commit comments

Comments
 (0)