Skip to content

Commit 5e50d30

Browse files
DavidSpickettZequanWu
authored andcommitted
[compiler-rt][Profile] Wait for child threads in set-file-object test
We've been seeing this test return 31 instead of 32 for the "functions" line in this test on our AArch64 bots. One possible cause is some of the children not finishing in time before the llvm-profdata commands are run, if the machine is heavily loaded. Wait for all the children to finish before exiting the parent. Reviewed By: zequanwu Differential Revision: https://reviews.llvm.org/D109222
1 parent d98c34f commit 5e50d30

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

compiler-rt/test/profile/ContinuousSyncMode/set-file-object.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@
4141
#include <stdio.h>
4242
#include <string.h>
4343

44+
#include <sys/types.h>
45+
#include <sys/wait.h>
46+
4447
const int num_child_procs_to_spawn = 32;
4548

4649
extern int __llvm_profile_is_continuous_mode_enabled(void);
@@ -70,6 +73,24 @@ int main(int argc, char **argv) {
7073
return 1;
7174
}
7275
}
76+
for (I = 0; I < num_child_procs_to_spawn; ++I) {
77+
int status;
78+
pid_t waited_pid = waitpid(child_pids[I], &status, 0);
79+
if (waited_pid != child_pids[I]) {
80+
fprintf(stderr, "Failed to wait on child %d\n", I);
81+
return 1;
82+
}
83+
if (!WIFEXITED(status)) {
84+
fprintf(stderr, "Child %d did not terminate normally\n", I);
85+
return 1;
86+
}
87+
int return_status = WEXITSTATUS(status);
88+
if (return_status != 0) {
89+
fprintf(stderr, "Child %d exited with non zero status %d\n", I,
90+
return_status);
91+
return 1;
92+
}
93+
}
7394
} else if (strcmp(argv[1], "set") == 0) {
7495
// Child processes.
7596
if (!__llvm_profile_is_continuous_mode_enabled()) {

0 commit comments

Comments
 (0)