From a48a935a50d2c45d86ceaf6ab7a7292e72427691 Mon Sep 17 00:00:00 2001 From: aviramd Date: Thu, 28 Nov 2024 14:49:10 +0000 Subject: [PATCH] fix and add unittests - draft --- lib/Recorder.cpp | 2 +- lib/RedisRemoteSaiInterface.cpp | 2 +- proxylib/Proxy.cpp | 24 +++++++++++++++++++ proxylib/Proxy.h | 3 +++ proxylib/Sai.cpp | 6 ++++- unittest/lib/TestSai.cpp | 13 ++++++++++ unittest/meta/TestDummySaiInterface.cpp | 11 +++++++++ unittest/vslib/TestSai.cpp | 1 - .../vslib/TestVirtualSwitchSaiInterface.cpp | 7 ++++++ vslib/Sai.cpp | 2 +- 10 files changed, 66 insertions(+), 5 deletions(-) diff --git a/lib/Recorder.cpp b/lib/Recorder.cpp index 3faf3af94..643553a32 100644 --- a/lib/Recorder.cpp +++ b/lib/Recorder.cpp @@ -321,7 +321,7 @@ void Recorder::recordDbgGenDumpResponse( { SWSS_LOG_ENTER(); - recordLine("F|" + sai_serialize_status(status)); + recordLine("G|" + sai_serialize_status(status)); } void Recorder::recordQueryAttributeCapability( diff --git a/lib/RedisRemoteSaiInterface.cpp b/lib/RedisRemoteSaiInterface.cpp index 2af0b723c..91d847441 100644 --- a/lib/RedisRemoteSaiInterface.cpp +++ b/lib/RedisRemoteSaiInterface.cpp @@ -1926,7 +1926,7 @@ sai_status_t RedisRemoteSaiInterface::dbgGenerateDump( if (m_syncMode) { - SWSS_LOG_DEBUG("wait for generate dump response"); + SWSS_LOG_DEBUG("wait for generate dump response"); swss::KeyOpFieldsValuesTuple kco; auto status = m_communicationChannel->wait(REDIS_ASIC_STATE_COMMAND_DBG_GEN_DUMPRESPONSE, kco); m_recorder->recordDbgGenDumpResponse(status); diff --git a/proxylib/Proxy.cpp b/proxylib/Proxy.cpp index ab3a280e0..6b6d741b3 100644 --- a/proxylib/Proxy.cpp +++ b/proxylib/Proxy.cpp @@ -362,9 +362,33 @@ void Proxy::processSingleEvent( if (op == "clear_stats") return processClearStats(kco); + if (op == "dbg_gen_dump") + return processDbgGenerateDump(kco); + SWSS_LOG_THROW("event op '%s' is not implemented, FIXME", op.c_str()); } +void Proxy::processDbgGenerateDump( + _In_ const swss::KeyOpFieldsValuesTuple &kco) +{ + SWSS_LOG_ENTER(); + + const auto& values = kfvFieldsValues(kco); + if (values.size() != 1) + { + SWSS_LOG_THROW("Invalid input: expected 1 arguments, received %zu", values.size()); + } + + auto& fieldValues = kfvFieldsValues(kco); + + auto value = fvValue(fieldValues[0]); + const char* value_cstr = value.c_str(); + + sai_status_t status = m_vendorSai->dbgGenerateDump(value_cstr); + + m_selectableChannel->set(sai_serialize_status(status), {} , "dbg_gen_dumpresponse"); +} + void Proxy::processCreate( _In_ const swss::KeyOpFieldsValuesTuple &kco) { diff --git a/proxylib/Proxy.h b/proxylib/Proxy.h index 029772634..e97b15b53 100644 --- a/proxylib/Proxy.h +++ b/proxylib/Proxy.h @@ -106,6 +106,9 @@ namespace saiproxy void processClearStats( _In_ const swss::KeyOpFieldsValuesTuple &kco); + void processDbgGenerateDump( + _In_ const swss::KeyOpFieldsValuesTuple &kco); + private: // notifications void onFdbEvent( diff --git a/proxylib/Sai.cpp b/proxylib/Sai.cpp index 826fcf8f1..93b1a55b5 100644 --- a/proxylib/Sai.cpp +++ b/proxylib/Sai.cpp @@ -1131,7 +1131,11 @@ sai_status_t Sai::dbgGenerateDump( std::string key = "DBG_GEN_DUMP:01"; - m_communicationChannel->set(key, entry, "dbg_gen_dump"); + /*m_communicationChannel->set(key, entry, "dbg_gen_dump"); + + swss::KeyOpFieldsValuesTuple kco; + + return m_communicationChannel->wait("dbg_gen_dumpresponse", kco);*/ return SAI_STATUS_SUCCESS; } diff --git a/unittest/lib/TestSai.cpp b/unittest/lib/TestSai.cpp index 9d3e11790..73766bd10 100644 --- a/unittest/lib/TestSai.cpp +++ b/unittest/lib/TestSai.cpp @@ -40,6 +40,19 @@ TEST(Sai, queryApiVersion) EXPECT_EQ(sai.queryApiVersion(&version), SAI_STATUS_SUCCESS); } +TEST(Sai, dbgGenerateDump) +{ + Sai sai; + + sai.apiInitialize(0,&test_services); + + const std::string filePath = "/var/log/testDump.log"; + + auto status = sai.dbgGenerateDump(filePath.c_str()); + + EXPECT_EQ(status, SAI_STATUS_SUCCESS); +} + TEST(Sai, bulkGet) { Sai sai; diff --git a/unittest/meta/TestDummySaiInterface.cpp b/unittest/meta/TestDummySaiInterface.cpp index 4c8ca1ca5..15436dd30 100644 --- a/unittest/meta/TestDummySaiInterface.cpp +++ b/unittest/meta/TestDummySaiInterface.cpp @@ -20,6 +20,17 @@ TEST(DummySaiInterface, queryApiVersion) EXPECT_EQ(sai.queryApiVersion(&version), SAI_STATUS_SUCCESS); } +TEST(DummySaiInterface, dbgGenerateDump) +{ + DummySaiInterface sai; + + sai.apiInitialize(0,0); + + const std::string filePath = "/var/log/testDump.log"; + + EXPECT_EQ(sai.dbgGenerateDump(filePath.c_str()), SAI_STATUS_SUCCESS); +} + TEST(DummySaiInterface, bulkGet) { DummySaiInterface sai; diff --git a/unittest/vslib/TestSai.cpp b/unittest/vslib/TestSai.cpp index c45663de8..fde5b75ce 100644 --- a/unittest/vslib/TestSai.cpp +++ b/unittest/vslib/TestSai.cpp @@ -25,4 +25,3 @@ TEST(Sai, bulkGet) SAI_BULK_OP_ERROR_MODE_STOP_ON_ERROR, statuses)); } - diff --git a/unittest/vslib/TestVirtualSwitchSaiInterface.cpp b/unittest/vslib/TestVirtualSwitchSaiInterface.cpp index 445bc56b6..c07ecd16c 100644 --- a/unittest/vslib/TestVirtualSwitchSaiInterface.cpp +++ b/unittest/vslib/TestVirtualSwitchSaiInterface.cpp @@ -122,6 +122,13 @@ TEST_F(VirtualSwitchSaiInterfaceTest, queryApiVersion) EXPECT_EQ(m_vssai->queryApiVersion(&version), SAI_STATUS_SUCCESS); } +TEST_F(VirtualSwitchSaiInterfaceTest, dbgGenerateDump) +{ + const std::string filePath = "/var/log/testDump.log"; + + EXPECT_EQ(m_vssai->dbgGenerateDump(filePath.c_str()), SAI_STATUS_SUCCESS); +} + TEST_F(VirtualSwitchSaiInterfaceTest, bulkGet) { sai_object_id_t oids[1] = {0}; diff --git a/vslib/Sai.cpp b/vslib/Sai.cpp index 02d50bb43..2248a9e52 100644 --- a/vslib/Sai.cpp +++ b/vslib/Sai.cpp @@ -860,7 +860,7 @@ sai_status_t Sai::dbgGenerateDump( SWSS_LOG_ENTER(); VS_CHECK_API_INITIALIZED(); - return m_meta->dbgGenerateDump(dump_file_name); + return m_meta->dbgGenerateDump(dump_file_name); }