diff mbox

Asan/Tsan Unit/Regression testing (was [asan] Emit GIMPLE direclty, small cleanups)

Message ID 20121114095202.GC1886@tucnak.redhat.com
State New
Headers show

Commit Message

Jakub Jelinek Nov. 14, 2012, 9:52 a.m. UTC
On Tue, Nov 13, 2012 at 11:13:03AM -0800, Wei Mi wrote:
> I migrate a test in the third category. Please help to check whether
> it is ok. Then I will migrate the left. The files added are as follows
> and attached. (Please forgive I use -fasan in asan.exp because I use
> an old repository to try the migration)

I don't like it.  While I am nowhere close to be an experienced tcl
hacker, IMHO you copy lots of unneeded cruft, on the other side you are
missing important details (and mudflap was a particularly bad choice
to copy bits from).

Here is my alternative, so far missing any bits to actually run addr2line
on the output and match the backtraces if requested.

With this, tests for C and C++ can be placed in c-c++-common/*.c, C only tests
in gcc.dg/asan/*.c and C++ only tests in g++.dg/asan/*.C.
make check RUNTESTFLAGS='--target_board=unix\{-m32,-m64\} asan.exp'
should run both all C and all C++ tests, with both -m32 and -m64 (and
torture through all standard -O* options e.g. dg-torture.exp cycles
through).  dg-options can be left out, -faddress-sanitizer is implied
(would need to be overridden by -fno-address-sanitizer), -fno-builtin-memcmp
is on the example test just if we later on match the backtrace, because
without it memcmp won't appear in the backtrace, just main (as the bug
is caught already there).  I've also tweaked the test to 5+argc instead
of 4+argc, I fear that on some embedded targets argc can be 0.

2012-11-14  Jakub Jelinek  <jakub@redhat.com>

	* lib/asan-dg.exp: New file.
	* gcc.dg/asan/asan.exp: New file.
	* g++.dg/dg.exp: Prune also asan tests.
	* g++.dg/asan/asan.exp: New file.
	* c-c++-common/asan/memcmp-1.c: New test.


	Jakub
diff mbox

Patch

--- gcc/testsuite/lib/asan-dg.exp.jj	2012-11-14 09:11:13.086054131 +0100
+++ gcc/testsuite/lib/asan-dg.exp	2012-11-14 10:37:18.904032326 +0100
@@ -0,0 +1,88 @@ 
+# Copyright (C) 2012 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GCC; see the file COPYING3.  If not see
+# <http://www.gnu.org/licenses/>.
+
+load_lib target-libpath.exp
+
+# Return 1 if compilation with -faddress-sanitizer is error-free for trivial
+# code, 0 otherwise.
+
+proc check_effective_target_faddress_sanitizer {} {
+    return [check_no_compiler_messages faddress_sanitizer object {
+        void foo (void) { }
+    } "-faddress-sanitizer"]
+}
+
+#
+# asan_link_flags -- compute library path and flags to find libasan.
+# (originally from g++.exp)
+#
+
+proc asan_link_flags { paths } {
+    global srcdir
+    global ld_library_path
+    global shlib_ext
+
+    set gccpath ${paths}
+    set flags ""
+
+    set shlib_ext [get_shlib_extension]
+
+    if { $gccpath != "" } {
+      if { [file exists "${gccpath}/libsanitizer/asan/.libs/libasan.a"]
+	   || [file exists "${gccpath}/libsanitizer/asan/.libs/libasan.${shlib_ext}"] } {
+          append flags " -L${gccpath}/libsanitizer/asan/.libs "
+          append ld_library_path ":${gccpath}/libsanitizer/asan/.libs"
+      }
+    } else {
+      global tool_root_dir
+
+      set libasan [lookfor_file ${tool_root_dir} libasan]
+      if { $libasan != "" } {
+          append flags "-L${libasan} "
+          append ld_library_path ":${libasan}"
+      }
+    }
+
+    set_ld_library_path_env_vars
+
+    return "$flags"
+}
+
+#
+# asan_init -- called at the start of each subdir of tests
+#
+
+proc asan_init { args } {
+    global TEST_ALWAYS_FLAGS
+    global ALWAYS_CXXFLAGS
+    global TOOL_OPTIONS
+
+    set link_flags ""
+    if ![is_remote host] {
+	if [info exists TOOL_OPTIONS] {
+	    set link_flags "[asan_link_flags [get_multilibs ${TOOL_OPTIONS}]]"
+	} else {
+	    set link_flags "[asan_link_flags [get_multilibs]]"
+	}
+    }
+
+    if [info exists ALWAYS_CXXFLAGS] {
+	set ALWAYS_CXXFLAGS [concat "{ldflags=$link_flags}" $ALWAYS_CXXFLAGS]
+	set ALWAYS_CXXFLAGS [concat "{additional_flags=-faddress-sanitizer}" $ALWAYS_CXXFLAGS]
+    } else {
+	set TEST_ALWAYS_FLAGS "$link_flags -faddress-sanitizer $TEST_ALWAYS_FLAGS"
+    }
+}
--- gcc/testsuite/gcc.dg/asan/asan.exp.jj	2012-11-14 10:25:31.504713624 +0100
+++ gcc/testsuite/gcc.dg/asan/asan.exp	2012-11-14 10:27:08.109935623 +0100
@@ -0,0 +1,37 @@ 
+# Copyright (C) 2012 Free Software Foundation, Inc.
+#
+# This file is part of GCC.
+#
+# GCC is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GCC is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GCC; see the file COPYING3.  If not see
+# <http://www.gnu.org/licenses/>.
+
+# GCC testsuite that uses the `dg.exp' driver.
+
+# Load support procs.
+load_lib gcc-dg.exp
+load_lib asan-dg.exp
+
+if ![check_effective_target_faddress_sanitizer] {
+  return
+}
+
+# Initialize `dg'.
+dg-init
+asan_init
+
+# Main loop.
+gcc-dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.c $srcdir/c-c++-common/asan/*.c]] ""
+
+# All done.
+dg-finish
--- gcc/testsuite/g++.dg/dg.exp.jj	2011-11-10 18:09:12.000000000 +0100
+++ gcc/testsuite/g++.dg/dg.exp	2012-11-14 09:07:04.043033232 +0100
@@ -1,4 +1,5 @@ 
-#   Copyright (C) 2000, 2007, 2009, 2010 Free Software Foundation, Inc.
+#   Copyright (C) 2000, 2007, 2009, 2010, 2011, 2012
+#   Free Software Foundation, Inc.
 
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -50,6 +51,7 @@  set tests [prune $tests $srcdir/$subdir/
 set tests [prune $tests $srcdir/$subdir/tm/*]
 set tests [prune $tests $srcdir/$subdir/guality/*]
 set tests [prune $tests $srcdir/$subdir/simulate-thread/*]
+set tests [prune $tests $srcdir/$subdir/asan/*]
 
 # Main loop.
 g++-dg-runtest $tests $DEFAULT_CXXFLAGS
--- gcc/testsuite/g++.dg/asan/asan.exp.jj	2012-11-14 09:08:58.748511740 +0100
+++ gcc/testsuite/g++.dg/asan/asan.exp	2012-11-14 10:27:13.571985934 +0100
@@ -0,0 +1,35 @@ 
+# Copyright (C) 2012 Free Software Foundation, Inc.
+#
+# This file is part of GCC.
+#
+# GCC is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GCC is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GCC; see the file COPYING3.  If not see
+# <http://www.gnu.org/licenses/>.
+
+# Load support procs.
+load_lib g++-dg.exp
+load_lib asan-dg.exp
+
+if ![check_effective_target_faddress_sanitizer] {
+  return
+}
+
+# Initialize `dg'.
+dg-init
+asan_init
+
+# Main loop.
+gcc-dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.C $srcdir/c-c++-common/asan/*.c]] ""
+
+# All done.
+dg-finish
--- gcc/testsuite/c-c++-common/asan/memcmp-1.c.jj	2012-11-14 10:21:19.881128491 +0100
+++ gcc/testsuite/c-c++-common/asan/memcmp-1.c	2012-11-14 10:21:15.820152280 +0100
@@ -0,0 +1,16 @@ 
+/* { dg-do run } */
+/* { dg-options "-fno-builtin-memcmp" } */
+/* { dg-shouldfail "asan" } */
+
+#include <string.h>
+
+int
+main (int argc, char **argv)
+{
+  char a1[] = {argc, 2, 3, 4};
+  char a2[] = {1, 2*argc, 3, 4};
+  int res = memcmp (a1, a2, 5 + argc);
+  return res;
+}
+
+/* { dg-output "ERROR: AddressSanitizer stack-buffer-overflow.*" } */