Skip to content

Commit

Permalink
tests: Add support for Address Sanitizer.
Browse files Browse the repository at this point in the history
This makes the tests all pass cleanly when Address Sanitizer is enabled.

Acked-by: Mark Michelson <mmichels@redhat.com>
Acked-by: Justin Pettit <jpettit@ovn.org>
Signed-off-by: Ben Pfaff <blp@ovn.org>
  • Loading branch information
blp committed Dec 3, 2018
1 parent 21b5221 commit 5f223e9
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Documentation/intro/install/general.rst
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,13 @@ target machine.

$ make EXTRA_CFLAGS="-Wno-error=date-time"

If you are a developer and want to enable Address Sanitizer for debugging
purposes, at about a 2x runtime cost, you can add
``-fsanitize=address -fno-omit-frame-pointer -fno-common`` to CFLAGS. For
example::

$ ./configure CFLAGS="-g -O2 -fsanitize=address -fno-omit-frame-pointer -fno-common"

To build the Linux kernel module, so that you can run the kernel-based switch,
pass the location of the kernel build directory on ``--with-linux``. For
example, to build for a running instance of Linux::
Expand Down
8 changes: 8 additions & 0 deletions tests/atlocal.in
Original file line number Diff line number Diff line change
Expand Up @@ -220,3 +220,11 @@ export OVS_SYSLOG_METHOD
# Set default timeout for control utils
OVS_CTL_TIMEOUT=30
export OVS_CTL_TIMEOUT

# Add some default flags to make the tests run better under Address
# Sanitizer, if it was used for the build.
#
# We disable leak detection because otherwise minor leaks that don't
# matter break everything.
ASAN_OPTIONS=detect_leaks=0:abort_on_error=true:log_path=asan:$ASAN_OPTIONS
export ASAN_OPTIONS
8 changes: 8 additions & 0 deletions tests/daemon.at
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ AT_CLEANUP

AT_SETUP([daemon --monitor])
AT_SKIP_IF([test "$IS_WIN32" = "yes"])

# This test intentionally causes SIGSEGV, so make Address Sanitizer ignore it.
ASAN_OPTIONS=$ASAN_OPTIONS:handle_segv=0; export ASAN_OPTIONS

OVSDB_INIT([db])
AT_CAPTURE_FILE([pid])
AT_CAPTURE_FILE([parent])
Expand Down Expand Up @@ -101,6 +105,10 @@ AT_CLEANUP

AT_SETUP([daemon --detach --monitor])
AT_SKIP_IF([test "$IS_WIN32" = "yes"])

# This test intentionally causes SIGSEGV, so make Address Sanitizer ignore it.
ASAN_OPTIONS=$ASAN_OPTIONS:handle_segv=0; export ASAN_OPTIONS

OVSDB_INIT([db])
AT_CAPTURE_FILE([daemon])
AT_CAPTURE_FILE([olddaemon])
Expand Down
14 changes: 14 additions & 0 deletions tests/ovs-macros.at
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ m4_define([AT_SETUP], [OVS_AT_SETUP($@)
ovs_init
])

dnl Make AT_CLEANUP check for Address Sanitizer errors as the last step
dnl in every test.
m4_rename([AT_CLEANUP], [OVS_AT_CLEANUP])
m4_define([AT_CLEANUP], [ovs_cleanup
OVS_AT_CLEANUP($@)
])

dnl OVS_START_SHELL_HELPERS...OVS_END_SHELL_HELPERS may bracket shell
dnl function definitions that invoke AT_CHECK and other Autotest macros
dnl that can ordinarily be run only within AT_SETUP...AT_CLEANUP.
Expand Down Expand Up @@ -180,6 +187,13 @@ fi
m4_divert_pop([PREPARE_TESTS])

OVS_START_SHELL_HELPERS
ovs_cleanup() {
if test "$(echo asan.*)" != 'asan.*'; then
echo "Address Sanitizer reported errors in:" asan.*
AT_FAIL_IF([:])
fi
}

ovs_wait () {
echo "$1: waiting $2..." >&AS_MESSAGE_LOG_FD

Expand Down
16 changes: 16 additions & 0 deletions tests/ovsdb-server.at
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,10 @@ AT_CLEANUP
AT_SETUP([ovsdb-server/add-db with --monitor])
AT_KEYWORDS([ovsdb server positive])
AT_SKIP_IF([test "$IS_WIN32" = "yes"])

# This test intentionally causes SIGSEGV, so make Address Sanitizer ignore it.
ASAN_OPTIONS=$ASAN_OPTIONS:handle_segv=0; export ASAN_OPTIONS

# Start ovsdb-server, initially with one db.
ordinal_schema > schema
AT_CHECK([ovsdb-tool create db1 schema], [0], [ignore], [ignore])
Expand Down Expand Up @@ -316,6 +320,10 @@ AT_CLEANUP
AT_SETUP([ovsdb-server/add-db and remove-db with --monitor])
AT_KEYWORDS([ovsdb server positive])
AT_SKIP_IF([test "$IS_WIN32" = "yes"])

# This test intentionally causes SIGSEGV, so make Address Sanitizer ignore it.
ASAN_OPTIONS=$ASAN_OPTIONS:handle_segv=0; export ASAN_OPTIONS

# Start ovsdb-server, initially with one db.
ordinal_schema > schema
AT_CHECK([ovsdb-tool create db1 schema], [0], [ignore], [ignore])
Expand Down Expand Up @@ -462,6 +470,10 @@ AT_CLEANUP
AT_SETUP([ovsdb-server/add-remote with --monitor])
AT_KEYWORDS([ovsdb server positive])
AT_SKIP_IF([test "$IS_WIN32" = "yes"])

# This test intentionally causes SIGSEGV, so make Address Sanitizer ignore it.
ASAN_OPTIONS=$ASAN_OPTIONS:handle_segv=0; export ASAN_OPTIONS

# Start ovsdb-server, initially with no remotes.
ordinal_schema > schema
AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
Expand Down Expand Up @@ -493,6 +505,10 @@ AT_CLEANUP
AT_SETUP([ovsdb-server/add-remote and remove-remote with --monitor])
AT_KEYWORDS([ovsdb server positive])
AT_SKIP_IF([test "$IS_WIN32" = "yes"])

# This test intentionally causes SIGSEGV, so make Address Sanitizer ignore it.
ASAN_OPTIONS=$ASAN_OPTIONS:handle_segv=0; export ASAN_OPTIONS

# Start ovsdb-server, initially with no remotes.
ordinal_schema > schema
AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore])
Expand Down

0 comments on commit 5f223e9

Please sign in to comment.