1// Test __llvm_profile_get_filename.
2// RUN: %clang_pgogen -O2 -o %t %s
3// RUN: %run %t
4
5#include <stdio.h>
6#include <string.h>
7
8const char *__llvm_profile_get_filename();
9void __llvm_profile_set_filename(const char *);
10
11int main(int argc, const char *argv[]) {
12 int i;
13 const char *filename;
14 const char *new_filename = "/path/to/test.profraw";
15
16 filename = __llvm_profile_get_filename();
17 if (strncmp(s1: filename, s2: "default_", n: 8)) {
18 fprintf(stderr,
19 format: "Error: got filename %s, expected it to start with 'default_'\n",
20 filename);
21 return 1;
22 }
23 if (strcmp(s1: filename + strlen(s: filename) - strlen(s: ".profraw"), s2: ".profraw")) {
24 fprintf(stderr,
25 format: "Error: got filename %s, expected it to end with '.profraw'\n",
26 filename);
27 return 1;
28 }
29
30 __llvm_profile_set_filename(new_filename);
31 filename = __llvm_profile_get_filename();
32 if (strcmp(s1: filename, s2: new_filename)) {
33 fprintf(stderr, format: "Error: got filename %s, expected '%s'\n", filename,
34 new_filename);
35 return 1;
36 }
37
38 return 0;
39}
40

source code of compiler-rt/test/profile/instrprof-get-filename.c