Skip to content

Commit

Permalink
change TEST(PORTMGR,DoTask)
Browse files Browse the repository at this point in the history
  • Loading branch information
muhammadalihussnain committed May 21, 2024
1 parent a14dad0 commit 7036b0f
Showing 1 changed file with 60 additions and 49 deletions.
109 changes: 60 additions & 49 deletions tests/mock_tests/portmgr_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,56 +37,67 @@ namespace portmgr_ut
};

TEST_F(PortMgrTest, DoTask)
{
Table state_port_table(m_state_db.get(), STATE_PORT_TABLE_NAME);
Table app_port_table(m_app_db.get(), APP_PORT_TABLE_NAME);
Table cfg_port_table(m_config_db.get(), CFG_PORT_TABLE_NAME);
{
Table state_port_table(m_state_db.get(), STATE_PORT_TABLE_NAME);
Table app_port_table(m_app_db.get(), APP_PORT_TABLE_NAME);
Table cfg_port_table(m_config_db.get(), CFG_PORT_TABLE_NAME);

// Port is not ready, verify that doTask does not handle port configuration
cfg_port_table.set("Ethernet0", {
{"speed", "100000"},
{"index", "1"},
{"dhcp_rate_limit", "300"}
});
mockCallArgs.clear();
m_portMgr->addExistingData(&cfg_port_table);
m_portMgr->doTask();
ASSERT_TRUE(mockCallArgs.empty());
std::vector<FieldValueTuple> values;
app_port_table.get("Ethernet0", values);
auto value_opt = swss::fvsGetValue(values, "mtu", true);
ASSERT_TRUE(value_opt);
ASSERT_EQ(DEFAULT_MTU_STR, value_opt.get());
value_opt = swss::fvsGetValue(values, "admin_status", true);
ASSERT_TRUE(value_opt);
ASSERT_EQ(DEFAULT_ADMIN_STATUS_STR, value_opt.get());
value_opt = swss::fvsGetValue(values, "speed", true);
ASSERT_TRUE(value_opt);
ASSERT_EQ("100000", value_opt.get());
value_opt = swss::fvsGetValue(values, "index", true);
ASSERT_TRUE(value_opt);
ASSERT_EQ("1", value_opt.get());

// Set port state to ok, verify that doTask handle port configuration
state_port_table.set("Ethernet0", {
{"state", "ok"}
});
m_portMgr->doTask();
ASSERT_EQ(size_t(4), mockCallArgs.size());
ASSERT_EQ("/sbin/ip link set dev \"Ethernet0\" mtu \"9100\"", mockCallArgs[0]);
ASSERT_EQ("/sbin/ip link set dev \"Ethernet0\" down", mockCallArgs[1]);
ASSERT_EQ("/usr/sbin/tc qdisc add dev Ethernet0 handle ffff: ingress && /usr/sbin/tc filter add dev Ethernet0 protocol ip parent ffff: prio 1 u32 match ip protocol 17 0xff match ip dport 67 0xffff police rate 300bps burst 300b conform-exceed drop", mockCallArgs[2]);

// Set port admin_status, verify that it could override the default value
cfg_port_table.set("Ethernet0", {
{"admin_status", "up"}
});
m_portMgr->addExistingData(&cfg_port_table);
m_portMgr->doTask();
app_port_table.get("Ethernet0", values);
value_opt = swss::fvsGetValue(values, "admin_status", true);
ASSERT_TRUE(value_opt);
ASSERT_EQ("up", value_opt.get());

// Set port dhcp_rate_limit and verify the kernel command
cfg_port_table.set("Ethernet0", {
{"dhcp_rate_limit", "406"}
});
m_portMgr->addExistingData(&cfg_port_table);
m_portMgr->doTask();
ASSERT_EQ(size_t(6), mockCallArgs.size());
ASSERT_EQ("/usr/sbin/tc qdisc add dev Ethernet0 handle ffff: ingress && /usr/sbin/tc filter add dev Ethernet0 protocol ip parent ffff: prio 1 u32 match ip protocol 17 0xff match ip dport 67 0xffff police rate 406bps burst 406b conform-exceed drop", mockCallArgs[5]);
}

// Port is not ready, verify that doTask does not handle port configuration

cfg_port_table.set("Ethernet0", {
{"speed", "100000"},
{"index", "1"}
});
mockCallArgs.clear();
m_portMgr->addExistingData(&cfg_port_table);
m_portMgr->doTask();
ASSERT_TRUE(mockCallArgs.empty());
std::vector<FieldValueTuple> values;
app_port_table.get("Ethernet0", values);
auto value_opt = swss::fvsGetValue(values, "mtu", true);
ASSERT_TRUE(value_opt);
ASSERT_EQ(DEFAULT_MTU_STR, value_opt.get());
value_opt = swss::fvsGetValue(values, "admin_status", true);
ASSERT_TRUE(value_opt);
ASSERT_EQ(DEFAULT_ADMIN_STATUS_STR, value_opt.get());
value_opt = swss::fvsGetValue(values, "speed", true);
ASSERT_TRUE(value_opt);
ASSERT_EQ("100000", value_opt.get());
value_opt = swss::fvsGetValue(values, "index", true);
ASSERT_TRUE(value_opt);
ASSERT_EQ("1", value_opt.get());

// Set port state to ok, verify that doTask handle port configuration
state_port_table.set("Ethernet0", {
{"state", "ok"}
});
m_portMgr->doTask();
ASSERT_EQ(size_t(3), mockCallArgs.size());
ASSERT_EQ("/sbin/ip link set dev \"Ethernet0\" mtu \"9100\"", mockCallArgs[0]);
ASSERT_EQ("/sbin/ip link set dev \"Ethernet0\" down", mockCallArgs[1]);

// Set port admin_status, verify that it could override the default value
cfg_port_table.set("Ethernet0", {
{"admin_status", "up"}
});
m_portMgr->addExistingData(&cfg_port_table);
m_portMgr->doTask();
app_port_table.get("Ethernet0", values);
value_opt = swss::fvsGetValue(values, "admin_status", true);
ASSERT_TRUE(value_opt);
ASSERT_EQ("up", value_opt.get());
}

TEST_F(PortMgrTest, ConfigureDuringRetry)
{
Expand Down

0 comments on commit 7036b0f

Please sign in to comment.