forked from sonic-net/sonic-buildimage
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add sairedis lib unit tests (sonic-net#919)
* [tests] Remove new operator from create objects * [sairedis] Move config examples from src dir to lib dir * [sairedis] Correct endpoint naming in client and server * Add ClientConfig tests * Add ClientServerSai tests * Fix ClientConfig tests * Add Context tests * Add ContextConfig tests * Add ContextConfigContainer tests * Add Utils tests * Fix Switch tests
- Loading branch information
Showing
16 changed files
with
276 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#include "ClientConfig.h" | ||
|
||
#include <gtest/gtest.h> | ||
|
||
using namespace sairedis; | ||
|
||
TEST(ClientConfig, loadFromFile) | ||
{ | ||
EXPECT_NE(ClientConfig::loadFromFile("non_existing"), nullptr); | ||
|
||
EXPECT_NE(ClientConfig::loadFromFile("files/client_config_bad.txt"), nullptr); | ||
|
||
EXPECT_NE(ClientConfig::loadFromFile("files/client_config_ok.txt"), nullptr); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#include "ClientServerSai.h" | ||
|
||
#include "swss/logger.h" | ||
|
||
#include <gtest/gtest.h> | ||
|
||
using namespace sairedis; | ||
|
||
static const char* profile_get_value( | ||
_In_ sai_switch_profile_id_t profile_id, | ||
_In_ const char* variable) | ||
{ | ||
SWSS_LOG_ENTER(); | ||
|
||
if (variable == NULL) | ||
return NULL; | ||
|
||
return nullptr; | ||
} | ||
|
||
static int profile_get_next_value( | ||
_In_ sai_switch_profile_id_t profile_id, | ||
_Out_ const char** variable, | ||
_Out_ const char** value) | ||
{ | ||
SWSS_LOG_ENTER(); | ||
|
||
return 0; | ||
} | ||
|
||
static sai_service_method_table_t test_services = { | ||
profile_get_value, | ||
profile_get_next_value | ||
}; | ||
|
||
TEST(ClientServerSai, ctr) | ||
{ | ||
auto css = std::make_shared<ClientServerSai>(); | ||
} | ||
|
||
TEST(ClientServerSai, initialize) | ||
{ | ||
auto css = std::make_shared<ClientServerSai>(); | ||
|
||
EXPECT_NE(SAI_STATUS_SUCCESS, css->initialize(1, nullptr)); | ||
|
||
EXPECT_NE(SAI_STATUS_SUCCESS, css->initialize(0, nullptr)); | ||
|
||
EXPECT_EQ(SAI_STATUS_SUCCESS, css->initialize(0, &test_services)); | ||
|
||
css = nullptr; // invoke uninitialize in destructor | ||
|
||
css = std::make_shared<ClientServerSai>(); | ||
|
||
EXPECT_EQ(SAI_STATUS_SUCCESS, css->initialize(0, &test_services)); | ||
|
||
EXPECT_NE(SAI_STATUS_SUCCESS, css->initialize(0, &test_services)); | ||
} | ||
|
||
TEST(ClientServerSai, objectTypeQuery) | ||
{ | ||
auto css = std::make_shared<ClientServerSai>(); | ||
|
||
EXPECT_EQ(SAI_OBJECT_TYPE_NULL, css->objectTypeQuery(0x1111111111111111L)); | ||
} | ||
|
||
TEST(ClientServerSai, switchIdQuery) | ||
{ | ||
auto css = std::make_shared<ClientServerSai>(); | ||
|
||
EXPECT_EQ(SAI_NULL_OBJECT_ID, css->switchIdQuery(0x1111111111111111L)); | ||
} | ||
|
||
TEST(ClientServerSai, logSet) | ||
{ | ||
auto css = std::make_shared<ClientServerSai>(); | ||
|
||
EXPECT_NE(SAI_STATUS_SUCCESS, css->logSet(SAI_API_PORT, SAI_LOG_LEVEL_NOTICE)); | ||
|
||
EXPECT_EQ(SAI_STATUS_SUCCESS, css->initialize(0, &test_services)); | ||
|
||
EXPECT_EQ(SAI_STATUS_SUCCESS, css->logSet(SAI_API_PORT, SAI_LOG_LEVEL_NOTICE)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#include "Context.h" | ||
|
||
#include "swss/logger.h" | ||
|
||
#include <gtest/gtest.h> | ||
|
||
using namespace sairedis; | ||
|
||
static sai_switch_notifications_t handle_notification( | ||
_In_ std::shared_ptr<Notification> notification, | ||
_In_ Context* context) | ||
{ | ||
SWSS_LOG_ENTER(); | ||
|
||
sai_switch_notifications_t ntf; | ||
|
||
memset(&ntf, 0, sizeof(ntf)); | ||
|
||
return ntf; | ||
} | ||
|
||
TEST(Context, populateMetadata) | ||
{ | ||
auto recorder = std::make_shared<Recorder>(); | ||
|
||
auto cc = std::make_shared<ContextConfig>(0, "syncd", "ASIC_DB", "COUNTERS_DB","FLEX_DB", "STATE_DB"); | ||
|
||
auto ctx = std::make_shared<Context>(cc, recorder,handle_notification); | ||
|
||
ctx->populateMetadata(0x212121212212121L); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#include "ContextConfig.h" | ||
|
||
#include "swss/logger.h" | ||
|
||
#include <gtest/gtest.h> | ||
|
||
using namespace sairedis; | ||
|
||
TEST(ContextConfig, hasConflict) | ||
{ | ||
auto cc = std::make_shared<ContextConfig>(0, "syncd", "ASIC_DB", "COUNTERS_DB","FLEX_DB", "STATE_DB"); | ||
|
||
EXPECT_TRUE(cc->hasConflict(std::make_shared<ContextConfig>(0, "syncd", "ASIC_DB", "COUNTERS_DB","FLEX_DB", "STATE_DB"))); | ||
EXPECT_TRUE(cc->hasConflict(std::make_shared<ContextConfig>(1, "syncd", "ASIC_DB", "COUNTERS_DB","FLEX_DB", "STATE_DB"))); | ||
EXPECT_TRUE(cc->hasConflict(std::make_shared<ContextConfig>(1, "syncb", "ASIC_DB", "COUNTERS_DB","FLEX_DB", "STATE_DB"))); | ||
EXPECT_TRUE(cc->hasConflict(std::make_shared<ContextConfig>(1, "syncb", "ASIC_DD", "COUNTERS_DB","FLEX_DB", "STATE_DB"))); | ||
EXPECT_TRUE(cc->hasConflict(std::make_shared<ContextConfig>(1, "syncb", "ASIC_DD", "COUNTERS_DD","FLEX_DB", "STATE_DB"))); | ||
EXPECT_TRUE(cc->hasConflict(std::make_shared<ContextConfig>(1, "syncb", "ASIC_DD", "COUNTERS_DD","FLEX_DD", "STATE_DB"))); | ||
EXPECT_TRUE(cc->hasConflict(std::make_shared<ContextConfig>(1, "syncb", "ASIC_DD", "COUNTERS_DD","FLEX_DD", "STATE_DD"))); | ||
|
||
auto aa = std::make_shared<ContextConfig>(1, "syncb", "ASIC_DD", "COUNTERS_DD","FLEX_DD", "STATE_DD"); | ||
|
||
aa->m_zmqEndpoint = "AA"; | ||
|
||
EXPECT_TRUE(cc->hasConflict(aa)); | ||
|
||
aa->m_zmqNtfEndpoint = "AA"; | ||
|
||
EXPECT_FALSE(cc->hasConflict(aa)); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#include "ContextConfigContainer.h" | ||
|
||
#include "swss/logger.h" | ||
|
||
#include <gtest/gtest.h> | ||
|
||
using namespace sairedis; | ||
|
||
TEST(ContextConfigContainer, get) | ||
{ | ||
ContextConfigContainer ccc; | ||
|
||
EXPECT_EQ(ccc.get(0), nullptr); | ||
} | ||
|
||
TEST(ContextConfigContainer, loadFromFile) | ||
{ | ||
ContextConfigContainer ccc; | ||
|
||
EXPECT_NE(ccc.loadFromFile("files/ccc_bad.txt"), nullptr); | ||
} | ||
|
||
TEST(ContextConfigContainer, insert) | ||
{ | ||
ContextConfigContainer ccc; | ||
|
||
auto cc = std::make_shared<ContextConfig>(0, "syncd", "ASIC_DB", "COUNTERS_DB","FLEX_DB", "STATE_DB"); | ||
|
||
ccc.insert(cc); | ||
|
||
EXPECT_THROW(ccc.insert(cc), std::runtime_error); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#include "Utils.h" | ||
|
||
#include "swss/logger.h" | ||
|
||
#include <gtest/gtest.h> | ||
|
||
using namespace sairedis; | ||
|
||
TEST(Utils, clearOidValues) | ||
{ | ||
sai_attribute_t attr; | ||
|
||
sai_object_id_t oids[1]; | ||
|
||
attr.id = 1000; | ||
|
||
EXPECT_THROW(Utils::clearOidValues(SAI_OBJECT_TYPE_NULL, 1, &attr), std::runtime_error); | ||
|
||
attr.id = SAI_ACL_ENTRY_ATTR_FIELD_IN_PORT; | ||
|
||
attr.value.aclfield.data.oid = 1; | ||
|
||
Utils::clearOidValues(SAI_OBJECT_TYPE_ACL_ENTRY, 1, &attr); | ||
|
||
EXPECT_EQ(attr.value.aclfield.data.oid, 0); | ||
|
||
attr.id = SAI_ACL_ENTRY_ATTR_FIELD_IN_PORTS; | ||
|
||
attr.value.aclfield.enable = true; | ||
|
||
attr.value.aclfield.data.objlist.count = 1; | ||
attr.value.aclfield.data.objlist.list = oids; | ||
|
||
oids[0] = 1; | ||
|
||
Utils::clearOidValues(SAI_OBJECT_TYPE_ACL_ENTRY, 1, &attr); | ||
|
||
EXPECT_EQ(oids[0], 0); | ||
|
||
attr.id = SAI_ACL_ENTRY_ATTR_ACTION_COUNTER; | ||
|
||
attr.value.aclaction.parameter.oid = 1; | ||
|
||
Utils::clearOidValues(SAI_OBJECT_TYPE_ACL_ENTRY, 1, &attr); | ||
|
||
EXPECT_EQ(attr.value.aclaction.parameter.oid, 0); | ||
|
||
attr.id = SAI_ACL_ENTRY_ATTR_ACTION_REDIRECT_LIST; | ||
|
||
attr.value.aclaction.enable = true; | ||
|
||
attr.value.aclaction.parameter.objlist.count = 1; | ||
attr.value.aclaction.parameter.objlist.list = oids; | ||
|
||
oids[0] = 1; | ||
|
||
Utils::clearOidValues(SAI_OBJECT_TYPE_ACL_ENTRY, 1, &attr); | ||
|
||
EXPECT_EQ(oids[0], 0); | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
foo bar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
foo bar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"zmq_endpoint": "ipc:///tmp/saiServer", | ||
"zmq_ntf_endpoint": "ipc:///tmp/saiServerNtf" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters