brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.6 KiB · 9f5a3df Raw
93 lines · c
1//===-- Simple checkers for integrations tests ------------------*- 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_UTILS_INTEGRATION_TEST_TEST_H10#define LLVM_LIBC_UTILS_INTEGRATION_TEST_TEST_H11 12#include "src/__support/OSUtil/exit.h"13#include "src/__support/OSUtil/io.h"14#include "src/__support/macros/properties/architectures.h"15 16#define __AS_STRING(val) #val17#define __CHECK_TRUE(file, line, val, should_exit)                             \18  if (!(val)) {                                                                \19    LIBC_NAMESPACE::write_to_stderr(file ":" __AS_STRING(                      \20        line) ": Expected '" #val "' to be true, but is false\n");             \21    if (should_exit)                                                           \22      LIBC_NAMESPACE::internal::exit(127);                                     \23  }24 25#define __CHECK_FALSE(file, line, val, should_exit)                            \26  if (val) {                                                                   \27    LIBC_NAMESPACE::write_to_stderr(file ":" __AS_STRING(                      \28        line) ": Expected '" #val "' to be false, but is true\n");             \29    if (should_exit)                                                           \30      LIBC_NAMESPACE::internal::exit(127);                                     \31  }32 33#define __CHECK_EQ(file, line, val1, val2, should_exit)                        \34  if ((val1) != (val2)) {                                                      \35    LIBC_NAMESPACE::write_to_stderr(file ":" __AS_STRING(                      \36        line) ": Expected '" #val1 "' to be equal to '" #val2 "'\n");          \37    if (should_exit)                                                           \38      LIBC_NAMESPACE::internal::exit(127);                                     \39  }40 41#define __CHECK_NE(file, line, val1, val2, should_exit)                        \42  if ((val1) == (val2)) {                                                      \43    LIBC_NAMESPACE::write_to_stderr(file ":" __AS_STRING(                      \44        line) ": Expected '" #val1 "' to not be equal to '" #val2 "'\n");      \45    if (should_exit)                                                           \46      LIBC_NAMESPACE::internal::exit(127);                                     \47  }48 49////////////////////////////////////////////////////////////////////////////////50// Boolean checks are handled as comparison to the true / false values.51 52#define EXPECT_TRUE(val) __CHECK_TRUE(__FILE__, __LINE__, val, false)53#define ASSERT_TRUE(val) __CHECK_TRUE(__FILE__, __LINE__, val, true)54#define EXPECT_FALSE(val) __CHECK_FALSE(__FILE__, __LINE__, val, false)55#define ASSERT_FALSE(val) __CHECK_FALSE(__FILE__, __LINE__, val, true)56 57////////////////////////////////////////////////////////////////////////////////58// Binary equality / inequality.59 60#define EXPECT_EQ(val1, val2)                                                  \61  __CHECK_EQ(__FILE__, __LINE__, (val1), (val2), false)62#define ASSERT_EQ(val1, val2)                                                  \63  __CHECK_EQ(__FILE__, __LINE__, (val1), (val2), true)64#define EXPECT_NE(val1, val2)                                                  \65  __CHECK_NE(__FILE__, __LINE__, (val1), (val2), false)66#define ASSERT_NE(val1, val2)                                                  \67  __CHECK_NE(__FILE__, __LINE__, (val1), (val2), true)68 69////////////////////////////////////////////////////////////////////////////////70// Errno checks.71 72#ifdef LIBC_TARGET_ARCH_IS_GPU73#define ASSERT_ERRNO_EQ(VAL)74#define ASSERT_ERRNO_SUCCESS()75#define ASSERT_ERRNO_FAILURE()76#else77#define ASSERT_ERRNO_EQ(VAL) ASSERT_EQ(VAL, static_cast<int>(errno))78#define ASSERT_ERRNO_SUCCESS() ASSERT_EQ(0, static_cast<int>(errno))79#define ASSERT_ERRNO_FAILURE() ASSERT_NE(0, static_cast<int>(errno))80#endif81 82// Integration tests are compiled with -ffreestanding which stops treating83// the main function as a non-overloadable special function. Hence, we use a84// convenience macro which declares it 'extern "C"'.85//86// When we are able to reuse the unit test infrastructure for integration87// tests, then we should not need to explicitly declare/define the main88// function in individual integration tests. We will not need this macro89// then.90#define TEST_MAIN extern "C" int main91 92#endif // LLVM_LIBC_UTILS_INTEGRATION_TEST_TEST_H93