Skip to content

Commit

Permalink
[unittest] Bump code coverage on meta to over 80% (sonic-net#949)
Browse files Browse the repository at this point in the history
  • Loading branch information
kcudnik authored Oct 18, 2021
1 parent ecb95a8 commit f3933e0
Show file tree
Hide file tree
Showing 2 changed files with 309 additions and 0 deletions.
5 changes: 5 additions & 0 deletions unittest/lib/test_sai_redis_nexthopgroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,9 @@ TEST(libsairedis, next_hop_group)

EXPECT_NE(SAI_STATUS_SUCCESS, api->create_next_hop_group_members(0,0,0,0,SAI_BULK_OP_ERROR_MODE_IGNORE_ERROR,0,0));
EXPECT_NE(SAI_STATUS_SUCCESS, api->remove_next_hop_group_members(0,0,SAI_BULK_OP_ERROR_MODE_IGNORE_ERROR,0));

EXPECT_NE(SAI_STATUS_SUCCESS, api->create_next_hop_group_map(&id,0,0,0));
EXPECT_NE(SAI_STATUS_SUCCESS, api->remove_next_hop_group_map(0));
EXPECT_NE(SAI_STATUS_SUCCESS, api->set_next_hop_group_map_attribute(0,0));
EXPECT_NE(SAI_STATUS_SUCCESS, api->get_next_hop_group_map_attribute(0,0,0));
}
304 changes: 304 additions & 0 deletions unittest/meta/TestMeta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -752,3 +752,307 @@ TEST(Meta, quad_bulk_nat_entry)

EXPECT_EQ(SAI_STATUS_SUCCESS, m.bulkRemove(2, e, SAI_BULK_OP_ERROR_MODE_IGNORE_ERROR, statuses));
}

TEST(Meta, getStats)
{
Meta m(std::make_shared<MetaTestSaiInterface>());

sai_object_id_t switchId = 0;

sai_attribute_t attr;

attr.id = SAI_SWITCH_ATTR_INIT_SWITCH;
attr.value.booldata = true;

EXPECT_EQ(SAI_STATUS_SUCCESS, m.create(SAI_OBJECT_TYPE_SWITCH, &switchId, SAI_NULL_OBJECT_ID, 1, &attr));

sai_stat_id_t counter_ids[2];

counter_ids[0] = SAI_SWITCH_STAT_IN_CONFIGURED_DROP_REASONS_0_DROPPED_PKTS;
counter_ids[1] = SAI_SWITCH_STAT_IN_CONFIGURED_DROP_REASONS_1_DROPPED_PKTS;

uint64_t counters[2];

EXPECT_EQ(SAI_STATUS_SUCCESS, m.getStats(SAI_OBJECT_TYPE_SWITCH, switchId, 2, counter_ids, counters));
}

TEST(Meta, getStatsExt)
{
Meta m(std::make_shared<MetaTestSaiInterface>());

sai_object_id_t switchId = 0;

sai_attribute_t attr;

attr.id = SAI_SWITCH_ATTR_INIT_SWITCH;
attr.value.booldata = true;

EXPECT_EQ(SAI_STATUS_SUCCESS, m.create(SAI_OBJECT_TYPE_SWITCH, &switchId, SAI_NULL_OBJECT_ID, 1, &attr));

sai_stat_id_t counter_ids[2];

counter_ids[0] = SAI_SWITCH_STAT_IN_CONFIGURED_DROP_REASONS_0_DROPPED_PKTS;
counter_ids[1] = SAI_SWITCH_STAT_IN_CONFIGURED_DROP_REASONS_1_DROPPED_PKTS;

uint64_t counters[2];

EXPECT_EQ(SAI_STATUS_SUCCESS, m.getStatsExt(SAI_OBJECT_TYPE_SWITCH, switchId, 2, counter_ids, SAI_STATS_MODE_READ, counters));
}

