brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.1 KiB · 747d9dd Raw
39 lines · cpp
1//===- ErrnoTest.cpp - Error handling unit tests --------------------------===//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-exception6//7//===----------------------------------------------------------------------===//8 9#include "llvm/Support/Errno.h"10#include "gtest/gtest.h"11 12using namespace llvm::sys;13 14TEST(ErrnoTest, RetryAfterSignal) {15  EXPECT_EQ(1, RetryAfterSignal(-1, [] { return 1; }));16 17  EXPECT_EQ(-1, RetryAfterSignal(-1, [] {18    errno = EAGAIN;19    return -1;20  }));21  EXPECT_EQ(EAGAIN, errno);22 23  unsigned calls = 0;24  EXPECT_EQ(1, RetryAfterSignal(-1, [&calls] {25              errno = EINTR;26              ++calls;27              return calls == 1 ? -1 : 1;28            }));29  EXPECT_EQ(2u, calls);30 31  EXPECT_EQ(1, RetryAfterSignal(-1, [](int x) { return x; }, 1));32 33  std::unique_ptr<int> P(RetryAfterSignal(nullptr, [] { return new int(47); }));34  EXPECT_EQ(47, *P);35 36  errno = EINTR;37  EXPECT_EQ(-1, RetryAfterSignal(-1, [] { return -1; }));38}39