Skip to content

Commit

Permalink
fix and add unittests - draft
Browse files Browse the repository at this point in the history
  • Loading branch information
aviramd committed Dec 1, 2024
1 parent 932a732 commit a48a935
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/Recorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion lib/RedisRemoteSaiInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
24 changes: 24 additions & 0 deletions proxylib/Proxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
3 changes: 3 additions & 0 deletions proxylib/Proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ namespace saiproxy
void processClearStats(
_In_ const swss::KeyOpFieldsValuesTuple &kco);

void processDbgGenerateDump(
_In_ const swss::KeyOpFieldsValuesTuple &kco);

private: // notifications

void onFdbEvent(
Expand Down
6 changes: 5 additions & 1 deletion proxylib/Sai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
13 changes: 13 additions & 0 deletions unittest/lib/TestSai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 11 additions & 0 deletions unittest/meta/TestDummySaiInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion unittest/vslib/TestSai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,3 @@ TEST(Sai, bulkGet)
SAI_BULK_OP_ERROR_MODE_STOP_ON_ERROR,
statuses));
}

7 changes: 7 additions & 0 deletions unittest/vslib/TestVirtualSwitchSaiInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
2 changes: 1 addition & 1 deletion vslib/Sai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}


Expand Down

0 comments on commit a48a935

Please sign in to comment.