Commit 5e50d307 authored by David Spickett's avatar David Spickett Committed by Zequan Wu
Browse files

[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
parent d98c34f4
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
@@ -41,6 +41,9 @@
#include <stdio.h>
#include <string.h>

#include <sys/types.h>
#include <sys/wait.h>

const int num_child_procs_to_spawn = 32;

extern int __llvm_profile_is_continuous_mode_enabled(void);
@@ -70,6 +73,24 @@ int main(int argc, char **argv) {
        return 1;
      }
    }
    for (I = 0; I < num_child_procs_to_spawn; ++I) {
      int status;
      pid_t waited_pid = waitpid(child_pids[I], &status, 0);
      if (waited_pid != child_pids[I]) {
        fprintf(stderr, "Failed to wait on child %d\n", I);
        return 1;
      }
      if (!WIFEXITED(status)) {
        fprintf(stderr, "Child %d did not terminate normally\n", I);
        return 1;
      }
      int return_status = WEXITSTATUS(status);
      if (return_status != 0) {
        fprintf(stderr, "Child %d exited with non zero status %d\n", I,
                return_status);
        return 1;
      }
    }
  } else if (strcmp(argv[1], "set") == 0) {
    // Child processes.
    if (!__llvm_profile_is_continuous_mode_enabled()) {