[InstCombine] Signed saturation patterns
[llvm-complete.git] / unittests / Support / SignalsTest.cpp
blob8c595c203ae1baad52151b2e4dabe6e54dc32ed9
1 //========- unittests/Support/SignalsTest.cpp - Signal handling test =========//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
9 #if !defined(_WIN32)
10 #include <unistd.h>
11 #include <sysexits.h>
12 #include <signal.h>
13 #endif // !defined(_WIN32)
15 #include "llvm/Support/Signals.h"
17 #include "gtest/gtest.h"
19 using namespace llvm;
21 #if !defined(_WIN32)
22 TEST(SignalTest, IgnoreMultipleSIGPIPEs) {
23 // Ignore SIGPIPE.
24 signal(SIGPIPE, SIG_IGN);
26 // Disable exit-on-SIGPIPE.
27 sys::SetPipeSignalFunction(nullptr);
29 // Create unidirectional read/write pipes.
30 int fds[2];
31 int err = pipe(fds);
32 if (err != 0)
33 return; // If we can't make pipes, this isn't testing anything.
35 // Close the read pipe.
36 close(fds[0]);
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);
50 ASSERT_EQ(err, -1);
51 err = write(fds[1], buf, 1);
52 ASSERT_EQ(err, -1);
54 #endif // !defined(_WIN32)