| 1 | // REQUIRES: continuous-mode |
| 2 | |
| 3 | // RUN: rm -rf %t.dir && mkdir -p %t.dir |
| 4 | // |
| 5 | // Note: %%p is needed here, not %p, because of lit's path substitution. |
| 6 | // RUN: %clang_profgen=%t.dir/-%%p -fprofile-continuous -o %t.exe %s |
| 7 | // RUN: %run %t.exe |
| 8 | // RUN: %clang_pgogen -fprofile-continuous -o %t.exe %s |
| 9 | // RUN: env LLVM_PROFILE_FILE="%t.dir/%c-%%p" %run %t.exe |
| 10 | |
| 11 | #include <stdlib.h> |
| 12 | #include <string.h> |
| 13 | |
| 14 | extern int __llvm_profile_is_continuous_mode_enabled(void); |
| 15 | extern const char *__llvm_profile_get_filename(void); |
| 16 | extern int getpid(void); |
| 17 | |
| 18 | int main() { |
| 19 | // Check that continuous mode is enabled. |
| 20 | if (!__llvm_profile_is_continuous_mode_enabled()) |
| 21 | return 1; |
| 22 | |
| 23 | // Check that the PID is actually in the filename. |
| 24 | const char *Filename = __llvm_profile_get_filename(); |
| 25 | |
| 26 | int Len = strlen(s: Filename); |
| 27 | --Len; |
| 28 | while (Filename[Len] != '-') |
| 29 | --Len; |
| 30 | |
| 31 | const char *PidStr = Filename + Len + 1; |
| 32 | int Pid = atoi(nptr: PidStr); |
| 33 | |
| 34 | if (Pid != getpid()) |
| 35 | return 1; |
| 36 | |
| 37 | return 0; |
| 38 | } |
| 39 | |