brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.3 KiB · 111d812 Raw
63 lines · c
1//===-- ErrnoCheckingTest.h ------------------------------------*- C++ -*-===//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#ifndef LLVM_LIBC_TEST_UNITTEST_ERRNOCHECKINGTEST_H10#define LLVM_LIBC_TEST_UNITTEST_ERRNOCHECKINGTEST_H11 12#include "src/__support/libc_errno.h"13#include "src/__support/macros/config.h"14#include "src/__support/macros/properties/architectures.h"15#include "test/UnitTest/Test.h"16 17// Define macro to validate the value stored in the errno and restore it18// to zero.19 20#ifdef LIBC_TARGET_ARCH_IS_GPU21#define ASSERT_ERRNO_EQ(VAL)22#define ASSERT_ERRNO_SUCCESS()23#define ASSERT_ERRNO_FAILURE()24#else25#define ASSERT_ERRNO_EQ(VAL)                                                   \26  do {                                                                         \27    ASSERT_EQ(VAL, static_cast<int>(libc_errno));                              \28    libc_errno = 0;                                                            \29  } while (0)30#define ASSERT_ERRNO_SUCCESS() ASSERT_EQ(0, static_cast<int>(libc_errno))31#define ASSERT_ERRNO_FAILURE()                                                 \32  do {                                                                         \33    ASSERT_NE(0, static_cast<int>(libc_errno));                                \34    libc_errno = 0;                                                            \35  } while (0)36#endif37 38namespace LIBC_NAMESPACE_DECL {39namespace testing {40 41// Provides a test fixture for tests that validate modifications of the errno.42// It clears out the errno at the beginning of the test (e.g. in case it43// contained the value pre-set by the system), and confirms it's still zero44// at the end of the test, forcing the test author to explicitly account for all45// non-zero values.46class ErrnoCheckingTest : public Test {47public:48  void SetUp() override {49    Test::SetUp();50    libc_errno = 0;51  }52 53  void TearDown() override {54    ASSERT_ERRNO_SUCCESS();55    Test::TearDown();56  }57};58 59} // namespace testing60} // namespace LIBC_NAMESPACE_DECL61 62#endif // LLVM_LIBC_TEST_UNITTEST_ERRNOCHECKINGTEST_H63