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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/allocator/malloc_zone_aggregator_mac.h"
6 #include "testing/gtest/include/gtest/gtest.h"
7
8 namespace base {
9 namespace allocator {
10
11 TEST(MallocZoneAggregatorTest, TestDefaultZoneMallocFree) {
12 MallocZoneAggregator aggregator;
13 ChromeMallocZone* malloc_zone =
14 reinterpret_cast<ChromeMallocZone*>(malloc_default_zone());
15 aggregator.StoreZone(malloc_zone);
16 int* test =
17 reinterpret_cast<int*>(aggregator.DispatchMallocToZone(malloc_zone, 33));
18 test[0] = 1;
19 test[1] = 2;
20 aggregator.DispatchFreeToZone(malloc_zone, test);
21 }
22
23 TEST(MallocZoneAggregatorTest, IsZoneAlreadyStored) {
24 MallocZoneAggregator aggregator;
25 ChromeMallocZone* malloc_zone =
26 reinterpret_cast<ChromeMallocZone*>(malloc_default_zone());
27 EXPECT_FALSE(aggregator.IsZoneAlreadyStored(malloc_zone));
28 aggregator.StoreZone(malloc_zone);
29 EXPECT_TRUE(aggregator.IsZoneAlreadyStored(malloc_zone));
30 }
31
32 TEST(MallocZoneAggregatorTest, CannotDoubleStoreZone) {
33 MallocZoneAggregator aggregator;
34 ChromeMallocZone* malloc_zone =
35 reinterpret_cast<ChromeMallocZone*>(malloc_default_zone());
36 aggregator.StoreZone(malloc_zone);
37 aggregator.StoreZone(malloc_zone);
38 EXPECT_EQ(1, aggregator.GetZoneCount());
39 }
40
41 TEST(MallocZoneAggregatorTest, CannotStoreMoreThanMaxZones) {
42 MallocZoneAggregator aggregator;
43
44 std::vector<ChromeMallocZone> zones;
45 zones.resize(MallocZoneAggregator::kMaxZoneCount * 2);
46 for (int i = 0; i < MallocZoneAggregator::kMaxZoneCount * 2; ++i) {
47 ChromeMallocZone& zone = zones[i];
48 memcpy(&zone, malloc_default_zone(), sizeof(ChromeMallocZone));
49 aggregator.StoreZone(&zone);
50 }
51
52 int max_zone_count = MallocZoneAggregator::kMaxZoneCount;
53 EXPECT_EQ(max_zone_count, aggregator.GetZoneCount());
54 }
55
56 } // namespace allocator
57 } // namespace base
OLDNEW
« 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