From b2e8b77334334984b2e136126e5b40108a9ca0ef Mon Sep 17 00:00:00 2001 From: Sundara Gurunathan Date: Mon, 2 Dec 2024 20:41:43 +0000 Subject: [PATCH] add mock test --- tests/mock_tests/flexcounter_ut.cpp | 29 ++++++++++++++++++++++++++ tests/mock_tests/mock_orch_test.cpp | 11 +++++++++- tests/mock_tests/mock_orch_test.h | 1 + tests/mock_tests/mock_orchagent_main.h | 1 + 4 files changed, 41 insertions(+), 1 deletion(-) diff --git a/tests/mock_tests/flexcounter_ut.cpp b/tests/mock_tests/flexcounter_ut.cpp index fa3b62e795..eb3a2a9aa5 100644 --- a/tests/mock_tests/flexcounter_ut.cpp +++ b/tests/mock_tests/flexcounter_ut.cpp @@ -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 @@ -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)); + } } diff --git a/tests/mock_tests/mock_orch_test.cpp b/tests/mock_tests/mock_orch_test.cpp index c6898188b4..278c87961e 100644 --- a/tests/mock_tests/mock_orch_test.cpp +++ b/tests/mock_tests/mock_orch_test.cpp @@ -222,6 +222,15 @@ void MockOrchTest::SetUp() gDirectory.set(m_DashOrch); ut_orch_list.push_back((Orch **)&m_DashOrch); + vector 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); @@ -276,4 +285,4 @@ void MockOrchTest::TearDown() ut_helper::uninitSaiApi(); } -} \ No newline at end of file +} diff --git a/tests/mock_tests/mock_orch_test.h b/tests/mock_tests/mock_orch_test.h index 86c5a36655..9a643f0545 100644 --- a/tests/mock_tests/mock_orch_test.h +++ b/tests/mock_tests/mock_orch_test.h @@ -51,6 +51,7 @@ namespace mock_orch_test FlexCounterOrch *m_FlexCounterOrch; VxlanTunnelOrch *m_VxlanTunnelOrch; DashOrch *m_DashOrch; + DashMeterOrch *m_DashMeterOrch; void PrepareSai(); void SetUp(); diff --git a/tests/mock_tests/mock_orchagent_main.h b/tests/mock_tests/mock_orchagent_main.h index f2469a09ef..5dd269826a 100644 --- a/tests/mock_tests/mock_orchagent_main.h +++ b/tests/mock_tests/mock_orchagent_main.h @@ -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