blob: 6bb375ada53ca06fde67570546f2df2e29e87b04 [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 * Create a Blur intrinsic with scriptIntrinsicCreate, and call
21 * scriptSetTimeZone to make sure it is not crashing.
22 *
23 * Calls: elementCreate, scriptIntrinsicCreate, scriptSetTimeZone
24 */
25TEST_F(RenderscriptHidlTest, IntrinsicTest) {
26 // uint8
27 Element element = context->elementCreate(DataType::UNSIGNED_8, DataKind::USER, false, 1);
28 Script script = context->scriptIntrinsicCreate(ScriptIntrinsicID::ID_BLUR, element);
29 EXPECT_NE(Script(0), script);
30
31 context->scriptSetTimeZone(script, "UTF-8");
32}
33
34/*
35 * Create a user script “struct_test”, and verified the setters and getters work
36 * for the global variables.
37 *
38 * Calls: scriptCCreate, scriptGetVarV, scriptSetVarI, scriptSetVarJ,
39 * scriptSetVarF, scriptSetVarD, elementCreate, typeCreate,
40 * allocationCreateTyped, scriptSetVarObj, scriptSetVarV, scriptSetVarVE
41 */
42TEST_F(RenderscriptHidlTest, ScriptVarTest) {
43 hidl_vec<uint8_t> bitcode;
44 bitcode.setToExternal((uint8_t*)bitCode, bitCodeLength);
45 Script script = context->scriptCCreate("struct_test", "/data/local/tmp/", bitcode);
46 EXPECT_NE(Script(0), script);
47
48 // arg tests
Michael Butlerda8c2c12017-03-17 13:02:53 -070049 context->scriptSetVarI(script, mExportVarIdx_var_int, 100);
Michael Butler2d4d6d92017-03-01 15:32:30 -080050 int resultI = 0;
Michael Butlerda8c2c12017-03-17 13:02:53 -070051 context->scriptGetVarV(script, mExportVarIdx_var_int, sizeof(int),
52 [&](const hidl_vec<uint8_t>& _data){ resultI = *((int*)_data.data()); });
Michael Butler2d4d6d92017-03-01 15:32:30 -080053 EXPECT_EQ(100, resultI);
54
Michael Butlerda8c2c12017-03-17 13:02:53 -070055 context->scriptSetVarJ(script, mExportVarIdx_var_long, 101l);
Michael Butler2d4d6d92017-03-01 15:32:30 -080056 int resultJ = 0;
Michael Butlerda8c2c12017-03-17 13:02:53 -070057 context->scriptGetVarV(script, mExportVarIdx_var_long, sizeof(long),
58 [&](const hidl_vec<uint8_t>& _data){
Michael Butler2d4d6d92017-03-01 15:32:30 -080059 resultJ = *((long*)_data.data()); });
Michael Butlerda8c2c12017-03-17 13:02:53 -070060 EXPECT_EQ(101l, resultJ);
Michael Butler2d4d6d92017-03-01 15:32:30 -080061
Michael Butlerda8c2c12017-03-17 13:02:53 -070062 context->scriptSetVarF(script, mExportVarIdx_var_float, 102.0f);
Michael Butler2d4d6d92017-03-01 15:32:30 -080063 int resultF = 0.0f;
Michael Butlerda8c2c12017-03-17 13:02:53 -070064 context->scriptGetVarV(script, mExportVarIdx_var_float, sizeof(float),
65 [&](const hidl_vec<uint8_t>& _data){
Michael Butler2d4d6d92017-03-01 15:32:30 -080066 resultF = *((float*)_data.data()); });
67 EXPECT_EQ(102.0f, resultF);
68
Michael Butlerda8c2c12017-03-17 13:02:53 -070069 context->scriptSetVarD(script, mExportVarIdx_var_double, 103.0);
Michael Butler2d4d6d92017-03-01 15:32:30 -080070 int resultD = 0.0;
Michael Butlerda8c2c12017-03-17 13:02:53 -070071 context->scriptGetVarV(script, mExportVarIdx_var_double, sizeof(double),
72 [&](const hidl_vec<uint8_t>& _data){
Michael Butler2d4d6d92017-03-01 15:32:30 -080073 resultD = *((double*)_data.data()); });
74 EXPECT_EQ(103.0, resultD);
75
76 // float1
77 Element element = context->elementCreate(DataType::FLOAT_32, DataKind::USER, false, 1);
78 // 128 x float1
79 Type type = context->typeCreate(element, 128, 0, 0, false, false, YuvFormat::YUV_NONE);
80 // 128 x float1
81 Allocation allocationIn = context->allocationCreateTyped(type, AllocationMipmapControl::NONE,
82 (int)AllocationUsageType::SCRIPT,
83 (Ptr)nullptr);
84 Allocation allocationOut = Allocation(0);
Michael Butlerda8c2c12017-03-17 13:02:53 -070085 context->scriptSetVarObj(script, mExportVarIdx_var_allocation, (ObjectBase)allocationIn);
86 context->scriptGetVarV(script, mExportVarIdx_var_allocation, sizeof(ObjectBase),
87 [&](const hidl_vec<uint8_t>& _data){
Michael Butler2d4d6d92017-03-01 15:32:30 -080088 allocationOut = (Allocation) *((ObjectBase*)_data.data()); });
89 EXPECT_EQ(allocationOut, allocationIn);
90
Michael Butlerda8c2c12017-03-17 13:02:53 -070091 uint32_t valueV = 104u;
92 hidl_vec<uint8_t> _dataV;
93 _dataV.setToExternal((uint8_t*)&valueV, sizeof(uint32_t));
94 context->scriptSetVarV(script, mExportVarIdx_var_uint32_t, _dataV);
95 uint32_t resultV = 0u;
96 context->scriptGetVarV(script, mExportVarIdx_var_uint32_t, sizeof(uint32_t),
97 [&](const hidl_vec<uint8_t>& _data){
98 resultV = *((uint32_t*)_data.data()); });
99 EXPECT_EQ(104u, resultV);
Michael Butler2d4d6d92017-03-01 15:32:30 -0800100
101 std::vector<int> dataVE = {1000, 1001};
102 std::vector<uint32_t> dimsVE = {1};
103 std::vector<int> outVE(2);
104 hidl_vec<uint8_t> _dataVE;
105 hidl_vec<uint32_t> _dimsVE;
106 _dataVE.setToExternal((uint8_t*)dataVE.data(), dataVE.size()*sizeof(int));
107 _dimsVE.setToExternal((uint32_t*)dimsVE.data(), dimsVE.size());
Michael Butlerda8c2c12017-03-17 13:02:53 -0700108 // intx2 to represent point2 which is {int, int}
Michael Butler2d4d6d92017-03-01 15:32:30 -0800109 Element elementVE = context->elementCreate(DataType::SIGNED_32, DataKind::USER, false, 2);
Michael Butlerda8c2c12017-03-17 13:02:53 -0700110 context->scriptSetVarVE(script, mExportVarIdx_var_point2, _dataVE, elementVE, _dimsVE);
111 context->scriptGetVarV(script, mExportVarIdx_var_point2, 2*sizeof(int),
112 [&](const hidl_vec<uint8_t>& _data){
113 outVE = std::vector<int>(
114 (int*)_data.data(), (int*)_data.data() + 2); });
Michael Butler2d4d6d92017-03-01 15:32:30 -0800115 EXPECT_EQ(1000, outVE[0]);
116 EXPECT_EQ(1001, outVE[1]);
117}
118
119/*
120 * Create a user script “struct_test”, and input and output Allocations.
121 * Verified the foreach launch correctly for the invoke kernel.
122 *
123 * Calls: scriptCCreate, scriptInvoke, scriptGetVarV, scriptInvokeV
124 */
125TEST_F(RenderscriptHidlTest, ScriptInvokeTest) {
126 hidl_vec<uint8_t> bitcode;
127 bitcode.setToExternal((uint8_t*)bitCode, bitCodeLength);
128 Script script = context->scriptCCreate("struct_test", "/data/local/tmp/", bitcode);
129 EXPECT_NE(Script(0), script);
130
131 // invoke test
Michael Butlerda8c2c12017-03-17 13:02:53 -0700132 int resultI = 0;
133 long resultJ = 0l;
134 float resultF = 0.0f;
135 double resultD = 0.0;
136 uint32_t resultV = 0u;
137 std::vector<int> resultVE(2);
138 context->scriptInvoke(script, mExportFuncIdx_function);
139 context->scriptGetVarV(script, mExportVarIdx_var_int, sizeof(int),
140 [&](const hidl_vec<uint8_t>& _data){ resultI = *((int*)_data.data()); });
141 context->scriptGetVarV(script, mExportVarIdx_var_long, sizeof(long),
142 [&](const hidl_vec<uint8_t>& _data){
143 resultJ = *((long*)_data.data()); });
144 context->scriptGetVarV(script, mExportVarIdx_var_float, sizeof(float),
145 [&](const hidl_vec<uint8_t>& _data){
146 resultF = *((float*)_data.data()); });
147 context->scriptGetVarV(script, mExportVarIdx_var_double, sizeof(double),
148 [&](const hidl_vec<uint8_t>& _data){
149 resultD = *((double*)_data.data()); });
150 context->scriptGetVarV(script, mExportVarIdx_var_uint32_t, sizeof(uint32_t),
151 [&](const hidl_vec<uint8_t>& _data){
152 resultV = *((uint32_t*)_data.data()); });
153 context->scriptGetVarV(script, mExportVarIdx_var_point2, 2*sizeof(int),
154 [&](const hidl_vec<uint8_t>& _data){
155 resultVE = std::vector<int>(
156 (int*)_data.data(), (int*)_data.data() + 2); });
157 EXPECT_EQ(1, resultI);
158 EXPECT_EQ(2l, resultJ);
159 EXPECT_EQ(3.0f, resultF);
160 EXPECT_EQ(4.0, resultD);
161 EXPECT_EQ(5u, resultV);
162 EXPECT_EQ(6, resultVE[0]);
163 EXPECT_EQ(7, resultVE[1]);
Michael Butler2d4d6d92017-03-01 15:32:30 -0800164
165 // invokeV test
166 int functionV_arg = 5;
167 int functionV_res = 0;
168 hidl_vec<uint8_t> functionV_data;
169 functionV_data.setToExternal((uint8_t*)&functionV_arg, sizeof(int));
Michael Butlerda8c2c12017-03-17 13:02:53 -0700170 context->scriptInvokeV(script, mExportFuncIdx_functionV, functionV_data);
171 context->scriptGetVarV(script, mExportVarIdx_var_int, sizeof(int),
172 [&](const hidl_vec<uint8_t>& _data){
Michael Butler2d4d6d92017-03-01 15:32:30 -0800173 functionV_res = *((int*)_data.data()); });
174 EXPECT_EQ(5, functionV_res);
175}
176
177/*
178 * Create a user script “struct_test”, and input and output Allocations.
179 * Verified the foreach launch correctly for the foreach kernel.
180 *
181 * Calls: scriptCCreate, elementCreate, typeCreate, allocationCreateTyped,
182 * allocation1DWrite, scriptForEach, allocationRead
183 */
184TEST_F(RenderscriptHidlTest, ScriptForEachTest) {
185 hidl_vec<uint8_t> bitcode;
186 bitcode.setToExternal((uint8_t*)bitCode, bitCodeLength);
187 Script script = context->scriptCCreate("struct_test", "/data/local/tmp/", bitcode);
188 EXPECT_NE(Script(0), script);
189
190 // uint8_t
191 Element element = context->elementCreate(DataType::UNSIGNED_8, DataKind::USER, false, 1);
192 // 64 x uint8_t
193 Type type = context->typeCreate(element, 64, 0, 0, false, false, YuvFormat::YUV_NONE);
Michael Butlerda8c2c12017-03-17 13:02:53 -0700194 std::vector<uint8_t> dataIn(64), dataOut(64), expected(64);
Michael Butler2d4d6d92017-03-01 15:32:30 -0800195 std::generate(dataIn.begin(), dataIn.end(), [](){ static uint8_t val = 0; return val++; });
Michael Butlerda8c2c12017-03-17 13:02:53 -0700196 std::generate(expected.begin(), expected.end(), [](){ static uint8_t val = 1; return val++; });
Michael Butler2d4d6d92017-03-01 15:32:30 -0800197 hidl_vec<uint8_t> _data;
198 _data.setToExternal((uint8_t*)dataIn.data(), dataIn.size());
199 // 64 x float1
200 Allocation allocation = context->allocationCreateTyped(type, AllocationMipmapControl::NONE,
201 (int)AllocationUsageType::SCRIPT,
202 (Ptr)nullptr);
203 Allocation vout = context->allocationCreateTyped(type, AllocationMipmapControl::NONE,
204 (int)AllocationUsageType::SCRIPT,
205 (Ptr)nullptr);
206 context->allocation1DWrite(allocation, 0, 0, (Size)dataIn.size(), _data);
207 hidl_vec<Allocation> vains;
208 vains.setToExternal(&allocation, 1);
209 hidl_vec<uint8_t> params;
Michael Butlerda8c2c12017-03-17 13:02:53 -0700210 context->scriptForEach(script, mExportForEachIdx_increment, vains, vout, params, nullptr);
Michael Butler2d4d6d92017-03-01 15:32:30 -0800211 context->allocationRead(vout, (Ptr)dataOut.data(), (Size)dataOut.size()*sizeof(uint8_t));
Michael Butlerda8c2c12017-03-17 13:02:53 -0700212 EXPECT_EQ(expected, dataOut);
Michael Butler2d4d6d92017-03-01 15:32:30 -0800213}
214
215/*
216 * Create a user script “struct_test”, and input and output Allocations.
217 * Verified the foreach launch correctly for the reduction kernel.
218 *
219 * Calls: scriptCCreate, elementCreate, typeCreate, allocationCreateTyped,
220 * allocation1DWrite, scriptReduce, contextFinish, allocationRead
221 */
222TEST_F(RenderscriptHidlTest, ScriptReduceTest) {
223 hidl_vec<uint8_t> bitcode;
224 bitcode.setToExternal((uint8_t*)bitCode, bitCodeLength);
225 Script script = context->scriptCCreate("struct_test", "/data/local/tmp/", bitcode);
226 EXPECT_NE(Script(0), script);
227
228 // uint8_t
229 Element element = context->elementCreate(DataType::SIGNED_32, DataKind::USER, false, 1);
230 // 64 x uint8_t
231 Type type = context->typeCreate(element, 64, 0, 0, false, false, YuvFormat::YUV_NONE);
232 Type type2 = context->typeCreate(element, 1, 0, 0, false, false, YuvFormat::YUV_NONE);
233 std::vector<int> dataIn(64), dataOut(1);
234 std::generate(dataIn.begin(), dataIn.end(), [](){ static int val = 0; return val++; });
235 hidl_vec<uint8_t> _data;
236 _data.setToExternal((uint8_t*)dataIn.data(), dataIn.size()*sizeof(int));
237 // 64 x float1
238 Allocation allocation = context->allocationCreateTyped(type, AllocationMipmapControl::NONE,
239 (int)AllocationUsageType::SCRIPT,
240 (Ptr)nullptr);
241 Allocation vaout = context->allocationCreateTyped(type2, AllocationMipmapControl::NONE,
242 (int)AllocationUsageType::SCRIPT,
243 (Ptr)nullptr);
244 context->allocation1DWrite(allocation, 0, 0, (Size)dataIn.size(), _data);
245 hidl_vec<Allocation> vains;
246 vains.setToExternal(&allocation, 1);
Michael Butlerda8c2c12017-03-17 13:02:53 -0700247 context->scriptReduce(script, mExportReduceIdx_summation, vains, vaout, nullptr);
Michael Butler2d4d6d92017-03-01 15:32:30 -0800248 context->contextFinish();
249 context->allocationRead(vaout, (Ptr)dataOut.data(), (Size)dataOut.size()*sizeof(int));
250 // sum of 0, 1, 2, ..., 62, 63
251 int sum = 63*64/2;
252 EXPECT_EQ(sum, dataOut[0]);
253}
254
255/*
256 * This test creates an allocation and binds it to a data segment in the
257 * RenderScript script, represented in the bitcode.
258 *
259 * Calls: scriptCCreate, elementCreate, typeCreate, allocationCreateTyped,
Michael Butlerda8c2c12017-03-17 13:02:53 -0700260 * scriptSetVarV, scriptBindAllocation, allocationRead
Michael Butler2d4d6d92017-03-01 15:32:30 -0800261 */
Michael Butler2d4d6d92017-03-01 15:32:30 -0800262TEST_F(RenderscriptHidlTest, ScriptBindTest) {
263 hidl_vec<uint8_t> bitcode;
264 bitcode.setToExternal((uint8_t*)bitCode, bitCodeLength);
265 Script script = context->scriptCCreate("struct_test", "/data/local/tmp/", bitcode);
266 EXPECT_NE(Script(0), script);
267
Michael Butlerda8c2c12017-03-17 13:02:53 -0700268 // in32
Michael Butler2d4d6d92017-03-01 15:32:30 -0800269 Element element = context->elementCreate(DataType::SIGNED_32, DataKind::USER, false, 1);
Michael Butlerda8c2c12017-03-17 13:02:53 -0700270 // 64 x int32
Michael Butler2d4d6d92017-03-01 15:32:30 -0800271 Type type = context->typeCreate(element, 64, 0, 0, false, false, YuvFormat::YUV_NONE);
Michael Butlerda8c2c12017-03-17 13:02:53 -0700272 // 64 x int32
Michael Butler2d4d6d92017-03-01 15:32:30 -0800273 Allocation allocation = context->allocationCreateTyped(type, AllocationMipmapControl::NONE,
274 (int)AllocationUsageType::SCRIPT,
275 (Ptr)nullptr);
Michael Butlerda8c2c12017-03-17 13:02:53 -0700276 std::vector<int> dataIn(64), dataOut(64), expected(64, 5);
277 hidl_vec<uint8_t> _data;
278 _data.setToExternal((uint8_t*)dataIn.data(), dataIn.size()*sizeof(int));
279 context->allocation1DWrite(allocation, 0, 0, (Size)dataIn.size(), _data);
280 context->scriptBindAllocation(script, allocation, mExportVarIdx_var_int_ptr);
281 int dim = 64;
282 hidl_vec<uint8_t> _dim;
283 _dim.setToExternal((uint8_t*)&dim, sizeof(int));
284 context->scriptInvokeV(script, mExportFuncIdx_setBuffer, _dim);
285 context->allocationRead(allocation, (Ptr)dataOut.data(), (Size)dataOut.size()*sizeof(int));
286 EXPECT_EQ(expected, dataOut);
Michael Butler2d4d6d92017-03-01 15:32:30 -0800287}
Michael Butler2d4d6d92017-03-01 15:32:30 -0800288
289/*
290 * This test groups together two RenderScript intrinsic kernels to run one after
291 * the other asynchronously with respect to the client. The test configures YuvToRGB(A) and Blur,
292 * and links them together such that Blur will execute after YuvToRGB(A) and use its result. The
293 * test checks the data returned to make sure it was changed after passing through the entire
294 * ScriptGroup.
295 *
296 * Calls: elementCreate, typeCreate, allocationCreateTyped, allocation2DWrite,
Michael Butlerda8c2c12017-03-17 13:02:53 -0700297 * scriptIntrinsicCreate, scriptKernelIDCreate, scriptFieldIDCreate,
298 * scriptGroupCreate, scriptGroupSetOutput, scriptGroupExecute, allocation2DRead
Michael Butler2d4d6d92017-03-01 15:32:30 -0800299 */
Michael Butler2d4d6d92017-03-01 15:32:30 -0800300TEST_F(RenderscriptHidlTest, ScriptGroupTest) {
Michael Butlerda8c2c12017-03-17 13:02:53 -0700301 std::vector<uint8_t> dataIn(256*256*1, 128), dataOut(256*256*4, 0), zeros(256*256*4, 0);
Michael Butler2d4d6d92017-03-01 15:32:30 -0800302 hidl_vec<uint8_t> _dataIn, _dataOut;
303 _dataIn.setToExternal(dataIn.data(), dataIn.size());
Michael Butlerda8c2c12017-03-17 13:02:53 -0700304 _dataOut.setToExternal(dataOut.data(), dataOut.size());
Michael Butler2d4d6d92017-03-01 15:32:30 -0800305
306 // 256 x 256 YUV pixels
307 Element element1 = context->elementCreate(DataType::UNSIGNED_8, DataKind::PIXEL_YUV, true, 1);
Michael Butlerda8c2c12017-03-17 13:02:53 -0700308 Type type1 = context->typeCreate(element1, 256, 256, 0, false, false, YuvFormat::YUV_420_888);
Michael Butler2d4d6d92017-03-01 15:32:30 -0800309 Allocation allocation1 = context->allocationCreateTyped(type1, AllocationMipmapControl::NONE,
310 (int)AllocationUsageType::SCRIPT,
311 (Ptr)nullptr);
312 context->allocation2DWrite(allocation1, 0, 0, 0, AllocationCubemapFace::POSITIVE_X, 256, 256,
313 _dataIn, 0);
Michael Butler2d4d6d92017-03-01 15:32:30 -0800314
Michael Butlerda8c2c12017-03-17 13:02:53 -0700315 // 256 x 256 RGBA pixels
Michael Butler2d4d6d92017-03-01 15:32:30 -0800316 Element element2 = context->elementCreate(DataType::UNSIGNED_8, DataKind::PIXEL_RGBA, true, 4);
317 Type type2 = context->typeCreate(element2, 256, 256, 0, false, false, YuvFormat::YUV_NONE);
318 Allocation allocation2 = context->allocationCreateTyped(type2, AllocationMipmapControl::NONE,
319 (int)AllocationUsageType::SCRIPT,
320 (Ptr)nullptr);
321 context->allocation2DWrite(allocation2, 0, 0, 0, AllocationCubemapFace::POSITIVE_X, 256, 256,
322 _dataOut, 0);
Michael Butlerda8c2c12017-03-17 13:02:53 -0700323
324 // create scripts
325 Script yuv2rgb = context->scriptIntrinsicCreate(ScriptIntrinsicID::ID_YUV_TO_RGB, element1);
326 EXPECT_NE(Script(0), yuv2rgb);
327
328 ScriptKernelID yuv2rgbKID = context->scriptKernelIDCreate(yuv2rgb, 0, 2);
329 EXPECT_NE(ScriptKernelID(0), yuv2rgbKID);
330
Michael Butler2d4d6d92017-03-01 15:32:30 -0800331 Script blur = context->scriptIntrinsicCreate(ScriptIntrinsicID::ID_BLUR, element2);
332 EXPECT_NE(Script(0), blur);
333
334 ScriptKernelID blurKID = context->scriptKernelIDCreate(blur, 0, 2);
335 EXPECT_NE(ScriptKernelID(0), blurKID);
Michael Butlerda8c2c12017-03-17 13:02:53 -0700336 ScriptFieldID blurFID = context->scriptFieldIDCreate(blur, 1);
337 EXPECT_NE(ScriptFieldID(0), blurFID);
Michael Butler2d4d6d92017-03-01 15:32:30 -0800338
339 // ScriptGroup
340 hidl_vec<ScriptKernelID> kernels = {yuv2rgbKID, blurKID};
341 hidl_vec<ScriptKernelID> srcK = {yuv2rgbKID};
Michael Butlerda8c2c12017-03-17 13:02:53 -0700342 hidl_vec<ScriptKernelID> dstK = {ScriptKernelID(0)};
343 hidl_vec<ScriptFieldID> dstF = {blurFID};
Michael Butler2d4d6d92017-03-01 15:32:30 -0800344 hidl_vec<Type> types = {type2};
345 ScriptGroup scriptGroup = context->scriptGroupCreate(kernels, srcK, dstK, dstF, types);
346 EXPECT_NE(ScriptGroup(0), scriptGroup);
347
Michael Butlerda8c2c12017-03-17 13:02:53 -0700348 context->scriptSetVarObj(yuv2rgb, 0, (ObjectBase)allocation1);
Michael Butler2d4d6d92017-03-01 15:32:30 -0800349 context->scriptGroupSetOutput(scriptGroup, blurKID, allocation2);
350 context->scriptGroupExecute(scriptGroup);
Michael Butlerda8c2c12017-03-17 13:02:53 -0700351 context->contextFinish();
Michael Butler2d4d6d92017-03-01 15:32:30 -0800352
353 // verify contents were changed
354 context->allocation2DRead(allocation2, 0, 0, 0, AllocationCubemapFace::POSITIVE_X, 256, 256,
355 (Ptr)dataOut.data(), (Size)dataOut.size(), 0);
Michael Butlerda8c2c12017-03-17 13:02:53 -0700356 EXPECT_NE(zeros, dataOut);
Michael Butler2d4d6d92017-03-01 15:32:30 -0800357}
Michael Butler2d4d6d92017-03-01 15:32:30 -0800358
359/*
360 * Similar to the ScriptGroup test, this test verifies the execution flow of
361 * RenderScript kernels and invokables.
362 *
363 * Calls: scriptFieldIDCreate, closureCreate, scriptInvokeIDCreate,
Michael Butlerda8c2c12017-03-17 13:02:53 -0700364 * invokeClosureCreate, closureSetGlobal, scriptGroup2Create, scriptGroupExecute
Michael Butler2d4d6d92017-03-01 15:32:30 -0800365 */
Michael Butler2d4d6d92017-03-01 15:32:30 -0800366TEST_F(RenderscriptHidlTest, ScriptGroup2Test) {
Michael Butlerda8c2c12017-03-17 13:02:53 -0700367 hidl_vec<uint8_t> bitcode;
368 bitcode.setToExternal((uint8_t*)bitCode, bitCodeLength);
369 Script script = context->scriptCCreate("struct_test", "/data/local/tmp/", bitcode);
370 EXPECT_NE(Script(0), script);
Michael Butler2d4d6d92017-03-01 15:32:30 -0800371
Michael Butlerda8c2c12017-03-17 13:02:53 -0700372 std::vector<uint8_t> dataIn(128, 128), dataOut(128, 0), expected(128, 7+1);
373 hidl_vec<uint8_t> _dataIn, _dataOut;
374 _dataIn.setToExternal(dataIn.data(), dataIn.size());
375
376 // 256 x 256 YUV pixels
377 Element element = context->elementCreate(DataType::UNSIGNED_8, DataKind::USER, false, 1);
378 Type type = context->typeCreate(element, 128, 0, 0, false, false, YuvFormat::YUV_NONE);
379 Allocation allocation = context->allocationCreateTyped(type, AllocationMipmapControl::NONE,
380 (int)AllocationUsageType::SCRIPT,
381 (Ptr)nullptr);
382 context->allocation1DWrite(allocation, 0, 0, (Size)_dataIn.size(), _dataIn);
383
384 ScriptFieldID fieldID = context->scriptFieldIDCreate(script, mExportVarIdx_var_allocation);
Michael Butler2d4d6d92017-03-01 15:32:30 -0800385 EXPECT_NE(ScriptFieldID(0), fieldID);
Michael Butlerda8c2c12017-03-17 13:02:53 -0700386 ASSERT_NE(ScriptFieldID(0), fieldID);
Michael Butler2d4d6d92017-03-01 15:32:30 -0800387
Michael Butlerda8c2c12017-03-17 13:02:53 -0700388 // invoke
389 ScriptInvokeID invokeID = context->scriptInvokeIDCreate(script, mExportFuncIdx_setAllocation);
Michael Butler2d4d6d92017-03-01 15:32:30 -0800390 EXPECT_NE(ScriptInvokeID(0), invokeID);
Michael Butlerda8c2c12017-03-17 13:02:53 -0700391 ASSERT_NE(ScriptInvokeID(0), invokeID);
Michael Butler2d4d6d92017-03-01 15:32:30 -0800392
Michael Butlerda8c2c12017-03-17 13:02:53 -0700393 int dim = 128;
394 hidl_vec<uint8_t> params;
395 params.setToExternal((uint8_t*)&dim, sizeof(dim));
396 hidl_vec<ScriptFieldID> fieldIDS1 = {fieldID};
397 hidl_vec<int64_t> values1 = {int64_t(0)};
398 hidl_vec<int32_t> sizes1 = {int32_t(0)};
399 Closure closure1 = context->invokeClosureCreate(invokeID, params, fieldIDS1, values1, sizes1);
400 EXPECT_NE(Closure(0), closure1);
401 ASSERT_NE(Closure(0), closure1);
402
403 // kernel
404 ScriptKernelID kernelID = context->scriptKernelIDCreate(script, mExportForEachIdx_increment, 3);
405 EXPECT_NE(ScriptKernelID(0), kernelID);
406 ASSERT_NE(ScriptKernelID(0), kernelID);
407
408 hidl_vec<ScriptFieldID> fieldIDS2 = {ScriptFieldID(0)};
409 hidl_vec<int64_t> values2 = {(int64_t)(intptr_t)allocation};
410 hidl_vec<int32_t> sizes2 = {-1 /* allocation */};
411 hidl_vec<Closure> depClosures2 = {closure1};
412 hidl_vec<ScriptFieldID> depFieldIDS2 = {fieldID};
413 Closure closure2 = context->closureCreate(kernelID, allocation /* returnValue */, fieldIDS2,
414 values2, sizes2, depClosures2, depFieldIDS2);
Michael Butler2d4d6d92017-03-01 15:32:30 -0800415 EXPECT_NE(Closure(0), closure2);
Michael Butlerda8c2c12017-03-17 13:02:53 -0700416 ASSERT_NE(Closure(0), closure2);
Michael Butler2d4d6d92017-03-01 15:32:30 -0800417
Michael Butlerda8c2c12017-03-17 13:02:53 -0700418 // set argument
419 context->closureSetGlobal(closure1, fieldID, (int64_t)(intptr_t)allocation,
420 -1 /* allocation */);
Michael Butler2d4d6d92017-03-01 15:32:30 -0800421
Michael Butlerda8c2c12017-03-17 13:02:53 -0700422 // execute
Michael Butler2d4d6d92017-03-01 15:32:30 -0800423 hidl_string name = "script_group_2_test";
Michael Butlerda8c2c12017-03-17 13:02:53 -0700424 hidl_string cacheDir = "/data/local/tmp";
425 hidl_vec<Closure> closures = {closure1, closure2};
Michael Butler2d4d6d92017-03-01 15:32:30 -0800426 ScriptGroup2 scriptGroup2 = context->scriptGroup2Create(name, cacheDir, closures);
427 EXPECT_NE(ScriptGroup2(0), scriptGroup2);
Michael Butlerda8c2c12017-03-17 13:02:53 -0700428 ASSERT_NE(ScriptGroup2(0), scriptGroup2);
Michael Butler2d4d6d92017-03-01 15:32:30 -0800429
430 context->scriptGroupExecute(scriptGroup2);
Michael Butlerda8c2c12017-03-17 13:02:53 -0700431 context->allocationRead(allocation, (Ptr)dataOut.data(), (Size)dataOut.size()*sizeof(uint8_t));
432 EXPECT_EQ(expected, dataOut);
Michael Butler2d4d6d92017-03-01 15:32:30 -0800433}
Michael Butlerda8c2c12017-03-17 13:02:53 -0700434
435/*
436 * Similar to the ScriptGroup test, this test verifies a single kernel can be
437 * called by ScriptGroup with an unbound allocation specified before launch
438 *
439 * Calls: scriptFieldIDCreate, closureCreate, scriptInvokeIDCreate,
440 * invokeClosureCreate, closureSetArg, scriptGroup2Create, scriptGroupExecute
441 */
442TEST_F(RenderscriptHidlTest, ScriptGroup2KernelTest) {
443 hidl_vec<uint8_t> bitcode;
444 bitcode.setToExternal((uint8_t*)bitCode, bitCodeLength);
445 Script script = context->scriptCCreate("struct_test", "/data/local/tmp/", bitcode);
446 EXPECT_NE(Script(0), script);
447
448 std::vector<uint8_t> dataIn(128, 128), dataOut(128, 0), expected(128, 128 + 1);
449 hidl_vec<uint8_t> _dataIn, _dataOut;
450 _dataIn.setToExternal(dataIn.data(), dataIn.size());
451
452 // 256 x 256 YUV pixels
453 Element element = context->elementCreate(DataType::UNSIGNED_8, DataKind::USER, false, 1);
454 Type type = context->typeCreate(element, 128, 0, 0, false, false, YuvFormat::YUV_NONE);
455 Allocation allocation = context->allocationCreateTyped(type, AllocationMipmapControl::NONE,
456 (int)AllocationUsageType::SCRIPT,
457 (Ptr)nullptr);
458 context->allocation1DWrite(allocation, 0, 0, (Size)_dataIn.size(), _dataIn);
459
460 // kernel
461 ScriptKernelID kernelID = context->scriptKernelIDCreate(script, mExportForEachIdx_increment, 3);
462 EXPECT_NE(ScriptKernelID(0), kernelID);
463 ASSERT_NE(ScriptKernelID(0), kernelID);
464
465 hidl_vec<ScriptFieldID> fieldIDS = {ScriptFieldID(0)};
466 hidl_vec<int64_t> values = {int64_t(0)};
467 hidl_vec<int32_t> sizes = {int32_t(0)};
468 hidl_vec<Closure> depClosures = {Closure(0)};
469 hidl_vec<ScriptFieldID> depFieldIDS = {ScriptFieldID(0)};
470 Closure closure = context->closureCreate(kernelID, allocation /* returnValue */, fieldIDS,
471 values, sizes, depClosures, depFieldIDS);
472 EXPECT_NE(Closure(0), closure);
473 ASSERT_NE(Closure(0), closure);
474
475 // set argument
476 context->closureSetArg(closure, 0 /* first argument */, (Ptr)allocation, -1);
477
478 // execute
479 hidl_string name = "script_group_2_test";
480 hidl_string cacheDir = "/data/local/tmp";
481 hidl_vec<Closure> closures = {closure};
482 ScriptGroup2 scriptGroup2 = context->scriptGroup2Create(name, cacheDir, closures);
483 EXPECT_NE(ScriptGroup2(0), scriptGroup2);
484 ASSERT_NE(ScriptGroup2(0), scriptGroup2);
485
486 context->scriptGroupExecute(scriptGroup2);
487 context->allocationRead(allocation, (Ptr)dataOut.data(), (Size)dataOut.size()*sizeof(uint8_t));
488 EXPECT_EQ(expected, dataOut);
489}