diff options
Diffstat (limited to 'llvm/unittests')
-rw-r--r-- | llvm/unittests/Support/CMakeLists.txt | 1 | ||||
-rw-r--r-- | llvm/unittests/Support/ErrnoTest.cpp | 33 |
2 files changed, 34 insertions, 0 deletions
diff --git a/llvm/unittests/Support/CMakeLists.txt b/llvm/unittests/Support/CMakeLists.txt index e2a6561089b..641163e39ed 100644 --- a/llvm/unittests/Support/CMakeLists.txt +++ b/llvm/unittests/Support/CMakeLists.txt @@ -21,6 +21,7 @@ add_llvm_unittest(SupportTests DebugTest.cpp EndianStreamTest.cpp EndianTest.cpp + ErrnoTest.cpp ErrorOrTest.cpp ErrorTest.cpp FileOutputBufferTest.cpp diff --git a/llvm/unittests/Support/ErrnoTest.cpp b/llvm/unittests/Support/ErrnoTest.cpp new file mode 100644 index 00000000000..72b52c01ee3 --- /dev/null +++ b/llvm/unittests/Support/ErrnoTest.cpp @@ -0,0 +1,33 @@ +//===- ErrnoTest.cpp - Error handling unit tests --------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "llvm/Support/Errno.h" +#include "gtest/gtest.h" + +using namespace llvm::sys; + +TEST(ErrnoTest, RetryAfterSignal) { + EXPECT_EQ(1, RetryAfterSignal(-1, [] { return 1; })); + + EXPECT_EQ(-1, RetryAfterSignal(-1, [] { + errno = EAGAIN; + return -1; + })); + EXPECT_EQ(EAGAIN, errno); + + unsigned calls = 0; + EXPECT_EQ(1, RetryAfterSignal(-1, [&calls] { + errno = EINTR; + ++calls; + return calls == 1 ? -1 : 1; + })); + EXPECT_EQ(2u, calls); + + EXPECT_EQ(1, RetryAfterSignal(-1, [](int x) { return x; }, 1)); +} |