55 lines · cpp
1// The for loop in the backticks below requires bash.2// REQUIRES: shell3//4// RUN: %clangxx_memprof %s -o %t5 6// stderr log_path7// RUN: %env_memprof_opts=print_text=true:log_path=stderr %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-GOOD --dump-input=always8 9// Good log_path.10// RUN: rm -f %t.log.*11// RUN: %env_memprof_opts=print_text=true:log_path=%t.log %run %t12// RUN: FileCheck %s --check-prefix=CHECK-GOOD --dump-input=always < %t.log.*13 14// Invalid log_path.15// RUN: %env_memprof_opts=print_text=true:log_path=/INVALID not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-INVALID --dump-input=always16 17// Directory of log_path can't be created.18// RUN: %env_memprof_opts=print_text=true:log_path=/dev/null/INVALID not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-BAD-DIR --dump-input=always19 20// Too long log_path.21// RUN: %python -c "for i in range(0, 10000): print(i, end='')" > %t.long_log_path22// RUN: %env_memprof_opts=print_text=true:log_path=%{readfile:%t.long_log_path} \23// RUN: not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-LONG --dump-input=always24 25// Specifying the log name via the __memprof_profile_filename variable.26// Note we use an invalid path since that is sufficient for checking that the27// specified __memprof_profile_filename value is passed through to the runtime.28// Using an automatically generated name via %t can cause weird issues with29// unexpected macro expansion if the path includes tokens that match a build30// system macro (e.g. "linux").31// RUN: %clangxx_memprof %s -o %t -DPROFILE_NAME_VAR="/INVALID"32// RUN: not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-INVALID --dump-input=always33 34#include <sanitizer/memprof_interface.h>35 36#ifdef PROFILE_NAME_VAR37#define xstr(s) str(s)38#define str(s) #s39char __memprof_profile_filename[] = xstr(PROFILE_NAME_VAR);40#endif41 42#include <stdlib.h>43#include <string.h>44int main(int argc, char **argv) {45 char *x = (char *)malloc(10);46 memset(x, 0, 10);47 free(x);48 __memprof_profile_dump();49 return 0;50}51// CHECK-GOOD: Memory allocation stack id52// CHECK-INVALID: ERROR: Can't open file: /INVALID53// CHECK-BAD-DIR: ERROR: Can't create directory: /dev/null54// CHECK-LONG: ERROR: Path is too long: 0123455