Skip to content

Commit

Permalink
Improve coverage
Browse files Browse the repository at this point in the history
Signed-off-by: Stephen Sun <stephens@nvidia.com>
  • Loading branch information
stephenxs committed Apr 3, 2024
1 parent ac1646a commit 7adaf0c
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
37 changes: 37 additions & 0 deletions unittest/syncd/TestNotificationHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,20 @@ using namespace syncd;
static std::string natData =
"[{\"nat_entry\":\"{\\\"nat_data\\\":{\\\"key\\\":{\\\"dst_ip\\\":\\\"10.10.10.10\\\",\\\"l4_dst_port\\\":\\\"20006\\\",\\\"l4_src_port\\\":\\\"0\\\",\\\"proto\\\":\\\"6\\\",\\\"src_ip\\\":\\\"0.0.0.0\\\"},\\\"mask\\\":{\\\"dst_ip\\\":\\\"255.255.255.255\\\",\\\"l4_dst_port\\\":\\\"65535\\\",\\\"l4_src_port\\\":\\\"0\\\",\\\"proto\\\":\\\"255\\\",\\\"src_ip\\\":\\\"0.0.0.0\\\"}},\\\"nat_type\\\":\\\"SAI_NAT_TYPE_DESTINATION_NAT\\\",\\\"switch_id\\\":\\\"oid:0x21000000000000\\\",\\\"vr\\\":\\\"oid:0x3000000000048\\\"}\",\"nat_event\":\"SAI_NAT_EVENT_AGED\"}]";

// Test ASIC/SDK health event
std::string asheData = "{"
"\"category\":\"SAI_SWITCH_ASIC_SDK_HEALTH_CATEGORY_FW\","
"\"data.data_type\":\"SAI_HEALTH_DATA_TYPE_GENERAL\","
"\"description\":\"2:30,30\","
"\"severity\":\"SAI_SWITCH_ASIC_SDK_HEALTH_SEVERITY_FATAL\","
"\"switch_id\":\"oid:0x21000000000000\","
"\"timestamp\":\"{"
"\\\"tv_nsec\\\":\\\"28715881\\\","
"\\\"tv_sec\\\":\\\"1700042919\\\""
"}\""
"}";


TEST(NotificationHandler, NotificationHandlerTest)
{
std::vector<sai_attribute_t> attrs;
Expand All @@ -29,4 +43,27 @@ TEST(NotificationHandler, NotificationHandlerTest)

sai_deserialize_nat_event_ntf(natData, count, &natevent);
notificationHandler->onNatEvent(count, natevent);

sai_object_id_t switch_id;
sai_switch_asic_sdk_health_severity_t severity;
sai_timespec_t timestamp;
sai_switch_asic_sdk_health_category_t category;
sai_switch_health_data_t data;
sai_u8_list_t description;
sai_deserialize_switch_asic_sdk_health_event(asheData,
switch_id,
severity,
timestamp,
category,
data,
description);
assert(switch_id == 0x21000000000000);
assert(severity == SAI_SWITCH_ASIC_SDK_HEALTH_SEVERITY_FATAL);
assert(category == SAI_SWITCH_ASIC_SDK_HEALTH_CATEGORY_FW);
notificationHandler->onSwitchAsicSdkHealthEvent(switch_id,
severity,
timestamp,
category,
data,
description);
}
18 changes: 18 additions & 0 deletions unittest/syncd/TestNotificationProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,22 @@ TEST(NotificationProcessor, NotificationProcessorTest)
EXPECT_NE(bridgeport, nullptr);
EXPECT_EQ(*bridgeport, "oid:0x3a000000000a99");
EXPECT_EQ(ip, nullptr);

// Test ASIC/SDK health event
std::string asheString = "{"
"\"category\":\"SAI_SWITCH_ASIC_SDK_HEALTH_CATEGORY_FW\","
"\"data.data_type\":\"SAI_HEALTH_DATA_TYPE_GENERAL\","
"\"description\":\"2:30,30\","
"\"severity\":\"SAI_SWITCH_ASIC_SDK_HEALTH_SEVERITY_FATAL\","
"\"switch_id\":\"oid:0x21000000000000\","
"\"timestamp\":\"{"
"\\\"tv_nsec\\\":\\\"28715881\\\","
"\\\"tv_sec\\\":\\\"1700042919\\\""
"}\""
"}";
std::vector<swss::FieldValueTuple> asheEntry;
swss::KeyOpFieldsValuesTuple asheItem(SAI_SWITCH_NOTIFICATION_NAME_SWITCH_ASIC_SDK_HEALTH_EVENT, asheString, asheEntry);
translator->insertRidAndVid(0x21000000000000,0x210000000000);
notificationProcessor->syncProcessNotification(asheItem);
translator->eraseRidAndVid(0x21000000000000,0x210000000000);
}

0 comments on commit 7adaf0c

Please sign in to comment.