1// The for loop in the backticks below requires bash.
2// REQUIRES: shell
3//
4// RUN: %clangxx_memprof %s -o %t
5
6// stderr 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 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 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=always
16
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=always
19
20// Too long log_path.
21// RUN: %env_memprof_opts=print_text=true:log_path=`for((i=0;i<10000;i++)); do echo -n $i; done` \
22// RUN: not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-LONG --dump-input=always
23
24// Specifying the log name via the __memprof_profile_filename variable.
25// Note we use an invalid path since that is sufficient for checking that the
26// specified __memprof_profile_filename value is passed through to the runtime.
27// Using an automatically generated name via %t can cause weird issues with
28// unexpected macro expansion if the path includes tokens that match a build
29// system macro (e.g. "linux").
30// RUN: %clangxx_memprof %s -o %t -DPROFILE_NAME_VAR="/INVALID"
31// RUN: not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-INVALID --dump-input=always
32
33#include <sanitizer/memprof_interface.h>
34
35#ifdef PROFILE_NAME_VAR
36#define xstr(s) str(s)
37#define str(s) #s
38char __memprof_profile_filename[] = xstr(PROFILE_NAME_VAR);
39#endif
40
41#include <stdlib.h>
42#include <string.h>
43int main(int argc, char **argv) {
44 char *x = (char *)malloc(size: 10);
45 memset(s: x, c: 0, n: 10);
46 free(ptr: x);
47 __memprof_profile_dump();
48 return 0;
49}
50// CHECK-GOOD: Memory allocation stack id
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/memprof/TestCases/log_path_test.cpp