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