From e059dad5ea3e781786f155ff9806602a4374b5fa Mon Sep 17 00:00:00 2001 From: Iacopo Colonnelli Date: Thu, 8 Sep 2022 09:38:48 +0200 Subject: [PATCH] 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 --- .../handler/exception_handler_unittest.cc | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/client/linux/handler/exception_handler_unittest.cc b/src/client/linux/handler/exception_handler_unittest.cc index 01ec2ef9..691ea133 100644 --- a/src/client/linux/handler/exception_handler_unittest.cc +++ b/src/client/linux/handler/exception_handler_unittest.cc @@ -305,8 +305,22 @@ TEST(ExceptionHandlerTest, ParallelChildCrashesDontHang) { } } - // 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);