blob: 8c595c203ae1baad52151b2e4dabe6e54dc32ed9 [file] [log] [blame]
//========- unittests/Support/SignalsTest.cpp - Signal handling test =========//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#if !defined(_WIN32)
#include <unistd.h>
#include <sysexits.h>
#include <signal.h>
#endif // !defined(_WIN32)
#include "llvm/Support/Signals.h"
#include "gtest/gtest.h"
using namespace llvm;
#if !defined(_WIN32)
TEST(SignalTest, IgnoreMultipleSIGPIPEs) {
// Ignore SIGPIPE.
// Disable exit-on-SIGPIPE.
// 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.
// 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)