From 6798ba912e96d83dd2f4b16538fa0cf3c2db7346 Mon Sep 17 00:00:00 2001 From: Scott Graham Date: Thu, 15 Feb 2018 19:48:30 -0800 Subject: [PATCH] Reset CrashpadInfo after CrashpadInfoReader tests In preference to (the reverted) https://chromium-review.googlesource.com/c/crashpad/crashpad/+/923178 this does not share implementation with the tests in snapshot/crashpad_info_client_options_test.cc. This is not done because those tests use faked CrashpadInfo structures that are intentionally differently sized than the current defintion of CrashpadInfo, meaning that the scoped reset could overwrite past the end of the structure. Not resetting these was causing CrashpadInfoClientOptions tests to fail on Fuchsia, because dlclose() [legally] doesn't do anything, so modifying the current binaries CrashpadInfo caused the expected values from child .sos to be ignored. That could be worked around in that test too, but it's probably better to clean up the global state in this test anyway. Bug: crashpad:196 Change-Id: Ia3f81f1d5872b5ef7d543fcc68b56af4c0b6ca0a Reviewed-on: https://chromium-review.googlesource.com/923561 Reviewed-by: Joshua Peraza Commit-Queue: Scott Graham --- .../crashpad_info_reader_test.cc | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/snapshot/crashpad_types/crashpad_info_reader_test.cc b/snapshot/crashpad_types/crashpad_info_reader_test.cc index 73564177..87bafc68 100644 --- a/snapshot/crashpad_types/crashpad_info_reader_test.cc +++ b/snapshot/crashpad_types/crashpad_info_reader_test.cc @@ -17,6 +17,8 @@ #include #include +#include + #include "build/build_config.h" #include "client/annotation_list.h" #include "client/crashpad_info.h" @@ -43,10 +45,32 @@ constexpr TriState kGatherIndirectlyReferencedMemory = TriState::kUnset; constexpr uint32_t kIndirectlyReferencedMemoryCap = 42; +class ScopedUnsetCrashpadInfo { + public: + explicit ScopedUnsetCrashpadInfo(CrashpadInfo* crashpad_info) + : crashpad_info_(crashpad_info) {} + + ~ScopedUnsetCrashpadInfo() { + crashpad_info_->set_crashpad_handler_behavior(TriState::kUnset); + crashpad_info_->set_system_crash_reporter_forwarding(TriState::kUnset); + crashpad_info_->set_gather_indirectly_referenced_memory(TriState::kUnset, + 0); + crashpad_info_->set_extra_memory_ranges(nullptr); + crashpad_info_->set_simple_annotations(nullptr); + crashpad_info_->set_annotations_list(nullptr); + } + + private: + CrashpadInfo* crashpad_info_; + + DISALLOW_COPY_AND_ASSIGN(ScopedUnsetCrashpadInfo); +}; + class CrashpadInfoTestDataSetup { public: CrashpadInfoTestDataSetup() { CrashpadInfo* info = CrashpadInfo::GetCrashpadInfo(); + unset_.reset(new ScopedUnsetCrashpadInfo(info)); info->set_extra_memory_ranges(&extra_memory_); info->set_simple_annotations(&simple_annotations_); @@ -69,6 +93,7 @@ class CrashpadInfoTestDataSetup { } private: + std::unique_ptr unset_; SimpleAddressRangeBag extra_memory_; SimpleStringDictionary simple_annotations_; AnnotationList annotation_list_;