Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .azure-pipelines/build-template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,17 @@ jobs:
sudo mkdir /usr/local/yang-models

sudo dpkg -i libswsscommon_*.deb
sudo dpkg -i libswsscommon-dev_*.deb
sudo dpkg -i python-swsscommon_*.deb

./tests/tests
redis-cli FLUSHALL
pytest --cov=. --cov-report=xml
mv coverage.xml tests/coverage.xml
gcovr -r ./ -e ".*/swsscommon_wrap.cpp" --exclude-unreachable-branches --exclude-throw-branches -x --xml-pretty -o coverage.xml
redis-cli FLUSHALL
Copy link
Copy Markdown
Contributor

@qiluo-msft qiluo-msft Nov 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

redis-cli FLUSHALL

I guess you flush redis for test purpose, so it should be just above make -C goext check line. #Closed

make -C goext
make -C goext check

rm -rf $(Build.ArtifactStagingDirectory)/download
displayName: "Run swss common unit tests"
Expand Down
4 changes: 2 additions & 2 deletions common/configdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class ConfigDBConnector_Native : public SonicV2Connector_Native
std::string m_db_name;
};

#ifdef SWIG
#if defined(SWIG) && defined(SWIGPYTHON)
%pythoncode %{
## Note: diamond inheritance, reusing functions in both classes
class ConfigDBConnector(SonicV2Connector, ConfigDBConnector_Native):
Expand Down Expand Up @@ -307,7 +307,7 @@ class ConfigDBPipeConnector_Native: public ConfigDBConnector_Native
int _get_config(DBConnector& client, RedisTransactioner& pipe, std::map<std::string, std::map<std::string, std::map<std::string, std::string>>>& data, int cursor);
};

