Skip to content

Commit 67a086d

Browse files
committed
2 new test cases added
Signed-off-by: Vivek Reddy Karri <[email protected]>
1 parent e267fd9 commit 67a086d

File tree

2 files changed

+82
-9
lines changed

2 files changed

+82
-9
lines changed

portsyncd/linksync.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,4 +346,4 @@ void handlePortConfig(ProducerStateTable &p, map<string, KeyOpFieldsValuesTuple>
346346
it++;
347347
}
348348
}
349-
}
349+
}

tests/mock_tests/portsyncd/portsyncd_ut.cpp

Lines changed: 81 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,12 @@ namespace portsyncd_ut
103103

104104
/* Draft a rtnl_link msg */
105105
struct nl_object* draft_nlmsg(const std::string& name,
106-
std::vector<unsigned int> flags,
107-
const std::string& type,
108-
const std::string& ll_add,
109-
int ifindex,
110-
unsigned int mtu,
111-
int master_ifindex = 0){
106+
std::vector<unsigned int> flags,
107+
const std::string& type,
108+
const std::string& ll_add,
109+
int ifindex,
110+
unsigned int mtu,
111+
int master_ifindex = 0){
112112

113113
struct rtnl_link* nl_obj = rtnl_link_alloc();
114114
if (!nl_obj){
@@ -148,6 +148,10 @@ namespace portsyncd_ut
148148

149149
return (struct nl_object*)nl_obj;
150150
}
151+
152+
inline void free_nlobj(struct nl_object* msg){
153+
nl_object_free(msg);
154+
}
151155
}
152156

153157
namespace portsyncd_ut
@@ -208,7 +212,7 @@ namespace portsyncd_ut
208212
ASSERT_EQ(sync.m_ifindexOldNameMap[142], "Ethernet0");
209213
}
210214

211-
TEST_F(PortSyncdTest, test_onMsg)
215+
TEST_F(PortSyncdTest, test_onMsgNewLink)
212216
{
213217
swss::LinkSync sync(m_app_db.get(), m_state_db.get());
214218
/* Write config to Config DB */
@@ -246,6 +250,75 @@ namespace portsyncd_ut
246250
ASSERT_EQ(sync.m_ifindexNameMap[142], "Ethernet0");
247251

248252
/* Free Nl_object */
249-
nl_object_free(msg);
253+
free_nlobj(msg);
254+
}
255+
256+
TEST_F(PortSyncdTest, test_onMsgDelLink){
257+
258+
swss::LinkSync sync(m_app_db.get(), m_state_db.get());
259+
260+
/* Write config to Config DB */
261+
populateCfgDb(m_portCfgTable.get());
262+
swss::DBConnector cfg_db_conn("CONFIG_DB", 0);
263+
264+
/* Handle CFG DB notifs and Write them to APPL_DB */
265+
swss::ProducerStateTable p(m_app_db.get(), APP_PORT_TABLE_NAME);
266+
handlePortConfigFromConfigDB(p, cfg_db_conn, false);
267+
268+
/* Generate a netlink notification about the netdev iface */
269+
std::vector<unsigned int> flags = {IFF_UP, IFF_RUNNING};
270+
struct nl_object* msg = draft_nlmsg("Ethernet0",
271+
flags,
272+
"sx_netdev",
273+
"1c:34:da:1c:9f:00",
274+
142,
275+
9100,
276+
0);
277+
sync.onMsg(RTM_NEWLINK, msg);
278+
279+
/* Verify if the update has been written to State DB */
280+
std::vector<swss::FieldValueTuple> ovalues;
281+
ASSERT_EQ(sync.m_statePortTable.get("Ethernet0", ovalues), true);
282+
283+
/* Free Nl_object */
284+
free_nlobj(msg);
285+
286+
/* Generate a DELLINK Notif */
287+
msg = draft_nlmsg("Ethernet0",
288+
flags,
289+
"sx_netdev",
290+
"1c:34:da:1c:9f:00",
291+
142,
292+
9100,
293+
0);
294+
295+
sync.onMsg(RTM_DELLINK, msg);
296+
ovalues.clear();
297+
298+
/* Verify if the state_db entry is cleared */
299+
ASSERT_EQ(sync.m_statePortTable.get("Ethernet0", ovalues), false);
300+
}
301+
302+
TEST_F(PortSyncdTest, test_onMsgMgmtIface){
303+
swss::LinkSync sync(m_app_db.get(), m_state_db.get());
304+
305+
/* Generate a netlink notification about the eth0 netdev iface */
306+
std::vector<unsigned int> flags = {IFF_UP};
307+
struct nl_object* msg = draft_nlmsg("eth0",
308+
flags,
309+
"",
310+
"00:50:56:28:0e:4a",
311+
16222,
312+
9100,
313+
0);
314+
sync.onMsg(RTM_NEWLINK, msg);
315+
316+
/* Verify if the update has been written to State DB */
317+
std::string oper_status;
318+
ASSERT_EQ(sync.m_stateMgmtPortTable.hget("eth0", "oper_status", oper_status), true);
319+
ASSERT_EQ(oper_status, "down");
320+
321+
/* Free Nl_object */
322+
free_nlobj(msg);
250323
}
251324
}

0 commit comments

Comments
 (0)