brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.3 KiB · c9bbc44 Raw
40 lines · cpp
1// Test to ensure that multiple rounds of dumping, using the2// __memprof_profile_reset interface to close the initial file3// and cause the profile to be reopened, works as expected.4 5// RUN: %clangxx_memprof  %s -o %t6 7// RUN: rm -f %t.log.*8// RUN: %env_memprof_opts=print_text=true:log_path=%t.log %run %t9 10// Check both outputs, starting with the renamed initial dump, then remove it so11// that the second glob matches a single file.12// RUN: FileCheck %s < %t.log.*.sv13// RUN: rm -f %t.log.*.sv14// RUN: FileCheck %s < %t.log.*15// CHECK: Memory allocation stack id16 17#include <sanitizer/memprof_interface.h>18#include <stdio.h>19 20#include <stdlib.h>21#include <string.h>22#include <string>23int main(int argc, char **argv) {24  char *x = (char *)malloc(10);25  memset(x, 0, 10);26  free(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 the33  // the internal state reset so that the profile filename is reopened34  // on the next write.35  __memprof_profile_reset();36  // This will dump to origname again.37  __memprof_profile_dump();38  return 0;39}40