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