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