1 //========- unittests/Support/SignalsTest.cpp - Signal handling test =========//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
13 #endif // !defined(_WIN32)
15 #include "llvm/Support/Signals.h"
17 #include "gtest/gtest.h"
22 TEST(SignalTest
, IgnoreMultipleSIGPIPEs
) {
24 signal(SIGPIPE
, SIG_IGN
);
26 // Disable exit-on-SIGPIPE.
27 sys::SetPipeSignalFunction(nullptr);
29 // Create unidirectional read/write pipes.
33 return; // If we can't make pipes, this isn't testing anything.
35 // Close the read pipe.
38 // Attempt to write to the write pipe. Currently we're asserting that the
39 // write fails, which isn't great.
41 // What we really want is a death test that checks that this block exits
42 // with a special exit "success" code, as opposed to unexpectedly exiting due
43 // to a kill-by-SIGNAL or due to the default SIGPIPE handler.
45 // Unfortunately llvm's unit tests aren't set up to support death tests well.
46 // For one, death tests are flaky in a multithreaded context. And sigactions
47 // inherited from llvm-lit interfere with what's being tested.
48 const void *buf
= (const void *)&fds
;
49 err
= write(fds
[1], buf
, 1);
51 err
= write(fds
[1], buf
, 1);
54 #endif // !defined(_WIN32)