From patchwork Thu Nov 15 06:05:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Pfaff X-Patchwork-Id: 998098 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=openvswitch.org (client-ip=140.211.169.12; helo=mail.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ovn.org Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42wWDC3HJnz9s8F for ; Thu, 15 Nov 2018 17:09:47 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 45075BD5; Thu, 15 Nov 2018 06:06:00 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id B0E8FBA0 for ; Thu, 15 Nov 2018 06:05:58 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from relay10.mail.gandi.net (relay10.mail.gandi.net [217.70.178.230]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 5A39775B for ; Thu, 15 Nov 2018 06:05:57 +0000 (UTC) Received: from sigabrt.attlocal.net (75-54-222-30.lightspeed.rdcyca.sbcglobal.net [75.54.222.30]) (Authenticated sender: blp@ovn.org) by relay10.mail.gandi.net (Postfix) with ESMTPSA id C7D1824000A; Thu, 15 Nov 2018 06:05:54 +0000 (UTC) From: Ben Pfaff To: dev@openvswitch.org Date: Wed, 14 Nov 2018 22:05:34 -0800 Message-Id: <20181115060534.7146-10-blp@ovn.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20181115060534.7146-1-blp@ovn.org> References: <20181115060534.7146-1-blp@ovn.org> X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Cc: Ben Pfaff Subject: [ovs-dev] [PATCH 10/10] tests: Add support for Address Sanitizer. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org This makes the tests all pass cleanly when Address Sanitizer is enabled. Signed-off-by: Ben Pfaff Acked-by: Justin Pettit --- 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])