diff options
author | Vedant Kumar <vsk@apple.com> | 2019-10-18 21:05:30 +0000 |
---|---|---|
committer | Vedant Kumar <vsk@apple.com> | 2019-10-18 21:05:30 +0000 |
commit | 32ce14e55e5a99dd99c3b4fd4bd0ccaaf2948c30 (patch) | |
tree | 96db1514a1898bf521d81c6fe8d0bc591a5d8ee3 /llvm/unittests/Support | |
parent | 52d765544b50d2260cf4858ed63c827880b987df (diff) | |
download | bcm5719-llvm-32ce14e55e5a99dd99c3b4fd4bd0ccaaf2948c30.tar.gz bcm5719-llvm-32ce14e55e5a99dd99c3b4fd4bd0ccaaf2948c30.zip |
Disable exit-on-SIGPIPE in lldb
Occasionally, during test teardown, LLDB writes to a closed pipe.
Sometimes the communication is inherently unreliable, so LLDB tries to
avoid being killed due to SIGPIPE (it calls `signal(SIGPIPE, SIG_IGN)`).
However, LLVM's default SIGPIPE behavior overrides LLDB's, causing it to
exit with IO_ERR.
Opt LLDB out of the default SIGPIPE behavior. I expect that this will
resolve some LLDB test suite flakiness (tests randomly failing with
IO_ERR) that we've seen since r344372.
rdar://55750240
Differential Revision: https://reviews.llvm.org/D69148
llvm-svn: 375288
Diffstat (limited to 'llvm/unittests/Support')
-rw-r--r-- | llvm/unittests/Support/CMakeLists.txt | 1 | ||||
-rw-r--r-- | llvm/unittests/Support/SignalsTest.cpp | 53 |
2 files changed, 54 insertions, 0 deletions
diff --git a/llvm/unittests/Support/CMakeLists.txt b/llvm/unittests/Support/CMakeLists.txt index 161891517cf..385142278e4 100644 --- a/llvm/unittests/Support/CMakeLists.txt +++ b/llvm/unittests/Support/CMakeLists.txt @@ -58,6 +58,7 @@ add_llvm_unittest(SupportTests ReverseIterationTest.cpp ReplaceFileTest.cpp ScaledNumberTest.cpp + SignalsTest.cpp SourceMgrTest.cpp SpecialCaseListTest.cpp StringPool.cpp diff --git a/llvm/unittests/Support/SignalsTest.cpp b/llvm/unittests/Support/SignalsTest.cpp new file mode 100644 index 00000000000..6dfa4bf996d --- /dev/null +++ b/llvm/unittests/Support/SignalsTest.cpp @@ -0,0 +1,53 @@ +//========- unittests/Support/SignalsTest.cpp - Signal handling test =========// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#if !defined(_WIN32) +#include <unistd.h> +#include <sysexits.h> +#endif // !defined(_WIN32) + +#include "llvm/Support/Signals.h" + +#include "gtest/gtest.h" + +using namespace llvm; + +#if !defined(_WIN32) +TEST(SignalTest, IgnoreMultipleSIGPIPEs) { + // Ignore SIGPIPE. + signal(SIGPIPE, SIG_IGN); + + // Disable exit-on-SIGPIPE. + sys::SetPipeSignalFunction(nullptr); + + // Create unidirectional read/write pipes. + int fds[2]; + int err = pipe(fds); + if (err != 0) + return; // If we can't make pipes, this isn't testing anything. + + // Close the read pipe. + close(fds[0]); + + // Attempt to write to the write pipe. Currently we're asserting that the + // write fails, which isn't great. + // + // What we really want is a death test that checks that this block exits + // with a special exit "success" code, as opposed to unexpectedly exiting due + // to a kill-by-SIGNAL or due to the default SIGPIPE handler. + // + // Unfortunately llvm's unit tests aren't set up to support death tests well. + // For one, death tests are flaky in a multithreaded context. And sigactions + // inherited from llvm-lit interfere with what's being tested. + const void *buf = (const void *)&fds; + err = write(fds[1], buf, 1); + ASSERT_EQ(err, -1); + err = write(fds[1], buf, 1); + ASSERT_EQ(err, -1); +} +#endif // !defined(_WIN32) |