15d71de26cedae3dafc17449fe0182045c0bd20e8Stephen Hines// FIXME: https://code.google.com/p/address-sanitizer/issues/detail?id=316
25d71de26cedae3dafc17449fe0182045c0bd20e8Stephen Hines// XFAIL: android
35d71de26cedae3dafc17449fe0182045c0bd20e8Stephen Hines//
481dfbb76f858fbc4084771fce4967ede04ed5f44Kostya Serebryany// RUN: %clangxx_asan  %s -o %t
581dfbb76f858fbc4084771fce4967ede04ed5f44Kostya Serebryany
681dfbb76f858fbc4084771fce4967ede04ed5f44Kostya Serebryany// Regular run.
72d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines// RUN: not %run %t 2> %t.out
881dfbb76f858fbc4084771fce4967ede04ed5f44Kostya Serebryany// RUN: FileCheck %s --check-prefix=CHECK-ERROR < %t.out
981dfbb76f858fbc4084771fce4967ede04ed5f44Kostya Serebryany
1081dfbb76f858fbc4084771fce4967ede04ed5f44Kostya Serebryany// Good log_path.
1181dfbb76f858fbc4084771fce4967ede04ed5f44Kostya Serebryany// RUN: rm -f %t.log.*
122d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines// RUN: env ASAN_OPTIONS=log_path=%t.log not %run %t 2> %t.out
1381dfbb76f858fbc4084771fce4967ede04ed5f44Kostya Serebryany// RUN: FileCheck %s --check-prefix=CHECK-ERROR < %t.log.*
1481dfbb76f858fbc4084771fce4967ede04ed5f44Kostya Serebryany
1581dfbb76f858fbc4084771fce4967ede04ed5f44Kostya Serebryany// Invalid log_path.
162d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines// RUN: env ASAN_OPTIONS=log_path=/INVALID not %run %t 2> %t.out
1781dfbb76f858fbc4084771fce4967ede04ed5f44Kostya Serebryany// RUN: FileCheck %s --check-prefix=CHECK-INVALID < %t.out
1881dfbb76f858fbc4084771fce4967ede04ed5f44Kostya Serebryany
1981dfbb76f858fbc4084771fce4967ede04ed5f44Kostya Serebryany// Too long log_path.
202d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines// RUN: env ASAN_OPTIONS=log_path=`for((i=0;i<10000;i++)); do echo -n $i; done` \
212d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines// RUN:   not %run %t 2> %t.out
2281dfbb76f858fbc4084771fce4967ede04ed5f44Kostya Serebryany// RUN: FileCheck %s --check-prefix=CHECK-LONG < %t.out
2381dfbb76f858fbc4084771fce4967ede04ed5f44Kostya Serebryany
2481dfbb76f858fbc4084771fce4967ede04ed5f44Kostya Serebryany// Run w/o errors should not produce any log.
2581dfbb76f858fbc4084771fce4967ede04ed5f44Kostya Serebryany// RUN: rm -f %t.log.*
262d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines// RUN: env ASAN_OPTIONS=log_path=%t.log  %run %t ARG ARG ARG
2781dfbb76f858fbc4084771fce4967ede04ed5f44Kostya Serebryany// RUN: not cat %t.log.*
2881dfbb76f858fbc4084771fce4967ede04ed5f44Kostya Serebryany
295d71de26cedae3dafc17449fe0182045c0bd20e8Stephen Hines// FIXME: log_path is not supported on Windows yet.
305d71de26cedae3dafc17449fe0182045c0bd20e8Stephen Hines// XFAIL: win32
3181dfbb76f858fbc4084771fce4967ede04ed5f44Kostya Serebryany
3281dfbb76f858fbc4084771fce4967ede04ed5f44Kostya Serebryany#include <stdlib.h>
3381dfbb76f858fbc4084771fce4967ede04ed5f44Kostya Serebryany#include <string.h>
3481dfbb76f858fbc4084771fce4967ede04ed5f44Kostya Serebryanyint main(int argc, char **argv) {
3581dfbb76f858fbc4084771fce4967ede04ed5f44Kostya Serebryany  if (argc > 2) return 0;
3681dfbb76f858fbc4084771fce4967ede04ed5f44Kostya Serebryany  char *x = (char*)malloc(10);
3781dfbb76f858fbc4084771fce4967ede04ed5f44Kostya Serebryany  memset(x, 0, 10);
3881dfbb76f858fbc4084771fce4967ede04ed5f44Kostya Serebryany  int res = x[argc * 10];  // BOOOM
3981dfbb76f858fbc4084771fce4967ede04ed5f44Kostya Serebryany  free(x);
4081dfbb76f858fbc4084771fce4967ede04ed5f44Kostya Serebryany  return res;
4181dfbb76f858fbc4084771fce4967ede04ed5f44Kostya Serebryany}
4281dfbb76f858fbc4084771fce4967ede04ed5f44Kostya Serebryany// CHECK-ERROR: ERROR: AddressSanitizer
4381dfbb76f858fbc4084771fce4967ede04ed5f44Kostya Serebryany// CHECK-INVALID: ERROR: Can't open file: /INVALID
4481dfbb76f858fbc4084771fce4967ede04ed5f44Kostya Serebryany// CHECK-LONG: ERROR: Path is too long: 01234
45