Skip to content

Commit

Permalink
ff
Browse files Browse the repository at this point in the history
  • Loading branch information
JunhongMao committed Feb 5, 2024
1 parent 0cf0ce7 commit 2fe7748
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 234 deletions.
4 changes: 4 additions & 0 deletions saidump/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ saidump_CPPFLAGS = $(CODE_COVERAGE_CPPFLAGS)
saidump_CXXFLAGS = $(DBGFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS_COMMON) $(CODE_COVERAGE_CXXFLAGS)
saidump_LDADD = -lhiredis -lswsscommon -lpthread -L$(top_srcdir)/meta/.libs -lsaimetadata -lsaimeta \
-L$(top_srcdir)/lib/.libs -lsairedis -lzmq $(CODE_COVERAGE_LIBS)

noinst_LIBRARIES = libsaidump.a
libsaidump_a_SOURCES = saidump.cpp
AM_CPPFLAGS = -D_UNITTEST_
22 changes: 4 additions & 18 deletions saidump/saidump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,14 @@ extern "C" {
#include "meta/sai_serialize.h"
#include "sairediscommon.h"
#include "swss/json.hpp"

#include "saidump.h"
#include <getopt.h>

// TODO split to multiple cpp

using namespace swss;
using json = nlohmann::json;

// Default value: 100 MB
constexpr int64_t RDB_JSON_MAX_SIZE = 1024 * 1024 * 100;

struct CmdOptions
{
bool skipAttributes;
bool dumpTempView;
bool dumpGraph;
std::string rdbJsonFile;
uint64_t rdbJSonSizeLimit;
};


static CmdOptions g_cmdOptions;
CmdOptions g_cmdOptions;
static std::map<sai_object_id_t, const TableMap*> g_oid_map;

void printUsage()
Expand Down Expand Up @@ -451,7 +437,7 @@ void dumpGraph(const TableDump& td)
/**
* @brief Process the input JSON file to make sure it's a valid JSON file for the JSON library.
*/
static sai_status_t preProcessFile(const std::string file_name)
sai_status_t preProcessFile(const std::string file_name)
{
SWSS_LOG_ENTER();

Expand Down Expand Up @@ -502,7 +488,7 @@ static sai_status_t preProcessFile(const std::string file_name)
return SAI_STATUS_SUCCESS;
}

static sai_status_t dumpFromRedisRdbJson(const std::string file_name)
sai_status_t dumpFromRedisRdbJson(const std::string file_name)
{
SWSS_LOG_ENTER();

Expand Down
19 changes: 19 additions & 0 deletions saidump/saidump.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#pragma once
#include <inttypes.h>

// Default value: 100 MB
constexpr int64_t RDB_JSON_MAX_SIZE = 1024 * 1024 * 100;

struct CmdOptions
{
bool skipAttributes;
bool dumpTempView;
bool dumpGraph;
std::string rdbJsonFile;
uint64_t rdbJSonSizeLimit;
};

void printUsage();
CmdOptions handleCmdLine(int argc, char **argv);
sai_status_t dumpFromRedisRdbJson(const std::string file_name);
sai_status_t preProcessFile(const std::string file_name);
6 changes: 3 additions & 3 deletions unittest/saidump/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ LDADD_GTEST = -L/usr/src/gtest -lgtest -lgtest_main

tests_SOURCES = main.cpp

tests_CXXFLAGS = $(DBGFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS_COMMON) -D_UNITTEST_
tests_LDFLAGS = -Wl,-rpath,$(top_srcdir)/lib/.libs -Wl,-rpath,$(top_srcdir)/meta/.libs
tests_LDADD = $(LDADD_GTEST) -lhiredis -lswsscommon -lnl-genl-3 -lnl-nf-3 -lnl-route-3 -lnl-3 -lpthread -L$(top_srcdir)/lib/.libs -lsairedis -L$(top_srcdir)/meta/.libs -lsaimetadata -lsaimeta -lzmq $(CODE_COVERAGE_LIBS)
tests_CXXFLAGS = $(DBGFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS_COMMON)
tests_LDFLAGS = -D_UNITTEST_
tests_LDADD = $(LDADD_GTEST) $(top_srcdir)/saidump/libsaidump.a -lhiredis -lswsscommon -lnl-genl-3 -lnl-nf-3 -lnl-route-3 -lnl-3 -lpthread -L$(top_srcdir)/lib/.libs -lsairedis -L$(top_srcdir)/meta/.libs -lsaimetadata -lsaimeta -lzmq $(CODE_COVERAGE_LIBS)

TESTS = tests
8 changes: 5 additions & 3 deletions unittest/saidump/main.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#include <gtest/gtest.h>
#include "saidump.cpp"

#include "meta/sai_serialize.h"
#include "saidump.h"
#define ARGVN 5

extern CmdOptions g_cmdOptions;

TEST(SaiDump, printUsage)
{
SWSS_LOG_ENTER();
Expand All @@ -26,7 +28,7 @@ TEST(SaiDump, handleCmdLine)
g_cmdOptions = handleCmdLine(ARGVN, argv);
delete[] argv;
EXPECT_EQ(g_cmdOptions.rdbJsonFile, "./dump.json");
EXPECT_EQ(g_cmdOptions.rdbJSonSizeLimit, 100 * 1024 * 1024);
EXPECT_EQ(g_cmdOptions.rdbJSonSizeLimit, RDB_JSON_MAX_SIZE);
}

TEST(SaiDump, dumpFromRedisRdbJson)
Expand Down
210 changes: 0 additions & 210 deletions unittest/saidump/tests

This file was deleted.

0 comments on commit 2fe7748

Please sign in to comment.