Skip to content

Commit

Permalink
Push infra modifications
Browse files Browse the repository at this point in the history
Signed-off-by: Vivek Reddy Karri <vkarri@nvidia.com>
  • Loading branch information
vivekrnv committed Apr 29, 2022
1 parent 64a8ee1 commit 6909333
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 3 deletions.
3 changes: 1 addition & 2 deletions tests/mock_tests/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,6 @@ tests_LDADD = $(LDADD_GTEST) $(LDADD_SAI) -lnl-genl-3 -lhiredis -lhiredis -lpthr

## portsyncd unit tests

tests_portsyncd_INCLUDES = -I $(top_srcdir)/portsyncd -I $(top_srcdir)/cfgmgr

tests_portsyncd_SOURCES = portsyncd/portsyncd_ut.cpp \
$(top_srcdir)/portsyncd/linksync.cpp \
mock_dbconnector.cpp \
Expand All @@ -129,6 +127,7 @@ tests_portsyncd_SOURCES = portsyncd/portsyncd_ut.cpp \
mock_hiredis.cpp \
mock_redisreply.cpp

tests_portsyncd_INCLUDES = -I $(top_srcdir)/portsyncd -I $(top_srcdir)/cfgmgr
tests_portsyncd_CXXFLAGS = -Wl,-wrap,if_nameindex
tests_portsyncd_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_GTEST)
tests_portsyncd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_GTEST) $(tests_portsyncd_INCLUDES)
Expand Down
15 changes: 15 additions & 0 deletions tests/mock_tests/common/mock_shell_command.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include <string>
#include <vector>

int mockCmdReturn = 0;
std::string mockCmdStdcout = "";
std::vector<std::string> mockCallArgs;

namespace swss {
int exec(const std::string &cmd, std::string &stdout)
{
mockCallArgs.push_back(cmd);
stdout = mockCmdStdcout;
return mockCmdReturn;
}
}
50 changes: 49 additions & 1 deletion tests/mock_tests/mock_table.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#include "table.h"
#include "producerstatetable.h"
#include <set>

using TableDataT = std::map<std::string, std::vector<swss::FieldValueTuple>>;
using TablesT = std::map<std::string, TableDataT>;
Expand Down Expand Up @@ -62,6 +64,12 @@ namespace swss
table[key] = values;
}

void Table::del(const std::string &key, const std::string& /* op */, const std::string& /*prefix*/)
{
auto &table = gDB[m_pipe->getDbId()][getTableName()];
table.erase(key);
}

void Table::getKeys(std::vector<std::string> &keys)
{
keys.clear();
Expand All @@ -71,4 +79,44 @@ namespace swss
keys.push_back(it.first);
}
}
}

void ProducerStateTable::set(const std::string &key,
const std::vector<FieldValueTuple> &values,
const std::string &op,
const std::string &prefix)
{
auto &table = gDB[m_pipe->getDbId()][getTableName()];
auto iter = table.find(key);
if (iter == table.end())
{
table[key] = values;
}
else
{
std::vector<FieldValueTuple> new_values(values);
std::set<std::string> field_set;
for (auto &value : values)
{
field_set.insert(fvField(value));
}
for (auto &value : iter->second)
{
auto &field = fvField(value);
if (field_set.find(field) != field_set.end())
{
continue;
}
new_values.push_back(value);
}
iter->second.swap(new_values);
}
}

void ProducerStateTable::del(const std::string &key,
const std::string &op,
const std::string &prefix)
{
auto &table = gDB[m_pipe->getDbId()][getTableName()];
table.erase(key);
}
}

0 comments on commit 6909333

Please sign in to comment.