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

Unified Diff: tests/MemsetTest.cpp

Issue 967553003: Add rewind capability to SkChunkAlloc (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix variable sizes/signs Created 5 years, 10 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 | « src/utils/SkDeferredCanvas.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/MemsetTest.cpp
diff --git a/tests/MemsetTest.cpp b/tests/MemsetTest.cpp
index ee6aaea94e5bd10f785bfb3eb1874e635a021d99..1e1378b4ada343fd9910cc68f232a19a0a9aad92 100644
--- a/tests/MemsetTest.cpp
+++ b/tests/MemsetTest.cpp
@@ -9,32 +9,73 @@
#include "SkUtils.h"
#include "Test.h"
+static void check_alloc(skiatest::Reporter* reporter, const SkChunkAlloc& alloc,
+ size_t capacity, size_t used, int numBlocks) {
+ REPORTER_ASSERT(reporter, alloc.totalCapacity() >= capacity);
+ REPORTER_ASSERT(reporter, alloc.totalUsed() == used);
+ SkDEBUGCODE(REPORTER_ASSERT(reporter, alloc.blockCount() == numBlocks);)
+}
+
+static void* simple_alloc(skiatest::Reporter* reporter, SkChunkAlloc* alloc, size_t size) {
+ void* ptr = alloc->allocThrow(size);
+ check_alloc(reporter, *alloc, size, size, 1);
+ REPORTER_ASSERT(reporter, alloc->contains(ptr));
+ return ptr;
+}
+
static void test_chunkalloc(skiatest::Reporter* reporter) {
- size_t min = 256;
- SkChunkAlloc alloc(min);
+ static const size_t kMin = 1024;
+ SkChunkAlloc alloc(kMin);
- REPORTER_ASSERT(reporter, 0 == alloc.totalCapacity());
- REPORTER_ASSERT(reporter, 0 == alloc.totalUsed());
- REPORTER_ASSERT(reporter, 0 == alloc.blockCount());
+ //------------------------------------------------------------------------
+ // check empty
+ check_alloc(reporter, alloc, 0, 0, 0);
REPORTER_ASSERT(reporter, !alloc.contains(NULL));
REPORTER_ASSERT(reporter, !alloc.contains(reporter));
+ // reset on empty allocator
alloc.reset();
- REPORTER_ASSERT(reporter, 0 == alloc.totalCapacity());
- REPORTER_ASSERT(reporter, 0 == alloc.totalUsed());
- REPORTER_ASSERT(reporter, 0 == alloc.blockCount());
-
- size_t size = min >> 1;
- void* ptr = alloc.allocThrow(size);
- REPORTER_ASSERT(reporter, alloc.totalCapacity() >= size);
- REPORTER_ASSERT(reporter, alloc.totalUsed() == size);
- REPORTER_ASSERT(reporter, alloc.blockCount() > 0);
- REPORTER_ASSERT(reporter, alloc.contains(ptr));
+ check_alloc(reporter, alloc, 0, 0, 0);
+
+ // rewind on empty allocator
+ alloc.rewind();
+ check_alloc(reporter, alloc, 0, 0, 0);
+
+ //------------------------------------------------------------------------
+ // test reset when something is allocated
+ size_t size = kMin >> 1;
+ void* ptr = simple_alloc(reporter, &alloc, size);
+
+ alloc.reset();
+ check_alloc(reporter, alloc, 0, 0, 0);
+ REPORTER_ASSERT(reporter, !alloc.contains(ptr));
+
+ //------------------------------------------------------------------------
+ // test rewind when something is allocated
+ ptr = simple_alloc(reporter, &alloc, size);
+
+ alloc.rewind();
+ check_alloc(reporter, alloc, size, 0, 1);
+ REPORTER_ASSERT(reporter, !alloc.contains(ptr));
+ // use the available block
+ ptr = simple_alloc(reporter, &alloc, size);
alloc.reset();
+
+ //------------------------------------------------------------------------
+ // test out allocating a second block
+ ptr = simple_alloc(reporter, &alloc, size);
+
+ ptr = alloc.allocThrow(kMin);
+ check_alloc(reporter, alloc, 2*kMin, size+kMin, 2);
+ REPORTER_ASSERT(reporter, alloc.contains(ptr));
+
+ //------------------------------------------------------------------------
+ // test out unalloc
+ size_t freed = alloc.unalloc(ptr);
+ REPORTER_ASSERT(reporter, freed == kMin);
+ check_alloc(reporter, alloc, 2*kMin, size, 2);
REPORTER_ASSERT(reporter, !alloc.contains(ptr));
- REPORTER_ASSERT(reporter, 0 == alloc.totalCapacity());
- REPORTER_ASSERT(reporter, 0 == alloc.totalUsed());
}
///////////////////////////////////////////////////////////////////////////////
« no previous file with comments | « src/utils/SkDeferredCanvas.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698