Skip to content

Commit

Permalink
add mock test
Browse files Browse the repository at this point in the history
  • Loading branch information
sundar-pds committed Dec 2, 2024
1 parent 484dbaa commit b2e8b77
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 1 deletion.
29 changes: 29 additions & 0 deletions tests/mock_tests/flexcounter_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "mock_orchagent_main.h"
#include "mock_orch_test.h"
#include "dashorch.h"
#include "dashmeterorch.h"
#include "mock_table.h"
#include "notifier.h"
#define private public
Expand Down Expand Up @@ -873,4 +874,32 @@ namespace flexcounter_test
m_DashOrch->handleFCStatusUpdate(false);
ASSERT_FALSE(checkFlexCounter(ENI_STAT_COUNTER_FLEX_COUNTER_GROUP, tmp_entry.eni_id, ENI_COUNTER_ID_LIST));
}

class MeterStatFlexCounterTest : public MockOrchTest
{
virtual void PostSetUp() {
_hook_sai_switch_api();
}

virtual void PreTearDown() {
_unhook_sai_switch_api();
}
};

TEST_F(MeterStatFlexCounterTest, TestStatusUpdate)
{
/* Add a mock ENI */
EniEntry tmp_entry;
tmp_entry.eni_id = 0x7008000000021;
m_DashOrch->eni_entries_["497f23d7-f0ac-4c99-a98f-59b470e8c7c"] = tmp_entry;

/* Should create ENI Counter stats for existing ENI's */
m_DashMeterOrch->handleMeterFCStatusUpdate(true);
m_DashMeterOrch->doTask(*(m_DashMeterOrch->m_meter_fc_update_timer));
ASSERT_TRUE(checkFlexCounter(METER_STAT_COUNTER_FLEX_COUNTER_GROUP, tmp_entry.eni_id, DASH_METER_COUNTER_ID_LIST));

/* This should delete the STATS */
m_DashMeterOrch->handleMeterFCStatusUpdate(false);
ASSERT_FALSE(checkFlexCounter(METER_STAT_COUNTER_FLEX_COUNTER_GROUP, tmp_entry.eni_id, DASH_METER_COUNTER_ID_LIST));
}
}
11 changes: 10 additions & 1 deletion tests/mock_tests/mock_orch_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,15 @@ void MockOrchTest::SetUp()
gDirectory.set(m_DashOrch);
ut_orch_list.push_back((Orch **)&m_DashOrch);

vector<string> dash_meter_tables = {
APP_DASH_METER_POLICY_TABLE_NAME,
APP_DASH_METER_RULE_TABLE_NAME
};

m_DashMeterOrch = new DashMeterOrch(m_app_db.get(), dash_meter_tables, m_DashOrch, nullptr);
gDirectory.set(m_DashMeterOrch);
ut_orch_list.push_back((Orch **)&m_DashMeterOrch);

TableConnector confDbAclTable(m_config_db.get(), CFG_ACL_TABLE_TABLE_NAME);
TableConnector confDbAclTableType(m_config_db.get(), CFG_ACL_TABLE_TYPE_TABLE_NAME);
TableConnector confDbAclRuleTable(m_config_db.get(), CFG_ACL_RULE_TABLE_NAME);
Expand Down Expand Up @@ -276,4 +285,4 @@ void MockOrchTest::TearDown()

ut_helper::uninitSaiApi();
}
}
}
1 change: 1 addition & 0 deletions tests/mock_tests/mock_orch_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ namespace mock_orch_test
FlexCounterOrch *m_FlexCounterOrch;
VxlanTunnelOrch *m_VxlanTunnelOrch;
DashOrch *m_DashOrch;
DashMeterOrch *m_DashMeterOrch;

void PrepareSai();
void SetUp();
Expand Down
1 change: 1 addition & 0 deletions tests/mock_tests/mock_orchagent_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "mirrororch.h"
#define private public
#include "dashorch.h"
#include "dashmeterorch.h"
#include "bufferorch.h"
#include "qosorch.h"
#define protected public
Expand Down

0 comments on commit b2e8b77

Please sign in to comment.