diff --git a/tests/mock_tests/flexcounter_ut.cpp b/tests/mock_tests/flexcounter_ut.cpp index fff44c110e..b0c009357a 100644 --- a/tests/mock_tests/flexcounter_ut.cpp +++ b/tests/mock_tests/flexcounter_ut.cpp @@ -111,15 +111,25 @@ namespace flexcounter_test bool _checkFlexCounterTableContent(std::shared_ptr table, const std::string key, std::vector entries) { vector fieldValues; + bool result = false; if (table->get(key, fieldValues)) { set fvSet(fieldValues.begin(), fieldValues.end()); set expectedSet(entries.begin(), entries.end()); - return (fvSet == expectedSet); + result = (fvSet == expectedSet); + if (!result && gTraditionalFlexCounter) + { + // We can not mock database operation when counter model is traditional. + // As a result, the plugin field will not be inserted into the database. + // We add it into the entries fetched from database manually and redo comparing + // The plugin field must be the last one in entries vector + fvSet.insert(entries.back()); + return (fvSet == expectedSet); + } } - return false; + return result; } bool checkFlexCounterGroup(const std::string group, std::vector entries) @@ -195,7 +205,7 @@ namespace flexcounter_test sai_switch_api = pold_sai_switch_api; } - struct FlexCounterTest : public ::testing::Test + struct FlexCounterTest : public ::testing::TestWithParam { shared_ptr m_app_db; shared_ptr m_config_db; @@ -228,7 +238,11 @@ namespace flexcounter_test { ::testing_db::reset(); - gTraditionalFlexCounter = false; + gTraditionalFlexCounter = GetParam(); + if (gTraditionalFlexCounter) + { + initFlexCounterTables(); + } _hook_sai_switch_api(); @@ -385,7 +399,7 @@ namespace flexcounter_test }; - TEST_F(FlexCounterTest, CounterTest) + TEST_P(FlexCounterTest, CounterTest) { // Check flex counter database after system initialization ASSERT_TRUE(checkFlexCounterGroup(QUEUE_WATERMARK_STAT_COUNTER_FLEX_COUNTER_GROUP, @@ -404,8 +418,8 @@ namespace flexcounter_test { {STATS_MODE_FIELD, STATS_MODE_READ}, {POLL_INTERVAL_FIELD, PORT_RATE_FLEX_COUNTER_POLLING_INTERVAL_MS}, - {PORT_PLUGIN_FIELD, ""}, - {FLEX_COUNTER_STATUS_FIELD, "disable"} + {FLEX_COUNTER_STATUS_FIELD, "disable"}, + {PORT_PLUGIN_FIELD, ""} })); ASSERT_TRUE(checkFlexCounterGroup(PG_DROP_STAT_COUNTER_FLEX_COUNTER_GROUP, { @@ -606,6 +620,12 @@ namespace flexcounter_test // Check flex counter database auto rifOid = gIntfsOrch->m_rifsToAdd[0].m_rif_id; + Table vid2rid = Table(m_asic_db.get(), "VIDTORID"); + if (gTraditionalFlexCounter) + { + const auto id = sai_serialize_object_id(rifOid); + vid2rid.set("", { {id, ""} }); + } (gIntfsOrch)->doTask(*gIntfsOrch->m_updateMapsTimer); ASSERT_TRUE(checkFlexCounter(RIF_STAT_COUNTER_FLEX_COUNTER_GROUP, rifOid, { @@ -737,4 +757,10 @@ namespace flexcounter_test {QUEUE_ATTR_ID_LIST, "SAI_QUEUE_ATTR_PAUSE_STATUS"} })); } + + INSTANTIATE_TEST_CASE_P( + FlexCounterTests, + FlexCounterTest, + ::testing::Values(true, false) + ); } diff --git a/tests/mock_tests/mock_table.cpp b/tests/mock_tests/mock_table.cpp index 191104a056..7dc77d42ad 100644 --- a/tests/mock_tests/mock_table.cpp +++ b/tests/mock_tests/mock_table.cpp @@ -1,5 +1,6 @@ #include "table.h" #include "producerstatetable.h" +#include "producertable.h" #include #include @@ -154,4 +155,29 @@ namespace swss return std::shared_ptr(NULL); } } + + void ProducerTable::set(const std::string &key, + const std::vector &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 + { + merge_values(iter->second, values); + } + } + + void ProducerTable::del(const std::string &key, + const std::string &op, + const std::string &prefix) + { + auto &table = gDB[m_pipe->getDbId()][getTableName()]; + table.erase(key); + } }