>> > 3. Full output tests (a .cc file should be build with asan switch, >> > executable should be run and the stderr is compared with the expected >> > output) >> > Example: >> > http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/lit_tests/stack-overflow.cc?revision=165391&view=markup >> > The can be ported to GCC, but the uses of FileCheck >> > (http://llvm.org/docs/CommandGuide/FileCheck.html) will need to be >> > replaced with GCC's analog. >> > We should probably start with these tests. >> >> Dejagnu in GCC has >> >> ! { dg-do run } >> ! { dg-options "-fbounds-check" } >> ! { dg-shouldfail "Duplicate value 2 in ORDER argument to RESHAPE >> intrinsic" } >> program main >> implicit none >> integer(kind=1), dimension(6) :: source1 = (/ 1, 2, 3, 4, 5, 6 /) >> integer, dimension(2) :: shape1 = (/ 2, 3/) >> integer(kind=1), dimension(2) :: pad1 = (/ 0, 0/) >> character(len=200) :: l1, l2 >> integer :: i1, i2 >> >> l1 = "2 2" >> read(unit=l1,fmt=*) i1, i2 >> write (unit=l2,fmt=*) reshape(source1, shape1, pad1, (/i1, i2/)) ! >> Invalid >> end program main >> ! { dg-output "Fortran runtime error: Duplicate value 2 in ORDER argument >> to RESHAPE intrinsic" } >> >> style markings, dg-shouldfail says that the program is expected to fail >> rather than pass (if it aborts), and dg-output (perhaps multiple) can >> contain regexps to match against stderr + stdout joined. Haven't looked >> at the asan tests yet, do you expect just one ASAN abort per test, > > > These tests do just one abort (actually, _exit(1)) per test. > Let's start with these. > > --kcc >
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)
gcc/testsuite/lib/asan-dg.exp:
copy from libmudflap/lib/mfdg.exp, it rewrites the proc
dg-test, to enable dg-output check in xfail status. Existing
dg-output check in /usr/share/dejagnu/dg.exp only work in pass status
but not in xfail status.
gcc/testsuite/g++.dg/asan/asan.exp
gcc/testsuite/g++.dg/asan/memcmp_test.cc
A problem: llvm provides llvm-symbolizer and asan_symbolize.py to map
virtual address to its parent func name, which is used in "CHECK:
{{#0.*memcmp}}" in llvm test below. I don't know whether gcc provides
similar tools. How to deal with it?
memcmp_test.cc in llvm:
1 // RUN: %clangxx_asan -m64 -O0 %s -o %t %lib && %t 2>&1 |
%symbolize | FileCheck %s
2 // RUN: %clangxx_asan -m64 -O1 %s -o %t %lib && %t 2>&1 |
%symbolize | FileCheck %s
3 // RUN: %clangxx_asan -m64 -O2 %s -o %t %lib && %t 2>&1 |
%symbolize | FileCheck %s
4 // RUN: %clangxx_asan -m64 -O3 %s -o %t %lib && %t 2>&1 |
%symbolize | FileCheck %s
5 // RUN: %clangxx_asan -m32 -O0 %s -o %t %lib && %t 2>&1 |
%symbolize | FileCheck %s
6 // RUN: %clangxx_asan -m32 -O1 %s -o %t %lib && %t 2>&1 |
%symbolize | FileCheck %s
7 // RUN: %clangxx_asan -m32 -O2 %s -o %t %lib && %t 2>&1 |
%symbolize | FileCheck %s
8 // RUN: %clangxx_asan -m32 -O3 %s -o %t %lib && %t 2>&1 |
%symbolize | FileCheck %s
9
10 #include <string.h>
11 int main(int argc, char **argv) {
12 char a1[] = {argc, 2, 3, 4};
13 char a2[] = {1, 2*argc, 3, 4};
14 int res = memcmp(a1, a2, 4 + argc); // BOOM
15 // CHECK: AddressSanitizer stack-buffer-overflow
16 // CHECK: {{#0.*memcmp}}
17 // CHECK: {{#1.*main}}
18 return res;
19 }
memcmp_test.cc planed for gcc:
1 #include <string.h>
2 int main(int argc, char **argv) {
3 char a1[] = {argc, 2, 3, 4};
4 char a2[] = {1, 2*argc, 3, 4};
5 int res = memcmp(a1, a2, 4 + argc); // BOOM
6 return res;
7 }
8
9 /* { dg-output "AddressSanitizer stack-buffer-overflow.*" } */
10 /* { dg-do run { xfail *-*-* } } */
11
Thanks,
Wei.
asan-dg.exp
Description: Binary data
asan.exp
Description: Binary data
memcmp_test.cc
Description: Binary data
