This makes the tests all pass cleanly when Address Sanitizer is enabled.
Signed-off-by: Ben Pfaff <[email protected]>
---
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(+)
diff --git a/Documentation/intro/install/general.rst
b/Documentation/intro/install/general.rst
index 71dfeaefca27..fa99491f6b50 100644
--- a/Documentation/intro/install/general.rst
+++ b/Documentation/intro/install/general.rst
@@ -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::
diff --git a/tests/atlocal.in b/tests/atlocal.in
index abfc1acf36d3..6f971cd652d7 100644
--- a/tests/atlocal.in
+++ b/tests/atlocal.in
@@ -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
diff --git a/tests/daemon.at b/tests/daemon.at
index b379fa83f9aa..fa4844ae8eaa 100644
--- a/tests/daemon.at
+++ b/tests/daemon.at
@@ -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])
diff --git a/tests/ovs-macros.at b/tests/ovs-macros.at
index 8389eeb2996a..f2e6114ae822 100644
--- a/tests/ovs-macros.at
+++ b/tests/ovs-macros.at
@@ -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
diff --git a/tests/ovsdb-server.at b/tests/ovsdb-server.at
index 4a71efbd5d7f..81f03d28b090 100644
--- a/tests/ovsdb-server.at
+++ b/tests/ovsdb-server.at
@@ -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])
--
2.16.1
_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev