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

Side by Side Diff: base/allocator/allocator_interception_mac_unittest.cc

Issue 2712363002: Use mach_override to intercept all newly registered malloc zones.
Patch Set: compile error. Created 3 years, 9 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
« no previous file with comments | « base/allocator/allocator_interception_mac.mm ('k') | base/allocator/allocator_shim.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/allocator_interception_mac.h"
6 #include "base/allocator/malloc_zone_functions_mac.h"
7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "third_party/apple_apsl/malloc.h"
9
10 namespace base {
11 namespace allocator {
12
13 namespace {
14 void* TestMalloc(struct _malloc_zone_t* zone, size_t size) {
15 return reinterpret_cast<void*>(0x123);
16 }
17 } // namespace
18
19 class AllocatorInterceptionMacTest : public testing::Test {
20 protected:
21 void TearDown() override { UninterceptMallocZonesForTesting(); }
22 };
23
24 TEST_F(AllocatorInterceptionMacTest, InterceptNewlyRegisteredZone) {
25 ChromeMallocZone* default_zone =
26 reinterpret_cast<ChromeMallocZone*>(malloc_default_zone());
27 MallocZoneFunctions default_zone_functions;
28 StoreZoneFunctions(default_zone, &default_zone_functions);
29 default_zone_functions.malloc = &TestMalloc;
30 InterceptNewlyRegisteredMallocZones(&default_zone_functions);
31
32 struct _malloc_zone_t* test_malloc_zone = malloc_create_zone(0, 0);
33 ChromeMallocZone* test_zone =
34 reinterpret_cast<ChromeMallocZone*>(test_malloc_zone);
35 EXPECT_EQ(test_zone->malloc, &TestMalloc);
36
37 void* result = malloc_zone_malloc(test_malloc_zone, 13);
38 EXPECT_EQ(reinterpret_cast<void*>(0x123), result);
39
40 malloc_destroy_zone(test_malloc_zone);
41 }
42
43 } // namespace allocator
44 } // namespace base
OLDNEW
« no previous file with comments | « base/allocator/allocator_interception_mac.mm ('k') | base/allocator/allocator_shim.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698