Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / profile / ContinuousSyncMode / pid-substitution.c
blobb2b95f41f2bdf20c3f61d9bfd9e24bc60ed25bcc
1 // REQUIRES: darwin
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
9 #include <stdlib.h>
10 #include <string.h>
12 extern int __llvm_profile_is_continuous_mode_enabled(void);
13 extern const char *__llvm_profile_get_filename(void);
14 extern int getpid(void);
16 int main() {
17 // Check that continuous mode is enabled.
18 if (!__llvm_profile_is_continuous_mode_enabled())
19 return 1;
21 // Check that the PID is actually in the filename.
22 const char *Filename = __llvm_profile_get_filename();
24 int Len = strlen(Filename);
25 --Len;
26 while (Filename[Len] != '-')
27 --Len;
29 const char *PidStr = Filename + Len + 1;
30 int Pid = atoi(PidStr);
32 if (Pid != getpid())
33 return 1;
35 return 0;