@@ -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::
@@ -220,3 +220,8 @@ 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.
+ASAN_OPTIONS=detect_leaks=0:abort_on_error=true:log_path=asan:$ASAN_OPTIONS
+export ASAN_OPTIONS
@@ -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])
@@ -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])
@@ -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.
@@ -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
@@ -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])
@@ -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])
@@ -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])
@@ -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])
This makes the tests all pass cleanly when Address Sanitizer is enabled. Signed-off-by: Ben Pfaff <blp@ovn.org> --- Documentation/intro/install/general.rst | 7 +++++++ tests/atlocal.in | 5 +++++ tests/daemon.at | 8 ++++++++ tests/ovs-macros.at | 14 ++++++++++++++ tests/ovsdb-server.at | 16 ++++++++++++++++ 5 files changed, 50 insertions(+)