TEST(Meta, clearStats)
{
Meta m(std::make_shared<MetaTestSaiInterface>());

sai_object_id_t switchId = 0;

sai_attribute_t attr;

attr.id = SAI_SWITCH_ATTR_INIT_SWITCH;
attr.value.booldata = true;

EXPECT_EQ(SAI_STATUS_SUCCESS, m.create(SAI_OBJECT_TYPE_SWITCH, &switchId, SAI_NULL_OBJECT_ID, 1, &attr));

sai_stat_id_t counter_ids[2];

counter_ids[0] = SAI_SWITCH_STAT_IN_CONFIGURED_DROP_REASONS_0_DROPPED_PKTS;
counter_ids[1] = SAI_SWITCH_STAT_IN_CONFIGURED_DROP_REASONS_1_DROPPED_PKTS;

EXPECT_EQ(SAI_STATUS_SUCCESS, m.clearStats(SAI_OBJECT_TYPE_SWITCH, switchId, 2, counter_ids));
}

TEST(Meta, quad_bulk_my_sid_entry)
{
Meta m(std::make_shared<MetaTestSaiInterface>());

sai_object_id_t switchId = 0;

sai_attribute_t attr;

attr.id = SAI_SWITCH_ATTR_INIT_SWITCH;
attr.value.booldata = true;

EXPECT_EQ(SAI_STATUS_SUCCESS, m.create(SAI_OBJECT_TYPE_SWITCH, &switchId, SAI_NULL_OBJECT_ID, 1, &attr));

sai_object_id_t vlanId = 0;

attr.id = SAI_VLAN_ATTR_VLAN_ID;
attr.value.u16 = 2;

EXPECT_EQ(SAI_STATUS_SUCCESS, m.create(SAI_OBJECT_TYPE_VLAN, &vlanId, switchId, 1, &attr));

sai_object_id_t vrId = 0;

EXPECT_EQ(SAI_STATUS_SUCCESS, m.create(SAI_OBJECT_TYPE_VIRTUAL_ROUTER, &vrId, switchId, 0, &attr));

// create

sai_my_sid_entry_t e[2];

memset(e, 0, sizeof(e));

e[0].switch_id = switchId;
e[1].switch_id = switchId;

e[0].vr_id = vrId;
e[1].vr_id = vrId;

e[0].locator_block_len = 1;
e[1].locator_block_len = 2;

uint32_t attr_count[2];

attr_count[0] = 1;
attr_count[1] = 1;

sai_attribute_t list1[2];
sai_attribute_t list2[2];

list1[0].id = SAI_MY_SID_ENTRY_ATTR_ENDPOINT_BEHAVIOR;
list1[0].value.s32 = SAI_MY_SID_ENTRY_ENDPOINT_BEHAVIOR_E;

list2[0].id = SAI_MY_SID_ENTRY_ATTR_ENDPOINT_BEHAVIOR;
list2[0].value.s32 = SAI_MY_SID_ENTRY_ENDPOINT_BEHAVIOR_E;

std::vector<const sai_attribute_t*> alist;

alist.push_back(list1);
alist.push_back(list2);

const sai_attribute_t **attr_list = alist.data();

sai_status_t statuses[2];

EXPECT_EQ(SAI_STATUS_SUCCESS, m.bulkCreate(2, e, attr_count, attr_list, SAI_BULK_OP_ERROR_MODE_IGNORE_ERROR, statuses));

// set

sai_attribute_t setlist[2];

setlist[0].id = SAI_MY_SID_ENTRY_ATTR_ENDPOINT_BEHAVIOR;
setlist[0].value.s32 = SAI_MY_SID_ENTRY_ENDPOINT_BEHAVIOR_X;

setlist[1].id = SAI_MY_SID_ENTRY_ATTR_ENDPOINT_BEHAVIOR;
setlist[1].value.s32 = SAI_MY_SID_ENTRY_ENDPOINT_BEHAVIOR_X;

EXPECT_EQ(SAI_STATUS_SUCCESS, m.bulkSet(2, e, setlist, SAI_BULK_OP_ERROR_MODE_IGNORE_ERROR, statuses));

// remove

EXPECT_EQ(SAI_STATUS_SUCCESS, m.bulkRemove(2, e, SAI_BULK_OP_ERROR_MODE_IGNORE_ERROR, statuses));
}

