xref: /llvm-project/compiler-rt/test/lsan/TestCases/Linux/log-path_test.cpp (revision b2aa0a465013aca2fc43ca729fdb714eb52150b3)
197ccf6b8SFangrui Song // RUN: %clangxx_lsan %s -o %t
297ccf6b8SFangrui Song // The globs below do not work in the lit shell.
397ccf6b8SFangrui Song 
497ccf6b8SFangrui Song // Regular run.
597ccf6b8SFangrui Song // RUN: %env_lsan_opts="use_stacks=0" not %run %t > %t.out 2>&1
697ccf6b8SFangrui Song // RUN: FileCheck %s --check-prefix=CHECK-ERROR < %t.out
797ccf6b8SFangrui Song 
897ccf6b8SFangrui Song // Good log_path.
9ee6c5b44SVitaly Buka // RUN: rm -f %t.log.* %t.log
103b3aef19SVy Nguyen // RUN: %adb_shell 'rm -f %t.log.*'
113b3aef19SVy Nguyen // RUN: %env_lsan_opts="use_stacks=0:log_path='"%device_rundir/%t.log"'" not %run %t > %t.out 2>&1
123b3aef19SVy Nguyen // adb-pull doesn't support wild cards so we need to rename the log file.
13ee6c5b44SVitaly Buka // RUN: cat %device_rundir/%t.log.* >> %t.log
14ee6c5b44SVitaly Buka // RUN: %adb_shell 'cat %device_rundir/%t.log.*' >> %t.log
1597ccf6b8SFangrui Song // RUN: FileCheck %s --check-prefix=CHECK-ERROR < %t.log.*
1697ccf6b8SFangrui Song 
1797ccf6b8SFangrui Song #include <stdio.h>
1897ccf6b8SFangrui Song #include <stdlib.h>
1997ccf6b8SFangrui Song #include "sanitizer_common/print_address.h"
2097ccf6b8SFangrui Song 
main()2197ccf6b8SFangrui Song int main() {
2297ccf6b8SFangrui Song   void *stack_var = malloc(1337);
2397ccf6b8SFangrui Song   print_address("Test alloc: ", 1, stack_var);
2497ccf6b8SFangrui Song   // Do not return from main to prevent the pointer from going out of scope.
2597ccf6b8SFangrui Song   exit(0);
2697ccf6b8SFangrui Song }
2797ccf6b8SFangrui Song 
2897ccf6b8SFangrui Song // CHECK-ERROR: LeakSanitizer: detected memory leaks
2997ccf6b8SFangrui Song // CHECK-ERROR: Direct leak of 1337 byte(s) in 1 object(s) allocated from
30*b2aa0a46SKirill Stoimenov // CHECK-ERROR: SUMMARY: {{.*}}Sanitizer:
31