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

Unified 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, 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
« no previous file with comments | « base/allocator/allocator_interception_mac.mm ('k') | base/allocator/allocator_shim.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/allocator/allocator_interception_mac_unittest.cc
diff --git a/base/allocator/allocator_interception_mac_unittest.cc b/base/allocator/allocator_interception_mac_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..95e026bd1c5ef0863bf9e4abe6ce36ab0f013f6e
--- /dev/null
+++ b/base/allocator/allocator_interception_mac_unittest.cc
@@ -0,0 +1,44 @@
+// 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/allocator_interception_mac.h"
+#include "base/allocator/malloc_zone_functions_mac.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "third_party/apple_apsl/malloc.h"
+
+namespace base {
+namespace allocator {
+
+namespace {
+void* TestMalloc(struct _malloc_zone_t* zone, size_t size) {
+ return reinterpret_cast<void*>(0x123);
+}
+} // namespace
+
+class AllocatorInterceptionMacTest : public testing::Test {
+ protected:
+ void TearDown() override { UninterceptMallocZonesForTesting(); }
+};
+
+TEST_F(AllocatorInterceptionMacTest, InterceptNewlyRegisteredZone) {
+ ChromeMallocZone* default_zone =
+ reinterpret_cast<ChromeMallocZone*>(malloc_default_zone());
+ MallocZoneFunctions default_zone_functions;
+ StoreZoneFunctions(default_zone, &default_zone_functions);
+ default_zone_functions.malloc = &TestMalloc;
+ InterceptNewlyRegisteredMallocZones(&default_zone_functions);
+
+ struct _malloc_zone_t* test_malloc_zone = malloc_create_zone(0, 0);
+ ChromeMallocZone* test_zone =
+ reinterpret_cast<ChromeMallocZone*>(test_malloc_zone);
+ EXPECT_EQ(test_zone->malloc, &TestMalloc);
+
+ void* result = malloc_zone_malloc(test_malloc_zone, 13);
+ EXPECT_EQ(reinterpret_cast<void*>(0x123), result);
+
+ malloc_destroy_zone(test_malloc_zone);
+}
+
+} // namespace allocator
+} // namespace base
« 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