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

source code of compiler-rt/test/profile/ContinuousSyncMode/pid-substitution.c