1 // The for loop in the backticks below requires bash. 2 // REQUIRES: shell 3 // 4 // RUN: %clangxx_memprof %s -o %t 5 6 // stderr print_text=true:log_path 7 // RUN: %env_memprof_opts=print_text=true:log_path=stderr %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-GOOD --dump-input=always 8 9 // Good print_text=true:log_path. 10 // RUN: rm -f %t.log.* 11 // RUN: %env_memprof_opts=print_text=true:log_path=%t.log %run %t 12 // RUN: FileCheck %s --check-prefix=CHECK-GOOD --dump-input=always < %t.log.* 13 14 // Invalid print_text=true:log_path. 15 // RUN: %env_memprof_opts=print_text=true:log_path=/dev/null/INVALID not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-INVALID --dump-input=always 16 17 // Too long print_text=true:log_path. 18 // RUN: %env_memprof_opts=print_text=true: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 // Note we use an invalid path since that is sufficient for checking that the 23 // specified __memprof_profile_filename value is passed through to the runtime. 24 // Using an automatically generated name via %t can cause weird issues with 25 // unexpected macro expansion if the path includes tokens that match a build 26 // system macro (e.g. "linux"). 27 // RUN: %clangxx_memprof %s -o %t -DPROFILE_NAME_VAR="/dev/null/INVALID" 28 // RUN: not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-INVALID --dump-input=always 29 30 #include <sanitizer/memprof_interface.h> 31 32 #ifdef PROFILE_NAME_VAR 33 #define xstr(s) str(s) 34 #define str(s) #s 35 char __memprof_profile_filename[] = xstr(PROFILE_NAME_VAR); 36 #endif 37 38 #include <stdlib.h> 39 #include <string.h> 40 int main(int argc, char **argv) { 41 char *x = (char *)malloc(10); 42 memset(x, 0, 10); 43 free(x); 44 __memprof_profile_dump(); 45 return 0; 46 } 47 // CHECK-GOOD: Memory allocation stack id 48 // CHECK-INVALID: ERROR: Can't open file: /dev/null/INVALID 49 // CHECK-LONG: ERROR: Path is too long: 01234 50