log-path_test.cc revision 2d1fdb26e458c4ddc04155c1d421bced3ba90cd0
1// RUN: %clangxx_asan  %s -o %t
2
3// Regular run.
4// RUN: not %run %t 2> %t.out
5// RUN: FileCheck %s --check-prefix=CHECK-ERROR < %t.out
6
7// Good log_path.
8// RUN: rm -f %t.log.*
9// RUN: env ASAN_OPTIONS=log_path=%t.log not %run %t 2> %t.out
10// RUN: FileCheck %s --check-prefix=CHECK-ERROR < %t.log.*
11
12// Invalid log_path.
13// RUN: env ASAN_OPTIONS=log_path=/INVALID not %run %t 2> %t.out
14// RUN: FileCheck %s --check-prefix=CHECK-INVALID < %t.out
15
16// Too long log_path.
17// RUN: env ASAN_OPTIONS=log_path=`for((i=0;i<10000;i++)); do echo -n $i; done` \
18// RUN:   not %run %t 2> %t.out
19// RUN: FileCheck %s --check-prefix=CHECK-LONG < %t.out
20
21// Run w/o errors should not produce any log.
22// RUN: rm -f %t.log.*
23// RUN: env ASAN_OPTIONS=log_path=%t.log  %run %t ARG ARG ARG
24// RUN: not cat %t.log.*
25
26
27#include <stdlib.h>
28#include <string.h>
29int main(int argc, char **argv) {
30  if (argc > 2) return 0;
31  char *x = (char*)malloc(10);
32  memset(x, 0, 10);
33  int res = x[argc * 10];  // BOOOM
34  free(x);
35  return res;
36}
37// CHECK-ERROR: ERROR: AddressSanitizer
38// CHECK-INVALID: ERROR: Can't open file: /INVALID
39// CHECK-LONG: ERROR: Path is too long: 01234
40