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

Unified Diff: base/allocator/malloc_zone_aggregator_mac_unittest.cc

Issue 2703803004: macOS: Shim all malloc zones. (Closed)
Patch Set: Minor formatting. Created 3 years, 10 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
Index: base/allocator/malloc_zone_aggregator_mac_unittest.cc
diff --git a/base/allocator/malloc_zone_aggregator_mac_unittest.cc b/base/allocator/malloc_zone_aggregator_mac_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..c9b3f32bbc89d0e3f6a91a15ad3ae0abc694bc38
--- /dev/null
+++ b/base/allocator/malloc_zone_aggregator_mac_unittest.cc
@@ -0,0 +1,57 @@
+// Copyright 2017 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 "base/allocator/malloc_zone_aggregator_mac.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace base {
+namespace allocator {
+
+TEST(MallocZoneAggregatorTest, TestDefaultZoneMallocFree) {
+ MallocZoneAggregator aggregator;
+ ChromeMallocZone* malloc_zone =
+ reinterpret_cast<ChromeMallocZone*>(malloc_default_zone());
+ aggregator.StoreZone(malloc_zone);
+ int* test =
+ reinterpret_cast<int*>(aggregator.DispatchMallocToZone(malloc_zone, 33));
+ test[0] = 1;
+ test[1] = 2;
+ aggregator.DispatchFreeToZone(malloc_zone, test);
+}
+
+TEST(MallocZoneAggregatorTest, IsZoneAlreadyStored) {
+ MallocZoneAggregator aggregator;
+ ChromeMallocZone* malloc_zone =
+ reinterpret_cast<ChromeMallocZone*>(malloc_default_zone());
+ EXPECT_FALSE(aggregator.IsZoneAlreadyStored(malloc_zone));
+ aggregator.StoreZone(malloc_zone);
+ EXPECT_TRUE(aggregator.IsZoneAlreadyStored(malloc_zone));
+}
+
+TEST(MallocZoneAggregatorTest, CannotDoubleStoreZone) {
+ MallocZoneAggregator aggregator;
+ ChromeMallocZone* malloc_zone =
+ reinterpret_cast<ChromeMallocZone*>(malloc_default_zone());
+ aggregator.StoreZone(malloc_zone);
+ aggregator.StoreZone(malloc_zone);
+ EXPECT_EQ(1, aggregator.GetZoneCount());
+}
+
+TEST(MallocZoneAggregatorTest, CannotStoreMoreThanMaxZones) {
+ MallocZoneAggregator aggregator;
+
+ std::vector<ChromeMallocZone> zones;
+ zones.resize(MallocZoneAggregator::kMaxZoneCount * 2);
+ for (int i = 0; i < MallocZoneAggregator::kMaxZoneCount * 2; ++i) {
+ ChromeMallocZone& zone = zones[i];
+ memcpy(&zone, malloc_default_zone(), sizeof(ChromeMallocZone));
+ aggregator.StoreZone(&zone);
+ }
+
+ int max_zone_count = MallocZoneAggregator::kMaxZoneCount;
+ EXPECT_EQ(max_zone_count, aggregator.GetZoneCount());
+}
+
+} // namespace allocator
+} // namespace base
« base/allocator/malloc_zone_aggregator_mac.cc ('K') | « base/allocator/malloc_zone_aggregator_mac.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698