forked from sonic-net/sonic-buildimage
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[saiasiccmp] Add saiasiccmp tool to compare 2 asic views (sonic-net#791)
Will be used to compare 2 independent ASIC view dumps for unittest. File format must by provided by command: ``` $ ./redisdl.py -d 1 -y ``` from https://github.com/p/redis-dump-load repo Signed-off-by: kcudnik <kcudnik@gmail.com>
- Loading branch information
Showing
21 changed files
with
59,554 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
SUBDIRS = meta lib vslib python | ||
|
||
if SYNCD | ||
SUBDIRS += syncd saiplayer saidump saidiscovery saisdkdump tests | ||
SUBDIRS += syncd saiplayer saidump saidiscovery saisdkdump saiasiccmp tests | ||
endif | ||
|
||
ACLOCAL_AMFLAGS = -I m4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#include "AsicCmp.h" | ||
#include "ViewCmp.h" | ||
|
||
#include "swss/logger.h" | ||
|
||
#include <iostream> | ||
|
||
using namespace saiasiccmp; | ||
|
||
AsicCmp::AsicCmp( | ||
_In_ std::shared_ptr<CommandLineOptions> options): | ||
m_commandLineOptions(options) | ||
{ | ||
SWSS_LOG_ENTER(); | ||
|
||
// empty | ||
} | ||
|
||
bool AsicCmp::compare() | ||
{ | ||
SWSS_LOG_ENTER(); | ||
|
||
auto& args = m_commandLineOptions->m_args; | ||
|
||
if (args.size() != 2) | ||
{ | ||
SWSS_LOG_ERROR("ERROR: expected 2 input files, but given: %zu", args.size()); | ||
return false; | ||
} | ||
|
||
try | ||
{ | ||
auto a = std::make_shared<View>(args[0]); | ||
auto b = std::make_shared<View>(args[1]); | ||
|
||
SWSS_LOG_NOTICE("max objects: %lu %lu", a->m_maxObjectIndex, b->m_maxObjectIndex); | ||
|
||
b->translateViewVids(a->m_maxObjectIndex); | ||
|
||
ViewCmp cmp(a, b); | ||
|
||
return cmp.compareViews(m_commandLineOptions->m_dumpDiffToStdErr); | ||
} | ||
catch (const std::exception& e) | ||
{ | ||
std::cerr << "Exception: " << e.what() << std::endl; | ||
|
||
SWSS_LOG_ERROR("Exception: %s", e.what()); | ||
|
||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#pragma once | ||
|
||
#include "swss/sal.h" | ||
|
||
#include "CommandLineOptions.h" | ||
|
||
#include <memory> | ||
|
||
namespace saiasiccmp | ||
{ | ||
class AsicCmp | ||
{ | ||
public: | ||
|
||
AsicCmp( | ||
_In_ std::shared_ptr<CommandLineOptions> options); | ||
|
||
public: | ||
|
||
bool compare(); | ||
|
||
private: | ||
|
||
std::shared_ptr<CommandLineOptions> m_commandLineOptions; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#include "CommandLineOptions.h" | ||
|
||
#include "meta/sai_serialize.h" | ||
|
||
#include "swss/logger.h" | ||
|
||
#include <sstream> | ||
|
||
using namespace saiasiccmp; | ||
|
||
CommandLineOptions::CommandLineOptions() | ||
{ | ||
SWSS_LOG_ENTER(); | ||
|
||
// default values for command line options | ||
|
||
m_enableLogLevelInfo = false; | ||
m_dumpDiffToStdErr = false; | ||
} | ||
|
||
std::string CommandLineOptions::getCommandLineString() const | ||
{ | ||
SWSS_LOG_ENTER(); | ||
|
||
std::stringstream ss; | ||
|
||
ss << " EnableLogLevelInfo=" << (m_enableLogLevelInfo ? "YES" : "NO"); | ||
ss << " DumpDiffToStdErr=" << (m_dumpDiffToStdErr ? "YES" : "NO"); | ||
|
||
for (auto &arg: m_args) | ||
{ | ||
ss << " " << arg ; | ||
} | ||
|
||
return ss.str(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#pragma once | ||
|
||
#include "swss/sal.h" | ||
|
||
#include <string> | ||
#include <vector> | ||
|
||
namespace saiasiccmp | ||
{ | ||
class CommandLineOptions | ||
{ | ||
public: | ||
|
||
CommandLineOptions(); | ||
|
||
virtual ~CommandLineOptions() = default; | ||
|
||
public: | ||
|
||
virtual std::string getCommandLineString() const; | ||
|
||
public: | ||
|
||
bool m_enableLogLevelInfo; | ||
bool m_dumpDiffToStdErr; | ||
|
||
std::vector<std::string> m_args; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
#include "CommandLineOptionsParser.h" | ||
|
||
#include "meta/sai_serialize.h" | ||
|
||
#include "swss/logger.h" | ||
|
||
#include <getopt.h> | ||
|
||
#include <iostream> | ||
|
||
using namespace saiasiccmp; | ||
|
||
std::shared_ptr<CommandLineOptions> CommandLineOptionsParser::parseCommandLine( | ||
_In_ int argc, | ||
_In_ char **argv) | ||
{ | ||
SWSS_LOG_ENTER(); | ||
|
||
auto options = std::make_shared<CommandLineOptions>(); | ||
|
||
const char* const optstring = "idh"; | ||
|
||
while (true) | ||
{ | ||
static struct option long_options[] = | ||
{ | ||
{ "enableLogLevelInfo", no_argument, 0, 'i' }, | ||
{ "dumpDiffToStdErr", no_argument, 0, 'd' }, | ||
{ "help", no_argument, 0, 'h' }, | ||
{ 0, 0, 0, 0 } | ||
}; | ||
|
||
int option_index = 0; | ||
|
||
int c = getopt_long(argc, argv, optstring, long_options, &option_index); | ||
|
||
if (c == -1) | ||
{ | ||
break; | ||
} | ||
|
||
switch (c) | ||
{ | ||
case 'i': | ||
options->m_enableLogLevelInfo = true; | ||
break; | ||
|
||
case 'd': | ||
options->m_dumpDiffToStdErr = true; | ||
break; | ||
|
||
case 'h': | ||
printUsage(); | ||
exit(EXIT_SUCCESS); | ||
|
||
case '?': | ||
SWSS_LOG_WARN("unknown option %c", optopt); | ||
printUsage(); | ||
exit(EXIT_FAILURE); | ||
|
||
default: | ||
SWSS_LOG_ERROR("getopt_long failure"); | ||
exit(EXIT_FAILURE); | ||
} | ||
} | ||
|
||
for (int index = optind; index < argc; index++) | ||
{ | ||
options->m_args.push_back(argv[index]); | ||
} | ||
|
||
return options; | ||
} | ||
|
||
void CommandLineOptionsParser::printUsage() | ||
{ | ||
SWSS_LOG_ENTER(); | ||
|
||
std::cout << "Usage: saiasiccmp [-i] [-d] [-h] file1 file2" << std::endl << std::endl; | ||
|
||
std::cout << " file1 and file2 must be in json fromat produced by redis-dump-load" << std::endl; | ||
std::cout << " for example: redisdl.py -d 1 -y" << std::endl << std::endl; | ||
|
||
std::cout << " -i --enableLogLevelInfo" << std::endl; | ||
std::cout << " Enable LogLevel INFO" << std::endl; | ||
std::cout << " -d --dumpDiffToStdErr" << std::endl; | ||
std::cout << " Dump asic diff to stderr" << std::endl; | ||
std::cout << " -h --help" << std::endl; | ||
std::cout << " Print out this message" << std::endl; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#pragma once | ||
|
||
#include "CommandLineOptions.h" | ||
|
||
#include <memory> | ||
|
||
namespace saiasiccmp | ||
{ | ||
class CommandLineOptionsParser | ||
{ | ||
private: | ||
|
||
CommandLineOptionsParser() = delete; | ||
|
||
~CommandLineOptionsParser() = delete; | ||
|
||
public: | ||
|
||
static std::shared_ptr<CommandLineOptions> parseCommandLine( | ||
_In_ int argc, | ||
_In_ char **argv); | ||
|
||
static void printUsage(); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
AM_CPPFLAGS = \ | ||
-I$(top_srcdir)/lib/inc \ | ||
-I$(top_srcdir)/SAI/inc \ | ||
-I$(top_srcdir)/SAI/meta \ | ||
-I$(top_srcdir)/SAI/experimental \ | ||
-I$(top_srcdir)/meta \ | ||
-I$(top_srcdir)/syncd | ||
|
||
bin_PROGRAMS = saiasiccmp | ||
|
||
if DEBUG | ||
DBGFLAGS = -ggdb -DDEBUG | ||
else | ||
DBGFLAGS = -g | ||
endif | ||
|
||
noinst_LIBRARIES = libAsicCmp.a | ||
libAsicCmp_a_SOURCES = \ | ||
AsicCmp.cpp \ | ||
View.cpp \ | ||
ViewCmp.cpp \ | ||
SaiSwitchAsic.cpp \ | ||
CommandLineOptions.cpp \ | ||
CommandLineOptionsParser.cpp | ||
|
||
libAsicCmp_a_CPPFLAGS = $(DBGFLAGS) $(AM_CPPFLAGS) $(CFLAGS_COMMON) $(SAIFLAGS) | ||
|
||
saiasiccmp_SOURCES = main.cpp | ||
saiasiccmp_CPPFLAGS = $(DBGFLAGS) $(AM_CPPFLAGS) $(CFLAGS_COMMON) $(SAIFLAGS) | ||
saiasiccmp_LDADD = libAsicCmp.a \ | ||
-lsaimetadata -lsaimeta -ldl -lhiredis -lswsscommon -lpthread -lzmq \ | ||
$(top_srcdir)/syncd/libSyncd.a \ | ||
-L$(top_srcdir)/syncd/.libs \ | ||
$(top_srcdir)/lib/src/libSaiRedis.a \ | ||
-L$(top_srcdir)/meta/.libs | ||
|
||
TESTS = test.sh |
Oops, something went wrong.