Commit 0d4683df authored by Joe Downing's avatar Joe Downing Committed by Commit Bot

Revert "Make DestructorAtExit LazyInstances leak."

This reverts commit 1b97e93c.

Reason for revert: Speculative revert due to Linux TSAN unittest errors:
https://uberchromegw.corp.google.com/i/chromium.memory/builders/Linux%20TSan%20Tests/builds/17057

Original change's description:
> Make DestructorAtExit LazyInstances leak.
> 
> This means that tests may no longer rely on LazyInstance<T> to clean
> up global state between tests. Tests that depend on globals but need
> a clean test environment should use explicit test hooks to reset this
> state.
> 
> Only one test depends on DestructorAtExit for correct functionality.
> cast_audio_backend_unittests creates several mocks that are owned by a
> base::LazyInstance. Since Gmock verifies expectations in destructors,
> switching all LazyInstances to leaky ones breaks this verification.
> The solution is to manually verify and check the expectations at the
> end of the test.
> 
> Note that while the mock objects are annotated as leaked for Gmock,
> that does not mean the cast_audio_backend_unittests will leak
> arbitrary amounts of memory. The test fixture already configures
> StreamMixer for each test run; this setup will clear up any leftover
> objects from the previous test.
> 
> DestructorAtExit will be removed in a followup.
> 
> Bug: 698982
> Cq-Include-Trybots: master.tryserver.chromium.android:android_optional_gpu_tests_rel;master.tryserver.chromium.linux:linux_optional_gpu_tests_rel;master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs;master.tryserver.chromium.mac:mac_optional_gpu_tests_rel;master.tryserver.chromium.win:win_optional_gpu_tests_rel
> Change-Id: I822ce507dbb98067a788466e7c8fcc96c3a64ef9
> Reviewed-on: https://chromium-review.googlesource.com/874994
> Commit-Queue: Daniel Cheng <dcheng@chromium.org>
> Reviewed-by: Kenneth MacKay <kmackay@chromium.org>
> Reviewed-by: Gabriel Charette <gab@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#531385}

TBR=dcheng@chromium.org,gab@chromium.org,kmackay@chromium.org

Change-Id: Ief1f9169caa0ff81e2c095df0a0520a71d7640a1
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 698982
Cq-Include-Trybots: master.tryserver.chromium.android:android_optional_gpu_tests_rel;master.tryserver.chromium.linux:linux_optional_gpu_tests_rel;master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs;master.tryserver.chromium.mac:mac_optional_gpu_tests_rel;master.tryserver.chromium.win:win_optional_gpu_tests_rel
Reviewed-on: https://chromium-review.googlesource.com/882506Reviewed-by: default avatarJoe Downing <joedow@chromium.org>
Commit-Queue: Joe Downing <joedow@chromium.org>
Cr-Commit-Position: refs/heads/master@{#531398}
parent cf60b272
...@@ -81,6 +81,25 @@ struct LazyInstanceTraitsBase { ...@@ -81,6 +81,25 @@ struct LazyInstanceTraitsBase {
// can implement the more complicated pieces out of line in the .cc file. // can implement the more complicated pieces out of line in the .cc file.
namespace internal { namespace internal {
// This traits class causes destruction the contained Type at process exit via
// AtExitManager. This is probably generally not what you want. Instead, prefer
// Leaky below.
template <typename Type>
struct DestructorAtExitLazyInstanceTraits {
static const bool kRegisterOnExit = true;
#if DCHECK_IS_ON()
static const bool kAllowedToAccessOnNonjoinableThread = false;
#endif
static Type* New(void* instance) {
return LazyInstanceTraitsBase<Type>::New(instance);
}
static void Delete(Type* instance) {
LazyInstanceTraitsBase<Type>::CallDestructor(instance);
}
};
// Use LazyInstance<T>::Leaky for a less-verbose call-site typedef; e.g.: // Use LazyInstance<T>::Leaky for a less-verbose call-site typedef; e.g.:
// base::LazyInstance<T>::Leaky my_leaky_lazy_instance; // base::LazyInstance<T>::Leaky my_leaky_lazy_instance;
// instead of: // instead of:
...@@ -104,11 +123,6 @@ struct LeakyLazyInstanceTraits { ...@@ -104,11 +123,6 @@ struct LeakyLazyInstanceTraits {
} }
}; };
// TODO(dcheng): DestructorAtExit will be completely removed in followups if
// there are no issues discovered.
template <typename Type>
using DestructorAtExitLazyInstanceTraits = LeakyLazyInstanceTraits<Type>;
template <typename Type> template <typename Type>
struct ErrorMustSelectLazyOrDestructorAtExitForLazyInstance {}; struct ErrorMustSelectLazyOrDestructorAtExitForLazyInstance {};
...@@ -133,10 +147,9 @@ class LazyInstance { ...@@ -133,10 +147,9 @@ class LazyInstance {
// Convenience typedef to avoid having to repeat Type for leaky lazy // Convenience typedef to avoid having to repeat Type for leaky lazy
// instances. // instances.
using Leaky = LazyInstance<Type, internal::LeakyLazyInstanceTraits<Type>>; typedef LazyInstance<Type, internal::LeakyLazyInstanceTraits<Type>> Leaky;
// TODO(dcheng): DestructorAtExit will be completely removed in followups if typedef LazyInstance<Type, internal::DestructorAtExitLazyInstanceTraits<Type>>
// there are no issues discovered. DestructorAtExit;
using DestructorAtExit = Leaky;
Type& Get() { Type& Get() {
return *Pointer(); return *Pointer();
......
This diff is collapsed.
...@@ -472,22 +472,7 @@ class StreamMixerTest : public testing::Test { ...@@ -472,22 +472,7 @@ class StreamMixerTest : public testing::Test {
StreamMixer::Get()->SetMixerOutputStreamForTest(std::move(output)); StreamMixer::Get()->SetMixerOutputStreamForTest(std::move(output));
} }
~StreamMixerTest() override { ~StreamMixerTest() override { StreamMixer::Get()->ClearInputsForTest(); }
// The remaining MockPostProcessor objects are still indirectly owned by a
// leaky static. Manually verify and clear them here and mark them as
// leaked so Gmock doesn't complain.
for (auto& itr : *MockPostProcessor::instances()) {
testing::Mock::VerifyAndClear(itr.second);
testing::Mock::AllowLeak(itr.second);
}
MockPostProcessor::instances()->clear();
// Similarly, mock_alsa_ is also indirectly owned by a leaky static.
testing::Mock::VerifyAndClear(mock_alsa_);
testing::Mock::AllowLeak(mock_alsa_);
StreamMixer::Get()->ClearInputsForTest();
}
MockAlsaWrapper* mock_alsa() { return mock_alsa_; } MockAlsaWrapper* mock_alsa() { return mock_alsa_; }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment