From 1a77240d1c5b948a3d70bbcf1ed871e6b505007f Mon Sep 17 00:00:00 2001 From: junchao Date: Wed, 17 Aug 2022 11:35:08 +0800 Subject: [PATCH 1/3] Fix issue: bulk counter feature cannot compile on platforms having no sai_bulk_object_get_stats/sai_bulk_object_clear_stats --- configure.ac | 2 ++ syncd/VendorSai.cpp | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/configure.ac b/configure.ac index 6dc404010..b477f6b96 100644 --- a/configure.ac +++ b/configure.ac @@ -207,6 +207,8 @@ AC_MSG_ERROR("SAI headers API version and library version mismatch")])]) CXXFLAGS="$SAVED_FLAGS" ])]) +AC_CHECK_FUNCS(sai_bulk_object_clear_stats sai_bulk_object_get_stats) + AC_OUTPUT(Makefile meta/Makefile lib/Makefile diff --git a/syncd/VendorSai.cpp b/syncd/VendorSai.cpp index c7ce4eec9..4a8aec142 100644 --- a/syncd/VendorSai.cpp +++ b/syncd/VendorSai.cpp @@ -661,6 +661,7 @@ sai_status_t VendorSai::bulkGetStats( SWSS_LOG_ENTER(); VENDOR_CHECK_API_INITIALIZED(); +#ifdef HAVE_SAI_BULK_OBJECT_GET_STATS return sai_bulk_object_get_stats( switchId, object_type, @@ -671,6 +672,9 @@ sai_status_t VendorSai::bulkGetStats( mode, object_statuses, counters); +#else + return SAI_STATUS_NOT_IMPLEMENTED; +#endif } sai_status_t VendorSai::bulkClearStats( @@ -687,6 +691,7 @@ sai_status_t VendorSai::bulkClearStats( SWSS_LOG_ENTER(); VENDOR_CHECK_API_INITIALIZED(); +#ifdef HAVE_SAI_BULK_OBJECT_CLEAR_STATS return sai_bulk_object_clear_stats( switchId, object_type, @@ -696,6 +701,9 @@ sai_status_t VendorSai::bulkClearStats( counter_ids, mode, object_statuses); +#else + return SAI_STATUS_NOT_IMPLEMENTED; +#endif } // BULK QUAD OID From 262420d6a67aeda9afd53d1e02f22040094bd141 Mon Sep 17 00:00:00 2001 From: junchao Date: Thu, 25 Aug 2022 13:44:34 +0800 Subject: [PATCH 2/3] Update UT coverage --- unittest/syncd/Makefile.am | 3 +- unittest/syncd/TestVendorSai.cpp | 59 ++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 unittest/syncd/TestVendorSai.cpp diff --git a/unittest/syncd/Makefile.am b/unittest/syncd/Makefile.am index 6564f222f..1c15332d8 100644 --- a/unittest/syncd/Makefile.am +++ b/unittest/syncd/Makefile.am @@ -11,7 +11,8 @@ tests_SOURCES = main.cpp \ TestCommandLineOptions.cpp \ TestFlexCounter.cpp \ TestVirtualOidTranslator.cpp \ - TestNotificationQueue.cpp + TestNotificationQueue.cpp \ + TestVendorSai.cpp tests_CXXFLAGS = $(DBGFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS_COMMON) tests_LDADD = $(LDADD_GTEST) $(top_srcdir)/syncd/libSyncd.a $(top_srcdir)/vslib/libSaiVS.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) diff --git a/unittest/syncd/TestVendorSai.cpp b/unittest/syncd/TestVendorSai.cpp new file mode 100644 index 000000000..b598146e5 --- /dev/null +++ b/unittest/syncd/TestVendorSai.cpp @@ -0,0 +1,59 @@ +#include +#include "VendorSai.h" +#include "swss/logger.h" + +#ifdef HAVE_SAI_BULK_OBJECT_GET_STATS +#undef HAVE_SAI_BULK_OBJECT_GET_STATS +#endif + +using namespace syncd; + +static const char* profile_get_value( + _In_ sai_switch_profile_id_t profile_id, + _In_ const char* variable) +{ + SWSS_LOG_ENTER(); + + if (variable == NULL) + return NULL; + + return nullptr; +} + +static int profile_get_next_value( + _In_ sai_switch_profile_id_t profile_id, + _Out_ const char** variable, + _Out_ const char** value) +{ + SWSS_LOG_ENTER(); + + return 0; +} + +static sai_service_method_table_t test_services = { + profile_get_value, + profile_get_next_value +}; + +TEST(VendorSai, bulkGetStats) +{ + VendorSai sai; + sai.initialize(0, &test_services); + ASSERT_EQ(SAI_STATUS_NOT_IMPLEMENTED, sai.bulkGetStats(SAI_NULL_OBJECT_ID, + SAI_OBJECT_TYPE_PORT, + 0, + nullptr, + 0, + nullptr, + SAI_STATS_MODE_BULK_READ_AND_CLEAR, + nullptr, + nullptr)); + ASSERT_EQ(SAI_STATUS_NOT_IMPLEMENTED, sai.bulkClearStats(SAI_NULL_OBJECT_ID, + SAI_OBJECT_TYPE_PORT, + 0, + nullptr, + 0, + nullptr, + SAI_STATS_MODE_BULK_READ_AND_CLEAR, + nullptr)); +} From fe7de1239a426f5022202139eba6646980fccc04 Mon Sep 17 00:00:00 2001 From: Junchao-Mellanox <57339448+Junchao-Mellanox@users.noreply.github.com> Date: Tue, 6 Sep 2022 16:22:03 +0800 Subject: [PATCH 3/3] Update VendorSai.cpp --- syncd/VendorSai.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/syncd/VendorSai.cpp b/syncd/VendorSai.cpp index 4a8aec142..13434e779 100644 --- a/syncd/VendorSai.cpp +++ b/syncd/VendorSai.cpp @@ -672,7 +672,7 @@ sai_status_t VendorSai::bulkGetStats( mode, object_statuses, counters); -#else +#else // For vendors do not support this API return SAI_STATUS_NOT_IMPLEMENTED; #endif } @@ -701,7 +701,7 @@ sai_status_t VendorSai::bulkClearStats( counter_ids, mode, object_statuses); -#else +#else // For vendors do not support this API return SAI_STATUS_NOT_IMPLEMENTED; #endif }