Polling in ParallelChildCrashesDontHang test

Instead of (arbitrarily) wait 1s for the child process to terminate, the
parent now polls the child process every 100ms to check if it's
terminated, and it does so for a much longer total time of 10s.

This implementation ensures correct check for slower architectures, and
fast success for faster ones.

Change-Id: I2ff38458bf747de5b74268a4e22fd6164450419b
Reviewed-on: https://chromium-review.googlesource.com/c/breakpad/breakpad/+/3876346
Reviewed-by: Mike Frysinger <vapier@chromium.org>
diff --git a/src/client/linux/handler/exception_handler_unittest.cc b/src/client/linux/handler/exception_handler_unittest.cc
index 01ec2ef..691ea13 100644
--- a/src/client/linux/handler/exception_handler_unittest.cc
+++ b/src/client/linux/handler/exception_handler_unittest.cc
@@ -305,8 +305,22 @@
     }
   }
 
-  // Wait a while until the child should have crashed.
-  usleep(1000000);
+  // Poll the child to see if it crashed.
+  int status, wp_pid;
+  for (int i = 0; i < 100; i++) {
+    wp_pid = HANDLE_EINTR(waitpid(child, &status, WNOHANG));
+    ASSERT_NE(-1, wp_pid);
+    if (wp_pid > 0) {
+      ASSERT_TRUE(WIFSIGNALED(status));
+      // If the child process terminated by itself,
+      // it will have returned SIGSEGV.
+      ASSERT_EQ(SIGSEGV, WTERMSIG(status));
+      return;
+    } else {
+      usleep(100000);
+    }
+  }
+
   // Kill the child if it is still running.
   kill(child, SIGKILL);