diff --git a/configure.ac b/configure.ac index 3763f5ab7..927bef255 100644 --- a/configure.ac +++ b/configure.ac @@ -17,6 +17,10 @@ AX_ADD_AM_MACRO_STATIC([]) AM_CONDITIONAL(SONIC_ASIC_PLATFORM_BAREFOOT, test x$CONFIGURED_PLATFORM = xbarefoot) AM_CONDITIONAL(SONIC_ASIC_PLATFORM_BROADCOM, test x$CONFIGURED_PLATFORM = xbroadcom) +AM_CONDITIONAL(SONIC_ASIC_PLATFORM_MELLANOX, test x$CONFIGURED_PLATFORM = xmellanox) + +AM_COND_IF([SONIC_ASIC_PLATFORM_MELLANOX], + AC_DEFINE([MELLANOX], [1], [Define to 1 on Mellanox Platform])) AC_ARG_ENABLE(debug, [ --enable-debug turn on debugging], diff --git a/syncd/Syncd.cpp b/syncd/Syncd.cpp index 508dadea1..d5116732a 100644 --- a/syncd/Syncd.cpp +++ b/syncd/Syncd.cpp @@ -3819,9 +3819,15 @@ sai_status_t Syncd::processNotifySyncd( m_veryFirstRun = false; m_asicInitViewMode = false; - - if (m_commandLineOptions->m_startType == SAI_START_TYPE_FASTFAST_BOOT || - m_commandLineOptions->m_startType == SAI_START_TYPE_EXPRESS_BOOT) +#ifdef MELLANOX + bool applyViewInFastFastBoot = m_commandLineOptions->m_startType == SAI_START_TYPE_FASTFAST_BOOT || + m_commandLineOptions->m_startType == SAI_START_TYPE_EXPRESS_BOOT || + m_commandLineOptions->m_startType == SAI_START_TYPE_FAST_BOOT; +#else + bool applyViewInFastFastBoot = m_commandLineOptions->m_startType == SAI_START_TYPE_FASTFAST_BOOT || + m_commandLineOptions->m_startType == SAI_START_TYPE_EXPRESS_BOOT; +#endif + if (applyViewInFastFastBoot) { // express/fastfast boot configuration end diff --git a/unittest/syncd/Makefile.am b/unittest/syncd/Makefile.am index 4c75d3672..48d29995d 100644 --- a/unittest/syncd/Makefile.am +++ b/unittest/syncd/Makefile.am @@ -2,7 +2,7 @@ AM_CXXFLAGS = $(SAIINC) -I$(top_srcdir)/syncd -I$(top_srcdir)/lib -I$(top_srcdir bin_PROGRAMS = tests -LDADD_GTEST = -L/usr/src/gtest -lgtest -lgtest_main +LDADD_GTEST = -L/usr/src/gtest -lgtest -lgtest_main -lgmock tests_SOURCES = main.cpp \ ../../meta/DummySaiInterface.cpp \ @@ -18,7 +18,8 @@ tests_SOURCES = main.cpp \ TestMdioIpcServer.cpp \ TestPortStateChangeHandler.cpp \ TestWorkaround.cpp \ - TestVendorSai.cpp + TestVendorSai.cpp \ + TestSyncd.cpp tests_CXXFLAGS = $(DBGFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS_COMMON) tests_LDFLAGS = -Wl,-rpath,$(top_srcdir)/lib/.libs -Wl,-rpath,$(top_srcdir)/meta/.libs diff --git a/unittest/syncd/TestSyncd.cpp b/unittest/syncd/TestSyncd.cpp new file mode 100644 index 000000000..baa6d014f --- /dev/null +++ b/unittest/syncd/TestSyncd.cpp @@ -0,0 +1,61 @@ +#include "Syncd.h" +#include "MockableSaiInterface.h" +#include "CommandLineOptions.h" +#include "sairediscommon.h" +#include "SelectableChannel.h" +#include "swss/dbconnector.h" +#include "swss/redisreply.h" + +#include +#include + +using namespace syncd; + +class MockSelectableChannel : public sairedis::SelectableChannel { +public: + MOCK_METHOD(bool, empty, (), (override)); + MOCK_METHOD(void, pop, (swss::KeyOpFieldsValuesTuple& kco, bool initViewMode), (override)); + MOCK_METHOD(void, set, (const std::string& key, const std::vector& values, const std::string& op), (override)); + MOCK_METHOD(int, getFd, (), (override)); + MOCK_METHOD(uint64_t, readData, (), (override)); +}; + +void clearDB() +{ + SWSS_LOG_ENTER(); + + swss::DBConnector db("ASIC_DB", 0, true); + swss::RedisReply r(&db, "FLUSHALL", REDIS_REPLY_STATUS); + + r.checkStatusOK(); +} + +class SyncdTest : public ::testing::Test +{ +protected: + void SetUp() override + { + clearDB(); + } + void TearDown() override + { + clearDB(); + } +}; + +TEST_F(SyncdTest, processNotifySyncd) +{ + auto sai = std::make_shared(); + auto opt = std::make_shared(); + opt->m_enableTempView = true; + opt->m_startType = SAI_START_TYPE_FASTFAST_BOOT; + syncd::Syncd syncd_object(sai, opt, false); + + MockSelectableChannel consumer; + EXPECT_CALL(consumer, empty()).WillOnce(testing::Return(true)); + EXPECT_CALL(consumer, pop(testing::_, testing::_)).WillOnce(testing::Invoke([](swss::KeyOpFieldsValuesTuple& kco, bool initViewMode) { + kfvKey(kco) = SYNCD_APPLY_VIEW; + kfvOp(kco) = REDIS_ASIC_STATE_COMMAND_NOTIFY; + })); + syncd_object.processEvent(consumer); +}