-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PA] Add PartitionAllocatorForTesting for PartitionAllocTest.
Since PartitionAllocGlobalUninitForTesting() releases the reserved address space, all allocators will not work correctly after invoking PartitionAllocGlobalUninitForTesting(). Instead make each allocator for testing release its allocated pages (and also address spaces) and make PartitionAllocGlobalUninitForTesting() do nothing for AddressPoolManager or PartitionAddressSpace. Change-Id: I242ecb98a4ed9647830bb1b83644619a3affd5b2 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4075584 Reviewed-by: Daniel Cheng <dcheng@chromium.org> Reviewed-by: Etienne Bergeron <etienneb@chromium.org> Reviewed-by: Bartek Nowierski <bartekn@chromium.org> Commit-Queue: Takashi Sakamoto <tasak@google.com> Cr-Commit-Position: refs/heads/main@{#1103652}
- Loading branch information
Showing
12 changed files
with
194 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
base/allocator/partition_allocator/partition_alloc_for_testing.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright 2023 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef BASE_ALLOCATOR_PARTITION_ALLOCATOR_PARTITION_ALLOC_FOR_TESTING_H_ | ||
#define BASE_ALLOCATOR_PARTITION_ALLOCATOR_PARTITION_ALLOC_FOR_TESTING_H_ | ||
|
||
#include "base/allocator/partition_allocator/partition_alloc.h" | ||
|
||
namespace partition_alloc { | ||
namespace internal { | ||
|
||
constexpr bool AllowLeaks = true; | ||
constexpr bool DisallowLeaks = false; | ||
|
||
// A subclass of PartitionAllocator for testing. It will free all resources, | ||
// i.e. allocated memory, memory inside freelist, and so on, when destructing | ||
// it or when manually invoking reset(). | ||
// If need to check if there are any memory allocated but not freed yet, | ||
// use allow_leaks=false. We will see CHECK failure inside reset() if any | ||
// leak is detected. Otherwise (e.g. intentional leaks), use allow_leaks=true. | ||
template <bool thread_safe, bool allow_leaks> | ||
struct PartitionAllocatorForTesting : public PartitionAllocator<thread_safe> { | ||
PartitionAllocatorForTesting() : PartitionAllocator<thread_safe>() {} | ||
|
||
explicit PartitionAllocatorForTesting(PartitionOptions opts) | ||
: PartitionAllocator<thread_safe>() { | ||
PartitionAllocator<thread_safe>::init(opts); | ||
} | ||
|
||
~PartitionAllocatorForTesting() { reset(); } | ||
|
||
PA_ALWAYS_INLINE void reset() { | ||
PartitionAllocator<thread_safe>::root()->ResetForTesting(allow_leaks); | ||
} | ||
}; | ||
|
||
} // namespace internal | ||
|
||
using PartitionAllocatorForTesting = | ||
internal::PartitionAllocatorForTesting<internal::ThreadSafe, | ||
internal::DisallowLeaks>; | ||
|
||
using PartitionAllocatorAllowLeaksForTesting = | ||
internal::PartitionAllocatorForTesting<internal::ThreadSafe, | ||
internal::AllowLeaks>; | ||
|
||
} // namespace partition_alloc | ||
|
||
#endif // BASE_ALLOCATOR_PARTITION_ALLOCATOR_PARTITION_ALLOC_FOR_TESTING_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.