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

source code of compiler-rt/test/asan/TestCases/log-path_test.cpp