summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/Support
diff options
context:
space:
mode:
authorPavel Labath <labath@google.com>2017-06-29 13:15:31 +0000
committerPavel Labath <labath@google.com>2017-06-29 13:15:31 +0000
commitfe09f506b689b17693d2f3568301dc2e94d93bf3 (patch)
tree450e836338a4d84a5be55773541e1a52ea6df4a8 /llvm/unittests/Support
parent0e44cff13b73ec0c143f68fad7e1d7f657ca4d86 (diff)
downloadbcm5719-llvm-fe09f506b689b17693d2f3568301dc2e94d93bf3.tar.gz
bcm5719-llvm-fe09f506b689b17693d2f3568301dc2e94d93bf3.zip
Recommit "[Support] Add RetryAfterSignal helper function"
The difference from the previous version is the use of decltype, as the implementation of std::result_of in libc++ did not work correctly for variadic function like open(2). Original summary: This function retries an operation if it was interrupted by a signal (failed with EINTR). It's inspired by the TEMP_FAILURE_RETRY macro in glibc, but I've turned that into a template function. I've also added a fail-value argument, to enable the function to be used with e.g. fopen(3), which is documented to fail for any reason that open(2) can fail (which includes EINTR). The main user of this function will be lldb, but there were also a couple of uses within llvm that I could simplify using this function. Reviewers: zturner, silvas, joerg Subscribers: mgorny, llvm-commits Differential Revision: https://reviews.llvm.org/D33895 llvm-svn: 306671
Diffstat (limited to 'llvm/unittests/Support')
-rw-r--r--llvm/unittests/Support/CMakeLists.txt1
-rw-r--r--llvm/unittests/Support/ErrnoTest.cpp36
2 files changed, 37 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..67f834a938d
--- /dev/null
+++ b/llvm/unittests/Support/ErrnoTest.cpp
@@ -0,0 +1,36 @@
+//===- 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));
+
+ std::unique_ptr<int> P(RetryAfterSignal(nullptr, [] { return new int(47); }));
+ EXPECT_EQ(47, *P);
+}
OpenPOWER on IntegriCloud