Skip to content

Commit

Permalink
[PA] Copy base/gtest_prod_util.h utils to PA library
Browse files Browse the repository at this point in the history
PS7 = simple copy

Bug: 1151236
Change-Id: I0772532eba3d00307b3cfd7bd9dcc993f9f7918b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3634978
Reviewed-by: Austin Sullivan <asully@chromium.org>
Commit-Queue: Bartek Nowierski <bartekn@chromium.org>
Reviewed-by: Takashi Sakamoto <tasak@google.com>
Cr-Commit-Position: refs/heads/main@{#1002059}
  • Loading branch information
bartekn-chromium authored and Chromium LUCI CQ committed May 11, 2022
1 parent e0f9a38 commit d2db606
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 30 deletions.
1 change: 1 addition & 0 deletions base/allocator/partition_allocator/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ target(partition_alloc_target_type, "partition_alloc") {
"partition_alloc_base/cxx17_backports.h",
"partition_alloc_base/debug/alias.cc",
"partition_alloc_base/debug/alias.h",
"partition_alloc_base/gtest_prod_util.h",
"partition_alloc_base/logging.cc",
"partition_alloc_base/logging.h",
"partition_alloc_base/migration_adapter.h",
Expand Down
2 changes: 1 addition & 1 deletion base/allocator/partition_allocator/DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ include_rules = [
"+base/dcheck_is_on.h",
"+base/debug/proc_maps_linux.h",
"+base/fuchsia/fuchsia_logging.h",
"+base/gtest_prod_util.h",
"+base/immediate_crash.h",
"+base/lazy_instance.h",
"+base/location.h",
Expand Down Expand Up @@ -43,6 +42,7 @@ include_rules = [
"+build/chromecast_buildflags.h",
"+testing/gmock/include/gmock/gmock.h",
"+testing/gtest/include/gtest/gtest.h",
"+testing/gtest/include/gtest/gtest_prod.h",
"+testing/perf/perf_result_reporter.h",
"+third_party/lss/linux_syscall_support.h",
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// 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_BASE_GTEST_PROD_UTIL_H_
#define BASE_ALLOCATOR_PARTITION_ALLOCATOR_PARTITION_ALLOC_BASE_GTEST_PROD_UTIL_H_

#include "testing/gtest/include/gtest/gtest_prod.h" // nogncheck

// This is a wrapper for gtest's FRIEND_TEST macro that friends
// test with all possible prefixes. This is very helpful when changing the test
// prefix, because the friend declarations don't need to be updated.
//
// Example usage:
//
// class MyClass {
// private:
// void MyMethod();
// PA_FRIEND_TEST_ALL_PREFIXES(MyClassTest, MyMethod);
// };
#define PA_FRIEND_TEST_ALL_PREFIXES(test_case_name, test_name) \
FRIEND_TEST(test_case_name, test_name); \
FRIEND_TEST(test_case_name, DISABLED_##test_name); \
FRIEND_TEST(test_case_name, FLAKY_##test_name)

// C++ compilers will refuse to compile the following code:
//
// namespace foo {
// class MyClass {
// private:
// PA_FRIEND_TEST_ALL_PREFIXES(MyClassTest, TestMethod);
// bool private_var;
// };
// } // namespace foo
//
// class MyClassTest::TestMethod() {
// foo::MyClass foo_class;
// foo_class.private_var = true;
// }
//
// Unless you forward declare MyClassTest::TestMethod outside of namespace foo.
// Use PA_FORWARD_DECLARE_TEST to do so for all possible prefixes.
//
// Example usage:
//
// PA_FORWARD_DECLARE_TEST(MyClassTest, TestMethod);
//
// namespace foo {
// class MyClass {
// private:
// PA_FRIEND_TEST_ALL_PREFIXES(::MyClassTest, TestMethod); // NOTE use of ::
// bool private_var;
// };
// } // namespace foo
//
// class MyClassTest::TestMethod() {
// foo::MyClass foo_class;
// foo_class.private_var = true;
// }

#define PA_FORWARD_DECLARE_TEST(test_case_name, test_name) \
class test_case_name##_##test_name##_Test; \
class test_case_name##_##DISABLED_##test_name##_Test; \
class test_case_name##_##FLAKY_##test_name##_Test

#endif // BASE_ALLOCATOR_PARTITION_ALLOCATOR_PARTITION_ALLOC_BASE_GTEST_PROD_UTIL_H_
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
#include <stddef.h>
#include <stdint.h>

#include "base/allocator/partition_allocator/partition_alloc_base/gtest_prod_util.h"
#include "base/allocator/partition_allocator/partition_alloc_base/migration_adapter.h"
#include "base/base_export.h"
#include "base/gtest_prod_util.h"
#include "build/build_config.h"

namespace partition_alloc {
Expand Down Expand Up @@ -81,12 +81,13 @@ class BASE_EXPORT InsecureRandomGenerator {
// free() time.
friend class ::partition_alloc::RandomGenerator;

FRIEND_TEST_ALL_PREFIXES(PartitionAllocBaseRandUtilTest,
InsecureRandomGeneratorProducesBothValuesOfAllBits);
FRIEND_TEST_ALL_PREFIXES(PartitionAllocBaseRandUtilTest,
InsecureRandomGeneratorChiSquared);
FRIEND_TEST_ALL_PREFIXES(PartitionAllocBaseRandUtilTest,
InsecureRandomGeneratorRandDouble);
PA_FRIEND_TEST_ALL_PREFIXES(
PartitionAllocBaseRandUtilTest,
InsecureRandomGeneratorProducesBothValuesOfAllBits);
PA_FRIEND_TEST_ALL_PREFIXES(PartitionAllocBaseRandUtilTest,
InsecureRandomGeneratorChiSquared);
PA_FRIEND_TEST_ALL_PREFIXES(PartitionAllocBaseRandUtilTest,
InsecureRandomGeneratorRandDouble);
};

} // namespace partition_alloc::internal::base
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include "base/bind.h"
#include "base/callback.h"
#include "base/test/bind.h"
#include "base/test/gtest_util.h"
#include "base/threading/platform_thread.h"
#include "base/time/time.h"
#include "build/build_config.h"
Expand Down
45 changes: 24 additions & 21 deletions base/allocator/partition_allocator/thread_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <limits>
#include <memory>

#include "base/allocator/partition_allocator/partition_alloc_base/gtest_prod_util.h"
#include "base/allocator/partition_allocator/partition_alloc_config.h"
#include "base/allocator/partition_allocator/partition_alloc_forward.h"
#include "base/allocator/partition_allocator/partition_bucket_lookup.h"
Expand All @@ -20,7 +21,6 @@
#include "base/base_export.h"
#include "base/compiler_specific.h"
#include "base/dcheck_is_on.h"
#include "base/gtest_prod_util.h"
#include "base/time/time.h"
#include "build/build_config.h"

Expand Down Expand Up @@ -418,26 +418,29 @@ class BASE_EXPORT ThreadCache {
friend class ThreadCacheRegistry;
friend class PartitionAllocThreadCacheTest;
friend class tools::ThreadCacheInspector;
FRIEND_TEST_ALL_PREFIXES(PartitionAllocThreadCacheTest, Simple);
FRIEND_TEST_ALL_PREFIXES(PartitionAllocThreadCacheTest,
MultipleObjectsCachedPerBucket);
FRIEND_TEST_ALL_PREFIXES(PartitionAllocThreadCacheTest,
LargeAllocationsAreNotCached);
FRIEND_TEST_ALL_PREFIXES(PartitionAllocThreadCacheTest, MultipleThreadCaches);
FRIEND_TEST_ALL_PREFIXES(PartitionAllocThreadCacheTest, RecordStats);
FRIEND_TEST_ALL_PREFIXES(PartitionAllocThreadCacheTest, ThreadCacheRegistry);
FRIEND_TEST_ALL_PREFIXES(PartitionAllocThreadCacheTest,
MultipleThreadCachesAccounting);
FRIEND_TEST_ALL_PREFIXES(PartitionAllocThreadCacheTest,
DynamicCountPerBucket);
FRIEND_TEST_ALL_PREFIXES(PartitionAllocThreadCacheTest,
DynamicCountPerBucketClamping);
FRIEND_TEST_ALL_PREFIXES(PartitionAllocThreadCacheTest,
DynamicCountPerBucketMultipleThreads);
FRIEND_TEST_ALL_PREFIXES(PartitionAllocThreadCacheTest, DynamicSizeThreshold);
FRIEND_TEST_ALL_PREFIXES(PartitionAllocThreadCacheTest,
DynamicSizeThresholdPurge);
FRIEND_TEST_ALL_PREFIXES(PartitionAllocThreadCacheTest, ClearFromTail);
PA_FRIEND_TEST_ALL_PREFIXES(PartitionAllocThreadCacheTest, Simple);
PA_FRIEND_TEST_ALL_PREFIXES(PartitionAllocThreadCacheTest,
MultipleObjectsCachedPerBucket);
PA_FRIEND_TEST_ALL_PREFIXES(PartitionAllocThreadCacheTest,
LargeAllocationsAreNotCached);
PA_FRIEND_TEST_ALL_PREFIXES(PartitionAllocThreadCacheTest,
MultipleThreadCaches);
PA_FRIEND_TEST_ALL_PREFIXES(PartitionAllocThreadCacheTest, RecordStats);
PA_FRIEND_TEST_ALL_PREFIXES(PartitionAllocThreadCacheTest,
ThreadCacheRegistry);
PA_FRIEND_TEST_ALL_PREFIXES(PartitionAllocThreadCacheTest,
MultipleThreadCachesAccounting);
PA_FRIEND_TEST_ALL_PREFIXES(PartitionAllocThreadCacheTest,
DynamicCountPerBucket);
PA_FRIEND_TEST_ALL_PREFIXES(PartitionAllocThreadCacheTest,
DynamicCountPerBucketClamping);
PA_FRIEND_TEST_ALL_PREFIXES(PartitionAllocThreadCacheTest,
DynamicCountPerBucketMultipleThreads);
PA_FRIEND_TEST_ALL_PREFIXES(PartitionAllocThreadCacheTest,
DynamicSizeThreshold);
PA_FRIEND_TEST_ALL_PREFIXES(PartitionAllocThreadCacheTest,
DynamicSizeThresholdPurge);
PA_FRIEND_TEST_ALL_PREFIXES(PartitionAllocThreadCacheTest, ClearFromTail);
};

ALWAYS_INLINE bool ThreadCache::MaybePutInCache(uintptr_t slot_start,
Expand Down

0 comments on commit d2db606

Please sign in to comment.