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

Unified Diff: base/memory/discardable_memory_unittest.cc

Issue 114923005: base: Discardable memory types. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years 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/memory/discardable_memory_unittest.cc
diff --git a/base/memory/discardable_memory_unittest.cc b/base/memory/discardable_memory_unittest.cc
index c9f67b2556f17a24a1e7f65d9533403106e6c94e..ebc5712293ed18bb8b8a90c16d99ad19a38e557b 100644
--- a/base/memory/discardable_memory_unittest.cc
+++ b/base/memory/discardable_memory_unittest.cc
@@ -2,18 +2,39 @@
// 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 <algorithm>
+#if defined(OS_ANDROID)
#include <limits>
+#endif
+#include "base/memory/discardable_memory.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace base {
+namespace {
+
+class DiscardableMemoryTest
+ : public testing::TestWithParam<DiscardableMemoryType> {
+ public:
+ // Overridden from testing::Test:
+ virtual void SetUp() OVERRIDE {
+ old_type_ = DiscardableMemory::GetType();
+ DiscardableMemory::SetType(GetParam());
+ }
+ virtual void TearDown() OVERRIDE {
+ DiscardableMemory::SetType(old_type_);
+ }
+
+ private:
+ DiscardableMemoryType old_type_;
+};
const size_t kSize = 1024;
#if defined(OS_ANDROID)
-TEST(DiscardableMemoryTest, TooLargeAllocationFails) {
+TEST_P(DiscardableMemoryTest, TooLargeAllocationFails) {
reveman 2013/12/13 18:21:53 Follow up patch will move this to _ashmem_unittest
Philippe 2013/12/17 14:28:21 SGTM
+ if (GetParam() != DISCARDABLE_MEMORY_ANDROID)
+ return;
const size_t kPageSize = 4096;
const size_t max_allowed_allocation_size =
std::numeric_limits<size_t>::max() - kPageSize + 1;
@@ -26,20 +47,30 @@ TEST(DiscardableMemoryTest, TooLargeAllocationFails) {
}
#endif
-TEST(DiscardableMemoryTest, SupportedNatively) {
+bool IsNativeType(DiscardableMemoryType type) {
+ return type == DISCARDABLE_MEMORY_ANDROID || type == DISCARDABLE_MEMORY_MAC;
+}
+
+TEST_P(DiscardableMemoryTest, SupportedNatively) {
#if defined(DISCARDABLE_MEMORY_ALWAYS_SUPPORTED_NATIVELY)
- ASSERT_TRUE(DiscardableMemory::SupportedNatively());
+ ASSERT_TRUE(std::find_if(DiscardableMemory::GetSupportedTypes().begin(),
Philippe 2013/12/17 14:28:21 JFYI, std::count_if() would be slightly more compa
reveman 2013/12/18 08:12:38 Good idea. Done.
+ DiscardableMemory::GetSupportedTypes().end(),
+ IsNativeType) !=
+ DiscardableMemory::GetSupportedTypes().end());
#else
// If we ever have a platform that decides at runtime if it can support
// discardable memory natively, then we'll have to add a 'never supported
// natively' define for this case. At present, if it's not always supported
// natively, it's never supported.
- ASSERT_FALSE(DiscardableMemory::SupportedNatively());
+ ASSERT_FALSE(std::find_if(DiscardableMemory::GetSupportedTypes().begin(),
+ DiscardableMemory::GetSupportedTypes().end(),
+ IsNativeType) !=
+ DiscardableMemory::GetSupportedTypes().end());
#endif
}
// Test Lock() and Unlock() functionalities.
-TEST(DiscardableMemoryTest, LockAndUnLock) {
+TEST_P(DiscardableMemoryTest, LockAndUnLock) {
const scoped_ptr<DiscardableMemory> memory(
DiscardableMemory::CreateLockedMemory(kSize));
ASSERT_TRUE(memory);
@@ -57,7 +88,7 @@ TEST(DiscardableMemoryTest, LockAndUnLock) {
}
// Test delete a discardable memory while it is locked.
-TEST(DiscardableMemoryTest, DeleteWhileLocked) {
+TEST_P(DiscardableMemoryTest, DeleteWhileLocked) {
const scoped_ptr<DiscardableMemory> memory(
DiscardableMemory::CreateLockedMemory(kSize));
ASSERT_TRUE(memory);
@@ -65,7 +96,7 @@ TEST(DiscardableMemoryTest, DeleteWhileLocked) {
#if !defined(OS_ANDROID)
// Test forced purging.
-TEST(DiscardableMemoryTest, Purge) {
+TEST_P(DiscardableMemoryTest, Purge) {
ASSERT_TRUE(DiscardableMemory::PurgeForTestingSupported());
const scoped_ptr<DiscardableMemory> memory(
@@ -80,7 +111,7 @@ TEST(DiscardableMemoryTest, Purge) {
#if !defined(NDEBUG) && !defined(OS_ANDROID)
// Death tests are not supported with Android APKs.
-TEST(DiscardableMemoryTest, UnlockedMemoryAccessCrashesInDebugMode) {
+TEST_P(DiscardableMemoryTest, UnlockedMemoryAccessCrashesInDebugMode) {
const scoped_ptr<DiscardableMemory> memory(
DiscardableMemory::CreateLockedMemory(kSize));
ASSERT_TRUE(memory);
@@ -90,4 +121,10 @@ TEST(DiscardableMemoryTest, UnlockedMemoryAccessCrashesInDebugMode) {
}
#endif
-}
+INSTANTIATE_TEST_CASE_P(
+ DiscardableMemoryTests,
+ DiscardableMemoryTest,
+ ::testing::ValuesIn(DiscardableMemory::GetSupportedTypes()));
reveman 2013/12/16 21:05:51 Runs all tests for all supported discardable memor
Philippe 2013/12/17 14:28:21 SGTM
+
+} // namespace
+} // namespace base

Powered by Google App Engine
This is Rietveld 408576698