aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/RecordTest.cpp
diff options
context:
space:
mode:
authorGravatar mtklein <mtklein@chromium.org>2014-08-28 14:10:05 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2014-08-28 14:10:05 -0700
commit0209e95cc2625a445c1cb6c4213d2182e5c832d7 (patch)
tree08c2a5c26bddb05543628e7509a75d00490c1558 /tests/RecordTest.cpp
parent23b406cc040d55b45acc96e63db5c2d5c934a53c (diff)
Align all SkRecord::alloc() calls up to at least a pointer size.
This should make the LSAN bots able to see all our pointers. BUG=skia: R=reed@google.com, robertphillips@google.com, mtklein@google.com Author: mtklein@chromium.org Review URL: https://codereview.chromium.org/517073002
Diffstat (limited to 'tests/RecordTest.cpp')
-rw-r--r--tests/RecordTest.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/tests/RecordTest.cpp b/tests/RecordTest.cpp
index 2240ae9858..2a0e615516 100644
--- a/tests/RecordTest.cpp
+++ b/tests/RecordTest.cpp
@@ -78,3 +78,28 @@ DEF_TEST(Record, r) {
#undef APPEND
+template <typename T>
+static bool is_aligned(const T* p) {
+ return (((uintptr_t)p) & (sizeof(T) - 1)) == 0;
+}
+
+DEF_TEST(Record_Alignment, r) {
+ SkRecord record;
+
+ // Of course a byte's always aligned.
+ REPORTER_ASSERT(r, is_aligned(record.alloc<uint8_t>()));
+
+ // (If packed tightly, the rest below here would be off by one.)
+
+ // It happens that the first implementation always aligned to 4 bytes,
+ // so these two were always correct.
+ REPORTER_ASSERT(r, is_aligned(record.alloc<uint16_t>()));
+ REPORTER_ASSERT(r, is_aligned(record.alloc<uint32_t>()));
+
+ // These two are regression tests (void* only on 64-bit machines).
+ REPORTER_ASSERT(r, is_aligned(record.alloc<uint64_t>()));
+ REPORTER_ASSERT(r, is_aligned(record.alloc<void*>()));
+
+ // We're not testing beyond sizeof(void*), which is where the current implementation will break.
+}
+