TEST(Meta, quad_bulk_inseg_entry)
{
Meta m(std::make_shared<MetaTestSaiInterface>());

sai_object_id_t switchId = 0;

sai_attribute_t attr;

attr.id = SAI_SWITCH_ATTR_INIT_SWITCH;
attr.value.booldata = true;

EXPECT_EQ(SAI_STATUS_SUCCESS, m.create(SAI_OBJECT_TYPE_SWITCH, &switchId, SAI_NULL_OBJECT_ID, 1, &attr));

sai_object_id_t vlanId = 0;

attr.id = SAI_VLAN_ATTR_VLAN_ID;
attr.value.u16 = 2;

EXPECT_EQ(SAI_STATUS_SUCCESS, m.create(SAI_OBJECT_TYPE_VLAN, &vlanId, switchId, 1, &attr));

sai_object_id_t vrId = 0;

EXPECT_EQ(SAI_STATUS_SUCCESS, m.create(SAI_OBJECT_TYPE_VIRTUAL_ROUTER, &vrId, switchId, 0, &attr));

// create

sai_inseg_entry_t e[2];

memset(e, 0, sizeof(e));

e[0].switch_id = switchId;
e[1].switch_id = switchId;

e[0].label = 1;
e[1].label = 2;

uint32_t attr_count[2];

attr_count[0] = 1;
attr_count[1] = 1;

sai_attribute_t list1[2];
sai_attribute_t list2[2];

list1[0].id = SAI_L2MC_ENTRY_ATTR_PACKET_ACTION;
list1[0].value.s32 = SAI_PACKET_ACTION_FORWARD;

list2[0].id = SAI_L2MC_ENTRY_ATTR_PACKET_ACTION;
list2[0].value.s32 = SAI_PACKET_ACTION_FORWARD;

std::vector<const sai_attribute_t*> alist;

alist.push_back(list1);
alist.push_back(list2);

const sai_attribute_t **attr_list = alist.data();

sai_status_t statuses[2];

EXPECT_EQ(SAI_STATUS_SUCCESS, m.bulkCreate(2, e, attr_count, attr_list, SAI_BULK_OP_ERROR_MODE_IGNORE_ERROR, statuses));

// set

sai_attribute_t setlist[2];

setlist[0].id = SAI_L2MC_ENTRY_ATTR_PACKET_ACTION;
setlist[0].value.s32 = SAI_PACKET_ACTION_DROP;

setlist[1].id = SAI_L2MC_ENTRY_ATTR_PACKET_ACTION;
setlist[1].value.s32 = SAI_PACKET_ACTION_DROP;

EXPECT_EQ(SAI_STATUS_SUCCESS, m.bulkSet(2, e, setlist, SAI_BULK_OP_ERROR_MODE_IGNORE_ERROR, statuses));

// remove

EXPECT_EQ(SAI_STATUS_SUCCESS, m.bulkRemove(2, e, SAI_BULK_OP_ERROR_MODE_IGNORE_ERROR, statuses));
}

TEST(Meta, logSet)
{
Meta m(std::make_shared<MetaTestSaiInterface>());

EXPECT_EQ(SAI_STATUS_SUCCESS, m.logSet(SAI_API_SWITCH, SAI_LOG_LEVEL_NOTICE));

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
EXPECT_EQ(SAI_STATUS_INVALID_PARAMETER, m.logSet((sai_api_t)1000, SAI_LOG_LEVEL_NOTICE));

EXPECT_EQ(SAI_STATUS_INVALID_PARAMETER, m.logSet(SAI_API_SWITCH, (sai_log_level_t)1000));
#pragma GCC diagnostic pop

}

