Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cherry pick PR #715: Fix gtest multithread crash #743

Merged
merged 1 commit into from
Jun 27, 2023

Conversation

cobalt-github-releaser-bot
Copy link
Collaborator

"Refer to the original PR: #715"

…os (#715)

on multiple threads. The failures will be correctly reported and no
longer crashes the app.

When GoogleTest is used in multi-thread mode (i.e. its macros are used
on thread other than the main thread), it may crash as
GetTestPartResultReporterForCurrentThread() returns nullptr on a forked
thread.

This is due to that the ThreadLocal class in our GTEST_OS_STARBOARD
implementation doesn't return the default value on newly created threads
The ThreadLocal ctor accepts a default value of T to be returned on a
thread where the thread local value hasn't been overridden.
The existing implementation incorrectly returns T() on a new thread
where the value has never been set. When T is a pointer, T() is nullptr
and causes crash when dereferenced.

Now the default value to ThreadLocal ctor is stored and a copy of it
will be returned on a new thread when the thread local value hasn't been
set. This ensures that GetTestPartResultReporterForCurrentThread()
returns the correct TestPartResultReporterInterface*, and failures of
GoogleTest's ASSERT and EXPECT macros on a different thread will be
correctly reported and no longer crashes the app.

b/230877781

Change-Id: Ibb5ced5611593092d6065af4474027404a783caa
(cherry picked from commit 0c9c2cf)
@WeiChungChang WeiChungChang merged commit 9ffe76a into 24.lts.1+ Jun 27, 2023
329 checks passed
@WeiChungChang WeiChungChang deleted the 24.lts.1+-715 branch June 27, 2023 18:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants