| 1 | // Test to ensure that multiple rounds of dumping, using the |
| 2 | // __memprof_profile_reset interface to close the initial file |
| 3 | // and cause the profile to be reopened, works as expected. |
| 4 | |
| 5 | // RUN: %clangxx_memprof %s -o %t |
| 6 | |
| 7 | // RUN: rm -f %t.log.* |
| 8 | // RUN: %env_memprof_opts=print_text=true:log_path=%t.log %run %t |
| 9 | |
| 10 | // Check both outputs, starting with the renamed initial dump, then remove it so |
| 11 | // that the second glob matches a single file. |
| 12 | // RUN: FileCheck %s < %t.log.*.sv |
| 13 | // RUN: rm -f %t.log.*.sv |
| 14 | // RUN: FileCheck %s < %t.log.* |
| 15 | // CHECK: Memory allocation stack id |
| 16 | |
| 17 | #include <sanitizer/memprof_interface.h> |
| 18 | #include <stdio.h> |
| 19 | |
| 20 | #include <stdlib.h> |
| 21 | #include <string.h> |
| 22 | #include <string> |
| 23 | int main(int argc, char **argv) { |
| 24 | char *x = (char *)malloc(size: 10); |
| 25 | memset(s: x, c: 0, n: 10); |
| 26 | free(ptr: x); |
| 27 | __memprof_profile_dump(); |
| 28 | // Save the initial dump in a different file. |
| 29 | std::string origname = __sanitizer_get_report_path(); |
| 30 | std::string svname = origname + ".sv" ; |
| 31 | rename(origname.c_str(), svname.c_str()); |
| 32 | // This should cause the current file descriptor to be closed and the |
| 33 | // the internal state reset so that the profile filename is reopened |
| 34 | // on the next write. |
| 35 | __memprof_profile_reset(); |
| 36 | // This will dump to origname again. |
| 37 | __memprof_profile_dump(); |
| 38 | return 0; |
| 39 | } |
| 40 | |