Skip to content

Commit 413ea6b

Browse files
committed
Fix and add unitest - draft
1 parent e1cbcb1 commit 413ea6b

9 files changed

+66
-4
lines changed

lib/Recorder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ void Recorder::recordDbgGenDumpResponse(
321321
{
322322
SWSS_LOG_ENTER();
323323

324-
recordLine("F|" + sai_serialize_status(status));
324+
recordLine("G|" + sai_serialize_status(status));
325325
}
326326

327327
void Recorder::recordQueryAttributeCapability(

lib/RedisRemoteSaiInterface.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1926,7 +1926,7 @@ sai_status_t RedisRemoteSaiInterface::dbgGenerateDump(
19261926

19271927
if (m_syncMode)
19281928
{
1929-
SWSS_LOG_DEBUG("wait for generate dump response");
1929+
SWSS_LOG_DEBUG("wait for generate dump response");
19301930
swss::KeyOpFieldsValuesTuple kco;
19311931
auto status = m_communicationChannel->wait(REDIS_ASIC_STATE_COMMAND_DBG_GEN_DUMPRESPONSE, kco);
19321932
m_recorder->recordDbgGenDumpResponse(status);

proxylib/Proxy.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,9 +362,33 @@ void Proxy::processSingleEvent(
362362
if (op == "clear_stats")
363363
return processClearStats(kco);
364364

365+
if (op == "dbg_gen_dump")
366+
return processDbgGenerateDump(kco);
367+
365368
SWSS_LOG_THROW("event op '%s' is not implemented, FIXME", op.c_str());
366369
}
367370

371+
void Proxy::processDbgGenerateDump(
372+
_In_ const swss::KeyOpFieldsValuesTuple &kco)
373+
{
374+
SWSS_LOG_ENTER();
375+
376+
const auto& values = kfvFieldsValues(kco);
377+
if (values.size() != 1)
378+
{
379+
SWSS_LOG_THROW("Invalid input: expected 1 arguments, received %zu", values.size());
380+
}
381+
382+
auto& fieldValues = kfvFieldsValues(kco);
383+
384+
auto value = fvValue(fieldValues[0]);
385+
const char* value_cstr = value.c_str();
386+
387+
sai_status_t status = m_vendorSai->dbgGenerateDump(value_cstr);
388+
389+
m_selectableChannel->set(sai_serialize_status(status), {} , "dbg_gen_dumpresponse");
390+
}
391+
368392
void Proxy::processCreate(
369393
_In_ const swss::KeyOpFieldsValuesTuple &kco)
370394
{

proxylib/Proxy.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ namespace saiproxy
106106
void processClearStats(
107107
_In_ const swss::KeyOpFieldsValuesTuple &kco);
108108

109+
void processDbgGenerateDump(
110+
_In_ const swss::KeyOpFieldsValuesTuple &kco);
111+
109112
private: // notifications
110113

111114
void onFdbEvent(

proxylib/Sai.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1133,7 +1133,11 @@ sai_status_t Sai::dbgGenerateDump(
11331133

11341134
m_communicationChannel->set(key, entry, "dbg_gen_dump");
11351135

1136-
return SAI_STATUS_SUCCESS;
1136+
swss::KeyOpFieldsValuesTuple kco;
1137+
1138+
auto status = m_communicationChannel->wait("dbg_gen_dumpresponse", kco);
1139+
1140+
return status;
11371141
}
11381142

11391143
void Sai::updateNotifications(

unittest/lib/TestSai.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,19 @@ TEST(Sai, queryApiVersion)
4040
EXPECT_EQ(sai.queryApiVersion(&version), SAI_STATUS_SUCCESS);
4141
}
4242

43+
TEST(Sai, dbgGenerateDump)
44+
{
45+
Sai sai;
46+
47+
sai.apiInitialize(0,&test_services);
48+
49+
const std::string filePath = "/var/log/testDump.log";
50+
51+
auto status = sai.dbgGenerateDump(filePath.c_str());
52+
53+
EXPECT_EQ(status, SAI_STATUS_SUCCESS);
54+
}
55+
4356
TEST(Sai, bulkGet)
4457
{
4558
Sai sai;

unittest/meta/TestDummySaiInterface.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,17 @@ TEST(DummySaiInterface, queryApiVersion)
2020
EXPECT_EQ(sai.queryApiVersion(&version), SAI_STATUS_SUCCESS);
2121
}
2222

23+
TEST(DummySaiInterface, dbgGenerateDump)
24+
{
25+
DummySaiInterface sai;
26+
27+
sai.apiInitialize(0,0);
28+
29+
const std::string filePath = "/var/log/testDump.log";
30+
31+
EXPECT_EQ(sai.dbgGenerateDump(filePath.c_str()), SAI_STATUS_SUCCESS);
32+
}
33+
2334
TEST(DummySaiInterface, bulkGet)
2435
{
2536
DummySaiInterface sai;

unittest/vslib/TestVirtualSwitchSaiInterface.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,13 @@ TEST_F(VirtualSwitchSaiInterfaceTest, queryApiVersion)
122122
EXPECT_EQ(m_vssai->queryApiVersion(&version), SAI_STATUS_SUCCESS);
123123
}
124124

125+
TEST_F(VirtualSwitchSaiInterfaceTest, dbgGenerateDump)
126+
{
127+
const std::string filePath = "/var/log/testDump.log";
128+
129+
EXPECT_EQ(m_vssai->dbgGenerateDump(filePath.c_str()), SAI_STATUS_SUCCESS);
130+
}
131+
125132
TEST_F(VirtualSwitchSaiInterfaceTest, bulkGet)
126133
{
127134
sai_object_id_t oids[1] = {0};

0 commit comments

Comments
 (0)