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

Side by Side Diff: base/process/memory_unittest.cc

Issue 1825823002: Cleanup: LFH only needs to be enabled on XP/2003 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge Created 4 years, 8 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #define _CRT_SECURE_NO_WARNINGS 5 #define _CRT_SECURE_NO_WARNINGS
6 6
7 #include "base/process/memory.h" 7 #include "base/process/memory.h"
8 8
9 #include <stddef.h> 9 #include <stddef.h>
10 10
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 const_cast<int*>(&kConstantInModule))); 60 const_cast<int*>(&kConstantInModule)));
61 61
62 // Any address within the kernel32 module should return 62 // Any address within the kernel32 module should return
63 // kernel32's HMODULE. Our only assumption here is that 63 // kernel32's HMODULE. Our only assumption here is that
64 // kernel32 is larger than 4 bytes. 64 // kernel32 is larger than 4 bytes.
65 HMODULE kernel32 = ::GetModuleHandle(L"kernel32.dll"); 65 HMODULE kernel32 = ::GetModuleHandle(L"kernel32.dll");
66 HMODULE kernel32_from_address = 66 HMODULE kernel32_from_address =
67 base::GetModuleFromAddress(reinterpret_cast<DWORD*>(kernel32) + 1); 67 base::GetModuleFromAddress(reinterpret_cast<DWORD*>(kernel32) + 1);
68 EXPECT_EQ(kernel32, kernel32_from_address); 68 EXPECT_EQ(kernel32, kernel32_from_address);
69 } 69 }
70
71 TEST(ProcessMemoryTest, EnableLFH) {
72 ASSERT_TRUE(base::EnableLowFragmentationHeap());
73 if (IsDebuggerPresent()) {
74 // Under these conditions, LFH can't be enabled. There's no point to test
75 // anything.
76 const char* no_debug_env = getenv("_NO_DEBUG_HEAP");
77 if (!no_debug_env || strcmp(no_debug_env, "1"))
78 return;
79 }
80 HMODULE kernel32 = GetModuleHandle(L"kernel32.dll");
81 ASSERT_TRUE(kernel32 != NULL);
82 HeapQueryFn heap_query = reinterpret_cast<HeapQueryFn>(GetProcAddress(
83 kernel32,
84 "HeapQueryInformation"));
85
86 // On Windows 2000, the function is not exported. This is not a reason to
87 // fail but we won't be able to retrieves information about the heap, so we
88 // should stop here.
89 if (heap_query == NULL)
90 return;
91
92 HANDLE heaps[1024] = { 0 };
93 unsigned number_heaps = GetProcessHeaps(1024, heaps);
94 EXPECT_GT(number_heaps, 0u);
95 for (unsigned i = 0; i < number_heaps; ++i) {
96 ULONG flag = 0;
97 SIZE_T length;
98 ASSERT_NE(0, heap_query(heaps[i],
99 HeapCompatibilityInformation,
100 &flag,
101 sizeof(flag),
102 &length));
103 // If flag is 0, the heap is a standard heap that does not support
104 // look-asides. If flag is 1, the heap supports look-asides. If flag is 2,
105 // the heap is a low-fragmentation heap (LFH). Note that look-asides are not
106 // supported on the LFH.
107
108 // We don't have any documented way of querying the HEAP_NO_SERIALIZE flag.
109 EXPECT_LE(flag, 2u);
110 EXPECT_NE(flag, 1u);
111 }
112 }
113 #endif // defined(OS_WIN) 70 #endif // defined(OS_WIN)
114 71
115 #if defined(OS_MACOSX) 72 #if defined(OS_MACOSX)
116 73
117 // For the following Mac tests: 74 // For the following Mac tests:
118 // Note that base::EnableTerminationOnHeapCorruption() is called as part of 75 // Note that base::EnableTerminationOnHeapCorruption() is called as part of
119 // test suite setup and does not need to be done again, else mach_override 76 // test suite setup and does not need to be done again, else mach_override
120 // will fail. 77 // will fail.
121 78
122 TEST(ProcessMemoryTest, MacTerminateOnHeapCorruption) { 79 TEST(ProcessMemoryTest, MacTerminateOnHeapCorruption) {
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 for (size_t i = 0; i < (kSafeCallocItems * kSafeCallocSize); ++i) 426 for (size_t i = 0; i < (kSafeCallocItems * kSafeCallocSize); ++i)
470 EXPECT_EQ(0, bytes[i]); 427 EXPECT_EQ(0, bytes[i]);
471 free(value_); 428 free(value_);
472 429
473 EXPECT_FALSE(base::UncheckedCalloc(1, test_size_, &value_)); 430 EXPECT_FALSE(base::UncheckedCalloc(1, test_size_, &value_));
474 EXPECT_TRUE(value_ == NULL); 431 EXPECT_TRUE(value_ == NULL);
475 } 432 }
476 #endif // !defined(MEMORY_TOOL_REPLACES_ALLOCATOR) 433 #endif // !defined(MEMORY_TOOL_REPLACES_ALLOCATOR)
477 #endif // !defined(OS_ANDROID) && !defined(OS_OPENBSD) && !(defined(OS_WIN) && 434 #endif // !defined(OS_ANDROID) && !defined(OS_OPENBSD) && !(defined(OS_WIN) &&
478 // !defined(ALLOCATOR_SHIM)) && !defined(MEMORY_TOOL_REPLACES_ALLOCATOR) 435 // !defined(ALLOCATOR_SHIM)) && !defined(MEMORY_TOOL_REPLACES_ALLOCATOR)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698