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

Unified Diff: base/allocator/allocator_shim_unittest.cc

Issue 2138173002: Hookup the generic heap intercept for Windows. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix dangling use of ::g_win_new_mode. Created 4 years, 5 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/allocator_shim_unittest.cc
diff --git a/base/allocator/allocator_shim_unittest.cc b/base/allocator/allocator_shim_unittest.cc
index e6abc698360f4468e4f1fc71adfa1e0a6c459a01..3a2124b525cf02e26747b1de71b06b5b6a2eb13c 100644
--- a/base/allocator/allocator_shim_unittest.cc
+++ b/base/allocator/allocator_shim_unittest.cc
@@ -7,7 +7,6 @@
#include <malloc.h>
#include <stdlib.h>
#include <string.h>
-#include <unistd.h>
#include <memory>
#include <new>
@@ -20,6 +19,10 @@
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
+#if !defined(OS_WIN)
+#include <unistd.h>
+#endif
+
// Some new Android NDKs (64 bit) does not expose (p)valloc anymore. These
// functions are implemented at the shim-layer level.
#if defined(OS_ANDROID)
@@ -168,6 +171,17 @@ class ThreadDelegateForNewHandlerTest : public PlatformThread::Delegate {
AllocatorShimTest* AllocatorShimTest::instance_ = nullptr;
+inline size_t GetPageSize() {
Primiano Tucci (use gerrit) 2016/07/12 14:51:05 I think you can use GetPageSize() from base/proces
Sigurður Ásgeirsson 2016/07/14 19:04:27 Done. I wonder if it's safe to use it also in all
Primiano Tucci (use gerrit) 2016/07/15 14:02:10 the main reason why I didn't use it straight there
+#if defined(OS_WIN)
+ return 4096;
+#else
+ static size_t pagesize = 0;
+ if (!pagesize)
+ pagesize = sysconf(_SC_PAGESIZE);
+ return pagesize;
+#endif
+}
+
AllocatorDispatch g_mock_dispatch = {
&AllocatorShimTest::MockAlloc, /* alloc_function */
&AllocatorShimTest::MockAllocZeroInit, /* alloc_zero_initialized_function */
@@ -178,7 +192,7 @@ AllocatorDispatch g_mock_dispatch = {
};
TEST_F(AllocatorShimTest, InterceptLibcSymbols) {
- const size_t kPageSize = sysconf(_SC_PAGESIZE);
+ const size_t kPageSize = GetPageSize();
InsertAllocatorDispatch(&g_mock_dispatch);
void* alloc_ptr = malloc(19);
@@ -189,6 +203,7 @@ TEST_F(AllocatorShimTest, InterceptLibcSymbols) {
ASSERT_NE(nullptr, zero_alloc_ptr);
ASSERT_GE(zero_allocs_intercepted_by_size[2 * 23], 1u);
+#if !defined(OS_WIN)
void* memalign_ptr = memalign(128, 53);
ASSERT_NE(nullptr, memalign_ptr);
ASSERT_EQ(0u, reinterpret_cast<uintptr_t>(memalign_ptr) % 128);
@@ -215,15 +230,17 @@ TEST_F(AllocatorShimTest, InterceptLibcSymbols) {
ASSERT_GE(aligned_allocs_intercepted_by_alignment[kPageSize], 1u);
// pvalloc rounds the size up to the next page.
ASSERT_GE(aligned_allocs_intercepted_by_size[kPageSize], 1u);
+#endif // OS_WIN
char* realloc_ptr = static_cast<char*>(realloc(nullptr, 71));
ASSERT_NE(nullptr, realloc_ptr);
ASSERT_GE(reallocs_intercepted_by_size[71], 1u);
ASSERT_GE(reallocs_intercepted_by_addr[Hash(nullptr)], 1u);
strcpy(realloc_ptr, "foobar");
+ void* old_realloc_ptr = realloc_ptr;
realloc_ptr = static_cast<char*>(realloc(realloc_ptr, 73));
ASSERT_GE(reallocs_intercepted_by_size[73], 1u);
- ASSERT_GE(reallocs_intercepted_by_addr[Hash(realloc_ptr)], 1u);
+ ASSERT_GE(reallocs_intercepted_by_addr[Hash(old_realloc_ptr)], 1u);
Primiano Tucci (use gerrit) 2016/07/12 14:51:05 uh?
Sigurður Ásgeirsson 2016/07/14 19:04:27 The test fixture records the inbound pointer to th
Primiano Tucci (use gerrit) 2016/07/15 14:02:10 Ahh I see. makes sense. Thanks.
ASSERT_EQ(0, strcmp(realloc_ptr, "foobar"));
free(alloc_ptr);
@@ -232,6 +249,7 @@ TEST_F(AllocatorShimTest, InterceptLibcSymbols) {
free(zero_alloc_ptr);
ASSERT_GE(frees_intercepted_by_addr[Hash(zero_alloc_ptr)], 1u);
+#if !defined(OS_WIN)
free(memalign_ptr);
ASSERT_GE(frees_intercepted_by_addr[Hash(memalign_ptr)], 1u);
@@ -243,6 +261,7 @@ TEST_F(AllocatorShimTest, InterceptLibcSymbols) {
free(pvalloc_ptr);
ASSERT_GE(frees_intercepted_by_addr[Hash(pvalloc_ptr)], 1u);
+#endif // OS_WIN
free(realloc_ptr);
ASSERT_GE(frees_intercepted_by_addr[Hash(realloc_ptr)], 1u);

Powered by Google App Engine
This is Rietveld 408576698