// Copyright 2024 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "partition_alloc/partition_alloc_for_testing.h" #include "partition_alloc/partition_page.h" #include "partition_alloc/use_death_tests.h" #include "testing/gtest/include/gtest/gtest.h" // These tests are default-disabled when PA passes through to a // sanitizer, in which case the values returned from `Alloc()` are not // managed by PartitionAlloc. #if !defined(MEMORY_TOOL_REPLACES_ALLOCATOR) namespace partition_alloc::internal { namespace { constexpr PartitionOptions kOptions{ … }; class SlotStartTest : public testing::Test { … }; TEST_F(SlotStartTest, SlotStartDoesntCrash) { … } #if PA_USE_DEATH_TESTS() TEST_F(SlotStartTest, SlotStartCrashes) { … } // In general, a `SlotStart` should not be constructed from a freed // pointer, but this is only _really_ crashy when the freed pointer // points to a direct map, which is decommitted immediately in // `PartitionDirectUnmap()`. Normal buckets may or may not be subject // to the same restriction, depending on the presence of the // `MemoryReclaimer`. TEST_F(SlotStartTest, SlotStartCrashesOnFreedDirectMap) { … } #endif // PA_USE_DEATH_TESTS() } // namespace } // namespace partition_alloc::internal #endif // !defined(MEMORY_TOOL_REPLACES_ALLOCATOR)