Skip to content

Commit

Permalink
deps: update googletest to 5197b1a
Browse files Browse the repository at this point in the history
PR-URL: #51657
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: Ulises Gascón <ulisesgascongonzalez@gmail.com>
Reviewed-By: Michael Dawson <midawson@redhat.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
nodejs-github-bot authored and targos committed May 21, 2024
1 parent c8305f6 commit 69959d0
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 101 deletions.
2 changes: 1 addition & 1 deletion deps/googletest/include/gtest/gtest-assertion-result.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ namespace testing {
//
// Expected: Foo() is even
// Actual: it's 5
//

class GTEST_API_ AssertionResult {
public:
// Copy constructor.
Expand Down
4 changes: 2 additions & 2 deletions deps/googletest/include/gtest/internal/gtest-filepath.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class GTEST_API_ FilePath {
public:
FilePath() : pathname_("") {}
FilePath(const FilePath& rhs) : pathname_(rhs.pathname_) {}
FilePath(FilePath&& rhs) : pathname_(std::move(rhs.pathname_)) {}
FilePath(FilePath&& rhs) noexcept : pathname_(std::move(rhs.pathname_)) {}

explicit FilePath(std::string pathname) : pathname_(std::move(pathname)) {
Normalize();
Expand All @@ -81,7 +81,7 @@ class GTEST_API_ FilePath {
Set(rhs);
return *this;
}
FilePath& operator=(FilePath&& rhs) {
FilePath& operator=(FilePath&& rhs) noexcept {
pathname_ = std::move(rhs.pathname_);
return *this;
}
Expand Down
54 changes: 10 additions & 44 deletions deps/googletest/include/gtest/internal/gtest-internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -1137,40 +1137,6 @@ class NativeArray {
void (NativeArray::*clone_)(const Element*, size_t);
};

// Backport of std::index_sequence.
template <size_t... Is>
struct IndexSequence {
using type = IndexSequence;
};

// Double the IndexSequence, and one if plus_one is true.
template <bool plus_one, typename T, size_t sizeofT>
struct DoubleSequence;
template <size_t... I, size_t sizeofT>
struct DoubleSequence<true, IndexSequence<I...>, sizeofT> {
using type = IndexSequence<I..., (sizeofT + I)..., 2 * sizeofT>;
};
template <size_t... I, size_t sizeofT>
struct DoubleSequence<false, IndexSequence<I...>, sizeofT> {
using type = IndexSequence<I..., (sizeofT + I)...>;
};

// Backport of std::make_index_sequence.
// It uses O(ln(N)) instantiation depth.
template <size_t N>
struct MakeIndexSequenceImpl
: DoubleSequence<N % 2 == 1, typename MakeIndexSequenceImpl<N / 2>::type,
N / 2>::type {};

template <>
struct MakeIndexSequenceImpl<0> : IndexSequence<> {};

template <size_t N>
using MakeIndexSequence = typename MakeIndexSequenceImpl<N>::type;

template <typename... T>
using IndexSequenceFor = typename MakeIndexSequence<sizeof...(T)>::type;

template <size_t>
struct Ignore {
Ignore(...); // NOLINT
Expand All @@ -1179,7 +1145,7 @@ struct Ignore {
template <typename>
struct ElemFromListImpl;
template <size_t... I>
struct ElemFromListImpl<IndexSequence<I...>> {
struct ElemFromListImpl<std::index_sequence<I...>> {
// We make Ignore a template to solve a problem with MSVC.
// A non-template Ignore would work fine with `decltype(Ignore(I))...`, but
// MSVC doesn't understand how to deal with that pack expansion.
Expand All @@ -1190,9 +1156,8 @@ struct ElemFromListImpl<IndexSequence<I...>> {

template <size_t N, typename... T>
struct ElemFromList {
using type =
decltype(ElemFromListImpl<typename MakeIndexSequence<N>::type>::Apply(
static_cast<T (*)()>(nullptr)...));
using type = decltype(ElemFromListImpl<std::make_index_sequence<N>>::Apply(
static_cast<T (*)()>(nullptr)...));
};

struct FlatTupleConstructTag {};
Expand All @@ -1217,9 +1182,9 @@ template <typename Derived, typename Idx>
struct FlatTupleBase;

template <size_t... Idx, typename... T>
struct FlatTupleBase<FlatTuple<T...>, IndexSequence<Idx...>>
struct FlatTupleBase<FlatTuple<T...>, std::index_sequence<Idx...>>
: FlatTupleElemBase<FlatTuple<T...>, Idx>... {
using Indices = IndexSequence<Idx...>;
using Indices = std::index_sequence<Idx...>;
FlatTupleBase() = default;
template <typename... Args>
explicit FlatTupleBase(FlatTupleConstructTag, Args&&... args)
Expand Down Expand Up @@ -1254,14 +1219,15 @@ struct FlatTupleBase<FlatTuple<T...>, IndexSequence<Idx...>>
// implementations.
// FlatTuple and ElemFromList are not recursive and have a fixed depth
// regardless of T...
// MakeIndexSequence, on the other hand, it is recursive but with an
// std::make_index_sequence, on the other hand, it is recursive but with an
// instantiation depth of O(ln(N)).
template <typename... T>
class FlatTuple
: private FlatTupleBase<FlatTuple<T...>,
typename MakeIndexSequence<sizeof...(T)>::type> {
using Indices = typename FlatTupleBase<
FlatTuple<T...>, typename MakeIndexSequence<sizeof...(T)>::type>::Indices;
std::make_index_sequence<sizeof...(T)>> {
using Indices =
typename FlatTupleBase<FlatTuple<T...>,
std::make_index_sequence<sizeof...(T)>>::Indices;

public:
FlatTuple() = default;
Expand Down
8 changes: 4 additions & 4 deletions deps/googletest/include/gtest/internal/gtest-param-util.h
Original file line number Diff line number Diff line change
Expand Up @@ -807,12 +807,12 @@ class ValueArray {

template <typename T>
operator ParamGenerator<T>() const { // NOLINT
return ValuesIn(MakeVector<T>(MakeIndexSequence<sizeof...(Ts)>()));
return ValuesIn(MakeVector<T>(std::make_index_sequence<sizeof...(Ts)>()));
}

private:
template <typename T, size_t... I>
std::vector<T> MakeVector(IndexSequence<I...>) const {
std::vector<T> MakeVector(std::index_sequence<I...>) const {
return std::vector<T>{static_cast<T>(v_.template Get<I>())...};
}

Expand Down Expand Up @@ -842,7 +842,7 @@ class CartesianProductGenerator
template <class I>
class IteratorImpl;
template <size_t... I>
class IteratorImpl<IndexSequence<I...>>
class IteratorImpl<std::index_sequence<I...>>
: public ParamIteratorInterface<ParamType> {
public:
IteratorImpl(const ParamGeneratorInterface<ParamType>* base,
Expand Down Expand Up @@ -933,7 +933,7 @@ class CartesianProductGenerator
std::shared_ptr<ParamType> current_value_;
};

using Iterator = IteratorImpl<typename MakeIndexSequence<sizeof...(T)>::type>;
using Iterator = IteratorImpl<std::make_index_sequence<sizeof...(T)>>;

std::tuple<ParamGenerator<T>...> generators_;
};
Expand Down
2 changes: 2 additions & 0 deletions deps/googletest/include/gtest/internal/gtest-port-arch.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
#elif WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_TV_TITLE)
#define GTEST_OS_WINDOWS_PHONE 1
#define GTEST_OS_WINDOWS_TV_TITLE 1
#elif WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_GAMES)
#define GTEST_OS_WINDOWS_GAMES 1
#else
// WINAPI_FAMILY defined but no known partition matched.
// Default to desktop.
Expand Down
13 changes: 7 additions & 6 deletions deps/googletest/include/gtest/internal/gtest-port.h
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,8 @@

#if defined(GTEST_HAS_ABSL) && !defined(GTEST_NO_ABSL_FLAGS)
#define GTEST_INTERNAL_HAS_ABSL_FLAGS // Used only in this file.
#include "absl/flags/flag.h"
#include "absl/flags/declare.h"
#include "absl/flags/flag.h"
#include "absl/flags/reflection.h"
#endif

Expand Down Expand Up @@ -659,9 +659,9 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
// platforms except known mobile / embedded ones. Also, if the port doesn't have
// a file system, stream redirection is not supported.
#if defined(GTEST_OS_WINDOWS_MOBILE) || defined(GTEST_OS_WINDOWS_PHONE) || \
defined(GTEST_OS_WINDOWS_RT) || defined(GTEST_OS_ESP8266) || \
defined(GTEST_OS_XTENSA) || defined(GTEST_OS_QURT) || \
!GTEST_HAS_FILE_SYSTEM
defined(GTEST_OS_WINDOWS_RT) || defined(GTEST_OS_WINDOWS_GAMES) || \
defined(GTEST_OS_ESP8266) || defined(GTEST_OS_XTENSA) || \
defined(GTEST_OS_QURT) || !GTEST_HAS_FILE_SYSTEM
#define GTEST_HAS_STREAM_REDIRECTION 0
#else
#define GTEST_HAS_STREAM_REDIRECTION 1
Expand Down Expand Up @@ -2108,8 +2108,9 @@ GTEST_DISABLE_MSC_DEPRECATED_PUSH_()
// defined there.
#if GTEST_HAS_FILE_SYSTEM
#if !defined(GTEST_OS_WINDOWS_MOBILE) && !defined(GTEST_OS_WINDOWS_PHONE) && \
!defined(GTEST_OS_WINDOWS_RT) && !defined(GTEST_OS_ESP8266) && \
!defined(GTEST_OS_XTENSA) && !defined(GTEST_OS_QURT)
!defined(GTEST_OS_WINDOWS_RT) && !defined(GTEST_OS_WINDOWS_GAMES) && \
!defined(GTEST_OS_ESP8266) && !defined(GTEST_OS_XTENSA) && \
!defined(GTEST_OS_QURT)
inline int ChDir(const char* dir) { return chdir(dir); }
#endif
inline FILE* FOpen(const char* path, const char* mode) {
Expand Down
53 changes: 34 additions & 19 deletions deps/googletest/src/gtest-port.cc
Original file line number Diff line number Diff line change
Expand Up @@ -587,25 +587,32 @@ class ThreadLocalRegistryImpl {
// thread's ID.
typedef std::map<DWORD, ThreadLocalValues> ThreadIdToThreadLocals;

// Holds the thread id and thread handle that we pass from
// StartWatcherThreadFor to WatcherThreadFunc.
typedef std::pair<DWORD, HANDLE> ThreadIdAndHandle;
struct WatcherThreadParams {
DWORD thread_id;
HANDLE handle;
Notification has_initialized;
};

static void StartWatcherThreadFor(DWORD thread_id) {
// The returned handle will be kept in thread_map and closed by
// watcher_thread in WatcherThreadFunc.
HANDLE thread =
::OpenThread(SYNCHRONIZE | THREAD_QUERY_INFORMATION, FALSE, thread_id);
GTEST_CHECK_(thread != nullptr);

WatcherThreadParams* watcher_thread_params = new WatcherThreadParams;
watcher_thread_params->thread_id = thread_id;
watcher_thread_params->handle = thread;

// We need to pass a valid thread ID pointer into CreateThread for it
// to work correctly under Win98.
DWORD watcher_thread_id;
HANDLE watcher_thread = ::CreateThread(
nullptr, // Default security.
0, // Default stack size
&ThreadLocalRegistryImpl::WatcherThreadFunc,
reinterpret_cast<LPVOID>(new ThreadIdAndHandle(thread_id, thread)),
CREATE_SUSPENDED, &watcher_thread_id);
HANDLE watcher_thread =
::CreateThread(nullptr, // Default security.
0, // Default stack size
&ThreadLocalRegistryImpl::WatcherThreadFunc,
reinterpret_cast<LPVOID>(watcher_thread_params),
CREATE_SUSPENDED, &watcher_thread_id);
GTEST_CHECK_(watcher_thread != nullptr)
<< "CreateThread failed with error " << ::GetLastError() << ".";
// Give the watcher thread the same priority as ours to avoid being
Expand All @@ -614,17 +621,25 @@ class ThreadLocalRegistryImpl {
::GetThreadPriority(::GetCurrentThread()));
::ResumeThread(watcher_thread);
::CloseHandle(watcher_thread);

// Wait for the watcher thread to start to avoid race conditions.
// One specific race condition that can happen is that we have returned
// from main and have started to tear down, the newly spawned watcher
// thread may access already-freed variables, like global shared_ptrs.
watcher_thread_params->has_initialized.WaitForNotification();
}

// Monitors exit from a given thread and notifies those
// ThreadIdToThreadLocals about thread termination.
static DWORD WINAPI WatcherThreadFunc(LPVOID param) {
const ThreadIdAndHandle* tah =
reinterpret_cast<const ThreadIdAndHandle*>(param);
GTEST_CHECK_(::WaitForSingleObject(tah->second, INFINITE) == WAIT_OBJECT_0);
OnThreadExit(tah->first);
::CloseHandle(tah->second);
delete tah;
WatcherThreadParams* watcher_thread_params =
reinterpret_cast<WatcherThreadParams*>(param);
watcher_thread_params->has_initialized.Notify();
GTEST_CHECK_(::WaitForSingleObject(watcher_thread_params->handle,
INFINITE) == WAIT_OBJECT_0);
OnThreadExit(watcher_thread_params->thread_id);
::CloseHandle(watcher_thread_params->handle);
delete watcher_thread_params;
return 0;
}

Expand Down Expand Up @@ -1033,12 +1048,12 @@ GTestLog::~GTestLog() {
}
}

#if GTEST_HAS_STREAM_REDIRECTION

// Disable Microsoft deprecation warnings for POSIX functions called from
// this class (creat, dup, dup2, and close)
GTEST_DISABLE_MSC_DEPRECATED_PUSH_()

#if GTEST_HAS_STREAM_REDIRECTION

namespace {

#if defined(GTEST_OS_LINUX_ANDROID) || defined(GTEST_OS_IOS)
Expand Down Expand Up @@ -1333,8 +1348,8 @@ bool ParseInt32(const Message& src_text, const char* str, int32_t* value) {
) {
Message msg;
msg << "WARNING: " << src_text
<< " is expected to be a 32-bit integer, but actually"
<< " has value " << str << ", which overflows.\n";
<< " is expected to be a 32-bit integer, but actually" << " has value "
<< str << ", which overflows.\n";
printf("%s", msg.GetString().c_str());
fflush(stdout);
return false;
Expand Down
Loading

0 comments on commit 69959d0

Please sign in to comment.