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

Unified Diff: base/memory/discardable_memory_unittest.cc

Issue 1009413002: Revert "base: Implement browser process support for discardable memory." (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/memory/discardable_memory_shmem_allocator.cc ('k') | base/test/BUILD.gn » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/memory/discardable_memory_unittest.cc
diff --git a/base/memory/discardable_memory_unittest.cc b/base/memory/discardable_memory_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..60750746a4beb1b98488cd0347abd9b42009b90e
--- /dev/null
+++ b/base/memory/discardable_memory_unittest.cc
@@ -0,0 +1,64 @@
+// Copyright (c) 2013 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/memory/discardable_memory.h"
+
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace base {
+namespace {
+
+const size_t kSize = 1024;
+
+// Test Lock() and Unlock() functionalities.
+TEST(DiscardableMemoryTest, LockAndUnLock) {
+ const scoped_ptr<DiscardableMemory> memory(
+ DiscardableMemory::CreateLockedMemory(kSize));
+ ASSERT_TRUE(memory);
+ void* addr = memory->Memory();
+ EXPECT_NE(nullptr, addr);
+ memory->Unlock();
+}
+
+// Test delete a discardable memory while it is locked.
+TEST(DiscardableMemoryTest, DeleteWhileLocked) {
+ const scoped_ptr<DiscardableMemory> memory(
+ DiscardableMemory::CreateLockedMemory(kSize));
+ ASSERT_TRUE(memory);
+}
+
+#if !defined(NDEBUG) && !defined(OS_ANDROID)
+// Death tests are not supported with Android APKs.
+TEST(DiscardableMemoryTest, UnlockedMemoryAccessCrashesInDebugMode) {
+ const scoped_ptr<DiscardableMemory> memory(
+ DiscardableMemory::CreateLockedMemory(kSize));
+ ASSERT_TRUE(memory);
+ memory->Unlock();
+ ASSERT_DEATH_IF_SUPPORTED(
+ { *static_cast<int*>(memory->Memory()) = 0xdeadbeef; }, ".*");
+}
+#endif
+
+// Test behavior when creating enough instances that could use up a 32-bit
+// address space.
+// This is disabled under AddressSanitizer on Windows as it crashes (by design)
+// on OOM. See http://llvm.org/PR22026 for the details.
+#if !defined(ADDRESS_SANITIZER) || !defined(OS_WIN)
+TEST(DiscardableMemoryTest, AddressSpace) {
+ const size_t kLargeSize = 4 * 1024 * 1024; // 4MiB.
+ const size_t kNumberOfInstances = 1024 + 1; // >4GiB total.
+
+ scoped_ptr<DiscardableMemory> instances[kNumberOfInstances];
+ for (auto& memory : instances) {
+ memory = DiscardableMemory::CreateLockedMemory(kLargeSize);
+ ASSERT_TRUE(memory);
+ void* addr = memory->Memory();
+ EXPECT_NE(nullptr, addr);
+ memory->Unlock();
+ }
+}
+#endif
+
+} // namespace
+} // namespace base
« no previous file with comments | « base/memory/discardable_memory_shmem_allocator.cc ('k') | base/test/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698