9
9
#include " notifier.h"
10
10
#define private public
11
11
#include " pfcactionhandler.h"
12
+ #include < sys/mman.h>
12
13
#undef private
13
14
14
15
#include < sstream>
@@ -21,6 +22,8 @@ namespace portsorch_test
21
22
22
23
sai_port_api_t ut_sai_port_api;
23
24
sai_port_api_t *pold_sai_port_api;
25
+ sai_switch_api_t ut_sai_switch_api;
26
+ sai_switch_api_t *pold_sai_switch_api;
24
27
25
28
bool not_support_fetching_fec;
26
29
vector<sai_port_fec_mode_t > mock_port_fec_modes = {SAI_PORT_FEC_MODE_RS, SAI_PORT_FEC_MODE_FC};
@@ -66,9 +69,28 @@ namespace portsorch_test
66
69
_sai_set_port_fec_count++;
67
70
_sai_port_fec_mode = attr[0 ].value .s32 ;
68
71
}
72
+ else if (attr[0 ].id == SAI_PORT_ATTR_AUTO_NEG_MODE)
73
+ {
74
+ /* Simulating failure case */
75
+ return SAI_STATUS_FAILURE;
76
+ }
69
77
return pold_sai_port_api->set_port_attribute (port_id, attr);
70
78
}
71
79
80
+ uint32_t *_sai_syncd_notifications_count;
81
+ int32_t *_sai_syncd_notification_event;
82
+ sai_status_t _ut_stub_sai_set_switch_attribute (
83
+ _In_ sai_object_id_t switch_id,
84
+ _In_ const sai_attribute_t *attr)
85
+ {
86
+ if (attr[0 ].id == SAI_REDIS_SWITCH_ATTR_NOTIFY_SYNCD)
87
+ {
88
+ *_sai_syncd_notifications_count =+ 1 ;
89
+ *_sai_syncd_notification_event = attr[0 ].value .s32 ;
90
+ }
91
+ return pold_sai_switch_api->set_switch_attribute (switch_id, attr);
92
+ }
93
+
72
94
void _hook_sai_port_api ()
73
95
{
74
96
ut_sai_port_api = *sai_port_api;
@@ -83,6 +105,19 @@ namespace portsorch_test
83
105
sai_port_api = pold_sai_port_api;
84
106
}
85
107
108
+ void _hook_sai_switch_api ()
109
+ {
110
+ ut_sai_switch_api = *sai_switch_api;
111
+ pold_sai_switch_api = sai_switch_api;
112
+ ut_sai_switch_api.set_switch_attribute = _ut_stub_sai_set_switch_attribute;
113
+ sai_switch_api = &ut_sai_switch_api;
114
+ }
115
+
116
+ void _unhook_sai_switch_api ()
117
+ {
118
+ sai_switch_api = pold_sai_switch_api;
119
+ }
120
+
86
121
sai_queue_api_t ut_sai_queue_api;
87
122
sai_queue_api_t *pold_sai_queue_api;
88
123
int _sai_set_queue_attr_count = 0 ;
@@ -473,6 +508,52 @@ namespace portsorch_test
473
508
_unhook_sai_port_api ();
474
509
}
475
510
511
+ TEST_F (PortsOrchTest, PortTestSAIFailureHandling)
512
+ {
513
+ _hook_sai_port_api ();
514
+ _hook_sai_switch_api ();
515
+ Table portTable = Table (m_app_db.get (), APP_PORT_TABLE_NAME);
516
+ std::deque<KeyOpFieldsValuesTuple> entries;
517
+
518
+ not_support_fetching_fec = false ;
519
+ // Get SAI default ports to populate DB
520
+ auto ports = ut_helper::getInitialSaiPorts ();
521
+
522
+ for (const auto &it : ports)
523
+ {
524
+ portTable.set (it.first , it.second );
525
+ }
526
+
527
+ // Set PortConfigDone
528
+ portTable.set (" PortConfigDone" , { { " count" , to_string (ports.size ()) } });
529
+
530
+ // refill consumer
531
+ gPortsOrch ->addExistingData (&portTable);
532
+
533
+ // Apply configuration :
534
+ // create ports
535
+ static_cast <Orch *>(gPortsOrch )->doTask ();
536
+
537
+ _sai_syncd_notifications_count = (uint32_t *)mmap (NULL , sizeof (int ), PROT_READ | PROT_WRITE,
538
+ MAP_SHARED | MAP_ANONYMOUS, -1 , 0 );
539
+ _sai_syncd_notification_event = (int32_t *)mmap (NULL , sizeof (int ), PROT_READ | PROT_WRITE,
540
+ MAP_SHARED | MAP_ANONYMOUS, -1 , 0 );
541
+ *_sai_syncd_notifications_count = 0 ;
542
+
543
+ entries.push_back ({" Ethernet0" , " SET" ,
544
+ {
545
+ {" autoneg" , " on" }
546
+ }});
547
+ auto consumer = dynamic_cast <Consumer *>(gPortsOrch ->getExecutor (APP_PORT_TABLE_NAME));
548
+ consumer->addToSync (entries);
549
+ ASSERT_DEATH ({static_cast <Orch *>(gPortsOrch )->doTask ();}, " " );
550
+
551
+ ASSERT_EQ (*_sai_syncd_notifications_count, 1 );
552
+ ASSERT_EQ (*_sai_syncd_notification_event, SAI_REDIS_NOTIFY_SYNCD_INVOKE_DUMP);
553
+ _unhook_sai_port_api ();
554
+ _unhook_sai_switch_api ();
555
+ }
556
+
476
557
TEST_F (PortsOrchTest, PortReadinessColdBoot)
477
558
{
478
559
Table portTable = Table (m_app_db.get (), APP_PORT_TABLE_NAME);
0 commit comments