Skip to content

Commit 4295cc6

Browse files
committed
fix and add unittests - draft
1 parent 932a732 commit 4295cc6

12 files changed

+87
-5
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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,6 +1133,10 @@ sai_status_t Sai::dbgGenerateDump(
11331133

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

1136+
/*swss::KeyOpFieldsValuesTuple kco;
1137+
1138+
return m_communicationChannel->wait("dbg_gen_dumpresponse", kco);*/
1139+
11361140
return SAI_STATUS_SUCCESS;
11371141
}
11381142

unittest/lib/TestClientSai.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,13 @@ TEST(ClientSai, bulkGet)
5050
statuses));
5151
}
5252

53+
TEST(ClientSai, dbgGenerateDump)
54+
{
55+
ClientSai sai;
56+
57+
sai.apiInitialize(0,&test_services);
58+
59+
const std::string filePath = "/var/log/dbgGenerateDump.log";
60+
61+
EXPECT_EQ(SAI_STATUS_NOT_IMPLEMENTED, sai.dbgGenerateDump(filePath.c_str()));
62+
}

unittest/lib/TestRedisRemoteSaiInterface.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,14 @@ TEST(RedisRemoteSaiInterface, bulkGet)
2828
statuses));
2929
}
3030

31+
TEST(RedisRemoteSaiInterface, dbgGenerateDump)
32+
{
33+
auto ctx = ContextConfigContainer::loadFromFile("foo");
34+
auto rec = std::make_shared<Recorder>();
35+
36+
RedisRemoteSaiInterface sai(ctx->get(0), nullptr, rec);
37+
38+
const std::string filePath = "/var/log/testDump.log";
39+
40+
EXPECT_EQ(sai.dbgGenerateDump(filePath.c_str()), SAI_STATUS_SUCCESS);
41+
}

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/TestSai.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,4 @@ TEST(Sai, bulkGet)
2424
attrs,
2525
SAI_BULK_OP_ERROR_MODE_STOP_ON_ERROR,
2626
statuses));
27-
}
28-
27+
}

0 commit comments

Comments
 (0)