TEST(Meta, meta_sai_on_switch_shutdown_request)
{
Meta m(std::make_shared<MetaTestSaiInterface>());

sai_object_id_t switchId = 0;

sai_attribute_t attr;

attr.id = SAI_SWITCH_ATTR_INIT_SWITCH;
attr.value.booldata = true;

EXPECT_EQ(SAI_STATUS_SUCCESS, m.create(SAI_OBJECT_TYPE_SWITCH, &switchId, SAI_NULL_OBJECT_ID, 1, &attr));

m.meta_sai_on_switch_shutdown_request(0);
m.meta_sai_on_switch_shutdown_request(switchId);
m.meta_sai_on_switch_shutdown_request(0x21000000000001);
}

TEST(Meta, meta_sai_on_switch_state_change)
{
Meta m(std::make_shared<MetaTestSaiInterface>());

sai_object_id_t switchId = 0;

sai_attribute_t attr;

attr.id = SAI_SWITCH_ATTR_INIT_SWITCH;
attr.value.booldata = true;

EXPECT_EQ(SAI_STATUS_SUCCESS, m.create(SAI_OBJECT_TYPE_SWITCH, &switchId, SAI_NULL_OBJECT_ID, 1, &attr));

m.meta_sai_on_switch_state_change(0, SAI_SWITCH_OPER_STATUS_UP);
m.meta_sai_on_switch_state_change(switchId, SAI_SWITCH_OPER_STATUS_UP);
m.meta_sai_on_switch_state_change(0x21000000000001, SAI_SWITCH_OPER_STATUS_UP);

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
m.meta_sai_on_switch_state_change(0, (sai_switch_oper_status_t)1000);
m.meta_sai_on_switch_state_change(switchId, (sai_switch_oper_status_t)1000);
m.meta_sai_on_switch_state_change(0x21000000000001, (sai_switch_oper_status_t)1000);
#pragma GCC diagnostic pop
}

TEST(Meta, populate)
{
Meta m(std::make_shared<MetaTestSaiInterface>());

swss::TableDump dump;

dump["SAI_OBJECT_TYPE_ACL_TABLE:oid:0x7000000000626"]["SAI_ACL_TABLE_ATTR_FIELD_ACL_IP_TYPE"] = "true";
dump["SAI_OBJECT_TYPE_ROUTE_ENTRY:{\"dest\":\"10.0.0.0/32\",\"switch_id\":\"oid:0x21000000000000\",\"vr\":\"oid:0x3000000000022\"}"]
["SAI_ROUTE_ENTRY_ATTR_NEXT_HOP_ID"] = "oid:0x60000000005cf";
dump["SAI_OBJECT_TYPE_VLAN:oid:0x2600000000002f"]["SAI_VLAN_ATTR_VLAN_ID"] = "2";
dump["SAI_OBJECT_TYPE_SWITCH:oid:0x21000000000000"]["SAI_SWITCH_ATTR_PORT_LIST"] =
"2:oid:0x1000000000002,oid:0x1000000000003";
dump["SAI_OBJECT_TYPE_ACL_ENTRY:oid:0x8000000000635"]["SAI_ACL_ENTRY_ATTR_FIELD_SRC_PORT"] = "oid:0x1000000000003";
dump["SAI_OBJECT_TYPE_ACL_ENTRY:oid:0x8000000000635"]["SAI_ACL_ENTRY_ATTR_FIELD_OUT_PORTS"] = "2:oid:0x1000000000002,oid:0x1000000000003";
dump["SAI_OBJECT_TYPE_ACL_ENTRY:oid:0x8000000000635"]["SAI_ACL_ENTRY_ATTR_ACTION_REDIRECT"] = "oid:0x1000000000003";
dump["SAI_OBJECT_TYPE_ACL_ENTRY:oid:0x8000000000635"]["SAI_ACL_ENTRY_ATTR_ACTION_REDIRECT_LIST"] = "2:oid:0x1000000000002,oid:0x1000000000003";

m.populate(dump);
}

0 comments on commit f3933e0

Please sign in to comment.