Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
arvbb authored Sep 12, 2022
2 parents 348bffd + 660a920 commit c835dd1
Show file tree
Hide file tree
Showing 16 changed files with 408 additions and 47 deletions.
17 changes: 16 additions & 1 deletion .azure-pipelines/test-docker-sonic-vs-template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,22 @@ jobs:
docker ps
ip netns list
pushd sonic-swss/tests
sudo py.test -v --force-flaky --junitxml=tr.xml --imgname=docker-sonic-vs:$(Build.DefinitionName).$(Build.BuildNumber)
all_tests=$(ls test_*.py)
all_tests="${all_tests} p4rt"
test_set=()
# Run 20 tests as a set.
for test in ${all_tests}; do
test_set+=("${test}")
if [ ${#test_set[@]} -ge 20 ]; then
test_name=$(echo "${test_set[0]}" | cut -d "." -f 1)
echo "${test_set[*]}" | xargs sudo py.test -v --force-flaky --junitxml="${test_name}_tr.xml" --imgname=docker-sonic-vs:$(Build.DefinitionName).$(Build.BuildNumber)
test_set=()
fi
done
if [ ${#test_set[@]} -gt 0 ]; then
test_name=$(echo "${test_set[0]}" | cut -d "." -f 1)
echo "${test_set[*]}" | xargs sudo py.test -v --force-flaky --junitxml="${test_name}_tr.xml" --imgname=docker-sonic-vs:$(Build.DefinitionName).$(Build.BuildNumber)
fi
rm -rf $(Build.ArtifactStagingDirectory)/download
displayName: "Run vs tests"
Expand Down
2 changes: 2 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions lgtm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ extraction:
- autoconf-archive
- libgtest-dev
- libgmock-dev
- uuid
- uuid-dev
after_prepare:
- ls -l
- git clone https://github.com/Azure/sonic-swss-common; pushd sonic-swss-common; ./autogen.sh; fakeroot dpkg-buildpackage -us -uc -b; popd
Expand Down
97 changes: 53 additions & 44 deletions lib/ZeroMQChannel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using namespace sairedis;

#define ZMQ_RESPONSE_BUFFER_SIZE (4*1024*1024)
#define ZMQ_MAX_RETRY 10

ZeroMQChannel::ZeroMQChannel(
_In_ const std::string& endpoint,
Expand Down Expand Up @@ -219,14 +220,22 @@ void ZeroMQChannel::set(

SWSS_LOG_DEBUG("sending: %s", msg.c_str());

int rc = zmq_send(m_socket, msg.c_str(), msg.length(), 0);

if (rc <= 0)
for (int i = 0; true ; ++i)
{
SWSS_LOG_THROW("zmq_send failed, on endpoint %s, zmqerrno: %d: %s",
m_endpoint.c_str(),
zmq_errno(),
zmq_strerror(zmq_errno()));
int rc = zmq_send(m_socket, msg.c_str(), msg.length(), 0);

if (rc <= 0 && zmq_errno() == EINTR && i < ZMQ_MAX_RETRY)
{
continue;
}
if (rc <= 0)
{
SWSS_LOG_THROW("zmq_send failed, on endpoint %s, zmqerrno: %d: %s",
m_endpoint.c_str(),
zmq_errno(),
zmq_strerror(zmq_errno()));
}
break;
}
}

Expand All @@ -238,23 +247,7 @@ void ZeroMQChannel::del(

std::vector<swss::FieldValueTuple> values;

swss::FieldValueTuple opdata(key, command);

values.insert(values.begin(), opdata);

std::string msg = swss::JSon::buildJson(values);

SWSS_LOG_DEBUG("sending: %s", msg.c_str());

int rc = zmq_send(m_socket, msg.c_str(), msg.length(), 0);

if (rc <= 0)
{
SWSS_LOG_THROW("zmq_send failed, on endpoint %s, zmqerrno: %d: %s",
m_endpoint.c_str(),
zmq_errno(),
zmq_strerror(zmq_errno()));
}
set(key, values, command);
}

sai_status_t ZeroMQChannel::wait(
Expand All @@ -270,35 +263,51 @@ sai_status_t ZeroMQChannel::wait(
items[0].socket = m_socket;
items[0].events = ZMQ_POLLIN;

int rc = zmq_poll(items, 1, (int)m_responseTimeoutMs);
int rc;

if (rc == 0)
for (int i = 0; true ; ++i)
{
SWSS_LOG_ERROR("zmq_poll timed out for: %s", command.c_str());
rc = zmq_poll(items, 1, (int)m_responseTimeoutMs);

// notice, at this point we could throw, since in REP/REQ pattern
// we are forced to use send/recv in that specific order
if (rc == 0)
{
SWSS_LOG_ERROR("zmq_poll timed out for: %s", command.c_str());

return SAI_STATUS_FAILURE;
}
// notice, at this point we could throw, since in REP/REQ pattern
// we are forced to use send/recv in that specific order

if (rc < 0)
{
SWSS_LOG_THROW("zmq_poll failed, zmqerrno: %d", zmq_errno());
return SAI_STATUS_FAILURE;
}
if (rc < 0 && zmq_errno() == EINTR && i < ZMQ_MAX_RETRY)
{
continue;
}
if (rc < 0)
{
SWSS_LOG_THROW("zmq_poll failed, zmqerrno: %d", zmq_errno());
}
break;
}

rc = zmq_recv(m_socket, m_buffer.data(), ZMQ_RESPONSE_BUFFER_SIZE, 0);

if (rc < 0)
for (int i = 0; true ; ++i)
{
SWSS_LOG_THROW("zmq_recv failed, zmqerrno: %d", zmq_errno());
}
rc = zmq_recv(m_socket, m_buffer.data(), ZMQ_RESPONSE_BUFFER_SIZE, 0);

if (rc >= ZMQ_RESPONSE_BUFFER_SIZE)
{
SWSS_LOG_THROW("zmq_recv message was truncated (over %d bytes, received %d), increase buffer size, message DROPPED",
ZMQ_RESPONSE_BUFFER_SIZE,
rc);
if (rc < 0 && zmq_errno() == EINTR && i < ZMQ_MAX_RETRY)
{
continue;
}
if (rc < 0)
{
SWSS_LOG_THROW("zmq_recv failed, zmqerrno: %d", zmq_errno());
}
if (rc >= ZMQ_RESPONSE_BUFFER_SIZE)
{
SWSS_LOG_THROW("zmq_recv message was truncated (over %d bytes, received %d), increase buffer size, message DROPPED",
ZMQ_RESPONSE_BUFFER_SIZE,
rc);
}
break;
}

m_buffer.at(rc) = 0; // make sure that we end string with zero before parse
Expand Down
8 changes: 8 additions & 0 deletions syncd/VendorSai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -671,6 +672,9 @@ sai_status_t VendorSai::bulkGetStats(
mode,
object_statuses,
counters);
#else // For vendors do not support this API
return SAI_STATUS_NOT_IMPLEMENTED;
#endif
}

sai_status_t VendorSai::bulkClearStats(
Expand All @@ -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,
Expand All @@ -696,6 +701,9 @@ sai_status_t VendorSai::bulkClearStats(
counter_ids,
mode,
object_statuses);
#else // For vendors do not support this API
return SAI_STATUS_NOT_IMPLEMENTED;
#endif
}

// BULK QUAD OID
Expand Down
51 changes: 51 additions & 0 deletions syncd/scripts/syncd_init_common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,55 @@ config_syncd_innovium()
mkdir -p $II_ROOT
}

config_syncd_xsight()
{
SYS_MODE="asic"
CFG_FILE="/etc/sonic/xlink.cfg"
LABEL_REVISION_FILE="/etc/sonic/hw_revision"
ONIE_MACHINE=`sed -n -e 's/^.*onie_machine=//p' /etc/machine.conf`

ln -sf /usr/share/sonic/hwsku/xdrv_config.json /etc/xsight/xdrv_config.json
ln -sf /usr/share/sonic/hwsku/xlink_cfg.json /etc/xsight/xlink_cfg.json
ln -sf /usr/share/sonic/hwsku/lanes_polarity.json /etc/xsight/lanes_polarity.json

if [ -f ${LABEL_REVISION_FILE} ]; then
LABEL_REVISION=`cat ${LABEL_REVISION_FILE}`
if [[ x${LABEL_REVISION} == x"R0B" ]] || [[ x${LABEL_REVISION} == x"R0B2" ]]; then
ln -sf /etc/xsight/serdes_config_A0.json /etc/xsight/serdes_config.json
else
ln -sf /etc/xsight/serdes_config_A1.json /etc/xsight/serdes_config.json
fi
fi

#export XLOG_DEBUG="XSW SAI SAI-HOST XHAL-TBL XHAL-LKP XHAL-LPM XHAL-TCAM XHAL-DTE XHAL-RNG XHAL-SP XHAL-RPC"
export XLOG_SYSLOG=ALL
export XLOG_LEVEL=ERROR
#export XLOG_FILE="/tmp/xsai.log"

#ports for XCLI Thrift client
export SAI_RPC_PORT=31000
export XSW_RPC_PORT=31001
export XHAL_RPC_PORT=31002

if [[ ${ONIE_MACHINE,,} != *"kvm"* ]]; then
# Working on HW box. Determine what to run XBM/ASIC
if [[ -f ${CFG_FILE} ]]; then
SYS_MODE=`sed -n -e 's/^.*sys_mode[[:blank:]]*=[[:blank:]]*//p' ${CFG_FILE}`
fi
else
SYS_MODE="xbm"
fi

if [[ ${SYS_MODE,,} == "xbm" ]]; then
rm -f /xbm/log/*
/xbm/run_xbm.sh &
else
export XDRV_PLUGIN_SO=libxpci_drv_plugin.so
fi

CMD_ARGS+=" -p $HWSKU_DIR/sai.profile"
}

config_syncd()
{
check_warm_boot
Expand Down Expand Up @@ -327,6 +376,8 @@ config_syncd()
config_syncd_innovium
elif [ "$SONIC_ASIC_TYPE" == "soda" ]; then
config_syncd_soda
elif [ "$SONIC_ASIC_TYPE" == "xsight" ]; then
config_syncd_xsight
else
echo "Unknown ASIC type $SONIC_ASIC_TYPE"
exit 1
Expand Down
55 changes: 55 additions & 0 deletions tests/tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

#include "meta/sai_serialize.h"

#include <unistd.h>
#include <signal.h>
#include <thread>
#include <memory>

Expand All @@ -19,6 +21,18 @@ using namespace sairedis;

#define ASSERT_EQ(a,b) if ((a) != (b)) { SWSS_LOG_THROW("ASSERT EQ FAILED: " #a " != " #b); }

#define ASSERT_THROW(a,b) \
try { \
a; \
SWSS_LOG_ERROR("ASSERT_THROW FAILED"); \
exit(1); \
} \
catch(const b &e) { \
} \
catch(...) { \
SWSS_LOG_THROW("ASSERT_THROW FAILED"); \
}

/*
* Test if destructor proper clean and join zeromq socket and context, and
* break recv method.
Expand Down Expand Up @@ -86,13 +100,54 @@ static void test_zeromqchannel_first_notification()
}
}

void send_signals()
{
SWSS_LOG_ENTER();
pid_t pid = getpid();
for (int i = 0; i < 11; ++i)
{
sleep(1);
kill(pid, SIGHUP);
}
};

/*
* Test if runtime_error will be thrown if zmq wait reaches max retry due to
* signal interrupt.
*/
static void test_zeromqchannel_eintr_errno_on_wait()
{
SWSS_LOG_ENTER();

std::cout << " * " << __FUNCTION__ << std::endl;

ZeroMQChannel z("ipc:///tmp/feeds1", "ipc:///tmp/feeds2", nullptr);
z.setResponseTimeout(60000);

std::thread signal_thread(send_signals);

swss::KeyOpFieldsValuesTuple kco;
ASSERT_THROW(z.wait("foo", kco), std::runtime_error);

signal_thread.join();
}

void sighup_handler(int signo)
{
SWSS_LOG_ENTER();
}

int main()
{
SWSS_LOG_ENTER();

signal(SIGHUP, sighup_handler);

test_zeromqchannel_destructor();

test_zeromqchannel_first_notification();

test_zeromqchannel_eintr_errno_on_wait();

return 0;
}
3 changes: 2 additions & 1 deletion unittest/syncd/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ tests_SOURCES = main.cpp \
TestVirtualOidTranslator.cpp \
TestNotificationQueue.cpp \
TestNotificationProcessor.cpp \
TestNotificationHandler.cpp
TestNotificationHandler.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)
Expand Down
Loading

0 comments on commit c835dd1

Please sign in to comment.