[libc-commits] [libc] p/libc gtest (PR #89659)

via libc-commits libc-commits at lists.llvm.org
Mon Apr 22 13:14:37 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libc

Author: Roland McGrath (frobtech)

<details>
<summary>Changes</summary>

- [mlir] fix typo in mem2reg [NFC]
- [InstCombine] Update BranchProbabilityAnalysis cache result (#<!-- -->86470)
- [SPIRV][HLSL] Add mad intrinsic lowering for spirv (#<!-- -->89130)
- [AArch64] Add phase ordering tests for some basic interleaving vectorization patterns. NFC
- [LV] Fix warning about Mask being set twice. NFC
- [nfc][github] subscribe myself to MLIR Mem2Reg PRs
- [clang][Interp] Change array index types in OffsetHelper
- [clang-repl] Keep the first llvm::Module empty to avoid invalid memory access. (#<!-- -->89031)
- [memprof] Accept Schema in the constructor of RecordWriterTrait (NFC) (#<!-- -->89486)
- [Interpreter] Fix warnings
- Revert "[clang-repl] Keep the first llvm::Module empty to avoid invalid memory access. (#<!-- -->89031)"
- Reland "[clang-repl] Keep the first llvm::Module empty to avoid invalid memory access. (#<!-- -->89031)"
- Revert "Reland "[python] Bump Python minimum version to 3.8 (#<!-- -->78828)""
- [X86] X86LowerTileCopy: Find dead register to use to prevent save-reload of tile register (#<!-- -->83628)
- [mlir][python] Fix generation of Python bindings for `async` dialect (#<!-- -->75960)
- [memprof] Omit the key length for the call stack table (#<!-- -->89510)
- [RISCV] Remove extra indentation from RISCVProcessors.td.
- [tidy] update check list [NFC]
- [InstCombine] Add check to avoid dependent optimization order, NFC
- [InstCombine] Optimize powi(X, Y)/ (X * Z) with Ofast
- [clang][Interp][NFC] Change pointer offset to uint64
- Revert "[X86] X86LowerTileCopy: Find dead register to use to prevent save-reload of tile register (#<!-- -->83628)"
- [Clang] Do not try to diagnose parameter packs in invalid pack expressions (#<!-- -->89257)
- [MLIR] Generalize expand_shape to take shape as explicit input (#<!-- -->69267)
- Revert "[MLIR] Generalize expand_shape to take shape as explicit input" (#<!-- -->89540)
- [AArch64] Add costs for LD3/LD4 shuffles.
-  [InstCombine] Fix unexpected overwriting in `foldSelectWithSRem` (#<!-- -->89539)
- [Transforms] Remove extraneous ArrayRef (NFC) (#<!-- -->89535)
- [ValueTracking] Combine variable declaration with its only assignment. NFC (#<!-- -->89526)
- [X86][MC] Error out for CMPCCXADD on 32 bit targets. (#<!-- -->88672)
- [MLIR][Linalg] Enable fuse consumer (#<!-- -->85528)
- [LTO] Allow target-specific module splittting (#<!-- -->83128)
- [clang][dataflow] Model conditional operator correctly. (#<!-- -->89213)
- Revert "[clang][dataflow] Model conditional operator correctly." (#<!-- -->89577)
- [InstCombine] Fold fabs over selects (#<!-- -->86390)
- [llvm-split] Require x86-registered-target for target-specific-split.ll
- [SelectionDAG] Remove redundant KnownBits smin and smax operations (#<!-- -->89519)
- [AArch64] Add tests for more undef lanes on zip/uzp. NFC
- [VectorCombine] Add test coverage for #<!-- -->89390
- [VectorCombine] foldShuffleOfBinops - don't fold shuffle(divrem(x,y),divrem(z,w)) if mask contains poison
- [clang][Interp] Create full type info for dummy pointers
- Reland "[clang] CTAD: Fix require-clause is not transformed." (#<!-- -->89476)
- Mark `mlir::Value::isa/dyn_cast/cast/...` member functions deprecated. (#<!-- -->89238)
- CodeGen: Strengthen definition of F{MIN|MAX}NUM_IEEE nodes (#<!-- -->85195)
- [llvm][bazel] Fix BUILD after e86ebe4ff8705ef30b332e2104ed1c84fc729966.
- [llvm-split] Add missing TargetParser dependency
- Revert "[clang][Interp] Create full type info for dummy pointers"
- [clang][Interp][NFC] Get ComplexType directly
- [clang][Interp][NFC] Test out-of-bounds access on vectors
- [libclc] Fix build with Unix Makefiles (#<!-- -->89147)
- [clang][Interp] Support ImplicitArrayInitExpr for vectors
- [flang] de-duplicate AbstractResult pass (#<!-- -->88867)
- [DAG] visitOR/visitORLike - merge repeated SDLoc calls.
- clang: Remove unnecessary pointer bitcast
- [DAG] visitORCommutative - use sd_match to reduce the need for commutative operand matching. NFCI.
- [AArch64][GlobalISel] Combine Shuffles of G_CONCAT_VECTORS (#<!-- -->87489)
- Revert "[TBAA] Add verifier for tbaa.struct metadata (#<!-- -->86709)"
- [flang][driver] Avoid mentions of Clang in Flang's command line reference. (#<!-- -->88932)
- [flang] Default -g to full debug info. (#<!-- -->89418)
- AMDGPU: Simplify DS atomicrmw fadd handling (#<!-- -->89468)
- [Clang] Fix template alias default DWARF version (#<!-- -->89594)
- Fix DW_TAG_template_alias refs in llvm-dwarfdump --verify (#<!-- -->89589)
- [llvm-split] Correctly deallocate TargetMachine
- [KnownBitsTest] Common up isCorrect and isOptimal. NFC. (#<!-- -->89585)
- [VPlan] Remove custom checks for EVL placement in verifier (NFCI).
- [KnownBitsTest] Print name of function when exhaustive tests fail (#<!-- -->89588)
- AMDGPU: Refactor atomicrmw fadd expansion logic (NFC) (#<!-- -->89469)
- [NFC] Fix comments in PassBuilder functions (#<!-- -->89513)
-  [clang] MveEmitter: Pass Args as a const reference  (#<!-- -->89551)
- [RemoveDIs] Make verify-uselistorder preserve the input debug info format (#<!-- -->87789)
- [clang][Interp][NFC] getRecord() might return null
- [clang][Interp] Fix casting pointers to int128
- [KnownBitsTest] Standardize variable names in exhaustive tests
- [libc++] Don't commit libcxx.imp (#<!-- -->89391)
- [libc++] Remove stray CMake install step for modulemap file (#<!-- -->89394)
- [mlir] fix latex formulas in the tutorial
- [mlir][Hoisting] Hoisting vector.extract/vector.broadcast pairs (#<!-- -->86108)
- [X86] Allow input vector extracted from larger vector when combining to VPMADDUBSW (#<!-- -->89584)
- [AArch64] Add some tests for reassociated addressing modes. NFC
- [Clang] Fix a crash introduced in PR#<!-- -->88666 (#<!-- -->89567)
- [LAA] Document reasoning in multiple places in isDependent (NFC). (#<!-- -->89381)
- [flang][OpenMP] Allow common blocks in nested directives (#<!-- -->88430)
- [mlir] fix polynomial dialect docs
- [clang][Interp][NFC] Refactor Program::getGlobal()
- [clang][Interp] Remove faulty assertion
- [clang][Interp] Implement C++23 [[assume]] support
- [SLP]Fix PR89438: check for all tree entries for the resized value.
- [gn] port e86ebe4ff870 (llvm-split target dep)
- [libc++][NFC] Fix unparenthesized comma expression in mem-initializer (#<!-- -->89605)
- [lldb][DWARF] Remove m_forward_decl_die_to_compiler_type as it never actually being used. (#<!-- -->89427)
- [AST] Dump argument types for TypeTraitExpr. (#<!-- -->89370)
- [LAA] Add etra tests with strides with different signs.
- [VectorCombine] foldShuffleOfShuffles - fold "shuffle (shuffle x, undef), (shuffle y, undef)" -> "shuffle x, y" (#<!-- -->88743)
- [SystemZ][z/OS] Implement llvm.returnaddress for XPLINK (#<!-- -->89440)
- [SLP][NFC]Add a test with incorrect size of the external user detection.
- [SLP]Fix a check for multi-users for icmp user.
- [SLP]Fix PR89614: phis can be reordered, if reuses are not empty.
- Reapply "[Clang][Sema] Fix crash when 'this' is used in a dependent class scope function template specialization that instantiates to a static member function (#<!-- -->87541, #<!-- -->88311)" (#<!-- -->88731)
- [OpenACC] Implement 'num_gangs' sema for compute constructs (#<!-- -->89460)
- [C23] Select the correct promoted type for a bit-field (#<!-- -->89254)
- [NVPTX][NFCI] Use DataLayout to determine short shared/local/const pointers (#<!-- -->89404)
- [RISCV] Precommit stack protector checks for Linux and Android (#<!-- -->87679)
- [Clang][Sema] Remove unused function after #<!-- -->88731 (#<!-- -->89618)
- [compiler-rt][ctx_instr] Add `ctx_profile` component (#<!-- -->89304)
- [SLP]Introduce transformNodes() and transform loads + reverse to strided loads.
- [X86] gfni-funnel-shifts.ll - add vXi8 variable/splat/constant test coverage
- Revert "[compiler-rt][ctx_instr] Add `ctx_profile` component" (#<!-- -->89625)
- [SPIRV][HLSL] map lerp to Fmix (#<!-- -->88976)
- [Clang] Fix crash on invalid size in user-defined `static_assert` message (#<!-- -->89420)
- [Offload] Move `/openmp/libomptarget` to `/offload` (#<!-- -->75125)
- [RemoveDIs] Preserve debug info format in llvm-reduce (#<!-- -->89220)
- [flang][cuda] fix parsing of cuda_kernel (#<!-- -->89613)
- Carving out -Wformat warning about scoped enums into a subwarning (#<!-- -->88595)
- [SystemZ][NFC] Use new getPointerSize function (#<!-- -->89623)
- [clangd] Fix unittests in TargetDeclTest bucket (#<!-- -->89630)
- [Clang] Fix __is_trivially_equaltiy_comparable documentation (#<!-- -->88528)
- [RISCV] Add extension information to RISCVFeatures.td. NFC (#<!-- -->89326)
- [clang][CoverageMapping] do not emit a gap region when either end doesn't have valid source locations (#<!-- -->89564)
- [lldb][MinidumpFileBuilder] Fix addition of MemoryList steam (#<!-- -->88564)
- [SPIR-V] Emit SPIR-V generator magic number and version (#<!-- -->87951)
- [flang][OpenMP] Concatenate begin and end clauses into single list (#<!-- -->89090)
- [clang-tidy] Improved --verify-config when using literal style in config file (#<!-- -->85591)
- [MIPS]: Rework atomic max/min expand for subword (#<!-- -->89575)
- [lldb][NFC] Remove unused pexpect/ptyprocess (#<!-- -->89609)
- [RISCV] Add freeze when expanding mul by constant to two or more uses (#<!-- -->89290)
- [BitInt] Expose a _BitInt literal suffix in C++ (#<!-- -->86586)
- [libc] don't over include stdlib in the hdr declaring bsearch (#<!-- -->89471)
- [llvm] Add support for zero-width integers in MathExtras.h (#<!-- -->87193)
- [libc][docs] codify Policy on Assembler Sources (#<!-- -->88185)
- [libc][POSIX][pthreads] implement pthread_rwlockattr_t functions (#<!-- -->89322)
- [RISCV][clang] Don't enable -mrelax-all for -O0 on RISC-V (#<!-- -->88538)
- [Offload] Fix per-target install directory (#<!-- -->89645)
- [llvm-readobj] Remove --raw-relr
- [libc] Clean up alternate test framework support


---
Full diff: https://github.com/llvm/llvm-project/pull/89659.diff


10 Files Affected:

- (modified) libc/src/__support/OSUtil/fuchsia/io.h (+9-4) 
- (modified) libc/test/UnitTest/FPExceptMatcher.cpp (+6) 
- (modified) libc/test/UnitTest/FPExceptMatcher.h (+9-5) 
- (added) libc/test/UnitTest/GTest.h (+23) 
- (modified) libc/test/UnitTest/LibcTest.h (+2-10) 
- (modified) libc/test/UnitTest/MemoryMatcher.cpp (+4) 
- (modified) libc/test/UnitTest/MemoryMatcher.h (+3-3) 
- (removed) libc/test/UnitTest/PigweedTest.h (-18) 
- (modified) libc/test/UnitTest/Test.h (+27-4) 
- (renamed) libc/test/UnitTest/ZxTest.h (+11-6) 


``````````diff
diff --git a/libc/src/__support/OSUtil/fuchsia/io.h b/libc/src/__support/OSUtil/fuchsia/io.h
index 9a5e00beaa316c..f68d734492fabe 100644
--- a/libc/src/__support/OSUtil/fuchsia/io.h
+++ b/libc/src/__support/OSUtil/fuchsia/io.h
@@ -9,18 +9,23 @@
 #ifndef LLVM_LIBC_SRC___SUPPORT_OSUTIL_FUCHSIA_IO_H
 #define LLVM_LIBC_SRC___SUPPORT_OSUTIL_FUCHSIA_IO_H
 
-#ifndef LIBC_COPT_TEST_USE_FUCHSIA
-#error this file should only be used by tests
-#endif
-
 #include "src/__support/CPP/string_view.h"
 
+#include <iostream>
 #include <zircon/sanitizer.h>
 
 namespace LIBC_NAMESPACE {
 
 LIBC_INLINE void write_to_stderr(cpp::string_view msg) {
+#if defined(LIBC_COPT_TEST_USE_ZXTEST)
+  // This is used in standalone context where there is nothing like POSIX I/O.
   __sanitizer_log_write(msg.data(), msg.size());
+#elif defined(LIBC_COPT_TEST_USE_GTEST)
+  // The gtest framework already relies on full standard C++ I/O via fdio.
+  std::cerr << std::string_view{msg.data(), msg.size()};
+#else
+#error this file should only be used by tests
+#endif
 }
 
 } // namespace LIBC_NAMESPACE
diff --git a/libc/test/UnitTest/FPExceptMatcher.cpp b/libc/test/UnitTest/FPExceptMatcher.cpp
index 53ea72ad9ddd8d..c1dfc539246623 100644
--- a/libc/test/UnitTest/FPExceptMatcher.cpp
+++ b/libc/test/UnitTest/FPExceptMatcher.cpp
@@ -8,12 +8,16 @@
 
 #include "FPExceptMatcher.h"
 
+#include "test/UnitTest/Test.h"
+
 #include "hdr/types/fenv_t.h"
 #include "src/__support/FPUtil/FEnvImpl.h"
 #include <memory>
 #include <setjmp.h>
 #include <signal.h>
 
+#if LIBC_TEST_HAS_MATCHERS()
+
 namespace LIBC_NAMESPACE {
 namespace testing {
 
@@ -49,3 +53,5 @@ FPExceptMatcher::FPExceptMatcher(FunctionCaller *func) {
 
 } // namespace testing
 } // namespace LIBC_NAMESPACE
+
+#endif // LIBC_TEST_HAS_MATCHERS()
diff --git a/libc/test/UnitTest/FPExceptMatcher.h b/libc/test/UnitTest/FPExceptMatcher.h
index d36e98d22d4b4e..5136e381081ee4 100644
--- a/libc/test/UnitTest/FPExceptMatcher.h
+++ b/libc/test/UnitTest/FPExceptMatcher.h
@@ -9,9 +9,10 @@
 #ifndef LLVM_LIBC_TEST_UNITTEST_FPEXCEPTMATCHER_H
 #define LLVM_LIBC_TEST_UNITTEST_FPEXCEPTMATCHER_H
 
-#ifndef LIBC_COPT_TEST_USE_FUCHSIA
-
 #include "test/UnitTest/Test.h"
+#include "test/UnitTest/TestLogger.h"
+
+#if LIBC_TEST_HAS_MATCHERS()
 
 namespace LIBC_NAMESPACE {
 namespace testing {
@@ -24,7 +25,7 @@ class FPExceptMatcher : public Matcher<bool> {
 public:
   class FunctionCaller {
   public:
-    virtual ~FunctionCaller(){};
+    virtual ~FunctionCaller() {}
     virtual void call() = 0;
   };
 
@@ -57,8 +58,11 @@ class FPExceptMatcher : public Matcher<bool> {
       true,                                                                    \
       LIBC_NAMESPACE::testing::FPExceptMatcher(                                \
           LIBC_NAMESPACE::testing::FPExceptMatcher::getFunctionCaller(func)))
-#else
+
+#else // !LIBC_TEST_HAS_MATCHERS()
+
 #define ASSERT_RAISES_FP_EXCEPT(func) ASSERT_DEATH(func, WITH_SIGNAL(SIGFPE))
-#endif // LIBC_COPT_TEST_USE_FUCHSIA
+
+#endif // LIBC_TEST_HAS_MATCHERS()
 
 #endif // LLVM_LIBC_TEST_UNITTEST_FPEXCEPTMATCHER_H
diff --git a/libc/test/UnitTest/GTest.h b/libc/test/UnitTest/GTest.h
new file mode 100644
index 00000000000000..d1637d3ba6583b
--- /dev/null
+++ b/libc/test/UnitTest/GTest.h
@@ -0,0 +1,23 @@
+//===-- Header for using the gtest framework -------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===---------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_UTILS_UNITTEST_GTEST_H
+#define LLVM_LIBC_UTILS_UNITTEST_GTEST_H
+
+#include <gtest/gtest.h>
+
+namespace LIBC_NAMESPACE::testing {
+
+using ::testing::Matcher;
+using ::testing::Test;
+
+} // namespace LIBC_NAMESPACE::testing
+
+#define LIBC_TEST_HAS_MATCHERS() (1)
+
+#endif // LLVM_LIBC_UTILS_UNITTEST_GTEST_H
diff --git a/libc/test/UnitTest/LibcTest.h b/libc/test/UnitTest/LibcTest.h
index a813a59d2d67f3..bba3c6d743bece 100644
--- a/libc/test/UnitTest/LibcTest.h
+++ b/libc/test/UnitTest/LibcTest.h
@@ -446,16 +446,6 @@ CString libc_make_test_file_path_func(const char *file_name);
 #define EXPECT_STRNE(LHS, RHS) LIBC_TEST_STR_(testStrNe, LHS, RHS, )
 #define ASSERT_STRNE(LHS, RHS) LIBC_TEST_STR_(testStrNe, LHS, RHS, return)
 
-////////////////////////////////////////////////////////////////////////////////
-// Errno checks.
-
-#define ASSERT_ERRNO_EQ(VAL)                                                   \
-  ASSERT_EQ(VAL, static_cast<int>(LIBC_NAMESPACE::libc_errno))
-#define ASSERT_ERRNO_SUCCESS()                                                 \
-  ASSERT_EQ(0, static_cast<int>(LIBC_NAMESPACE::libc_errno))
-#define ASSERT_ERRNO_FAILURE()                                                 \
-  ASSERT_NE(0, static_cast<int>(LIBC_NAMESPACE::libc_errno))
-
 ////////////////////////////////////////////////////////////////////////////////
 // Subprocess checks.
 
@@ -494,4 +484,6 @@ CString libc_make_test_file_path_func(const char *file_name);
 
 #define WITH_SIGNAL(X) X
 
+#define LIBC_TEST_HAS_MATCHERS() (1)
+
 #endif // LLVM_LIBC_TEST_UNITTEST_LIBCTEST_H
diff --git a/libc/test/UnitTest/MemoryMatcher.cpp b/libc/test/UnitTest/MemoryMatcher.cpp
index d9d89504dbeba7..c18bc4a8ab5903 100644
--- a/libc/test/UnitTest/MemoryMatcher.cpp
+++ b/libc/test/UnitTest/MemoryMatcher.cpp
@@ -10,6 +10,8 @@
 
 #include "test/UnitTest/Test.h"
 
+#if LIBC_TEST_HAS_MATCHERS()
+
 using LIBC_NAMESPACE::testing::tlog;
 
 namespace LIBC_NAMESPACE {
@@ -76,3 +78,5 @@ void MemoryMatcher::explainError() {
 
 } // namespace testing
 } // namespace LIBC_NAMESPACE
+
+#endif // LIBC_TEST_HAS_MATCHERS()
diff --git a/libc/test/UnitTest/MemoryMatcher.h b/libc/test/UnitTest/MemoryMatcher.h
index c548bafb7ae4d6..ab77eff153b406 100644
--- a/libc/test/UnitTest/MemoryMatcher.h
+++ b/libc/test/UnitTest/MemoryMatcher.h
@@ -21,7 +21,7 @@ using MemoryView = LIBC_NAMESPACE::cpp::span<const char>;
 } // namespace testing
 } // namespace LIBC_NAMESPACE
 
-#ifdef LIBC_COPT_TEST_USE_FUCHSIA
+#if !LIBC_TEST_HAS_MATCHERS()
 
 #define EXPECT_MEM_EQ(expected, actual)                                        \
   do {                                                                         \
@@ -39,7 +39,7 @@ using MemoryView = LIBC_NAMESPACE::cpp::span<const char>;
     ASSERT_BYTES_EQ(e.data(), a.data(), e.size());                             \
   } while (0)
 
-#else
+#else // LIBC_TEST_HAS_MATCHERS()
 
 namespace LIBC_NAMESPACE::testing {
 
@@ -64,6 +64,6 @@ class MemoryMatcher : public Matcher<MemoryView> {
 #define ASSERT_MEM_EQ(expected, actual)                                        \
   ASSERT_THAT(actual, LIBC_NAMESPACE::testing::MemoryMatcher(expected))
 
-#endif
+#endif // !LIBC_TEST_HAS_MATCHERS()
 
 #endif // LLVM_LIBC_TEST_UNITTEST_MEMORYMATCHER_H
diff --git a/libc/test/UnitTest/PigweedTest.h b/libc/test/UnitTest/PigweedTest.h
deleted file mode 100644
index 855633527fb359..00000000000000
--- a/libc/test/UnitTest/PigweedTest.h
+++ /dev/null
@@ -1,18 +0,0 @@
-//===-- Header for setting up the Pigweed tests -----------------*- C++ -*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_LIBC_UTILS_UNITTEST_PIGWEEDTEST_H
-#define LLVM_LIBC_UTILS_UNITTEST_PIGWEEDTEST_H
-
-#include <gtest/gtest.h>
-
-namespace LIBC_NAMESPACE::testing {
-using Test = ::testing::Test;
-}
-
-#endif // LLVM_LIBC_UTILS_UNITTEST_PIGWEEDTEST_H
diff --git a/libc/test/UnitTest/Test.h b/libc/test/UnitTest/Test.h
index f7ce3cfa5cf622..c7729606000c41 100644
--- a/libc/test/UnitTest/Test.h
+++ b/libc/test/UnitTest/Test.h
@@ -16,12 +16,35 @@
 // redefine it as necessary.
 #define libc_make_test_file_path(file_name) (file_name)
 
-#if defined(LIBC_COPT_TEST_USE_FUCHSIA)
-#include "FuchsiaTest.h"
-#elif defined(LIBC_COPT_TEST_USE_PIGWEED)
-#include "PigweedTest.h"
+// The LIBC_COPT_TEST_USE_* macros can select either of two alternate test
+// frameworks:
+//  * gtest, the well-known model for them all
+//  * zxtest, the gtest workalike subset sometimes used in the Fuchsia build
+// The default is to use llvm-libc's own gtest workalike framework.
+//
+// All the frameworks provide the basic EXPECT_* and ASSERT_* macros that gtest
+// does.  The wrapper headers below define LIBC_NAMESPACE::testing::Test as the
+// base class for test fixture classes.  Each also provides a definition of the
+// macro LIBC_TEST_HAS_MATCHERS() for use in `#if` conditionals to guard use of
+// gmock-style matchers, which zxtest does not support.
+
+#if defined(LIBC_COPT_TEST_USE_ZXTEST)
+#include "ZxTest.h"
+// TODO: Migrate Pigweed to setting LIBC_COPT_TEST_USE_GTEST instead.
+#elif defined(LIBC_COPT_TEST_USE_GTEST) || defined(LIBC_COPT_TEST_USE_PIGWEED)
+#include "GTest.h"
 #else
 #include "LibcTest.h"
 #endif
 
+// These are defined the same way for each framework, in terms of the macros
+// they all provide.
+
+#define ASSERT_ERRNO_EQ(VAL)                                                   \
+  ASSERT_EQ(VAL, static_cast<int>(LIBC_NAMESPACE::libc_errno))
+#define ASSERT_ERRNO_SUCCESS()                                                 \
+  ASSERT_EQ(0, static_cast<int>(LIBC_NAMESPACE::libc_errno))
+#define ASSERT_ERRNO_FAILURE()                                                 \
+  ASSERT_NE(0, static_cast<int>(LIBC_NAMESPACE::libc_errno))
+
 #endif // LLVM_LIBC_TEST_UNITTEST_TEST_H
diff --git a/libc/test/UnitTest/FuchsiaTest.h b/libc/test/UnitTest/ZxTest.h
similarity index 77%
rename from libc/test/UnitTest/FuchsiaTest.h
rename to libc/test/UnitTest/ZxTest.h
index e9e8348ee5ddb0..e6bd1e8b64372f 100644
--- a/libc/test/UnitTest/FuchsiaTest.h
+++ b/libc/test/UnitTest/ZxTest.h
@@ -1,13 +1,13 @@
-//===-- Header for setting up the Fuchsia tests -----------------*- C++ -*-===//
+//===-- Header for using Fuchsia's zxtest framework ------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
-//===----------------------------------------------------------------------===//
+//===---------------------------------------------------------------------===//
 
-#ifndef LLVM_LIBC_UTILS_UNITTEST_FUCHSIATEST_H
-#define LLVM_LIBC_UTILS_UNITTEST_FUCHSIATEST_H
+#ifndef LLVM_LIBC_UTILS_UNITTEST_ZXTEST_H
+#define LLVM_LIBC_UTILS_UNITTEST_ZXTEST_H
 
 #include <zxtest/zxtest.h>
 
@@ -29,7 +29,12 @@
 #endif
 
 namespace LIBC_NAMESPACE::testing {
+
 using Test = ::zxtest::Test;
-}
 
-#endif // LLVM_LIBC_UTILS_UNITTEST_FUCHSIATEST_H
+} // namespace LIBC_NAMESPACE::testing
+
+// zxtest does not have gmock-style matchers.
+#define LIBC_TEST_HAS_MATCHERS() (0)
+
+#endif // LLVM_LIBC_UTILS_UNITTEST_ZXTEST_H

``````````

</details>


https://github.com/llvm/llvm-project/pull/89659


More information about the libc-commits mailing list