1 //===-- Header selector for libc unittests ----------------------*- 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-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #ifndef LLVM_LIBC_TEST_UNITTEST_TEST_H 10 #define LLVM_LIBC_TEST_UNITTEST_TEST_H 11 12 // This macro takes a file name and returns a value implicitly castable to 13 // a const char*. That const char* is the path to a file with the provided name 14 // in a directory where the test is allowed to write. By default it writes 15 // directly to the filename provided, but implementations are allowed to 16 // redefine it as necessary. 17 #define libc_make_test_file_path(file_name) (file_name) 18 19 // The LIBC_COPT_TEST_USE_* macros can select either of two alternate test 20 // frameworks: 21 // * gtest, the well-known model for them all 22 // * zxtest, the gtest workalike subset sometimes used in the Fuchsia build 23 // The default is to use llvm-libc's own gtest workalike framework. 24 // 25 // All the frameworks provide the basic EXPECT_* and ASSERT_* macros that gtest 26 // does. The wrapper headers below define LIBC_NAMESPACE::testing::Test as the 27 // base class for test fixture classes. Each also provides a definition of the 28 // macro LIBC_TEST_HAS_MATCHERS() for use in `#if` conditionals to guard use of 29 // gmock-style matchers, which zxtest does not support. 30 31 #if defined(LIBC_COPT_TEST_USE_ZXTEST) 32 #include "ZxTest.h" 33 // TODO: Migrate Pigweed to setting LIBC_COPT_TEST_USE_GTEST instead. 34 #elif defined(LIBC_COPT_TEST_USE_GTEST) || defined(LIBC_COPT_TEST_USE_PIGWEED) 35 #include "GTest.h" 36 #else 37 #include "LibcTest.h" 38 #endif 39 40 // These are defined the same way for each framework, in terms of the macros 41 // they all provide. 42 43 #define ASSERT_ERRNO_EQ(VAL) \ 44 ASSERT_EQ(VAL, static_cast<int>(LIBC_NAMESPACE::libc_errno)) 45 #define ASSERT_ERRNO_SUCCESS() \ 46 ASSERT_EQ(0, static_cast<int>(LIBC_NAMESPACE::libc_errno)) 47 #define ASSERT_ERRNO_FAILURE() \ 48 ASSERT_NE(0, static_cast<int>(LIBC_NAMESPACE::libc_errno)) 49 50 #endif // LLVM_LIBC_TEST_UNITTEST_TEST_H 51