Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(106)

Unified Diff: net/quic/quic_one_block_arena_test.cc

Issue 1572353002: QuicAlarms are now allocated out of an arena in QuicConnection (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge recent changes. Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/quic/quic_one_block_arena.h ('k') | net/quic/quic_utils.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/quic/quic_one_block_arena_test.cc
diff --git a/net/quic/quic_one_block_arena_test.cc b/net/quic/quic_one_block_arena_test.cc
new file mode 100644
index 0000000000000000000000000000000000000000..0b5024865aaf9ca9b8f775f2cc03d35075cc55c2
--- /dev/null
+++ b/net/quic/quic_one_block_arena_test.cc
@@ -0,0 +1,68 @@
+// Copyright (c) 2016 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.
+
+#include "net/quic/quic_one_block_arena.h"
+
+#include "net/quic/interval_set.h"
+#include "net/quic/quic_flags.h"
+#include "net/quic/quic_utils.h"
+#include "net/test/gtest_util.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace net {
+namespace {
+
+static const uint32_t kMaxAlign = 8;
+
+struct TestObject {
+ uint32_t value;
+};
+
+TEST(QuicOneBlockArenaTest, AllocateSuccess) {
+ FLAGS_quic_enable_arena_allocation = true;
+ QuicOneBlockArena<1024> arena;
+ QuicArenaScopedPtr<TestObject> ptr = arena.New<TestObject>();
+ EXPECT_TRUE(ptr.is_from_arena());
+}
+
+TEST(QuicOneBlockArenaTest, Disabled) {
+ FLAGS_quic_enable_arena_allocation = false;
+ QuicOneBlockArena<1024> arena;
+ QuicArenaScopedPtr<TestObject> ptr = arena.New<TestObject>();
+ EXPECT_FALSE(ptr.is_from_arena());
+}
+
+TEST(QuicOneBlockArenaTest, Exhaust) {
+ FLAGS_quic_enable_arena_allocation = true;
+ QuicOneBlockArena<1024> arena;
+ for (size_t i = 0; i < 1024 / kMaxAlign; ++i) {
+ QuicArenaScopedPtr<TestObject> ptr = arena.New<TestObject>();
+ EXPECT_TRUE(ptr.is_from_arena());
+ }
+ QuicArenaScopedPtr<TestObject> ptr;
+ EXPECT_DFATAL(ptr = arena.New<TestObject>(),
+ "Ran out of space in QuicOneBlockArena");
+ EXPECT_FALSE(ptr.is_from_arena());
+}
+
+TEST(QuicOneBlockArenaTest, NoOverlaps) {
+ FLAGS_quic_enable_arena_allocation = true;
+ QuicOneBlockArena<1024> arena;
+ std::vector<QuicArenaScopedPtr<TestObject>> objects;
+ IntervalSet<uintptr_t> used;
+ for (size_t i = 0; i < 1024 / kMaxAlign; ++i) {
+ QuicArenaScopedPtr<TestObject> ptr = arena.New<TestObject>();
+ EXPECT_TRUE(ptr.is_from_arena());
+
+ uintptr_t begin = reinterpret_cast<uintptr_t>(ptr.get());
+ uintptr_t end = begin + sizeof(TestObject);
+ EXPECT_FALSE(used.Contains(begin));
+ EXPECT_FALSE(used.Contains(end - 1));
+ used.Add(begin, end);
+ }
+}
+
+} // namespace
+} // namespace net
« no previous file with comments | « net/quic/quic_one_block_arena.h ('k') | net/quic/quic_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698