[compiler-rt] 5e50d30 - [compiler-rt][Profile] Wait for child threads in set-file-object test

Zequan Wu via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 3 11:48:58 PDT 2021


Author: David Spickett
Date: 2021-09-03T11:48:50-07:00
New Revision: 5e50d3073a5ead122a731580ded3f1cb3c21ee54

URL: https://github.com/llvm/llvm-project/commit/5e50d3073a5ead122a731580ded3f1cb3c21ee54
DIFF: https://github.com/llvm/llvm-project/commit/5e50d3073a5ead122a731580ded3f1cb3c21ee54.diff

LOG: [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

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/compiler-rt/test/profile/ContinuousSyncMode/set-file-object.c b/compiler-rt/test/profile/ContinuousSyncMode/set-file-object.c
index d32dd57358c6a..d710b39aa050c 100644
--- a/compiler-rt/test/profile/ContinuousSyncMode/set-file-object.c
+++ b/compiler-rt/test/profile/ContinuousSyncMode/set-file-object.c
@@ -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()) {


        


More information about the llvm-commits mailing list