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

Unified Diff: tests/DiscardableMemoryTest.cpp

Issue 2323013002: Tests: DiscardableMemory test no longer relies on global state (Closed)
Patch Set: Created 4 years, 3 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/DiscardableMemoryTest.cpp
diff --git a/tests/DiscardableMemoryTest.cpp b/tests/DiscardableMemoryTest.cpp
index 28dd6e98a5d1bf35eacc3414986efc0885a3833c..5d2d6b9e1e96372fdfbd7bfb9db7bf2542a9405f 100644
--- a/tests/DiscardableMemoryTest.cpp
+++ b/tests/DiscardableMemoryTest.cpp
@@ -5,28 +5,56 @@
* found in the LICENSE file.
*/
-#include "SkDiscardableMemory.h"
+#include "SkDiscardableMemoryPool.h"
#include "Test.h"
-DEF_TEST(DiscardableMemory, reporter) {
- const char testString[] = "HELLO, WORLD!";
- const size_t len = sizeof(testString);
- SkAutoTDelete<SkDiscardableMemory> dm(SkDiscardableMemory::Create(len));
- REPORTER_ASSERT(reporter, dm.get() != nullptr);
- if (nullptr == dm.get()) {
+namespace {
+constexpr char kTestString[] = "HELLO, WORLD!";
+constexpr size_t kTestStringLength = sizeof(kTestString);
+}
+
+static void test_dm(skiatest::Reporter* reporter,
+ SkDiscardableMemory* dm,
+ bool assertRelock) {
+ REPORTER_ASSERT(reporter, dm);
+ if (!dm) {
return;
}
void* ptr = dm->data();
- REPORTER_ASSERT(reporter, ptr != nullptr);
- memcpy(ptr, testString, sizeof(testString));
+ REPORTER_ASSERT(reporter, ptr);
+ if (!ptr) {
+ return;
+ }
+ memcpy(ptr, kTestString, sizeof(kTestString));
dm->unlock();
- bool success = dm->lock();
- REPORTER_ASSERT(reporter, success);
- if (!success) {
+ bool relockSuccess = dm->lock();
+ if (assertRelock) {
+ REPORTER_ASSERT(reporter, relockSuccess);
+ }
+ if (!relockSuccess) {
return;
}
ptr = dm->data();
- REPORTER_ASSERT(reporter, 0 == memcmp(ptr, testString, len));
+ REPORTER_ASSERT(reporter, ptr);
+ if (!ptr) {
+ return;
+ }
+ REPORTER_ASSERT(reporter, 0 == memcmp(ptr, kTestString, kTestStringLength));
dm->unlock();
}
+
+DEF_TEST(DiscardableMemory_global, reporter) {
+ std::unique_ptr<SkDiscardableMemory> dm(SkDiscardableMemory::Create(kTestStringLength));
+ // lock() test is allowed to fail, since other threads could be
+ // using global pool.
+ test_dm(reporter, dm.get(), false);
+}
+
+DEF_TEST(DiscardableMemory_nonglobal, reporter) {
+ std::unique_ptr<SkDiscardableMemoryPool> pool(
+ SkDiscardableMemoryPool::Create(1024, /* mutex = */ nullptr));
+ std::unique_ptr<SkDiscardableMemory> dm(pool->create(kTestStringLength));
+ test_dm(reporter, dm.get(), true);
+}
+
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698