blob: 77217cb9a590ca436b7402c8223f7affc1be3c52 [file] [log] [blame]
Michael Butler2d4d6d92017-03-01 15:32:30 -08001/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15*/
16
17#include "VtsHalRenderscriptV1_0TargetTest.h"
18
19/*
20 * This test creates a 1D Allocation with 128 Float Elements, and two float
21 * vector dataIn & dataOut. dataIn is pre-populated with data, and copied into
22 * the Allocation using allocation1DWrite. Then the Allocation is copied into
23 * dataOut with allocation1DRead.
24 *
25 * Calls: elementCreate, typeCreate, allocationCreateTyped, allocation1DWrite,
26 * allocation1DRead
27 *
28 * Expect: dataIn & dataOut are the same.
29 */
30TEST_F(RenderscriptHidlTest, Simple1DCopyTest) {
31 // float1
32 Element element = context->elementCreate(DataType::FLOAT_32, DataKind::USER, false, 1);
33 // 128 x float1
34 Type type = context->typeCreate(element, 128, 0, 0, false, false, YuvFormat::YUV_NONE);
35 // 128 x float1
36 Allocation allocation = context->allocationCreateTyped(type, AllocationMipmapControl::NONE,
37 (int)AllocationUsageType::SCRIPT,
38 (Ptr)nullptr);
39 std::vector<float> dataIn(128), dataOut(128);
40 std::generate(dataIn.begin(), dataIn.end(), [](){ static int val = 0; return (float)val++; });
41 hidl_vec<uint8_t> _data;
42 _data.setToExternal((uint8_t*)dataIn.data(), dataIn.size()*sizeof(float));
43 context->allocation1DWrite(allocation, 0, 0, (Size)dataIn.size(), _data);
44 context->allocation1DRead(allocation, 0, 0, (uint32_t)dataOut.size(), (Ptr)dataOut.data(),
45 (Size)dataOut.size()*sizeof(float));
46 bool same = std::all_of(dataOut.begin(), dataOut.end(),
47 [](float x){ static int val = 0; return x == (float)val++; });
48 EXPECT_EQ(true, same);
49}
50
51/*
52 * This test creates a 2D Allocation with 128 * 128 Float Elements, and two
53 * float vector dataIn & dataOut. dataIn is pre-populated with data, and copied
54 * into the Allocation using allocation2DWrite. Then the Allocation is copied
55 * into dataOut with allocation2DRead.
56 *
57 * Calls: elementCreate, typeCreate, allocationCreateTyped, allocation2DWrite,
58 * allocation2DRead
59 *
60 * Expect: dataIn & dataOut are the same.
61 */
62TEST_F(RenderscriptHidlTest, Simple2DCopyTest) {
63 // float1
64 Element element = context->elementCreate(DataType::FLOAT_32, DataKind::USER, false, 1);
65 // 128 x 128 x float1
66 Type type = context->typeCreate(element, 128, 128, 0, false, false, YuvFormat::YUV_NONE);
67 // 128 x 128 x float1
68 Allocation allocation = context->allocationCreateTyped(type, AllocationMipmapControl::NONE,
69 (int)AllocationUsageType::SCRIPT,
70 (Ptr)nullptr);
71 std::vector<float> dataIn(128*128), dataOut(128*128);
72 std::generate(dataIn.begin(), dataIn.end(), [](){ static int val = 0; return (float)val++; });
73 hidl_vec<uint8_t> _data;
74 _data.setToExternal((uint8_t*)dataIn.data(), dataIn.size()*sizeof(float));
75 context->allocation2DWrite(allocation, 0, 0, 0, AllocationCubemapFace::POSITIVE_X, 128, 128,
76 _data, 0);
77 context->allocation2DRead(allocation, 0, 0, 0, AllocationCubemapFace::POSITIVE_X, 128, 128,
78 (Ptr)dataOut.data(), (Size)dataOut.size()*sizeof(float), 0);
79 bool same = std::all_of(dataOut.begin(), dataOut.end(),
80 [](float x){ static int val = 0; return x == (float)val++; });
81 EXPECT_EQ(true, same);
82}
83
84/*
85 * This test creates a 3D Allocation with 32 * 32 * 32 Float Elements, and two
86 * float vector dataIn & dataOut. dataIn is pre-populated with data, and copied
87 * into the Allocation using allocation3DWrite. Then the Allocation is copied
88 * into dataOut with allocation3DRead.
89 *
90 * Calls: elementCreate, typeCreate, allocationCreateTyped, allocation3DWrite,
91 * allocation3DRead
92 *
93 * Expect: dataIn & dataOut are the same.
94 */
95TEST_F(RenderscriptHidlTest, Simple3DCopyTest) {
96 // float1
97 Element element = context->elementCreate(DataType::FLOAT_32, DataKind::USER, false, 1);
98 // 32 x 32 x 32 x float1
99 Type type = context->typeCreate(element, 32, 32, 32, false, false, YuvFormat::YUV_NONE);
100 // 32 x 32 x 32 x float1
101 Allocation allocation = context->allocationCreateTyped(type, AllocationMipmapControl::NONE,
102 (int)AllocationUsageType::SCRIPT,
103 (Ptr)nullptr);
104 std::vector<float> dataIn(32*32*32), dataOut(32*32*32);
105 std::generate(dataIn.begin(), dataIn.end(), [](){ static int val = 0; return (float)val++; });
106 hidl_vec<uint8_t> _data;
107 _data.setToExternal((uint8_t*)dataIn.data(), dataIn.size()*sizeof(float));
108 context->allocation3DWrite(allocation, 0, 0, 0, 0, 32, 32, 32, _data, 0);
109 context->allocation3DRead(allocation, 0, 0, 0, 0, 32, 32, 32, (Ptr)dataOut.data(),
110 (Size)dataOut.size()*sizeof(float), 0);
111 bool same = std::all_of(dataOut.begin(), dataOut.end(),
112 [](float x){ static int val = 0; return x == (float)val++; });
113 EXPECT_EQ(true, same);
114}
115
116/*
117 * This test creates a 2D Allocation with 512 * 512 Float Elements with
118 * allocationCreateFromBitmap, and two float vector dataIn & dataOut. dataIn is
119 * pre-populated with data, and copied into the Allocation using
120 * allocationCopyToBitmap. Then the Allocation is copied into dataOut with
121 * allocationRead.
122 *
123 * Calls: elementCreate, typeCreate, allocationCreateFromBitmap,
124 * allocationCopyToBitmap, allocationRead
125 *
126 * Expect: dataIn & dataOut are the same.
127 */
128TEST_F(RenderscriptHidlTest, SimpleBitmapTest) {
129 // float1
130 Element element = context->elementCreate(DataType::FLOAT_32, DataKind::USER, false, 1);
131 // 512 x 512 x float1
132 Type type = context->typeCreate(element, 512, 512, 0, false, false, YuvFormat::YUV_NONE);
133 std::vector<float> dataIn(512*512), dataOut1(512*512), dataOut2(512*512);
134 std::generate(dataIn.begin(), dataIn.end(), [](){ static int val = 0; return (float)val++; });
135 hidl_vec<uint8_t> _data;
136 _data.setToExternal((uint8_t*)dataIn.data(), dataIn.size()*sizeof(float));
137 // 512 x 512 x float1
138 Allocation allocation = context->allocationCreateFromBitmap(type,
139 AllocationMipmapControl::NONE,
140 _data,
141 (int)AllocationUsageType::SCRIPT);
142 EXPECT_NE(allocation, Allocation(0));
143
144 context->allocationCopyToBitmap(allocation, (Ptr)dataOut1.data(),
145 (Size)dataOut1.size()*sizeof(float));
146 bool same1 = std::all_of(dataOut1.begin(), dataOut1.end(),
147 [](float x){ static int val = 0; return x == (float)val++; });
148 EXPECT_EQ(true, same1);
149
150 context->allocationRead(allocation, (Ptr)dataOut2.data(), (Size)dataOut2.size()*sizeof(float));
151 bool same2 = std::all_of(dataOut2.begin(), dataOut2.end(),
152 [](float x){ static int val = 0; return x == (float)val++; });
153 EXPECT_EQ(true, same2);
154}
155
156/*
157 * This test creates two 2D Allocations, one with 512 * 512 Float Elements, the
158 * other with 256 * 256 Float Elements. The larger Allocation is pre-populated
159 * with dataIn, and copied into the smaller Allocation using
160 * allocationCopy2DRange. Then the Allocation is copied into dataOut with
161 * allocationRead.
162 *
163 * Calls: elementCreate, typeCreate, allocationCreateFromBitmap,
164 * allocationCreateTyped, allocationCopy2DRange, allocationRead
165 *
166 * Expect: dataIn & dataOut are the same.
167 */
168TEST_F(RenderscriptHidlTest, AllocationCopy2DRangeTest) {
169 // float1
170 Element element = context->elementCreate(DataType::FLOAT_32, DataKind::USER, false, 1);
171 // 512 x 512 x float1
172 Type typeSrc = context->typeCreate(element, 512, 512, 0, false, false, YuvFormat::YUV_NONE);
173 // 256 x 256 x float1
174 Type typeDst = context->typeCreate(element, 256, 256, 0, false, false, YuvFormat::YUV_NONE);
175 std::vector<float> dataIn(512*512), dataOut(256*256), expected(256*256);
176 std::generate(dataIn.begin(), dataIn.end(), [](){ static int val = 0; return (float)val++; });
177 hidl_vec<uint8_t> _data;
178 _data.setToExternal((uint8_t*)dataIn.data(), dataIn.size()*sizeof(float));
179 // 512 x 512 x float1
180 Allocation allocSrc = context->allocationCreateFromBitmap(typeSrc,
181 AllocationMipmapControl::NONE, _data,
182 (int)AllocationUsageType::SCRIPT);
183 // 256 x 256 x float1
184 Allocation allocDst = context->allocationCreateTyped(typeDst, AllocationMipmapControl::NONE,
185 (int)AllocationUsageType::SCRIPT,
186 (Ptr)nullptr);
187 context->allocationCopy2DRange(allocDst, 0, 0, 0, AllocationCubemapFace::POSITIVE_X, 256, 256,
188 allocSrc, 128, 128, 0, AllocationCubemapFace::POSITIVE_X);
189 context->allocationRead(allocDst, (Ptr)dataOut.data(), (Size)dataOut.size()*sizeof(float));
190 for (int i = 0; i < 256; ++i) {
191 for (int j = 0; j < 256; ++j) {
192 expected[i*256 + j] = dataIn[(i+128)*512 + (j+128)];
193 }
194 }
195 EXPECT_EQ(expected, dataOut);
196}
197
198/*
199 * This test creates two 3D Allocations, one with 128 * 128 * 128 Float
200 * Elements, the other with 64 * 64 * 64 Float Elements. The larger Allocation
201 * is pre-populated with dataIn, and copied into the smaller Allocation using
202 * allocationCopy3DRange. Then the Allocation is copied into dataOut with
203 * allocationRead.
204 *
205 * Calls: elementCreate, typeCreate, allocationCreateTyped, allocation3DWrite,
206 * allocationCopy3DRange, allocationRead
207 *
208 * Expect: dataIn & dataOut are the same.
209 */
210TEST_F(RenderscriptHidlTest, AllocationCopy3DRangeTest) {
211 // float1
212 Element element = context->elementCreate(DataType::FLOAT_32, DataKind::USER, false, 1);
213 // 128 x 128 x 128 x float1
214 Type typeSrc = context->typeCreate(element, 128, 128, 128, false, false, YuvFormat::YUV_NONE);
215 // 64 x 64 x 64 x float1
216 Type typeDst = context->typeCreate(element, 64, 64, 64, false, false, YuvFormat::YUV_NONE);
217 std::vector<float> dataIn(128*128*128), dataOut(64*64*64), expected(64*64*64);
218 std::generate(dataIn.begin(), dataIn.end(), [](){ static int val = 0; return (float)val++; });
219 hidl_vec<uint8_t> _data;
220 _data.setToExternal((uint8_t*)dataIn.data(), dataIn.size()*sizeof(float));
221 // 512 x 512 x float1
222 Allocation allocSrc = context->allocationCreateTyped(typeSrc, AllocationMipmapControl::NONE,
223 (int)AllocationUsageType::SCRIPT,
224 (Ptr)nullptr);
225 // 256 x 256 x float1
226 Allocation allocDst = context->allocationCreateTyped(typeDst, AllocationMipmapControl::NONE,
227 (int)AllocationUsageType::SCRIPT,
228 (Ptr)nullptr);
229 context->allocation3DWrite(allocSrc, 0, 0, 0, 0, 128, 128, 128, _data, 128*sizeof(float));
230 context->allocationCopy3DRange(allocDst, 0, 0, 0, 0, 64, 64, 64, allocSrc, 32, 32, 32, 0);
231 context->allocationRead(allocDst, (Ptr)dataOut.data(), (Size)dataOut.size()*sizeof(float));
232 for (int i = 0; i < 64; ++i) {
233 for (int j = 0; j < 64; ++j) {
234 for (int k = 0; k < 64; ++k) {
235 expected[i*64*64 + j*64 + k] = dataIn[(i+32)*128*128 + (j+32)*128 + (k+32)];
236 }
237 }
238 }
239 EXPECT_EQ(expected, dataOut);
240}
241
242/*
243 * This test creates one 2D Allocations, one with 512 * 512 Float Elements, and
244 * one 2D AllocationAdapter with a window of 256 * 256 based on the Allocation.
245 * The Allocation is pre-populated with dataIn. Then the Allocation is copied
246 * into dataOut with allocationRead on the AllocationAdapter.
247 *
248 * Calls: elementCreate, typeCreate, allocationCreateFromBitmap,
249 * allocationAdapterCreate, allocationAdapterOffset, allocation2DRead
250 *
251 * Expect: dataIn & dataOut are the same.
252 */
253TEST_F(RenderscriptHidlTest, SimpleAdapterTest) {
254 // float1
255 Element element = context->elementCreate(DataType::FLOAT_32, DataKind::USER, false, 1);
256 // 512 x 512 x float1
257 Type type = context->typeCreate(element, 512, 512, 0, false, false, YuvFormat::YUV_NONE);
258 std::vector<float> dataIn(512*512), dataOut(256*256), expected;
259 std::generate(dataIn.begin(), dataIn.end(), [](){ static int val = 0; return (float)val++; });
260 hidl_vec<uint8_t> _data;
261 _data.setToExternal((uint8_t*)dataIn.data(), dataIn.size()*sizeof(float));
262 // 512 x 512 x float1
263 Allocation allocation = context->allocationCreateFromBitmap(type,
264 AllocationMipmapControl::NONE,
265 _data,
266 (int)AllocationUsageType::SCRIPT);
267 // 256 x 256 x float1
268 Type subType = context->typeCreate(element, 256, 256, 0, false, false, YuvFormat::YUV_NONE);
269 // 256 x 256 x float1
270 AllocationAdapter allocationAdapter = context->allocationAdapterCreate(subType, allocation);
271 EXPECT_NE(AllocationAdapter(0), allocationAdapter);
272
273 std::vector<uint32_t> offsets(9, 0);
274 offsets[0] = 128;
275 offsets[1] = 128;
276 hidl_vec<uint32_t> _offsets;
277 _offsets.setToExternal(offsets.data(), offsets.size());
278 // origin at (128,128)
279 context->allocationAdapterOffset(allocationAdapter, _offsets);
280
281 context->allocation2DRead(allocationAdapter, 0, 0, 0, AllocationCubemapFace::POSITIVE_X, 256,
282 256, (Ptr)dataOut.data(), (Size)dataOut.size()*sizeof(float), 0);
283 for (int i = 128; i < 128 + 256; ++i) {
284 for (int j = 128; j < 128 + 256; ++j) {
285 expected.push_back(i * 512 + j);
286 }
287 }
288 EXPECT_EQ(expected, dataOut);
289}
290
291/*
292 * This test creates one 2D Allocations, one with 64 * 64 USIGNED_8 Elements,
293 * and with AllocationMipmapControl::FULL. The Allocation is pre-populated with
294 * dataIn and the mipmaps are filled with allocationGenerateMipmaps. Then
295 * dataOut is then overridden with allocation2DRead.
296 *
297 * Calls: elementCreate, typeCreate, allocationCreateTyped, allocation2DWrite,
298 * allocationGenerateMipmaps, allocationSyncAll, allocation2DRead
299 *
300 * Expect: dataIn & dataOut are the same.
301 */
302TEST_F(RenderscriptHidlTest, SimpleMipmapTest) {
303 // uint8_t
304 Element element = context->elementCreate(DataType::UNSIGNED_8, DataKind::USER, false, 1);
305 // 64 x 64 x uint8_t
306 Type type = context->typeCreate(element, 64, 64, 0, true, false, YuvFormat::YUV_NONE);
307 std::vector<uint8_t> dataIn(64*64), dataOut(32*32), expected(32*32);
308 std::generate(dataIn.begin(), dataIn.end(),
309 [](){ static int val = 0; return (uint8_t)(0xFF & val++); });
310 hidl_vec<uint8_t> _data;
311 _data.setToExternal((uint8_t*)dataIn.data(), dataIn.size()*sizeof(uint8_t));
312 // 64 x 64 x uint8_t
313 Allocation allocation = context->allocationCreateTyped(type, AllocationMipmapControl::FULL,
314 (int)AllocationUsageType::SCRIPT,
315 (Ptr)nullptr);
316 context->allocation2DWrite(allocation, 0, 0, 0, AllocationCubemapFace::POSITIVE_X, 64, 64,
317 _data, 64*sizeof(uint8_t));
318 context->allocationGenerateMipmaps(allocation);
319 context->allocationSyncAll(allocation, AllocationUsageType::SCRIPT);
320 context->allocation2DRead(allocation, 0, 0, 1, AllocationCubemapFace::POSITIVE_X, 32, 32,
321 (Ptr)dataOut.data(), (Size)dataOut.size()*sizeof(uint8_t),
322 32*sizeof(uint8_t));
323 for (int i = 0; i < 32; ++i) {
324 for (int j = 0; j < 32; ++j) {
325 expected[i*32 + j] = ((uint32_t)dataIn[i*2*64 + j*2] + dataIn[i*2*64 + j*2 + 1] +
326 dataIn[i*2*64 + j*2 + 64] + dataIn[i*2*64 + j*2 + 64+1]) / 4;
327 }
328 }
329 EXPECT_EQ(expected, dataOut);
330}
331
332/*
333 * This test creates one 2D Allocations, one with 128 * 128 Float Elements with
334 * allocationCubeCreateFromBitmap. The Allocation is pre-populated with dataIn
335 * and the mipmaps are filled with allocationGenerateMipmaps. Then dataOut is
336 * then overridden with allocation2DRead.
337 *
338 * Calls: elementCreate, typeCreate, allocationCubeCreateFromBitmap,
339 * allocation2DRead
340 *
341 * Expect: dataIn & dataOut are the same.
342 */
343TEST_F(RenderscriptHidlTest, SimpleCubemapTest) {
344 // float1
345 Element element = context->elementCreate(DataType::FLOAT_32, DataKind::USER, false, 1);
346 // 128 x 128 x float1
347 Type type = context->typeCreate(element, 128, 128, 0, false, true, YuvFormat::YUV_NONE);
348 std::vector<float> dataIn(128*128*6), dataOut(128*128), expected(128*128);
349 std::generate(dataIn.begin(), dataIn.end(), [](){ static int val = 0; return (float)val++; });
350 hidl_vec<uint8_t> _data;
351 _data.setToExternal((uint8_t*)dataIn.data(), dataIn.size()*sizeof(float));
352 // 128 x 128 x float1 x 6
353 Allocation allocation = context->allocationCubeCreateFromBitmap(
354 type, AllocationMipmapControl::NONE, _data, (int)AllocationUsageType::SCRIPT);
355 EXPECT_NE(Allocation(0), allocation);
356
357 context->allocation2DRead(allocation, 0, 0, 0, AllocationCubemapFace::NEGATIVE_Z, 128,
358 128, (Ptr)dataOut.data(), (Size)dataOut.size()*sizeof(float),
359 128*sizeof(float));
360 for (int i = 0; i < 128; ++i) {
361 for (int j = 0; j < 128; ++j) {
362 expected[i*128 + j] = i*128*6 + j + 128*5;
363 }
364 }
365 EXPECT_EQ(expected, dataOut);
366}
367
368/*
369 * This test creates a complex element type (uint8_t, uint32_t) out of known
370 * elements. It then verifies the element structure was created correctly.
371 * Finally, the test creates a 128-wide, 1-dimension allocation of this type
372 * and transfers memory to and from this structure.
373 *
374 * Calls: elementCreate, elementComplexCreate, elementGetSubElements,
375 * typeCreate, allocationCreateTyped, allocationElementWrite,
376 * allocationElementRead
377 *
378 * This test currently has a bug, and should be fixed by 3/17.
379 * TODO(butlermichael)
380 */
381/*
382TEST_F(RenderscriptHidlTest, ComplexElementTest) {
383 Element element1 = context->elementCreate(DataType::UNSIGNED_8, DataKind::USER, false, 1);
384 Element element2 = context->elementCreate(DataType::UNSIGNED_32, DataKind::USER, false, 1);
385
386 hidl_vec<Element> eins = {element1, element2};
387 hidl_vec<hidl_string> names = {hidl_string("first"), hidl_string("second")};
388 hidl_vec<Size> arraySizesPtr = {sizeof(uint8_t), sizeof(uint32_t)};
389 Element element3 = context->elementComplexCreate(eins, names, arraySizesPtr);
390 EXPECT_NE(Element(0), element3);
391
392 std::vector<Element> ids;
393 std::vector<std::string> namesOut;
394 std::vector<Size> arraySizesOut;
395 context->elementGetSubElements(element3, 2, [&](const hidl_vec<Element>& _ids,
396 const hidl_vec<hidl_string>& _names,
397 const hidl_vec<Size>& _arraySizes){
398 ids = _ids;
399 namesOut.push_back(_names[0]);
400 namesOut.push_back(_names[1]);
401 arraySizesOut = _arraySizes;
402 });
403 EXPECT_NE(Element(0), ids[0]);
404 EXPECT_NE(Element(0), ids[1]);
405 EXPECT_EQ("first", namesOut[0]);
406 EXPECT_EQ("second", namesOut[1]);
407 EXPECT_EQ(sizeof(uint8_t), arraySizesOut[0]);
408 EXPECT_EQ(sizeof(uint32_t), arraySizesOut[1]);
409
410 // 128 x (uint8_t, uint32_t)
411 Type type = context->typeCreate(element3, 128, 0, 0, false, false, YuvFormat::YUV_NONE);
412 // 128 x (uint8_t, uint32_t)
413 Allocation allocation = context->allocationCreateTyped(type, AllocationMipmapControl::NONE,
414 (int)AllocationUsageType::SCRIPT,
415 (Ptr)nullptr);
416 std::vector<uint32_t> dataIn(128), dataOut(128);
417 std::generate(dataIn.begin(), dataIn.end(), [](){ static uint32_t val = 0; return val++; });
418 hidl_vec<uint8_t> _data;
419 _data.setToExternal((uint8_t*)dataIn.data(), dataIn.size()*sizeof(uint32_t));
420 context->allocationElementWrite(allocation, 0, 0, 0, 0, _data, 1);
421 context->allocationElementRead(allocation, 0, 0, 0, 0, (Ptr)dataOut.data(),
422 (Size)dataOut.size()*sizeof(uint32_t), 1);
423 bool same = std::all_of(dataOut.begin(), dataOut.end(),
424 [](uint32_t x){ static uint32_t val = 0; return x == val++; });
425 EXPECT_EQ(true, same);
426}
427*/