#ifdef SWIG
#if defined(SWIG) && defined(SWIGPYTHON)
%pythoncode %{
class ConfigDBPipeConnector(ConfigDBConnector, ConfigDBPipeConnector_Native):

Expand Down
2 changes: 1 addition & 1 deletion common/countertable.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class KeyCache {
return m_keyMap.at(name);
}

#ifdef SWIG
#if defined(SWIG) && defined(SWIGPYTHON)
%pythoncode %{
def __getitem__(self, name):
return self.at(name)
Expand Down
10 changes: 5 additions & 5 deletions common/dbconnector.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class SonicDBConfig
static constexpr const char *DEFAULT_SONIC_DB_CONFIG_FILE = "/var/run/redis/sonic-db/database_config.json";
static constexpr const char *DEFAULT_SONIC_DB_GLOBAL_CONFIG_FILE = "/var/run/redis/sonic-db/database_global.json";
static void initialize(const std::string &file = DEFAULT_SONIC_DB_CONFIG_FILE);
#ifdef SWIG
#if defined(SWIG) && defined(SWIGPYTHON)
%pythoncode %{
## TODO: the python function and C++ one is not on-par
@staticmethod
Expand All @@ -51,7 +51,7 @@ class SonicDBConfig
#endif

static void initializeGlobalConfig(const std::string &file = DEFAULT_SONIC_DB_GLOBAL_CONFIG_FILE);
#ifdef SWIG
#if defined(SWIG) && defined(SWIGPYTHON)
%pythoncode %{
## TODO: the python function and C++ one is not on-par
@staticmethod
Expand All @@ -70,7 +70,7 @@ class SonicDBConfig
static std::string getDbHostname(const std::string &dbName, const std::string &netns = EMPTY_NAMESPACE);
static int getDbPort(const std::string &dbName, const std::string &netns = EMPTY_NAMESPACE);
static std::vector<std::string> getNamespaces();
#ifdef SWIG
#if defined(SWIG) && defined(SWIGPYTHON)
%pythoncode %{
## TODO: the python function and C++ one is not on-par
@staticmethod
Expand Down Expand Up @@ -163,7 +163,7 @@ class DBConnector : public RedisContext
std::string getDbName() const;
std::string getNamespace() const;

#ifdef SWIG
#if defined(SWIG) && defined(SWIGPYTHON)
%pythoncode %{
namespace = property(getNamespace)
%}
Expand All @@ -181,7 +181,7 @@ class DBConnector : public RedisContext

int64_t del(const std::string &key);

#ifdef SWIG
#if defined(SWIG) && defined(SWIGPYTHON)
// SWIG interface file (.i) globally rename map C++ `del` to python `delete`,
// but applications already followed the old behavior of auto renamed `_del`.
// So we implemented old behavior for backward compatibility
Expand Down
2 changes: 1 addition & 1 deletion common/producerstatetable.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class ProducerStateTable : public TableBase, public TableName_KeySet
const std::string &op = DEL_COMMAND,
const std::string &prefix = EMPTY_PREFIX);

#ifdef SWIG
#if defined(SWIG) && defined(SWIGPYTHON)
// SWIG interface file (.i) globally rename map C++ `del` to python `delete`,
// but applications already followed the old behavior of auto renamed `_del`.
// So we implemented old behavior for backward compatibility
Expand Down
2 changes: 1 addition & 1 deletion common/producertable.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class ProducerTable : public TableBase, public TableName_KeyValueOpQueues
const std::string &op = DEL_COMMAND,
const std::string &prefix = EMPTY_PREFIX);

#ifdef SWIG
#if defined(SWIG) && defined(SWIGPYTHON)
// SWIG interface file (.i) globally rename map C++ `del` to python `delete`,
// but applications already followed the old behavior of auto renamed `_del`.
// So we implemented old behavior for backward compatibility
Expand Down
2 changes: 1 addition & 1 deletion common/sonicv2connector.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class SonicV2Connector_Native
std::string m_netns;
};

#ifdef SWIG
#if defined(SWIG) && defined(SWIGPYTHON)
%pythoncode %{
class SonicV2Connector(SonicV2Connector_Native):

Expand Down
4 changes: 2 additions & 2 deletions common/table.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class TableEntryPoppable {
}
};

#ifdef SWIG
#if defined(SWIG) && defined(SWIGPYTHON)
%pythoncode %{
def transpose_pops(m):
return [tuple(m[j][i] for j in range(len(m))) for i in range(len(m[0]))]
Expand Down Expand Up @@ -207,7 +207,7 @@ class Table : public TableBase, public TableEntryEnumerable {
/* Get the configured ttl value for key */
bool ttl(const std::string &key, int64_t &reply_value);

#ifdef SWIG
#if defined(SWIG) && defined(SWIGPYTHON)
// SWIG interface file (.i) globally rename map C++ `del` to python `delete`,
// but applications already followed the old behavior of auto renamed `_del`.
// So we implemented old behavior for backward compatibility
Expand Down
23 changes: 23 additions & 0 deletions goext/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
export CGO_LDFLAGS := -lswsscommon
export CGO_CXXFLAGS := -I/usr/include/swss/ -w -Wall -fpermissive

GO ?= /usr/local/go/bin/go
SWIG ?= /usr/bin/swig
RM=rm -f

SWIG_FLAG = -go -cgo -c++ -intgosize 64
ifeq ($(CONFIGURED_ARCH),arm64)
SWIG_FLAG += -DSWIGWORDSIZE64
endif

.PHONY: all check clean

all:
$(SWIG) $(SWIG_FLAG) -I/usr/include/swss/ swsscommon.i

check:
sudo CGO_LDFLAGS="$(CGO_LDFLAGS)" CGO_CXXFLAGS="$(CGO_CXXFLAGS)" $(GO) test

clean:
$(RM) swsscommon.go *.cxx

13 changes: 13 additions & 0 deletions goext/swsscommon.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
%module swsscommon
Copy link
Copy Markdown
Contributor

@qiluo-msft qiluo-msft Nov 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to reuse pyext/swsscommon.i? #Closed

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pyext/swsscommon.i is designed for python, and it has embedded python code:
https://github.com/sonic-net/sonic-swss-common/blob/master/pyext/swsscommon.i#L108
I think use another swig file will be better.


%{
#include "dbconnector.h"
#include "producerstatetable.h"
using namespace swss;
%}

%include "std_string.i"

%include "dbconnector.h"
%include "producerstatetable.h"

13 changes: 13 additions & 0 deletions goext/swsscommon_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package swsscommon

import (
"testing"
"os"
"path/filepath"
)

func TestSonicDBConfig(t *testing.T) {
pwd, _ := os.Getwd()
SonicDBConfigInitialize(filepath.Dir(pwd) + "/tests/redis_multi_db_ut_config/database_config.json")
}