1 // The for loop in the backticks below requires bash.
2 // REQUIRES: shell
3 //
4 // RUN: %clangxx_memprof  %s -o %t
5 
6 // Regular run.
7 // RUN: %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-GOOD --dump-input=always
8 
9 // Good log_path.
10 // RUN: rm -f %t.log.*
11 // RUN: %env_memprof_opts=log_path=%t.log %run %t
12 // RUN: FileCheck %s --check-prefix=CHECK-GOOD --dump-input=always < %t.log.*
13 
14 // Invalid log_path.
15 // RUN: %env_memprof_opts=log_path=/dev/null/INVALID not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-INVALID --dump-input=always
16 
17 // Too long log_path.
18 // RUN: %env_memprof_opts=log_path=`for((i=0;i<10000;i++)); do echo -n $i; done` \
19 // RUN:   not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-LONG --dump-input=always
20 
21 // Specifying the log name via the __memprof_profile_filename variable.
22 // TODO: Temporarily disabled due to llvm-avr-linux bot failure
23 // %clangxx_memprof  %s -o %t -DPROFILE_NAME_VAR="%t.log2"
24 // rm -f %t.log2.*
25 // %run %t
26 // FileCheck %s --check-prefix=CHECK-GOOD --dump-input=always < %t.log2.*
27 
28 #ifdef PROFILE_NAME_VAR
29 #define xstr(s) str(s)
30 #define str(s) #s
31 char __memprof_profile_filename[] = xstr(PROFILE_NAME_VAR);
32 #endif
33 
34 #include <stdlib.h>
35 #include <string.h>
36 int main(int argc, char **argv) {
37   char *x = (char *)malloc(10);
38   memset(x, 0, 10);
39   free(x);
40   return 0;
41 }
42 // CHECK-GOOD: Memory allocation stack id
43 // CHECK-INVALID: ERROR: Can't open file: /dev/null/INVALID
44 // CHECK-LONG: ERROR: Path is too long: 01234
45