OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkChunkAlloc.h" | 8 #include "SkChunkAlloc.h" |
9 #include "SkUtils.h" | 9 #include "SkUtils.h" |
10 #include "Test.h" | 10 #include "Test.h" |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 } | 88 } |
89 | 89 |
90 #define MAX_ALIGNMENT 64 | 90 #define MAX_ALIGNMENT 64 |
91 #define MAX_COUNT ((MAX_ALIGNMENT) * 32) | 91 #define MAX_COUNT ((MAX_ALIGNMENT) * 32) |
92 #define PAD 32 | 92 #define PAD 32 |
93 #define TOTAL (PAD + MAX_ALIGNMENT + MAX_COUNT + PAD) | 93 #define TOTAL (PAD + MAX_ALIGNMENT + MAX_COUNT + PAD) |
94 | 94 |
95 #define VALUE16 0x1234 | 95 #define VALUE16 0x1234 |
96 #define VALUE32 0x12345678 | 96 #define VALUE32 0x12345678 |
97 | 97 |
98 static bool compare16(const uint16_t base[], uint16_t value, int count) { | 98 static void compare16(skiatest::Reporter* r, const uint16_t base[], |
| 99 uint16_t value, int count) { |
99 for (int i = 0; i < count; ++i) { | 100 for (int i = 0; i < count; ++i) { |
100 if (base[i] != value) { | 101 if (base[i] != value) { |
101 SkDebugf("[%d] expected %x found %x\n", i, value, base[i]); | 102 ERRORF(r, "[%d] expected %x found %x\n", i, value, base[i]); |
102 return false; | 103 return; |
103 } | 104 } |
104 } | 105 } |
105 return true; | |
106 } | 106 } |
107 | 107 |
108 static bool compare32(const uint32_t base[], uint32_t value, int count) { | 108 static void compare32(skiatest::Reporter* r, const uint32_t base[], |
| 109 uint32_t value, int count) { |
109 for (int i = 0; i < count; ++i) { | 110 for (int i = 0; i < count; ++i) { |
110 if (base[i] != value) { | 111 if (base[i] != value) { |
111 SkDebugf("[%d] expected %x found %x\n", i, value, base[i]); | 112 ERRORF(r, "[%d] expected %x found %x\n", i, value, base[i]); |
112 return false; | 113 return; |
113 } | 114 } |
114 } | 115 } |
115 return true; | |
116 } | 116 } |
117 | 117 |
118 static void test_16(skiatest::Reporter* reporter) { | 118 static void test_16(skiatest::Reporter* reporter) { |
119 uint16_t buffer[TOTAL]; | 119 uint16_t buffer[TOTAL]; |
120 | 120 |
121 for (int count = 0; count < MAX_COUNT; ++count) { | 121 for (int count = 0; count < MAX_COUNT; ++count) { |
122 for (int alignment = 0; alignment < MAX_ALIGNMENT; ++alignment) { | 122 for (int alignment = 0; alignment < MAX_ALIGNMENT; ++alignment) { |
123 set_zero(buffer, sizeof(buffer)); | 123 set_zero(buffer, sizeof(buffer)); |
124 | 124 |
125 uint16_t* base = &buffer[PAD + alignment]; | 125 uint16_t* base = &buffer[PAD + alignment]; |
126 sk_memset16(base, VALUE16, count); | 126 sk_memset16(base, VALUE16, count); |
127 | 127 |
128 REPORTER_ASSERT(reporter, | 128 compare16(reporter, buffer, 0, PAD + alignment); |
129 compare16(buffer, 0, PAD + alignment) && | 129 compare16(reporter, base, VALUE16, count); |
130 compare16(base, VALUE16, count) && | 130 compare16(reporter, base + count, 0, TOTAL - count - PAD - ali
gnment); |
131 compare16(base + count, 0, TOTAL - count - PAD - alignment
)); | |
132 } | 131 } |
133 } | 132 } |
134 } | 133 } |
135 | 134 |
136 static void test_32(skiatest::Reporter* reporter) { | 135 static void test_32(skiatest::Reporter* reporter) { |
137 uint32_t buffer[TOTAL]; | 136 uint32_t buffer[TOTAL]; |
138 | 137 |
139 for (int count = 0; count < MAX_COUNT; ++count) { | 138 for (int count = 0; count < MAX_COUNT; ++count) { |
140 for (int alignment = 0; alignment < MAX_ALIGNMENT; ++alignment) { | 139 for (int alignment = 0; alignment < MAX_ALIGNMENT; ++alignment) { |
141 set_zero(buffer, sizeof(buffer)); | 140 set_zero(buffer, sizeof(buffer)); |
142 | 141 |
143 uint32_t* base = &buffer[PAD + alignment]; | 142 uint32_t* base = &buffer[PAD + alignment]; |
144 sk_memset32(base, VALUE32, count); | 143 sk_memset32(base, VALUE32, count); |
145 | 144 |
146 REPORTER_ASSERT(reporter, | 145 compare32(reporter, buffer, 0, PAD + alignment); |
147 compare32(buffer, 0, PAD + alignment) && | 146 compare32(reporter, base, VALUE32, count); |
148 compare32(base, VALUE32, count) && | 147 compare32(reporter, base + count, 0, TOTAL - count - PAD - ali
gnment); |
149 compare32(base + count, 0, TOTAL - count - PAD - alignment
)); | |
150 } | 148 } |
151 } | 149 } |
152 } | 150 } |
153 | 151 |
154 /** | 152 /** |
155 * Test sk_memset16 and sk_memset32. | 153 * Test sk_memset16 and sk_memset32. |
156 * For performance considerations, implementations may take different paths | 154 * For performance considerations, implementations may take different paths |
157 * depending on the alignment of the dst, and/or the size of the count. | 155 * depending on the alignment of the dst, and/or the size of the count. |
158 */ | 156 */ |
159 DEF_TEST(Memset, reporter) { | 157 DEF_TEST(Memset, reporter) { |
160 test_16(reporter); | 158 test_16(reporter); |
161 test_32(reporter); | 159 test_32(reporter); |
162 | 160 |
163 test_chunkalloc(reporter); | 161 test_chunkalloc(reporter); |
164 } | 162 } |
OLD | NEW |