From 6344a583ca8d1650def86d8effd1ad8a3a9598b1 Mon Sep 17 00:00:00 2001 From: Siva Chandra Reddy Date: Tue, 8 Jun 2021 23:30:21 +0000 Subject: [PATCH] [libc] Add a macro to include/exclude subprocess tests. This is useful when bringing up LLVM libc on a new OS on which we do not yet have the subprocess related helper functions. --- libc/utils/UnitTest/LibcTest.cpp | 3 +++ libc/utils/UnitTest/LibcTest.h | 6 ++++++ libc/utils/UnitTest/PlatformDefs.h | 16 ++++++++++++++++ 3 files changed, 25 insertions(+) create mode 100644 libc/utils/UnitTest/PlatformDefs.h diff --git a/libc/utils/UnitTest/LibcTest.cpp b/libc/utils/UnitTest/LibcTest.cpp index a8e32d1..016a4e5 100644 --- a/libc/utils/UnitTest/LibcTest.cpp +++ b/libc/utils/UnitTest/LibcTest.cpp @@ -262,6 +262,8 @@ bool Test::testMatch(bool MatchResult, MatcherBase &Matcher, const char *LHSStr, return false; } +#ifdef ENABLE_SUBPROCESS_TESTS + bool Test::testProcessKilled(testutils::FunctionCaller *Func, int Signal, const char *LHSStr, const char *RHSStr, const char *File, unsigned long Line) { @@ -344,6 +346,7 @@ bool Test::testProcessExits(testutils::FunctionCaller *Func, int ExitCode, return false; } +#endif // ENABLE_SUBPROCESS_TESTS } // namespace testing } // namespace __llvm_libc diff --git a/libc/utils/UnitTest/LibcTest.h b/libc/utils/UnitTest/LibcTest.h index 798acfe..d50f88d 100644 --- a/libc/utils/UnitTest/LibcTest.h +++ b/libc/utils/UnitTest/LibcTest.h @@ -12,6 +12,8 @@ // This file can only include headers from utils/CPP/ or utils/testutils. No // other headers should be included. +#include "PlatformDefs.h" + #include "utils/CPP/TypeTraits.h" #include "utils/testutils/ExecuteFunction.h" #include "utils/testutils/StreamWrapper.h" @@ -360,6 +362,8 @@ template using TypeList = internal::TypeList; if (!EXPECT_FALSE(VAL)) \ return +#ifdef ENABLE_SUBPROCESS_TESTS + #define EXPECT_EXITS(FUNC, EXIT) \ this->testProcessExits(__llvm_libc::testing::Test::createCallable(FUNC), \ EXIT, #FUNC, #EXIT, __FILE__, __LINE__) @@ -380,6 +384,8 @@ template using TypeList = internal::TypeList; #define __CAT(a, b) __CAT1(a, b) #define UNIQUE_VAR(prefix) __CAT(prefix, __LINE__) +#endif // ENABLE_SUBPROCESS_TESTS + #define EXPECT_THAT(MATCH, MATCHER) \ do { \ auto UNIQUE_VAR(__matcher) = (MATCHER); \ diff --git a/libc/utils/UnitTest/PlatformDefs.h b/libc/utils/UnitTest/PlatformDefs.h new file mode 100644 index 0000000..319b73e --- /dev/null +++ b/libc/utils/UnitTest/PlatformDefs.h @@ -0,0 +1,16 @@ +//===-- Platform specific defines for the unittest library ------*- 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_PLATFORMDEFS_H +#define LLVM_LIBC_UTILS_UNITTEST_PLATFORMDEFS_H + +#if !(defined(_WIN32) || defined(_WIN64)) +#define ENABLE_SUBPROCESS_TESTS +#endif + +#endif // LLVM_LIBC_UTILS_UNITTEST_PLATFORMDEFS_H -- 2.7.4