Skip to content

Commit

Permalink
[mock_test] create unittest for PortsOrch::allPortsReady cold/warm flows
Browse files Browse the repository at this point in the history
Signed-off-by: Stepan Blyschak <[email protected]>
  • Loading branch information
Stepan Blyschak committed Oct 31, 2019
1 parent 46f0658 commit 8de2a78
Show file tree
Hide file tree
Showing 11 changed files with 638 additions and 13 deletions.
1 change: 1 addition & 0 deletions tests/mock_tests/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tests
6 changes: 5 additions & 1 deletion tests/mock_tests/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@ endif
CFLAGS_GTEST =
LDADD_GTEST = -L/usr/src/gtest

tests_SOURCES = aclorch_ut.cpp saispy_ut.cpp \
tests_SOURCES = aclorch_ut.cpp \
portsorch_ut.cpp \
saispy_ut.cpp \
ut_saihelper.cpp \
mock_orchagent_main.cpp \
mock_dbconnector.cpp \
mock_consumerstatetable.cpp \
mock_table.cpp \
mock_hiredis.cpp \
mock_redisreply.cpp \
$(top_srcdir)/orchagent/orchdaemon.cpp \
Expand Down
18 changes: 9 additions & 9 deletions tests/mock_tests/aclorch_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -643,16 +643,16 @@ namespace aclorch_test
// leakage check
bool validateResourceCountWithLowerLayerDb(const AclOrch *aclOrch)
{
// TODO: Using the need to include "sai_vs_state.h". That will need the include path from `configure`
// Do this later ...
// TODO: Using the need to include "sai_vs_state.h". That will need the include path from `configure`
// Do this later ...
#if WITH_SAI == LIBVS
// {
// auto& aclTableHash = g_switch_state_map.at(gSwitchId)->objectHash.at(SAI_OBJECT_TYPE_ACL_TABLE);
//
// return aclTableHash.size() == Portal::AclOrchInternal::getAclTables(aclOrch).size();
// }
//
// TODO: add rule check
// {
// auto& aclTableHash = g_switch_state_map.at(gSwitchId)->objectHash.at(SAI_OBJECT_TYPE_ACL_TABLE);
//
// return aclTableHash.size() == Portal::AclOrchInternal::getAclTables(aclOrch).size();
// }
//
// TODO: add rule check
#endif

return true;
Expand Down
2 changes: 1 addition & 1 deletion tests/mock_tests/mock_consumerstatetable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ namespace swss
TableName_KeySet(tableName)
{
}
}
}
4 changes: 2 additions & 2 deletions tests/mock_tests/mock_dbconnector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ namespace swss

int DBConnector::getDbId() const
{
return 12345;
return m_dbId;
}
}
}
56 changes: 56 additions & 0 deletions tests/mock_tests/mock_orchagent_main.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#pragma once

#include "orch.h"
#include "switchorch.h"
#include "crmorch.h"
#include "portsorch.h"
#include "routeorch.h"
#include "intfsorch.h"
#include "neighorch.h"
#include "fdborch.h"
#include "mirrororch.h"
#include "bufferorch.h"
#include "vrforch.h"
#include "vnetorch.h"
#include "vxlanorch.h"
#include "policerorch.h"

extern int gBatchSize;
extern bool gSwssRecord;
extern bool gSairedisRecord;
extern bool gLogRotate;
extern ofstream gRecordOfs;
extern string gRecordFile;

extern MacAddress gMacAddress;
extern MacAddress gVxlanMacAddress;

extern sai_object_id_t gSwitchId;
extern sai_object_id_t gVirtualRouterId;
extern sai_object_id_t gUnderlayIfId;

extern SwitchOrch *gSwitchOrch;
extern CrmOrch *gCrmOrch;
extern PortsOrch *gPortsOrch;
extern RouteOrch *gRouteOrch;
extern IntfsOrch *gIntfsOrch;
extern NeighOrch *gNeighOrch;
extern FdbOrch *gFdbOrch;
extern MirrorOrch *gMirrorOrch;
extern BufferOrch *gBufferOrch;
extern VRFOrch *gVrfOrch;

extern sai_acl_api_t *sai_acl_api;
extern sai_switch_api_t *sai_switch_api;
extern sai_virtual_router_api_t *sai_virtual_router_api;
extern sai_port_api_t *sai_port_api;
extern sai_lag_api_t *sai_lag_api;
extern sai_vlan_api_t *sai_vlan_api;
extern sai_bridge_api_t *sai_bridge_api;
extern sai_router_interface_api_t *sai_router_intfs_api;
extern sai_route_api_t *sai_route_api;
extern sai_neighbor_api_t *sai_neighbor_api;
extern sai_tunnel_api_t *sai_tunnel_api;
extern sai_next_hop_api_t *sai_next_hop_api;
extern sai_hostif_api_t *sai_hostif_api;
extern sai_buffer_api_t *sai_buffer_api;
74 changes: 74 additions & 0 deletions tests/mock_tests/mock_table.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#include "table.h"

using TableDataT = std::map<std::string, std::vector<swss::FieldValueTuple>>;
using TablesT = std::map<std::string, TableDataT>;

namespace testing_db
{

TableDataT gTableData;
TablesT gTables;
std::map<int, TablesT> gDB;

void reset()
{
gDB.clear();
}
}

namespace swss
{

using namespace testing_db;

bool Table::get(const std::string &key, std::vector<FieldValueTuple> &ovalues)
{
auto table = gDB[getDbId()][getTableName()];
if (table.find(key) == table.end())
{
return false;
}

ovalues = table[key];
return true;
}

bool Table::hget(const std::string &key, const std::string &field, std::string &value)
{
auto table = gDB[getDbId()][getTableName()];
if (table.find(key) == table.end())
{
return false;
}

for (const auto &it : table[key])
{
if (it.first == field)
{
value = it.second;
return true;
}
}

return false;
}

void Table::set(const std::string &key,
const std::vector<FieldValueTuple> &values,
const std::string &op,
const std::string &prefix)
{
auto &table = gDB[getDbId()][getTableName()];
table[key] = values;
}

void Table::getKeys(std::vector<std::string> &keys)
{
keys.clear();
auto table = gDB[getDbId()][getTableName()];
for (const auto &it : table)
{
keys.push_back(it.first);
}
}
}
6 changes: 6 additions & 0 deletions tests/mock_tests/mock_table.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include "table.h"

namespace testing_db
{
void reset();
}
Loading

0 comments on commit 8de2a78

Please sign in to comment.