xref: /aosp_15_r20/external/compiler-rt/test/asan/TestCases/log-path_test.cc (revision 7c3d14c8b49c529e04be81a3ce6f5cc23712e4c6)
1*7c3d14c8STreehugger Robot // FIXME: https://code.google.com/p/address-sanitizer/issues/detail?id=316
2*7c3d14c8STreehugger Robot // XFAIL: android
3*7c3d14c8STreehugger Robot //
4*7c3d14c8STreehugger Robot // The for loop in the backticks below requires bash.
5*7c3d14c8STreehugger Robot // REQUIRES: shell
6*7c3d14c8STreehugger Robot //
7*7c3d14c8STreehugger Robot // RUN: %clangxx_asan  %s -o %t
8*7c3d14c8STreehugger Robot 
9*7c3d14c8STreehugger Robot // Regular run.
10*7c3d14c8STreehugger Robot // RUN: not %run %t 2> %t.out
11*7c3d14c8STreehugger Robot // RUN: FileCheck %s --check-prefix=CHECK-ERROR < %t.out
12*7c3d14c8STreehugger Robot 
13*7c3d14c8STreehugger Robot // Good log_path.
14*7c3d14c8STreehugger Robot // RUN: rm -f %t.log.*
15*7c3d14c8STreehugger Robot // RUN: %env_asan_opts=log_path=%t.log not %run %t 2> %t.out
16*7c3d14c8STreehugger Robot // RUN: FileCheck %s --check-prefix=CHECK-ERROR < %t.log.*
17*7c3d14c8STreehugger Robot 
18*7c3d14c8STreehugger Robot // Invalid log_path.
19*7c3d14c8STreehugger Robot // RUN: %env_asan_opts=log_path=/dev/null/INVALID not %run %t 2> %t.out
20*7c3d14c8STreehugger Robot // RUN: FileCheck %s --check-prefix=CHECK-INVALID < %t.out
21*7c3d14c8STreehugger Robot 
22*7c3d14c8STreehugger Robot // Too long log_path.
23*7c3d14c8STreehugger Robot // RUN: %env_asan_opts=log_path=`for((i=0;i<10000;i++)); do echo -n $i; done` \
24*7c3d14c8STreehugger Robot // RUN:   not %run %t 2> %t.out
25*7c3d14c8STreehugger Robot // RUN: FileCheck %s --check-prefix=CHECK-LONG < %t.out
26*7c3d14c8STreehugger Robot 
27*7c3d14c8STreehugger Robot // Run w/o errors should not produce any log.
28*7c3d14c8STreehugger Robot // RUN: rm -f %t.log.*
29*7c3d14c8STreehugger Robot // RUN: %env_asan_opts=log_path=%t.log  %run %t ARG ARG ARG
30*7c3d14c8STreehugger Robot // RUN: not cat %t.log.*
31*7c3d14c8STreehugger Robot 
32*7c3d14c8STreehugger Robot // FIXME: log_path is not supported on Windows yet.
33*7c3d14c8STreehugger Robot // XFAIL: win32
34*7c3d14c8STreehugger Robot 
35*7c3d14c8STreehugger Robot #include <stdlib.h>
36*7c3d14c8STreehugger Robot #include <string.h>
main(int argc,char ** argv)37*7c3d14c8STreehugger Robot int main(int argc, char **argv) {
38*7c3d14c8STreehugger Robot   if (argc > 2) return 0;
39*7c3d14c8STreehugger Robot   char *x = (char*)malloc(10);
40*7c3d14c8STreehugger Robot   memset(x, 0, 10);
41*7c3d14c8STreehugger Robot   int res = x[argc * 10];  // BOOOM
42*7c3d14c8STreehugger Robot   free(x);
43*7c3d14c8STreehugger Robot   return res;
44*7c3d14c8STreehugger Robot }
45*7c3d14c8STreehugger Robot // CHECK-ERROR: ERROR: AddressSanitizer
46*7c3d14c8STreehugger Robot // CHECK-INVALID: ERROR: Can't open file: /dev/null/INVALID
47*7c3d14c8STreehugger Robot // CHECK-LONG: ERROR: Path is too long: 01234
48