xref: /llvm-project/compiler-rt/test/profile/ContinuousSyncMode/get-filename.c (revision de294c968bf292794ca9f0a6a481d3dff3bcc2eb)
1*de294c96SNAKAMURA Takumi // REQUIRES: continuous-mode
2a7d48261SVedant Kumar 
34f2651c3SWael Yehia // RUN: %clang_pgogen_cont -o %t.exe %s
4a7d48261SVedant Kumar // RUN: env LLVM_PROFILE_FILE="%c%t.profraw" %run %t.exe %t.profraw
5a7d48261SVedant Kumar // RUN: env LLVM_PROFILE_FILE="%t%c.profraw" %run %t.exe %t.profraw
6a7d48261SVedant Kumar // RUN: env LLVM_PROFILE_FILE="%t.profraw%c" %run %t.exe %t.profraw
7a7d48261SVedant Kumar 
8a7d48261SVedant Kumar #include <string.h>
9a7d48261SVedant Kumar #include <stdio.h>
10a7d48261SVedant Kumar 
11a7d48261SVedant Kumar extern int __llvm_profile_is_continuous_mode_enabled(void);
12a7d48261SVedant Kumar extern const char *__llvm_profile_get_filename();
13a7d48261SVedant Kumar extern void __llvm_profile_set_dumped(void);
14a7d48261SVedant Kumar 
15a7d48261SVedant Kumar int main(int argc, char **argv) {
16a7d48261SVedant Kumar   if (!__llvm_profile_is_continuous_mode_enabled())
17a7d48261SVedant Kumar     return 1;
18a7d48261SVedant Kumar 
19a7d48261SVedant Kumar   // Check that the filename is "%t.profraw", followed by a null terminator.
20a7d48261SVedant Kumar   size_t n = strlen(argv[1]) + 1;
21a7d48261SVedant Kumar   const char *Filename = __llvm_profile_get_filename();
22a7d48261SVedant Kumar 
23a7d48261SVedant Kumar   for (int i = 0; i < n; ++i) {
24a7d48261SVedant Kumar     if (Filename[i] != argv[1][i]) {
25a7d48261SVedant Kumar       printf("Difference at: %d, Got: %c, Expected: %c\n", i, Filename[i], argv[1][i]);
26a7d48261SVedant Kumar       printf("Got: %s\n", Filename);
27a7d48261SVedant Kumar       printf("Expected: %s\n", argv[1]);
28a7d48261SVedant Kumar       return 1;
29a7d48261SVedant Kumar     }
30a7d48261SVedant Kumar   }
31a7d48261SVedant Kumar   return 0;
32a7d48261SVedant Kumar }
33