mirror of
https://github.com/chromium/crashpad.git
synced 2024-12-28 15:50:26 +08:00
94a5a72efa
Crashpad has many tests that crash intentionally. Some of these are gtest death tests, and others arrange for intentional crashes to test Crashpad’s own crash-catching logic. On macOS, all of the gtest death tests and some of the other intentional crashes were being logged by ReportCrash, the system’s crash reporter. Since these reports corresponded to intentional crashes, they were never useful, and served only to clutter ~/Library/Logs/DiagnosticReports. Since Crashpad is adept at handling exceptions on its own, this introduces the “exception swallowing server”, crashpad_exception_swallower, which is a Mach exception server that implements a no-op exception handler routine for all exceptions received. The exception swallowing server is established as the task handler for EXC_CRASH and EXC_CORPSE_NOTIFY exceptions during gtest death tests invoked by {ASSERT,EXPECT}_DEATH_{CHECK,CRASH}, and for all child processes invoked by the Multiprocess test infrastructure. The exception swallowing server is not in effect at other times, so unexpected crashes in test code can still be handled by ReportCrash or another crash reporter. With this change in place, no new reports are generated in the user-level ~/Library/Logs/DiagnosticReports or the system’s /Library/Logs/DiagnosticReports during a run of Crashpad’s full test suite on macOS. Bug: crashpad:33 Change-Id: I13891853a7e25accc30da21fa7ea8bd7d1f3bd2f Reviewed-on: https://chromium-review.googlesource.com/777859 Commit-Queue: Mark Mentovai <mark@chromium.org> Reviewed-by: Robert Sesek <rsesek@chromium.org>
110 lines
3.7 KiB
C++
110 lines
3.7 KiB
C++
// Copyright 2016 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.
|
|
|
|
#include "client/simple_address_range_bag.h"
|
|
|
|
#include "base/logging.h"
|
|
#include "gtest/gtest.h"
|
|
#include "test/gtest_death.h"
|
|
|
|
namespace crashpad {
|
|
namespace test {
|
|
namespace {
|
|
|
|
TEST(SimpleAddressRangeBag, Entry) {
|
|
using TestBag = TSimpleAddressRangeBag<15>;
|
|
TestBag bag;
|
|
|
|
const TestBag::Entry* entry = TestBag::Iterator(bag).Next();
|
|
EXPECT_FALSE(entry);
|
|
|
|
bag.Insert(reinterpret_cast<void*>(0x1000), 200);
|
|
entry = TestBag::Iterator(bag).Next();
|
|
ASSERT_TRUE(entry);
|
|
EXPECT_EQ(0x1000u, entry->base);
|
|
EXPECT_EQ(200u, entry->size);
|
|
|
|
bag.Remove(reinterpret_cast<void*>(0x1000), 200);
|
|
EXPECT_FALSE(entry->is_active());
|
|
EXPECT_EQ(0u, entry->base);
|
|
EXPECT_EQ(0u, entry->size);
|
|
}
|
|
|
|
TEST(SimpleAddressRangeBag, SimpleAddressRangeBag) {
|
|
SimpleAddressRangeBag bag;
|
|
|
|
EXPECT_TRUE(bag.Insert(reinterpret_cast<void*>(0x1000), 10));
|
|
EXPECT_TRUE(bag.Insert(reinterpret_cast<void*>(0x2000), 20));
|
|
EXPECT_TRUE(bag.Insert(CheckedRange<uint64_t>(0x3000, 30)));
|
|
|
|
EXPECT_EQ(3u, bag.GetCount());
|
|
|
|
// Duplicates added too.
|
|
EXPECT_TRUE(bag.Insert(CheckedRange<uint64_t>(0x3000, 30)));
|
|
EXPECT_TRUE(bag.Insert(CheckedRange<uint64_t>(0x3000, 30)));
|
|
EXPECT_EQ(5u, bag.GetCount());
|
|
|
|
// Can be removed 3 times, but not the 4th time.
|
|
EXPECT_TRUE(bag.Remove(CheckedRange<uint64_t>(0x3000, 30)));
|
|
EXPECT_TRUE(bag.Remove(CheckedRange<uint64_t>(0x3000, 30)));
|
|
EXPECT_TRUE(bag.Remove(CheckedRange<uint64_t>(0x3000, 30)));
|
|
EXPECT_EQ(2u, bag.GetCount());
|
|
EXPECT_FALSE(bag.Remove(CheckedRange<uint64_t>(0x3000, 30)));
|
|
EXPECT_EQ(2u, bag.GetCount());
|
|
|
|
EXPECT_TRUE(bag.Remove(reinterpret_cast<void*>(0x1000), 10));
|
|
EXPECT_TRUE(bag.Remove(reinterpret_cast<void*>(0x2000), 20));
|
|
EXPECT_EQ(0u, bag.GetCount());
|
|
}
|
|
|
|
TEST(SimpleAddressRangeBag, CopyAndAssign) {
|
|
TSimpleAddressRangeBag<10> bag;
|
|
EXPECT_TRUE(bag.Insert(CheckedRange<uint64_t>(1, 2)));
|
|
EXPECT_TRUE(bag.Insert(CheckedRange<uint64_t>(3, 4)));
|
|
EXPECT_TRUE(bag.Insert(CheckedRange<uint64_t>(5, 6)));
|
|
EXPECT_TRUE(bag.Remove(CheckedRange<uint64_t>(3, 4)));
|
|
EXPECT_EQ(bag.GetCount(), 2u);
|
|
|
|
// Test copy.
|
|
TSimpleAddressRangeBag<10> bag_copy(bag);
|
|
EXPECT_EQ(bag_copy.GetCount(), 2u);
|
|
EXPECT_TRUE(bag_copy.Remove(CheckedRange<uint64_t>(1, 2)));
|
|
EXPECT_TRUE(bag_copy.Remove(CheckedRange<uint64_t>(5, 6)));
|
|
EXPECT_EQ(bag_copy.GetCount(), 0u);
|
|
EXPECT_EQ(bag.GetCount(), 2u);
|
|
|
|
// Test assign.
|
|
TSimpleAddressRangeBag<10> bag_assign;
|
|
bag_assign = bag;
|
|
EXPECT_EQ(bag_assign.GetCount(), 2u);
|
|
EXPECT_TRUE(bag_assign.Remove(CheckedRange<uint64_t>(1, 2)));
|
|
EXPECT_TRUE(bag_assign.Remove(CheckedRange<uint64_t>(5, 6)));
|
|
EXPECT_EQ(bag_assign.GetCount(), 0u);
|
|
EXPECT_EQ(bag.GetCount(), 2u);
|
|
}
|
|
|
|
// Running out of space shouldn't crash.
|
|
TEST(SimpleAddressRangeBag, OutOfSpace) {
|
|
TSimpleAddressRangeBag<2> bag;
|
|
EXPECT_TRUE(bag.Insert(CheckedRange<uint64_t>(1, 2)));
|
|
EXPECT_TRUE(bag.Insert(CheckedRange<uint64_t>(3, 4)));
|
|
EXPECT_FALSE(bag.Insert(CheckedRange<uint64_t>(5, 6)));
|
|
EXPECT_EQ(bag.GetCount(), 2u);
|
|
EXPECT_FALSE(bag.Remove(CheckedRange<uint64_t>(5, 6)));
|
|
}
|
|
|
|
} // namespace
|
|
} // namespace test
|
|
} // namespace crashpad
|