Reset CrashpadInfo after CrashpadInfoReader tests

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: Ia8119ac7c554bea81e8373e2547faf192c629122
Reviewed-on: https://chromium-review.googlesource.com/923178
Commit-Queue: Scott Graham <scottmg@chromium.org>
Reviewed-by: Joshua Peraza <jperaza@chromium.org>
This commit is contained in:
Scott Graham 2018-02-15 17:22:30 -08:00 committed by Commit Bot
parent eec1e17ab5
commit 4717300fa4
5 changed files with 66 additions and 28 deletions

View File

@ -23,6 +23,7 @@
#include "gtest/gtest.h"
#include "test/errors.h"
#include "test/scoped_module_handle.h"
#include "test/scoped_unset_crashpad_info.h"
#include "test/test_paths.h"
#if defined(OS_MACOSX)
@ -57,25 +58,6 @@ TEST(CrashpadInfoClientOptions, TriStateFromCrashpadInfo) {
TriState::kUnset);
}
class ScopedUnsetCrashpadInfoOptions {
public:
explicit ScopedUnsetCrashpadInfoOptions(CrashpadInfo* crashpad_info)
: crashpad_info_(crashpad_info) {
}
~ScopedUnsetCrashpadInfoOptions() {
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);
}
private:
CrashpadInfo* crashpad_info_;
DISALLOW_COPY_AND_ASSIGN(ScopedUnsetCrashpadInfoOptions);
};
CrashpadInfoClientOptions SelfProcessSnapshotAndGetCrashpadOptions() {
#if defined(OS_MACOSX)
ProcessSnapshotMac process_snapshot;
@ -109,7 +91,7 @@ TEST(CrashpadInfoClientOptions, OneModule) {
ASSERT_TRUE(crashpad_info);
{
ScopedUnsetCrashpadInfoOptions unset(crashpad_info);
ScopedUnsetCrashpadInfo unset(crashpad_info);
crashpad_info->set_crashpad_handler_behavior(TriState::kEnabled);
@ -121,7 +103,7 @@ TEST(CrashpadInfoClientOptions, OneModule) {
}
{
ScopedUnsetCrashpadInfoOptions unset(crashpad_info);
ScopedUnsetCrashpadInfo unset(crashpad_info);
crashpad_info->set_system_crash_reporter_forwarding(TriState::kDisabled);
@ -133,7 +115,7 @@ TEST(CrashpadInfoClientOptions, OneModule) {
}
{
ScopedUnsetCrashpadInfoOptions unset(crashpad_info);
ScopedUnsetCrashpadInfo unset(crashpad_info);
crashpad_info->set_gather_indirectly_referenced_memory(TriState::kEnabled,
1234);
@ -188,8 +170,8 @@ TEST(CrashpadInfoClientOptions, TwoModules) {
ASSERT_TRUE(remote_crashpad_info);
{
ScopedUnsetCrashpadInfoOptions unset_local(local_crashpad_info);
ScopedUnsetCrashpadInfoOptions unset_remote(remote_crashpad_info);
ScopedUnsetCrashpadInfo unset_local(local_crashpad_info);
ScopedUnsetCrashpadInfo unset_remote(remote_crashpad_info);
// When only one module sets a value, it applies to the entire process.
remote_crashpad_info->set_crashpad_handler_behavior(TriState::kEnabled);
@ -211,8 +193,8 @@ TEST(CrashpadInfoClientOptions, TwoModules) {
}
{
ScopedUnsetCrashpadInfoOptions unset_local(local_crashpad_info);
ScopedUnsetCrashpadInfoOptions unset_remote(remote_crashpad_info);
ScopedUnsetCrashpadInfo unset_local(local_crashpad_info);
ScopedUnsetCrashpadInfo unset_remote(remote_crashpad_info);
// When only one module sets a value, it applies to the entire process.
remote_crashpad_info->set_system_crash_reporter_forwarding(
@ -281,7 +263,7 @@ TEST_P(CrashpadInfoSizes_ClientOptions, DifferentlySizedStruct) {
ASSERT_TRUE(remote_crashpad_info);
{
ScopedUnsetCrashpadInfoOptions unset_remote(remote_crashpad_info);
ScopedUnsetCrashpadInfo unset_remote(remote_crashpad_info);
// Make sure that a change in the remote structure can be read back out,
// even though its a different size.
@ -296,7 +278,7 @@ TEST_P(CrashpadInfoSizes_ClientOptions, DifferentlySizedStruct) {
}
{
ScopedUnsetCrashpadInfoOptions unset_remote(remote_crashpad_info);
ScopedUnsetCrashpadInfo unset_remote(remote_crashpad_info);
// Make sure that the portion of the remote structure lying beyond its
// declared size reads as zero.

View File

@ -14,6 +14,8 @@
#include "snapshot/crashpad_types/crashpad_info_reader.h"
#include <memory>
#include <sys/types.h>
#include <unistd.h>
@ -25,6 +27,7 @@
#include "gtest/gtest.h"
#include "test/multiprocess_exec.h"
#include "test/process_type.h"
#include "test/scoped_unset_crashpad_info.h"
#include "util/file/file_io.h"
#include "util/misc/from_pointer_cast.h"
#include "util/process/process_memory_native.h"
@ -47,6 +50,7 @@ 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 +73,7 @@ class CrashpadInfoTestDataSetup {
}
private:
std::unique_ptr<ScopedUnsetCrashpadInfo> unset_;
SimpleAddressRangeBag extra_memory_;
SimpleStringDictionary simple_annotations_;
AnnotationList annotation_list_;

View File

@ -40,6 +40,7 @@ static_library("test") {
"scoped_module_handle.h",
"scoped_temp_dir.cc",
"scoped_temp_dir.h",
"scoped_unset_crashpad_info.h",
"test_paths.cc",
"test_paths.h",
]

View File

@ -0,0 +1,49 @@
// Copyright 2018 The Crashpad Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef CRASHPAD_TEST_SCOPED_UNSET_CRASHPAD_INFO_H_
#define CRASHPAD_TEST_SCOPED_UNSET_CRASHPAD_INFO_H_
#include "base/macros.h"
#include "client/crashpad_info.h"
namespace crashpad {
namespace test {
//! \brief Resets members of CrashpadInfo to default state when destroyed.
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);
};
} // namespace test
} // namespace crashpad
#endif // CRASHPAD_TEST_SCOPED_UNSET_CRASHPAD_INFO_H_

View File

@ -71,6 +71,7 @@
'scoped_temp_dir.h',
'scoped_temp_dir_posix.cc',
'scoped_temp_dir_win.cc',
'scoped_unset_crashpad_info.h',
'test_paths.cc',
'test_paths.h',
'win/child_launcher.cc',