Remove static initialization of memory allocator in tests (#31776)

* Add more info to error

* Fix tests

* Remove static initialization of memory allocator

* Fix test failure

* Automated change: Fix sanity tests

Co-authored-by: ananda1066 <ananda1066@users.noreply.github.com>
pull/31805/head
Alisha Nanda 2 years ago committed by GitHub
parent 6eb6e00954
commit ad91404e0e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      test/core/channel/call_finalization_test.cc
  2. 11
      test/core/filters/client_authority_filter_test.cc
  3. 8
      test/core/gprpp/chunked_vector_fuzzer.cc
  4. 33
      test/core/gprpp/chunked_vector_test.cc
  5. 27
      test/core/promise/arena_promise_test.cc
  6. 19
      test/core/promise/for_each_test.cc
  7. 17
      test/core/promise/map_pipe_test.cc
  8. 27
      test/core/promise/pipe_test.cc
  9. 7
      test/core/promise/try_seq_metadata_test.cc
  10. 59
      test/core/resource_quota/arena_test.cc
  11. 7
      test/core/security/credentials_test.cc
  12. 10
      test/core/security/oauth2_utils.cc
  13. 39
      test/core/transport/binder/binder_transport_test.cc
  14. 7
      test/core/transport/chaotic_good/frame_fuzzer.cc
  15. 45
      test/core/transport/chttp2/flow_control_test.cc
  16. 16
      test/core/transport/chttp2/hpack_encoder_test.cc
  17. 10
      test/core/transport/chttp2/hpack_parser_test.cc
  18. 33
      test/core/transport/metadata_map_test.cc
  19. 24
      test/cpp/microbenchmarks/bm_arena.cc
  20. 13
      test/cpp/microbenchmarks/bm_call_create.cc
  21. 30
      test/cpp/microbenchmarks/bm_chttp2_hpack.cc
  22. 18
      test/cpp/microbenchmarks/bm_chttp2_transport.cc

@ -29,11 +29,10 @@
namespace grpc_core {
static auto* g_memory_allocator = new MemoryAllocator(
ResourceQuota::Default()->memory_quota()->CreateMemoryAllocator("test"));
TEST(CallFinalizationTest, Works) {
auto arena = MakeScopedArena(1024, g_memory_allocator);
auto memory_allocator = MemoryAllocator(
ResourceQuota::Default()->memory_quota()->CreateMemoryAllocator("test"));
auto arena = MakeScopedArena(1024, &memory_allocator);
std::string evidence;
TestContext<Arena> context(arena.get());
CallFinalization finalization;

@ -35,9 +35,6 @@
namespace grpc_core {
namespace {
auto* g_memory_allocator = new MemoryAllocator(
ResourceQuota::Default()->memory_quota()->CreateMemoryAllocator("test"));
ChannelArgs TestChannelArgs(absl::string_view default_authority) {
return ChannelArgs().Set(GRPC_ARG_DEFAULT_AUTHORITY, default_authority);
}
@ -64,7 +61,9 @@ TEST(ClientAuthorityFilterTest, NonStringArgFails) {
TEST(ClientAuthorityFilterTest, PromiseCompletesImmediatelyAndSetsAuthority) {
auto filter = *ClientAuthorityFilter::Create(
TestChannelArgs("foo.test.google.au"), ChannelFilter::Args());
auto arena = MakeScopedArena(1024, g_memory_allocator);
MemoryAllocator memory_allocator = MemoryAllocator(
ResourceQuota::Default()->memory_quota()->CreateMemoryAllocator("test"));
auto arena = MakeScopedArena(1024, &memory_allocator);
grpc_metadata_batch initial_metadata_batch(arena.get());
grpc_metadata_batch trailing_metadata_batch(arena.get());
bool seen = false;
@ -95,7 +94,9 @@ TEST(ClientAuthorityFilterTest,
PromiseCompletesImmediatelyAndDoesNotClobberAlreadySetsAuthority) {
auto filter = *ClientAuthorityFilter::Create(
TestChannelArgs("foo.test.google.au"), ChannelFilter::Args());
auto arena = MakeScopedArena(1024, g_memory_allocator);
MemoryAllocator memory_allocator = MemoryAllocator(
ResourceQuota::Default()->memory_quota()->CreateMemoryAllocator("test"));
auto arena = MakeScopedArena(1024, &memory_allocator);
grpc_metadata_batch initial_metadata_batch(arena.get());
grpc_metadata_batch trailing_metadata_batch(arena.get());
initial_metadata_batch.Set(HttpAuthorityMetadata(),

@ -34,10 +34,6 @@
bool squelch = true;
bool leak_check = true;
static auto* g_memory_allocator = new grpc_core::MemoryAllocator(
grpc_core::ResourceQuota::Default()->memory_quota()->CreateMemoryAllocator(
"test"));
static constexpr size_t kChunkSize = 17;
using IntHdl = std::shared_ptr<int>;
@ -169,7 +165,9 @@ class Fuzzer {
return &vectors_.emplace(index, Comparison(arena_.get())).first->second;
}
ScopedArenaPtr arena_ = MakeScopedArena(128, g_memory_allocator);
MemoryAllocator memory_allocator_ = MemoryAllocator(
ResourceQuota::Default()->memory_quota()->CreateMemoryAllocator("test"));
ScopedArenaPtr arena_ = MakeScopedArena(128, &memory_allocator_);
std::map<int, Comparison> vectors_;
};
} // namespace grpc_core

@ -28,20 +28,23 @@
namespace grpc_core {
namespace testing {
static auto* g_memory_allocator = new MemoryAllocator(
ResourceQuota::Default()->memory_quota()->CreateMemoryAllocator("test"));
static constexpr size_t kInitialArenaSize = 1024;
static constexpr size_t kChunkSize = 3;
TEST(ChunkedVector, Noop) {
auto arena = MakeScopedArena(kInitialArenaSize, g_memory_allocator);
class ChunkedVectorTest : public ::testing::Test {
protected:
MemoryAllocator memory_allocator_ = MemoryAllocator(
ResourceQuota::Default()->memory_quota()->CreateMemoryAllocator("test"));
};
TEST_F(ChunkedVectorTest, Noop) {
auto arena = MakeScopedArena(kInitialArenaSize, &memory_allocator_);
ChunkedVector<int, kChunkSize> v(arena.get());
EXPECT_EQ(0, v.size());
}
TEST(ChunkedVector, Stack) {
auto arena = MakeScopedArena(kInitialArenaSize, g_memory_allocator);
TEST_F(ChunkedVectorTest, Stack) {
auto arena = MakeScopedArena(kInitialArenaSize, &memory_allocator_);
ChunkedVector<int, kChunkSize> v(arena.get());
// Populate 2 chunks of memory, and 2/3 of a final chunk.
@ -82,8 +85,8 @@ TEST(ChunkedVector, Stack) {
EXPECT_EQ(0, v.size());
}
TEST(ChunkedVector, Iterate) {
auto arena = MakeScopedArena(kInitialArenaSize, g_memory_allocator);
TEST_F(ChunkedVectorTest, Iterate) {
auto arena = MakeScopedArena(kInitialArenaSize, &memory_allocator_);
ChunkedVector<int, kChunkSize> v(arena.get());
v.EmplaceBack(1);
v.EmplaceBack(2);
@ -114,8 +117,8 @@ TEST(ChunkedVector, Iterate) {
EXPECT_EQ(v.end(), it);
}
TEST(ChunkedVector, ConstIterate) {
auto arena = MakeScopedArena(kInitialArenaSize, g_memory_allocator);
TEST_F(ChunkedVectorTest, ConstIterate) {
auto arena = MakeScopedArena(kInitialArenaSize, &memory_allocator_);
ChunkedVector<int, kChunkSize> v(arena.get());
v.EmplaceBack(1);
v.EmplaceBack(2);
@ -146,8 +149,8 @@ TEST(ChunkedVector, ConstIterate) {
EXPECT_EQ(v.cend(), it);
}
TEST(ChunkedVector, Clear) {
auto arena = MakeScopedArena(kInitialArenaSize, g_memory_allocator);
TEST_F(ChunkedVectorTest, Clear) {
auto arena = MakeScopedArena(kInitialArenaSize, &memory_allocator_);
ChunkedVector<int, kChunkSize> v(arena.get());
v.EmplaceBack(1);
EXPECT_EQ(v.size(), 1);
@ -156,8 +159,8 @@ TEST(ChunkedVector, Clear) {
EXPECT_EQ(v.begin(), v.end());
}
TEST(ChunkedVector, RemoveIf) {
auto arena = MakeScopedArena(kInitialArenaSize, g_memory_allocator);
TEST_F(ChunkedVectorTest, RemoveIf) {
auto arena = MakeScopedArena(kInitialArenaSize, &memory_allocator_);
ChunkedVector<int, kChunkSize> v(arena.get());
v.EmplaceBack(1);
v.SetEnd(std::remove_if(v.begin(), v.end(), [](int i) { return i == 1; }));

@ -31,19 +31,22 @@
namespace grpc_core {
static auto* g_memory_allocator = new MemoryAllocator(
ResourceQuota::Default()->memory_quota()->CreateMemoryAllocator("test"));
class ArenaPromiseTest : public ::testing::Test {
protected:
MemoryAllocator memory_allocator_ = MemoryAllocator(
ResourceQuota::Default()->memory_quota()->CreateMemoryAllocator("test"));
};
TEST(ArenaPromiseTest, DefaultInitializationYieldsNoValue) {
auto arena = MakeScopedArena(1024, g_memory_allocator);
TEST_F(ArenaPromiseTest, DefaultInitializationYieldsNoValue) {
auto arena = MakeScopedArena(1024, &memory_allocator_);
TestContext<Arena> context(arena.get());
ArenaPromise<int> p;
EXPECT_FALSE(p.has_value());
}
TEST(ArenaPromiseTest, AllocatedWorks) {
TEST_F(ArenaPromiseTest, AllocatedWorks) {
ExecCtx exec_ctx;
auto arena = MakeScopedArena(1024, g_memory_allocator);
auto arena = MakeScopedArena(1024, &memory_allocator_);
TestContext<Arena> context(arena.get());
int x = 42;
ArenaPromise<int> p([x] { return Poll<int>(x); });
@ -53,9 +56,9 @@ TEST(ArenaPromiseTest, AllocatedWorks) {
EXPECT_EQ(p(), Poll<int>(43));
}
TEST(ArenaPromiseTest, DestructionWorks) {
TEST_F(ArenaPromiseTest, DestructionWorks) {
ExecCtx exec_ctx;
auto arena = MakeScopedArena(1024, g_memory_allocator);
auto arena = MakeScopedArena(1024, &memory_allocator_);
TestContext<Arena> context(arena.get());
auto x = std::make_shared<int>(42);
auto p = ArenaPromise<int>([x] { return Poll<int>(*x); });
@ -63,18 +66,18 @@ TEST(ArenaPromiseTest, DestructionWorks) {
EXPECT_EQ(q(), Poll<int>(42));
}
TEST(ArenaPromiseTest, MoveAssignmentWorks) {
TEST_F(ArenaPromiseTest, MoveAssignmentWorks) {
ExecCtx exec_ctx;
auto arena = MakeScopedArena(1024, g_memory_allocator);
auto arena = MakeScopedArena(1024, &memory_allocator_);
TestContext<Arena> context(arena.get());
auto x = std::make_shared<int>(42);
auto p = ArenaPromise<int>([x] { return Poll<int>(*x); });
p = ArenaPromise<int>();
}
TEST(ArenaPromiseTest, AllocatedUniquePtrWorks) {
TEST_F(ArenaPromiseTest, AllocatedUniquePtrWorks) {
ExecCtx exec_ctx;
auto arena = MakeScopedArena(1024, g_memory_allocator);
auto arena = MakeScopedArena(1024, &memory_allocator_);
TestContext<Arena> context(arena.get());
std::array<int, 5> garbage = {0, 1, 2, 3, 4};
auto freer = [garbage](int* p) { free(p + garbage[0]); };

@ -43,10 +43,13 @@ using testing::StrictMock;
namespace grpc_core {
static auto* g_memory_allocator = new MemoryAllocator(
ResourceQuota::Default()->memory_quota()->CreateMemoryAllocator("test"));
class ForEachTest : public ::testing::Test {
protected:
MemoryAllocator memory_allocator_ = MemoryAllocator(
ResourceQuota::Default()->memory_quota()->CreateMemoryAllocator("test"));
};
TEST(ForEachTest, SendThriceWithPipe) {
TEST_F(ForEachTest, SendThriceWithPipe) {
int num_received = 0;
StrictMock<MockFunction<void(absl::Status)>> on_done;
EXPECT_CALL(on_done, Call(absl::OkStatus()));
@ -76,7 +79,7 @@ TEST(ForEachTest, SendThriceWithPipe) {
},
NoWakeupScheduler(),
[&on_done](absl::Status status) { on_done.Call(std::move(status)); },
MakeScopedArena(1024, g_memory_allocator));
MakeScopedArena(1024, &memory_allocator_));
Mock::VerifyAndClearExpectations(&on_done);
EXPECT_EQ(num_received, 3);
}
@ -110,7 +113,7 @@ class MoveableUntilPolled {
int polls_ = 0;
};
TEST(ForEachTest, NoMoveAfterPoll) {
TEST_F(ForEachTest, NoMoveAfterPoll) {
int num_received = 0;
StrictMock<MockFunction<void(absl::Status)>> on_done;
EXPECT_CALL(on_done, Call(absl::OkStatus()));
@ -141,12 +144,12 @@ TEST(ForEachTest, NoMoveAfterPoll) {
},
NoWakeupScheduler(),
[&on_done](absl::Status status) { on_done.Call(std::move(status)); },
MakeScopedArena(1024, g_memory_allocator));
MakeScopedArena(1024, &memory_allocator_));
Mock::VerifyAndClearExpectations(&on_done);
EXPECT_EQ(num_received, 1);
}
TEST(ForEachTest, NextResultHeldThroughCallback) {
TEST_F(ForEachTest, NextResultHeldThroughCallback) {
int num_received = 0;
StrictMock<MockFunction<void(absl::Status)>> on_done;
EXPECT_CALL(on_done, Call(absl::OkStatus()));
@ -194,7 +197,7 @@ TEST(ForEachTest, NextResultHeldThroughCallback) {
},
NoWakeupScheduler(),
[&on_done](absl::Status status) { on_done.Call(std::move(status)); },
MakeScopedArena(1024, g_memory_allocator));
MakeScopedArena(1024, &memory_allocator_));
Mock::VerifyAndClearExpectations(&on_done);
EXPECT_EQ(num_received, 1);
}

@ -46,9 +46,6 @@ using testing::StrictMock;
namespace grpc_core {
static auto* g_memory_allocator = new MemoryAllocator(
ResourceQuota::Default()->memory_quota()->CreateMemoryAllocator("test"));
template <typename T>
class Delayed {
public:
@ -66,7 +63,13 @@ class Delayed {
T x_;
};
TEST(MapPipeTest, SendThriceWithPipeInterceptingReceive) {
class MapPipeTest : public ::testing::Test {
protected:
MemoryAllocator memory_allocator_ = MemoryAllocator(
ResourceQuota::Default()->memory_quota()->CreateMemoryAllocator("test"));
};
TEST_F(MapPipeTest, SendThriceWithPipeInterceptingReceive) {
int num_received = 0;
StrictMock<MockFunction<void(absl::Status)>> on_done;
EXPECT_CALL(on_done, Call(absl::OkStatus()));
@ -101,12 +104,12 @@ TEST(MapPipeTest, SendThriceWithPipeInterceptingReceive) {
},
NoWakeupScheduler(),
[&on_done](absl::Status status) { on_done.Call(std::move(status)); },
MakeScopedArena(1024, g_memory_allocator));
MakeScopedArena(1024, &memory_allocator_));
Mock::VerifyAndClearExpectations(&on_done);
EXPECT_EQ(num_received, 3);
}
TEST(MapPipeTest, SendThriceWithPipeInterceptingSend) {
TEST_F(MapPipeTest, SendThriceWithPipeInterceptingSend) {
int num_received = 0;
StrictMock<MockFunction<void(absl::Status)>> on_done;
EXPECT_CALL(on_done, Call(absl::OkStatus()));
@ -141,7 +144,7 @@ TEST(MapPipeTest, SendThriceWithPipeInterceptingSend) {
},
NoWakeupScheduler(),
[&on_done](absl::Status status) { on_done.Call(std::move(status)); },
MakeScopedArena(1024, g_memory_allocator));
MakeScopedArena(1024, &memory_allocator_));
Mock::VerifyAndClearExpectations(&on_done);
EXPECT_EQ(num_received, 3);
}

@ -40,10 +40,13 @@ using testing::StrictMock;
namespace grpc_core {
static auto* g_memory_allocator = new MemoryAllocator(
ResourceQuota::Default()->memory_quota()->CreateMemoryAllocator("test"));
class PipeTest : public ::testing::Test {
protected:
MemoryAllocator memory_allocator_ = MemoryAllocator(
ResourceQuota::Default()->memory_quota()->CreateMemoryAllocator("test"));
};
TEST(PipeTest, CanSendAndReceive) {
TEST_F(PipeTest, CanSendAndReceive) {
StrictMock<MockFunction<void(absl::Status)>> on_done;
EXPECT_CALL(on_done, Call(absl::OkStatus()));
MakeActivity(
@ -64,10 +67,10 @@ TEST(PipeTest, CanSendAndReceive) {
},
NoWakeupScheduler(),
[&on_done](absl::Status status) { on_done.Call(std::move(status)); },
MakeScopedArena(1024, g_memory_allocator));
MakeScopedArena(1024, &memory_allocator_));
}
TEST(PipeTest, CanReceiveAndSend) {
TEST_F(PipeTest, CanReceiveAndSend) {
StrictMock<MockFunction<void(absl::Status)>> on_done;
EXPECT_CALL(on_done, Call(absl::OkStatus()));
MakeActivity(
@ -88,10 +91,10 @@ TEST(PipeTest, CanReceiveAndSend) {
},
NoWakeupScheduler(),
[&on_done](absl::Status status) { on_done.Call(std::move(status)); },
MakeScopedArena(1024, g_memory_allocator));
MakeScopedArena(1024, &memory_allocator_));
}
TEST(PipeTest, CanSeeClosedOnSend) {
TEST_F(PipeTest, CanSeeClosedOnSend) {
StrictMock<MockFunction<void(absl::Status)>> on_done;
EXPECT_CALL(on_done, Call(absl::OkStatus()));
MakeActivity(
@ -118,10 +121,10 @@ TEST(PipeTest, CanSeeClosedOnSend) {
},
NoWakeupScheduler(),
[&on_done](absl::Status status) { on_done.Call(std::move(status)); },
MakeScopedArena(1024, g_memory_allocator));
MakeScopedArena(1024, &memory_allocator_));
}
TEST(PipeTest, CanSeeClosedOnReceive) {
TEST_F(PipeTest, CanSeeClosedOnReceive) {
StrictMock<MockFunction<void(absl::Status)>> on_done;
EXPECT_CALL(on_done, Call(absl::OkStatus()));
MakeActivity(
@ -150,10 +153,10 @@ TEST(PipeTest, CanSeeClosedOnReceive) {
},
NoWakeupScheduler(),
[&on_done](absl::Status status) { on_done.Call(std::move(status)); },
MakeScopedArena(1024, g_memory_allocator));
MakeScopedArena(1024, &memory_allocator_));
}
TEST(PipeTest, CanFlowControlThroughManyStages) {
TEST_F(PipeTest, CanFlowControlThroughManyStages) {
StrictMock<MockFunction<void(absl::Status)>> on_done;
EXPECT_CALL(on_done, Call(absl::OkStatus()));
auto done = std::make_shared<bool>(false);
@ -199,7 +202,7 @@ TEST(PipeTest, CanFlowControlThroughManyStages) {
},
NoWakeupScheduler(),
[&on_done](absl::Status status) { on_done.Call(std::move(status)); },
MakeScopedArena(1024, g_memory_allocator));
MakeScopedArena(1024, &memory_allocator_));
ASSERT_TRUE(*done);
}

@ -30,15 +30,14 @@
namespace grpc_core {
static auto* g_memory_allocator = new MemoryAllocator(
ResourceQuota::Default()->memory_quota()->CreateMemoryAllocator("test"));
struct TestMap : public MetadataMap<TestMap, GrpcStatusMetadata> {
using MetadataMap<TestMap, GrpcStatusMetadata>::MetadataMap;
};
TEST(PromiseTest, SucceedAndThenFail) {
auto arena = MakeScopedArena(1024, g_memory_allocator);
MemoryAllocator memory_allocator = MemoryAllocator(
ResourceQuota::Default()->memory_quota()->CreateMemoryAllocator("test"));
auto arena = MakeScopedArena(1024, &memory_allocator);
Poll<TestMap> r = TrySeq(
[&arena] {
TestMap m(arena.get());

@ -41,25 +41,6 @@
namespace grpc_core {
namespace {
auto* g_memory_allocator = new MemoryAllocator(
ResourceQuota::Default()->memory_quota()->CreateMemoryAllocator("test"));
}
TEST(ArenaTest, NoOp) {
ExecCtx exec_ctx;
Arena::Create(1, g_memory_allocator)->Destroy();
}
TEST(ArenaTest, ManagedNew) {
ExecCtx exec_ctx;
Arena* arena = Arena::Create(1, g_memory_allocator);
for (int i = 0; i < 100; i++) {
arena->ManagedNew<std::unique_ptr<int>>(std::make_unique<int>(i));
}
arena->Destroy();
}
struct AllocShape {
size_t initial_size;
std::vector<size_t> allocs;
@ -75,7 +56,9 @@ class AllocTest : public ::testing::TestWithParam<AllocShape> {};
TEST_P(AllocTest, Works) {
ExecCtx exec_ctx;
Arena* a = Arena::Create(GetParam().initial_size, g_memory_allocator);
MemoryAllocator memory_allocator = MemoryAllocator(
ResourceQuota::Default()->memory_quota()->CreateMemoryAllocator("test"));
Arena* a = Arena::Create(GetParam().initial_size, &memory_allocator);
std::vector<void*> allocated;
for (auto alloc : GetParam().allocs) {
void* p = a->Alloc(alloc);
@ -111,10 +94,30 @@ typedef struct {
Arena* arena;
} concurrent_test_args;
TEST(ArenaTest, ConcurrentAlloc) {
class ArenaTest : public ::testing::Test {
protected:
MemoryAllocator memory_allocator_ = MemoryAllocator(
ResourceQuota::Default()->memory_quota()->CreateMemoryAllocator("test"));
};
TEST_F(ArenaTest, NoOp) {
ExecCtx exec_ctx;
Arena::Create(1, &memory_allocator_)->Destroy();
}
TEST_F(ArenaTest, ManagedNew) {
ExecCtx exec_ctx;
Arena* arena = Arena::Create(1, &memory_allocator_);
for (int i = 0; i < 100; i++) {
arena->ManagedNew<std::unique_ptr<int>>(std::make_unique<int>(i));
}
arena->Destroy();
}
TEST_F(ArenaTest, ConcurrentAlloc) {
concurrent_test_args args;
gpr_event_init(&args.ev_start);
args.arena = Arena::Create(1024, g_memory_allocator);
args.arena = Arena::Create(1024, &memory_allocator_);
Thread thds[CONCURRENT_TEST_THREADS];
@ -141,10 +144,10 @@ TEST(ArenaTest, ConcurrentAlloc) {
args.arena->Destroy();
}
TEST(ArenaTest, ConcurrentManagedNew) {
TEST_F(ArenaTest, ConcurrentManagedNew) {
concurrent_test_args args;
gpr_event_init(&args.ev_start);
args.arena = Arena::Create(1024, g_memory_allocator);
args.arena = Arena::Create(1024, &memory_allocator_);
Thread thds[CONCURRENT_TEST_THREADS];
@ -172,12 +175,12 @@ TEST(ArenaTest, ConcurrentManagedNew) {
args.arena->Destroy();
}
TEST(ArenaTest, PooledObjectsArePooled) {
TEST_F(ArenaTest, PooledObjectsArePooled) {
struct TestObj {
char a[100];
};
auto arena = MakeScopedArena(1024, g_memory_allocator);
auto arena = MakeScopedArena(1024, &memory_allocator_);
auto obj = arena->MakePooled<TestObj>();
void* p = obj.get();
obj.reset();
@ -185,11 +188,11 @@ TEST(ArenaTest, PooledObjectsArePooled) {
EXPECT_EQ(p, obj.get());
}
TEST(ArenaTest, CreateManyObjects) {
TEST_F(ArenaTest, CreateManyObjects) {
struct TestObj {
char a[100];
};
auto arena = MakeScopedArena(1024, g_memory_allocator);
auto arena = MakeScopedArena(1024, &memory_allocator_);
std::vector<Arena::PoolPtr<TestObj>> objs;
objs.reserve(1000);
for (int i = 0; i < 1000; i++) {

@ -78,9 +78,6 @@ using internal::set_gce_tenancy_checker_for_testing;
namespace {
auto* g_memory_allocator = new MemoryAllocator(
ResourceQuota::Default()->memory_quota()->CreateMemoryAllocator("test"));
/* -- Constants. -- */
const char test_google_iam_authorization_token[] = "blahblahblhahb";
@ -583,7 +580,9 @@ class RequestMetadataState : public RefCounted<RequestMetadataState> {
grpc_error_handle expected_error_;
std::string expected_;
ScopedArenaPtr arena_ = MakeScopedArena(1024, g_memory_allocator);
MemoryAllocator memory_allocator_ = MemoryAllocator(
ResourceQuota::Default()->memory_quota()->CreateMemoryAllocator("test"));
ScopedArenaPtr arena_ = MakeScopedArena(1024, &memory_allocator_);
grpc_metadata_batch md_{arena_.get()};
grpc_call_credentials::GetRequestMetadataArgs get_request_metadata_args_;
grpc_polling_entity pollent_;

@ -35,10 +35,6 @@
#include "src/core/lib/security/context/security_context.h"
#include "src/core/lib/security/credentials/credentials.h"
static auto* g_memory_allocator = new grpc_core::MemoryAllocator(
grpc_core::ResourceQuota::Default()->memory_quota()->CreateMemoryAllocator(
"test"));
char* grpc_test_fetch_oauth2_token_with_credentials(
grpc_call_credentials* creds) {
grpc_core::ExecCtx exec_ctx;
@ -51,7 +47,11 @@ char* grpc_test_fetch_oauth2_token_with_credentials(
auto pops = grpc_polling_entity_create_from_pollset(pollset);
bool is_done = false;
auto arena = grpc_core::MakeScopedArena(1024, g_memory_allocator);
grpc_core::MemoryAllocator memory_allocator =
grpc_core::MemoryAllocator(grpc_core::ResourceQuota::Default()
->memory_quota()
->CreateMemoryAllocator("test"));
auto arena = grpc_core::MakeScopedArena(1024, &memory_allocator);
grpc_metadata_batch initial_metadata{arena.get()};
char* token = nullptr;

@ -37,10 +37,6 @@
#include "test/core/transport/binder/mock_objects.h"
#include "test/core/util/test_config.h"
static auto* g_memory_allocator = new grpc_core::MemoryAllocator(
grpc_core::ResourceQuota::Default()->memory_quota()->CreateMemoryAllocator(
"test"));
namespace grpc_binder {
namespace {
@ -51,9 +47,7 @@ using ::testing::Return;
class BinderTransportTest : public ::testing::Test {
public:
BinderTransportTest()
: arena_(grpc_core::Arena::Create(/* initial_size = */ 1,
g_memory_allocator)),
transport_(grpc_create_binder_transport_client(
: transport_(grpc_create_binder_transport_client(
std::make_unique<NiceMock<MockBinder>>(),
std::make_shared<
grpc::experimental::binder::UntrustedSecurityPolicy>())) {
@ -101,7 +95,12 @@ class BinderTransportTest : public ::testing::Test {
static void TearDownTestSuite() { grpc_shutdown(); }
protected:
grpc_core::Arena* arena_;
grpc_core::MemoryAllocator memory_allocator_ =
grpc_core::MemoryAllocator(grpc_core::ResourceQuota::Default()
->memory_quota()
->CreateMemoryAllocator("test"));
grpc_core::Arena* arena_ =
grpc_core::Arena::Create(/* initial_size = */ 1, &memory_allocator_);
grpc_transport* transport_;
grpc_stream_refcount ref_;
std::vector<grpc_binder_stream*> stream_buffer_;
@ -235,8 +234,12 @@ struct MakeSendInitialMetadata {
}
~MakeSendInitialMetadata() {}
grpc_core::MemoryAllocator memory_allocator =
grpc_core::MemoryAllocator(grpc_core::ResourceQuota::Default()
->memory_quota()
->CreateMemoryAllocator("test"));
grpc_core::ScopedArenaPtr arena =
grpc_core::MakeScopedArena(1024, g_memory_allocator);
grpc_core::MakeScopedArena(1024, &memory_allocator);
grpc_metadata_batch grpc_initial_metadata{arena.get()};
};
@ -262,8 +265,12 @@ struct MakeSendTrailingMetadata {
&grpc_trailing_metadata;
}
grpc_core::MemoryAllocator memory_allocator =
grpc_core::MemoryAllocator(grpc_core::ResourceQuota::Default()
->memory_quota()
->CreateMemoryAllocator("test"));
grpc_core::ScopedArenaPtr arena =
grpc_core::MakeScopedArena(1024, g_memory_allocator);
grpc_core::MakeScopedArena(1024, &memory_allocator);
grpc_metadata_batch grpc_trailing_metadata{arena.get()};
};
@ -286,8 +293,12 @@ struct MakeRecvInitialMetadata {
~MakeRecvInitialMetadata() {}
MockGrpcClosure ready;
grpc_core::MemoryAllocator memory_allocator =
grpc_core::MemoryAllocator(grpc_core::ResourceQuota::Default()
->memory_quota()
->CreateMemoryAllocator("test"));
grpc_core::ScopedArenaPtr arena =
grpc_core::MakeScopedArena(1024, g_memory_allocator);
grpc_core::MakeScopedArena(1024, &memory_allocator);
grpc_metadata_batch grpc_initial_metadata{arena.get()};
grpc_core::Notification notification;
};
@ -330,8 +341,12 @@ struct MakeRecvTrailingMetadata {
~MakeRecvTrailingMetadata() {}
MockGrpcClosure ready;
grpc_core::MemoryAllocator memory_allocator =
grpc_core::MemoryAllocator(grpc_core::ResourceQuota::Default()
->memory_quota()
->CreateMemoryAllocator("test"));
grpc_core::ScopedArenaPtr arena =
grpc_core::MakeScopedArena(1024, g_memory_allocator);
grpc_core::MakeScopedArena(1024, &memory_allocator);
grpc_metadata_batch grpc_trailing_metadata{arena.get()};
grpc_core::Notification notification;
};

@ -39,9 +39,6 @@ bool squelch = false;
namespace grpc_core {
namespace chaotic_good {
static auto* g_memory_allocator = new MemoryAllocator(
ResourceQuota::Default()->memory_quota()->CreateMemoryAllocator("test"));
template <typename T>
void AssertRoundTrips(const T& input, FrameType expected_frame_type) {
HPackCompressor hpack_compressor;
@ -82,7 +79,9 @@ int Run(const uint8_t* data, size_t size) {
if (!r.ok()) return 0;
size -= 64;
data += 64;
auto arena = MakeScopedArena(1024, g_memory_allocator);
MemoryAllocator memory_allocator = MemoryAllocator(
ResourceQuota::Default()->memory_quota()->CreateMemoryAllocator("test"));
auto arena = MakeScopedArena(1024, &memory_allocator);
TestContext<Arena> ctx(arena.get());
switch (r->type) {
default:

@ -38,9 +38,6 @@ namespace {
constexpr uint64_t kMaxAdvanceTimeMillis = 24ull * 365 * 3600 * 1000;
auto* g_memory_owner = new MemoryOwner(
ResourceQuota::Default()->memory_quota()->CreateMemoryOwner("test"));
gpr_timespec g_now;
gpr_timespec now_impl(gpr_clock_type clock_type) {
GPR_ASSERT(clock_type != GPR_TIMESPAN);
@ -83,9 +80,15 @@ class TransportTargetWindowEstimatesMocker
} // namespace
TEST(FlowControl, NoOp) {
class FlowControlTest : public ::testing::Test {
protected:
MemoryOwner memory_owner_ = MemoryOwner(
ResourceQuota::Default()->memory_quota()->CreateMemoryOwner("test"));
};
TEST_F(FlowControlTest, NoOp) {
ExecCtx exec_ctx;
TransportFlowControl tfc("test", true, g_memory_owner);
TransportFlowControl tfc("test", true, &memory_owner_);
StreamFlowControl sfc(&tfc);
// Check initial values are per http2 spec
EXPECT_EQ(tfc.acked_init_window(), 65535);
@ -97,9 +100,9 @@ TEST(FlowControl, NoOp) {
EXPECT_EQ(sfc.announced_window_delta(), 0);
}
TEST(FlowControl, SendData) {
TEST_F(FlowControlTest, SendData) {
ExecCtx exec_ctx;
TransportFlowControl tfc("test", true, g_memory_owner);
TransportFlowControl tfc("test", true, &memory_owner_);
StreamFlowControl sfc(&tfc);
int64_t prev_preferred_rx_frame_size =
tfc.target_preferred_rx_crypto_frame_size();
@ -113,24 +116,24 @@ TEST(FlowControl, SendData) {
prev_preferred_rx_frame_size);
}
TEST(FlowControl, InitialTransportUpdate) {
TEST_F(FlowControlTest, InitialTransportUpdate) {
ExecCtx exec_ctx;
TransportFlowControl tfc("test", true, g_memory_owner);
TransportFlowControl tfc("test", true, &memory_owner_);
EXPECT_EQ(TransportFlowControl::IncomingUpdateContext(&tfc).MakeAction(),
FlowControlAction());
}
TEST(FlowControl, InitialStreamUpdate) {
TEST_F(FlowControlTest, InitialStreamUpdate) {
ExecCtx exec_ctx;
TransportFlowControl tfc("test", true, g_memory_owner);
TransportFlowControl tfc("test", true, &memory_owner_);
StreamFlowControl sfc(&tfc);
EXPECT_EQ(StreamFlowControl::IncomingUpdateContext(&sfc).MakeAction(),
FlowControlAction());
}
TEST(FlowControl, PeriodicUpdate) {
TEST_F(FlowControlTest, PeriodicUpdate) {
ExecCtx exec_ctx;
TransportFlowControl tfc("test", true, g_memory_owner);
TransportFlowControl tfc("test", true, &memory_owner_);
constexpr int kNumPeriodicUpdates = 100;
Timestamp next_ping = Timestamp::Now() + Duration::Milliseconds(1000);
uint32_t prev_max_frame_size = tfc.target_frame_size();
@ -161,9 +164,9 @@ TEST(FlowControl, PeriodicUpdate) {
}
}
TEST(FlowControl, RecvData) {
TEST_F(FlowControlTest, RecvData) {
ExecCtx exec_ctx;
TransportFlowControl tfc("test", true, g_memory_owner);
TransportFlowControl tfc("test", true, &memory_owner_);
StreamFlowControl sfc(&tfc);
StreamFlowControl::IncomingUpdateContext sfc_upd(&sfc);
int64_t prev_preferred_rx_frame_size =
@ -176,9 +179,9 @@ TEST(FlowControl, RecvData) {
prev_preferred_rx_frame_size);
}
TEST(FlowControl, TrackMinProgressSize) {
TEST_F(FlowControlTest, TrackMinProgressSize) {
ExecCtx exec_ctx;
TransportFlowControl tfc("test", true, g_memory_owner);
TransportFlowControl tfc("test", true, &memory_owner_);
StreamFlowControl sfc(&tfc);
{
StreamFlowControl::IncomingUpdateContext sfc_upd(&sfc);
@ -212,9 +215,9 @@ TEST(FlowControl, TrackMinProgressSize) {
EXPECT_EQ(sfc.min_progress_size(), 0);
}
TEST(FlowControl, NoUpdateWithoutReader) {
TEST_F(FlowControlTest, NoUpdateWithoutReader) {
ExecCtx exec_ctx;
TransportFlowControl tfc("test", true, g_memory_owner);
TransportFlowControl tfc("test", true, &memory_owner_);
StreamFlowControl sfc(&tfc);
for (int i = 0; i < 65535; i++) {
StreamFlowControl::IncomingUpdateContext sfc_upd(&sfc);
@ -234,9 +237,9 @@ TEST(FlowControl, NoUpdateWithoutReader) {
EXPECT_GT(sfc.MaybeSendUpdate(), 0);
}
TEST(FlowControl, GradualReadsUpdate) {
TEST_F(FlowControlTest, GradualReadsUpdate) {
ExecCtx exec_ctx;
TransportFlowControl tfc("test", true, g_memory_owner);
TransportFlowControl tfc("test", true, &memory_owner_);
StreamFlowControl sfc(&tfc);
int immediate_updates = 0;
int queued_updates = 0;

@ -41,10 +41,6 @@
#include "test/core/util/slice_splitter.h"
#include "test/core/util/test_config.h"
static auto* g_memory_allocator = new grpc_core::MemoryAllocator(
grpc_core::ResourceQuota::Default()->memory_quota()->CreateMemoryAllocator(
"test"));
grpc_core::HPackCompressor* g_compressor;
typedef struct {
@ -158,7 +154,11 @@ grpc_slice EncodeHeaderIntoBytes(
std::unique_ptr<grpc_core::HPackCompressor> compressor =
std::make_unique<grpc_core::HPackCompressor>();
auto arena = grpc_core::MakeScopedArena(1024, g_memory_allocator);
grpc_core::MemoryAllocator memory_allocator =
grpc_core::MemoryAllocator(grpc_core::ResourceQuota::Default()
->memory_quota()
->CreateMemoryAllocator("test"));
auto arena = grpc_core::MakeScopedArena(1024, &memory_allocator);
grpc_metadata_batch b(arena.get());
for (const auto& field : header_fields) {
@ -303,7 +303,11 @@ TEST(HpackEncoderTest, UserAgentMetadataNoIndexing) {
static void verify_continuation_headers(const char* key, const char* value,
bool is_eof) {
auto arena = grpc_core::MakeScopedArena(1024, g_memory_allocator);
grpc_core::MemoryAllocator memory_allocator =
grpc_core::MemoryAllocator(grpc_core::ResourceQuota::Default()
->memory_quota()
->CreateMemoryAllocator("test"));
auto arena = grpc_core::MakeScopedArena(1024, &memory_allocator);
grpc_slice_buffer output;
grpc_metadata_batch b(arena.get());
b.Append(key, grpc_core::Slice::FromStaticString(value), CrashOnAppendError);

@ -46,10 +46,6 @@
#include "test/core/util/slice_splitter.h"
#include "test/core/util/test_config.h"
static auto* g_memory_allocator = new grpc_core::MemoryAllocator(
grpc_core::ResourceQuota::Default()->memory_quota()->CreateMemoryAllocator(
"test"));
struct TestInput {
const char* input;
const char* expected_parse;
@ -87,7 +83,11 @@ class ParseTest : public ::testing::TestWithParam<Test> {
void TestVector(grpc_slice_split_mode mode, const char* hexstring,
std::string expect) {
auto arena = grpc_core::MakeScopedArena(1024, g_memory_allocator);
grpc_core::MemoryAllocator memory_allocator =
grpc_core::MemoryAllocator(grpc_core::ResourceQuota::Default()
->memory_quota()
->CreateMemoryAllocator("test"));
auto arena = grpc_core::MakeScopedArena(1024, &memory_allocator);
grpc_core::ExecCtx exec_ctx;
grpc_slice input = parse_hexstring(hexstring);
grpc_slice* slices;

@ -37,9 +37,6 @@
namespace grpc_core {
namespace testing {
static auto* g_memory_allocator = new MemoryAllocator(
ResourceQuota::Default()->memory_quota()->CreateMemoryAllocator("test"));
struct EmptyMetadataMap : public MetadataMap<EmptyMetadataMap> {
using MetadataMap<EmptyMetadataMap>::MetadataMap;
};
@ -56,18 +53,24 @@ struct StreamNetworkStateMetadataMap
GrpcStreamNetworkState>::MetadataMap;
};
TEST(MetadataMapTest, Noop) {
auto arena = MakeScopedArena(1024, g_memory_allocator);
class MetadataMapTest : public ::testing::Test {
protected:
MemoryAllocator memory_allocator_ = MemoryAllocator(
ResourceQuota::Default()->memory_quota()->CreateMemoryAllocator("test"));
};
TEST_F(MetadataMapTest, Noop) {
auto arena = MakeScopedArena(1024, &memory_allocator_);
EmptyMetadataMap(arena.get());
}
TEST(MetadataMapTest, NoopWithDeadline) {
auto arena = MakeScopedArena(1024, g_memory_allocator);
TEST_F(MetadataMapTest, NoopWithDeadline) {
auto arena = MakeScopedArena(1024, &memory_allocator_);
TimeoutOnlyMetadataMap(arena.get());
}
TEST(MetadataMapTest, SimpleOps) {
auto arena = MakeScopedArena(1024, g_memory_allocator);
TEST_F(MetadataMapTest, SimpleOps) {
auto arena = MakeScopedArena(1024, &memory_allocator_);
TimeoutOnlyMetadataMap map(arena.get());
EXPECT_EQ(map.get_pointer(GrpcTimeoutMetadata()), nullptr);
EXPECT_EQ(map.get(GrpcTimeoutMetadata()), absl::nullopt);
@ -104,17 +107,17 @@ class FakeEncoder {
std::string output_;
};
TEST(MetadataMapTest, EmptyEncodeTest) {
TEST_F(MetadataMapTest, EmptyEncodeTest) {
FakeEncoder encoder;
auto arena = MakeScopedArena(1024, g_memory_allocator);
auto arena = MakeScopedArena(1024, &memory_allocator_);
TimeoutOnlyMetadataMap map(arena.get());
map.Encode(&encoder);
EXPECT_EQ(encoder.output(), "");
}
TEST(MetadataMapTest, TimeoutEncodeTest) {
TEST_F(MetadataMapTest, TimeoutEncodeTest) {
FakeEncoder encoder;
auto arena = MakeScopedArena(1024, g_memory_allocator);
auto arena = MakeScopedArena(1024, &memory_allocator_);
TimeoutOnlyMetadataMap map(arena.get());
map.Set(GrpcTimeoutMetadata(),
Timestamp::FromMillisecondsAfterProcessEpoch(1234));
@ -122,13 +125,13 @@ TEST(MetadataMapTest, TimeoutEncodeTest) {
EXPECT_EQ(encoder.output(), "grpc-timeout: deadline=1234\n");
}
TEST(MetadataMapTest, NonEncodableTrait) {
TEST_F(MetadataMapTest, NonEncodableTrait) {
struct EncoderWithNoTraitEncodeFunctions {
void Encode(const Slice&, const Slice&) {
abort(); // should not be called
}
};
auto arena = MakeScopedArena(1024, g_memory_allocator);
auto arena = MakeScopedArena(1024, &memory_allocator_);
StreamNetworkStateMetadataMap map(arena.get());
map.Set(GrpcStreamNetworkState(), GrpcStreamNetworkState::kNotSentOnWire);
EXPECT_EQ(map.get(GrpcStreamNetworkState()),

@ -28,19 +28,23 @@
using grpc_core::Arena;
static auto* g_memory_allocator = new grpc_core::MemoryAllocator(
grpc_core::ResourceQuota::Default()->memory_quota()->CreateMemoryAllocator(
"test"));
static void BM_Arena_NoOp(benchmark::State& state) {
grpc_core::MemoryAllocator memory_allocator =
grpc_core::MemoryAllocator(grpc_core::ResourceQuota::Default()
->memory_quota()
->CreateMemoryAllocator("test"));
for (auto _ : state) {
Arena::Create(state.range(0), g_memory_allocator)->Destroy();
Arena::Create(state.range(0), &memory_allocator)->Destroy();
}
}
BENCHMARK(BM_Arena_NoOp)->Range(1, 1024 * 1024);
static void BM_Arena_ManyAlloc(benchmark::State& state) {
Arena* a = Arena::Create(state.range(0), g_memory_allocator);
grpc_core::MemoryAllocator memory_allocator =
grpc_core::MemoryAllocator(grpc_core::ResourceQuota::Default()
->memory_quota()
->CreateMemoryAllocator("test"));
Arena* a = Arena::Create(state.range(0), &memory_allocator);
const size_t realloc_after =
1024 * 1024 * 1024 / ((state.range(1) + 15) & 0xffffff0u);
while (state.KeepRunning()) {
@ -48,7 +52,7 @@ static void BM_Arena_ManyAlloc(benchmark::State& state) {
// periodically recreate arena to avoid OOM
if (state.iterations() % realloc_after == 0) {
a->Destroy();
a = Arena::Create(state.range(0), g_memory_allocator);
a = Arena::Create(state.range(0), &memory_allocator);
}
}
a->Destroy();
@ -56,8 +60,12 @@ static void BM_Arena_ManyAlloc(benchmark::State& state) {
BENCHMARK(BM_Arena_ManyAlloc)->Ranges({{1, 1024 * 1024}, {1, 32 * 1024}});
static void BM_Arena_Batch(benchmark::State& state) {
grpc_core::MemoryAllocator memory_allocator =
grpc_core::MemoryAllocator(grpc_core::ResourceQuota::Default()
->memory_quota()
->CreateMemoryAllocator("test"));
for (auto _ : state) {
Arena* a = Arena::Create(state.range(0), g_memory_allocator);
Arena* a = Arena::Create(state.range(0), &memory_allocator);
for (int i = 0; i < state.range(1); i++) {
a->Alloc(state.range(2));
}

@ -53,10 +53,6 @@
#include "test/cpp/microbenchmarks/helpers.h"
#include "test/cpp/util/test_config.h"
static auto* g_memory_allocator = new grpc_core::MemoryAllocator(
grpc_core::ResourceQuota::Default()->memory_quota()->CreateMemoryAllocator(
"test"));
void BM_Zalloc(benchmark::State& state) {
// speed of light for call creation is zalloc, so benchmark a few interesting
// sizes
@ -540,6 +536,10 @@ static void BM_IsolatedFilter(benchmark::State& state) {
TestOp test_op_data;
const int kArenaSize = 32 * 1024 * 1024;
grpc_call_context_element context[GRPC_CONTEXT_COUNT] = {};
grpc_core::MemoryAllocator memory_allocator =
grpc_core::MemoryAllocator(grpc_core::ResourceQuota::Default()
->memory_quota()
->CreateMemoryAllocator("test"));
grpc_call_element_args call_args{
call_stack,
nullptr,
@ -547,7 +547,7 @@ static void BM_IsolatedFilter(benchmark::State& state) {
method,
start_time,
deadline,
grpc_core::Arena::Create(kArenaSize, g_memory_allocator),
grpc_core::Arena::Create(kArenaSize, &memory_allocator),
nullptr};
while (state.KeepRunning()) {
(void)grpc_call_stack_init(channel_stack, 1, DoNothing, nullptr,
@ -559,8 +559,7 @@ static void BM_IsolatedFilter(benchmark::State& state) {
// recreate arena every 64k iterations to avoid oom
if (0 == (state.iterations() & 0xffff)) {
call_args.arena->Destroy();
call_args.arena =
grpc_core::Arena::Create(kArenaSize, g_memory_allocator);
call_args.arena = grpc_core::Arena::Create(kArenaSize, &memory_allocator);
}
}
call_args.arena->Destroy();

@ -41,10 +41,6 @@
#include "test/cpp/microbenchmarks/helpers.h"
#include "test/cpp/util/test_config.h"
static auto* g_memory_allocator = new grpc_core::MemoryAllocator(
grpc_core::ResourceQuota::Default()->memory_quota()->CreateMemoryAllocator(
"test"));
static grpc_slice MakeSlice(const std::vector<uint8_t>& bytes) {
grpc_slice s = grpc_slice_malloc(bytes.size());
uint8_t* p = GRPC_SLICE_START_PTR(s);
@ -71,7 +67,11 @@ static void BM_HpackEncoderEncodeDeadline(benchmark::State& state) {
grpc_core::ExecCtx exec_ctx;
grpc_core::Timestamp saved_now = grpc_core::Timestamp::Now();
auto arena = grpc_core::MakeScopedArena(1024, g_memory_allocator);
grpc_core::MemoryAllocator memory_allocator =
grpc_core::MemoryAllocator(grpc_core::ResourceQuota::Default()
->memory_quota()
->CreateMemoryAllocator("test"));
auto arena = grpc_core::MakeScopedArena(1024, &memory_allocator);
grpc_metadata_batch b(arena.get());
b.Set(grpc_core::GrpcTimeoutMetadata(),
saved_now + grpc_core::Duration::Seconds(30));
@ -103,7 +103,11 @@ static void BM_HpackEncoderEncodeHeader(benchmark::State& state) {
grpc_core::ExecCtx exec_ctx;
static bool logged_representative_output = false;
auto arena = grpc_core::MakeScopedArena(1024, g_memory_allocator);
grpc_core::MemoryAllocator memory_allocator =
grpc_core::MemoryAllocator(grpc_core::ResourceQuota::Default()
->memory_quota()
->CreateMemoryAllocator("test"));
auto arena = grpc_core::MakeScopedArena(1024, &memory_allocator);
grpc_metadata_batch b(arena.get());
Fixture::Prepare(&b);
@ -336,7 +340,11 @@ static void BM_HpackParserParseHeader(benchmark::State& state) {
grpc_core::ExecCtx exec_ctx;
grpc_core::HPackParser p;
const int kArenaSize = 4096 * 4096;
auto* arena = grpc_core::Arena::Create(kArenaSize, g_memory_allocator);
grpc_core::MemoryAllocator memory_allocator =
grpc_core::MemoryAllocator(grpc_core::ResourceQuota::Default()
->memory_quota()
->CreateMemoryAllocator("test"));
auto* arena = grpc_core::Arena::Create(kArenaSize, &memory_allocator);
grpc_core::ManualConstructor<grpc_metadata_batch> b;
b.Init(arena);
p.BeginFrame(&*b, std::numeric_limits<uint32_t>::max(),
@ -359,7 +367,7 @@ static void BM_HpackParserParseHeader(benchmark::State& state) {
if (0 == (state.iterations() & 0xfff)) {
b.Destroy();
arena->Destroy();
arena = grpc_core::Arena::Create(kArenaSize, g_memory_allocator);
arena = grpc_core::Arena::Create(kArenaSize, &memory_allocator);
b.Init(arena);
p.BeginFrame(&*b, std::numeric_limits<uint32_t>::max(),
grpc_core::HPackParser::Boundary::None,
@ -387,7 +395,11 @@ class FromEncoderFixture {
static std::vector<grpc_slice> Generate(int iteration) {
grpc_core::ExecCtx exec_ctx;
auto arena = grpc_core::MakeScopedArena(1024, g_memory_allocator);
grpc_core::MemoryAllocator memory_allocator =
grpc_core::MemoryAllocator(grpc_core::ResourceQuota::Default()
->memory_quota()
->CreateMemoryAllocator("test"));
auto arena = grpc_core::MakeScopedArena(1024, &memory_allocator);
grpc_metadata_batch b(arena.get());
EncoderFixture::Prepare(&b);

@ -40,10 +40,6 @@
#include "test/cpp/microbenchmarks/helpers.h"
#include "test/cpp/util/test_config.h"
static auto* g_memory_allocator = new grpc_core::MemoryAllocator(
grpc_core::ResourceQuota::Default()->memory_quota()->CreateMemoryAllocator(
"test"));
////////////////////////////////////////////////////////////////////////////////
// Helper classes
//
@ -199,7 +195,7 @@ class Stream {
explicit Stream(Fixture* f) : f_(f) {
stream_size_ = grpc_transport_stream_size(f->transport());
stream_ = gpr_malloc(stream_size_);
arena_ = grpc_core::Arena::Create(4096, g_memory_allocator);
arena_ = grpc_core::Arena::Create(4096, &memory_allocator_);
}
~Stream() {
@ -215,7 +211,7 @@ class Stream {
memset(stream_, 0, stream_size_);
if ((state.iterations() & 0xffff) == 0) {
arena_->Destroy();
arena_ = grpc_core::Arena::Create(4096, g_memory_allocator);
arena_ = grpc_core::Arena::Create(4096, &memory_allocator_);
}
grpc_transport_init_stream(f_->transport(),
static_cast<grpc_stream*>(stream_), &refcount_,
@ -251,6 +247,10 @@ class Stream {
Fixture* f_;
grpc_stream_refcount refcount_;
grpc_core::MemoryAllocator memory_allocator_ =
grpc_core::MemoryAllocator(grpc_core::ResourceQuota::Default()
->memory_quota()
->CreateMemoryAllocator("test"));
grpc_core::Arena* arena_;
size_t stream_size_;
void* stream_;
@ -329,7 +329,11 @@ static void BM_StreamCreateSendInitialMetadataDestroy(benchmark::State& state) {
op.payload = &op_payload;
};
auto arena = grpc_core::MakeScopedArena(1024, g_memory_allocator);
grpc_core::MemoryAllocator memory_allocator =
grpc_core::MemoryAllocator(grpc_core::ResourceQuota::Default()
->memory_quota()
->CreateMemoryAllocator("test"));
auto arena = grpc_core::MakeScopedArena(1024, &memory_allocator);
grpc_metadata_batch b(arena.get());
Metadata::Prepare(&b);

Loading…
Cancel
Save