Skip to content

Added sanitizer testing for swss-common unit test. #561

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions .azure-pipelines/build-template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ jobs:
sudo dpkg -i python-swsscommon_*.deb

./tests/tests
./tests/tests_asan
./tests/tests_tsan
./tests/tests_usan
redis-cli FLUSHALL
pytest --cov=. --cov-report=xml
mv coverage.xml tests/coverage.xml
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ stamp-h1
###############
common/swssloglevel
tests/tests
tests/tests_asan
tests/tests_tsan
tests/tests_usan

# Bazel Build System #
/bazel-*
23 changes: 22 additions & 1 deletion tests/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
INCLUDES = -I $(top_srcdir)

bin_PROGRAMS = tests
bin_PROGRAMS = tests tests_asan tests_tsan tests_usan

if DEBUG
DBGFLAGS = -ggdb -DDEBUG
Expand All @@ -10,6 +10,9 @@ endif

CFLAGS_GTEST =
LDADD_GTEST = -L/usr/src/gtest -lgtest -lgtest_main -lgmock -lgmock_main
CFLAGS_ASAN = -fsanitize=address -static-libasan
CFLAGS_TSAN = -fsanitize=thread
CFLAGS_USAN = -fsanitize=undefined
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not combine them together? Even further, just integrate all the options to the original tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It doesn't seem to work if I combine them.

Copy link
Contributor

Choose a reason for hiding this comment

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

Could you share the error message?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Address sanitizer cannot combine with thread sanitizer: https://gcc.gnu.org/onlinedocs/gcc/Instrumentation-Options.html
(Check "-fsanitize=address" or "-fsanitize=thread".)


tests_SOURCES = redis_ut.cpp \
redis_piped_ut.cpp \
Expand Down Expand Up @@ -40,3 +43,21 @@ tests_SOURCES = redis_ut.cpp \
tests_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_GTEST) $(LIBNL_CFLAGS)
tests_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_GTEST) $(LIBNL_CFLAGS)
tests_LDADD = $(LDADD_GTEST) -lpthread -L$(top_srcdir)/common -lswsscommon $(LIBNL_LIBS) $(CODE_COVERAGE_LIBS)

tests_asan_SOURCES = $(tests_SOURCES)
tests_asan_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_GTEST) $(LIBNL_CFLAGS)
tests_asan_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_GTEST) $(LIBNL_CFLAGS)
tests_asan_LDFLAGS = $(CFLAGS_ASAN)
tests_asan_LDADD = $(LDADD_GTEST) -lpthread -L$(top_srcdir)/common -lswsscommon $(LIBNL_LIBS)

tests_tsan_SOURCES = $(tests_SOURCES)
tests_tsan_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_GTEST) $(LIBNL_CFLAGS)
tests_tsan_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_GTEST) $(LIBNL_CFLAGS)
tests_tsan_LDFLAGS = $(CFLAGS_TSAN)
tests_tsan_LDADD = $(LDADD_GTEST) -lpthread -L$(top_srcdir)/common -lswsscommon $(LIBNL_LIBS)

tests_usan_SOURCES = $(tests_SOURCES)
tests_usan_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_GTEST) $(LIBNL_CFLAGS)
tests_usan_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_GTEST) $(LIBNL_CFLAGS)
tests_usan_LDFLAGS = $(CFLAGS_USAN)
tests_usan_LDADD = $(LDADD_GTEST) -lpthread -L$(top_srcdir)/common -lswsscommon $(LIBNL_LIBS)