blob: 9531e1934c9d575141d73ccc13026267cb24dfd4 [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
49 context->scriptSetVarI(script, 0, 100);
50 int resultI = 0;
51 context->scriptGetVarV(script, 0, sizeof(int), [&](const hidl_vec<uint8_t>& _data){
52 resultI = *((int*)_data.data()); });
53 EXPECT_EQ(100, resultI);
54
55 context->scriptSetVarJ(script, 1, 101l);
56 int resultJ = 0;
57 context->scriptGetVarV(script, 1, sizeof(long), [&](const hidl_vec<uint8_t>& _data){
58 resultJ = *((long*)_data.data()); });
59 EXPECT_EQ(101, resultJ);
60
61 context->scriptSetVarF(script, 2, 102.0f);
62 int resultF = 0.0f;
63 context->scriptGetVarV(script, 2, sizeof(float), [&](const hidl_vec<uint8_t>& _data){
64 resultF = *((float*)_data.data()); });
65 EXPECT_EQ(102.0f, resultF);
66
67 context->scriptSetVarD(script, 3, 103.0);
68 int resultD = 0.0;
69 context->scriptGetVarV(script, 3, sizeof(double), [&](const hidl_vec<uint8_t>& _data){
70 resultD = *((double*)_data.data()); });
71 EXPECT_EQ(103.0, resultD);
72
73 // float1
74 Element element = context->elementCreate(DataType::FLOAT_32, DataKind::USER, false, 1);
75 // 128 x float1
76 Type type = context->typeCreate(element, 128, 0, 0, false, false, YuvFormat::YUV_NONE);
77 // 128 x float1
78 Allocation allocationIn = context->allocationCreateTyped(type, AllocationMipmapControl::NONE,
79 (int)AllocationUsageType::SCRIPT,
80 (Ptr)nullptr);
81 Allocation allocationOut = Allocation(0);
82 context->scriptSetVarObj(script, 4, (ObjectBase)allocationIn);
83 context->scriptGetVarV(script, 4, sizeof(ObjectBase), [&](const hidl_vec<uint8_t>& _data){
84 allocationOut = (Allocation) *((ObjectBase*)_data.data()); });
85 EXPECT_EQ(allocationOut, allocationIn);
86
87 std::vector<int> arrayIn = {500, 501, 502, 503};
88 std::vector<int> arrayOut(4);
89 hidl_vec<uint8_t> arrayData;
90 arrayData.setToExternal((uint8_t*)arrayIn.data(), arrayIn.size()*sizeof(int));
91 context->scriptSetVarV(script, 5, arrayData);
92 context->scriptGetVarV(script, 5, 4*sizeof(int), [&](const hidl_vec<uint8_t>& _data){
93 arrayOut = std::vector<int>((int*)_data.data(),
94 (int*)_data.data() + 4); });
95 EXPECT_EQ(500, arrayOut[0]);
96 EXPECT_EQ(501, arrayOut[1]);
97 EXPECT_EQ(502, arrayOut[2]);
98 EXPECT_EQ(503, arrayOut[3]);
99
100 std::vector<int> dataVE = {1000, 1001};
101 std::vector<uint32_t> dimsVE = {1};
102 std::vector<int> outVE(2);
103 hidl_vec<uint8_t> _dataVE;
104 hidl_vec<uint32_t> _dimsVE;
105 _dataVE.setToExternal((uint8_t*)dataVE.data(), dataVE.size()*sizeof(int));
106 _dimsVE.setToExternal((uint32_t*)dimsVE.data(), dimsVE.size());
107 // intx2
108 Element elementVE = context->elementCreate(DataType::SIGNED_32, DataKind::USER, false, 2);
109 context->scriptSetVarVE(script, 6, _dataVE, elementVE, _dimsVE);
110 context->scriptGetVarV(script, 6, 2*sizeof(int), [&](const hidl_vec<uint8_t>& _data){
111 outVE = std::vector<int>((int*)_data.data(),
112 (int*)_data.data() + 2); });
113 EXPECT_EQ(1000, outVE[0]);
114 EXPECT_EQ(1001, outVE[1]);
115}
116
117/*
118 * Create a user script “struct_test”, and input and output Allocations.
119 * Verified the foreach launch correctly for the invoke kernel.
120 *
121 * Calls: scriptCCreate, scriptInvoke, scriptGetVarV, scriptInvokeV
122 */
123TEST_F(RenderscriptHidlTest, ScriptInvokeTest) {
124 hidl_vec<uint8_t> bitcode;
125 bitcode.setToExternal((uint8_t*)bitCode, bitCodeLength);
126 Script script = context->scriptCCreate("struct_test", "/data/local/tmp/", bitcode);
127 EXPECT_NE(Script(0), script);
128
129 // invoke test
130 int function_res = 0;
131 context->scriptInvoke(script, 0);
132 context->scriptGetVarV(script, 0, sizeof(int), [&](const hidl_vec<uint8_t>& _data){
133 function_res = *((int*)_data.data()); });
134 EXPECT_NE(100, function_res);
135
136 // invokeV test
137 int functionV_arg = 5;
138 int functionV_res = 0;
139 hidl_vec<uint8_t> functionV_data;
140 functionV_data.setToExternal((uint8_t*)&functionV_arg, sizeof(int));
141 context->scriptInvokeV(script, 1, functionV_data);
142 context->scriptGetVarV(script, 0, sizeof(int), [&](const hidl_vec<uint8_t>& _data){
143 functionV_res = *((int*)_data.data()); });
144 EXPECT_EQ(5, functionV_res);
145}
146
147/*
148 * Create a user script “struct_test”, and input and output Allocations.
149 * Verified the foreach launch correctly for the foreach kernel.
150 *
151 * Calls: scriptCCreate, elementCreate, typeCreate, allocationCreateTyped,
152 * allocation1DWrite, scriptForEach, allocationRead
153 */
154TEST_F(RenderscriptHidlTest, ScriptForEachTest) {
155 hidl_vec<uint8_t> bitcode;
156 bitcode.setToExternal((uint8_t*)bitCode, bitCodeLength);
157 Script script = context->scriptCCreate("struct_test", "/data/local/tmp/", bitcode);
158 EXPECT_NE(Script(0), script);
159
160 // uint8_t
161 Element element = context->elementCreate(DataType::UNSIGNED_8, DataKind::USER, false, 1);
162 // 64 x uint8_t
163 Type type = context->typeCreate(element, 64, 0, 0, false, false, YuvFormat::YUV_NONE);
164 std::vector<uint8_t> dataIn(64), dataOut(64);
165 std::generate(dataIn.begin(), dataIn.end(), [](){ static uint8_t val = 0; return val++; });
166 hidl_vec<uint8_t> _data;
167 _data.setToExternal((uint8_t*)dataIn.data(), dataIn.size());
168 // 64 x float1
169 Allocation allocation = context->allocationCreateTyped(type, AllocationMipmapControl::NONE,
170 (int)AllocationUsageType::SCRIPT,
171 (Ptr)nullptr);
172 Allocation vout = context->allocationCreateTyped(type, AllocationMipmapControl::NONE,
173 (int)AllocationUsageType::SCRIPT,
174 (Ptr)nullptr);
175 context->allocation1DWrite(allocation, 0, 0, (Size)dataIn.size(), _data);
176 hidl_vec<Allocation> vains;
177 vains.setToExternal(&allocation, 1);
178 hidl_vec<uint8_t> params;
179 context->scriptForEach(script, 1, vains, vout, params, nullptr);
180 context->allocationRead(vout, (Ptr)dataOut.data(), (Size)dataOut.size()*sizeof(uint8_t));
181 bool same = std::all_of(dataOut.begin(), dataOut.end(),
182 [](uint8_t x){ static uint8_t val = 1; return x == val++; });
183 EXPECT_EQ(true, same);
184}
185
186/*
187 * Create a user script “struct_test”, and input and output Allocations.
188 * Verified the foreach launch correctly for the reduction kernel.
189 *
190 * Calls: scriptCCreate, elementCreate, typeCreate, allocationCreateTyped,
191 * allocation1DWrite, scriptReduce, contextFinish, allocationRead
192 */
193TEST_F(RenderscriptHidlTest, ScriptReduceTest) {
194 hidl_vec<uint8_t> bitcode;
195 bitcode.setToExternal((uint8_t*)bitCode, bitCodeLength);
196 Script script = context->scriptCCreate("struct_test", "/data/local/tmp/", bitcode);
197 EXPECT_NE(Script(0), script);
198
199 // uint8_t
200 Element element = context->elementCreate(DataType::SIGNED_32, DataKind::USER, false, 1);
201 // 64 x uint8_t
202 Type type = context->typeCreate(element, 64, 0, 0, false, false, YuvFormat::YUV_NONE);
203 Type type2 = context->typeCreate(element, 1, 0, 0, false, false, YuvFormat::YUV_NONE);
204 std::vector<int> dataIn(64), dataOut(1);
205 std::generate(dataIn.begin(), dataIn.end(), [](){ static int val = 0; return val++; });
206 hidl_vec<uint8_t> _data;
207 _data.setToExternal((uint8_t*)dataIn.data(), dataIn.size()*sizeof(int));
208 // 64 x float1
209 Allocation allocation = context->allocationCreateTyped(type, AllocationMipmapControl::NONE,
210 (int)AllocationUsageType::SCRIPT,
211 (Ptr)nullptr);
212 Allocation vaout = context->allocationCreateTyped(type2, AllocationMipmapControl::NONE,
213 (int)AllocationUsageType::SCRIPT,
214 (Ptr)nullptr);
215 context->allocation1DWrite(allocation, 0, 0, (Size)dataIn.size(), _data);
216 hidl_vec<Allocation> vains;
217 vains.setToExternal(&allocation, 1);
218 context->scriptReduce(script, 0, vains, vaout, nullptr);
219 context->contextFinish();
220 context->allocationRead(vaout, (Ptr)dataOut.data(), (Size)dataOut.size()*sizeof(int));
221 // sum of 0, 1, 2, ..., 62, 63
222 int sum = 63*64/2;
223 EXPECT_EQ(sum, dataOut[0]);
224}
225
226/*
227 * This test creates an allocation and binds it to a data segment in the
228 * RenderScript script, represented in the bitcode.
229 *
230 * Calls: scriptCCreate, elementCreate, typeCreate, allocationCreateTyped,
231 * allocationGetPointer, scriptBindAllocation
232 *
233 * This test currently has a bug, and should be fixed by 3/17.
234 * TODO(butlermichael)
235 */
236/*
237TEST_F(RenderscriptHidlTest, ScriptBindTest) {
238 hidl_vec<uint8_t> bitcode;
239 bitcode.setToExternal((uint8_t*)bitCode, bitCodeLength);
240 Script script = context->scriptCCreate("struct_test", "/data/local/tmp/", bitcode);
241 EXPECT_NE(Script(0), script);
242
243 // uint8_t
244 Element element = context->elementCreate(DataType::SIGNED_32, DataKind::USER, false, 1);
245 // 64 x uint8_t
246 Type type = context->typeCreate(element, 64, 0, 0, false, false, YuvFormat::YUV_NONE);
247 // 64 x float1
248 Allocation allocation = context->allocationCreateTyped(type, AllocationMipmapControl::NONE,
249 (int)AllocationUsageType::SCRIPT,
250 (Ptr)nullptr);
251 Ptr dataPtr1, dataPtr2;
252 Size stride;
253 context->allocationGetPointer(allocation, 0, AllocationCubemapFace::POSITIVE_X, 0,
254 [&](Ptr _dataPtr, Size _stride){ dataPtr1 = _dataPtr;
255 stride = _stride; });
256 context->scriptBindAllocation(script, allocation, 7);
257 context->allocationGetPointer(allocation, 0, AllocationCubemapFace::POSITIVE_X, 0,
258 [&](Ptr _dataPtr, Size _stride){ dataPtr2 = _dataPtr;
259 stride = _stride; });
260 EXPECT_NE(dataPtr1, dataPtr2);
261}
262*/
263
264/*
265 * This test groups together two RenderScript intrinsic kernels to run one after
266 * the other asynchronously with respect to the client. The test configures YuvToRGB(A) and Blur,
267 * and links them together such that Blur will execute after YuvToRGB(A) and use its result. The
268 * test checks the data returned to make sure it was changed after passing through the entire
269 * ScriptGroup.
270 *
271 * Calls: elementCreate, typeCreate, allocationCreateTyped, allocation2DWrite,
272 * scriptIntrinsicCreate, scriptKernelIDCreate, scriptGroupCreate,
273 * scriptGroupSetInput, scriptGroupSetOutput, scriptGroupExecute,
274 * allocation2DRead
275 *
276 * This test currently has a bug, and should be fixed by 3/17.
277 * TODO(butlermichael)
278 */
279/*
280TEST_F(RenderscriptHidlTest, ScriptGroupTest) {
281 //std::vector<uint8_t> dataIn(256*256*1, 128), dataOut(256*256*3, 0);
282 std::vector<uint8_t> dataIn(256*256*1, 128), dataOut(256*256*4, 0);
283 hidl_vec<uint8_t> _dataIn, _dataOut;
284 _dataIn.setToExternal(dataIn.data(), dataIn.size());
285 _dataOut.setToExternal(dataOut.data(), dataIn.size());
286
287 // 256 x 256 YUV pixels
288 Element element1 = context->elementCreate(DataType::UNSIGNED_8, DataKind::PIXEL_YUV, true, 1);
289 //Type type1 = context->typeCreate(element1, 256, 256, 0, false, false, YuvFormat::YUV_420_888);
290 Type type1 = context->typeCreate(element1, 256, 256, 0, false, false, YuvFormat::YUV_NV21);
291 Allocation allocation1 = context->allocationCreateTyped(type1, AllocationMipmapControl::NONE,
292 (int)AllocationUsageType::SCRIPT,
293 (Ptr)nullptr);
294 context->allocation2DWrite(allocation1, 0, 0, 0, AllocationCubemapFace::POSITIVE_X, 256, 256,
295 _dataIn, 0);
296 Script yuv2rgb = context->scriptIntrinsicCreate(ScriptIntrinsicID::ID_YUV_TO_RGB, element1);
297 EXPECT_NE(Script(0), yuv2rgb);
298
299 ScriptKernelID yuv2rgbKID = context->scriptKernelIDCreate(yuv2rgb, 0, 2);
300 EXPECT_NE(ScriptKernelID(0), yuv2rgbKID);
301
302 // 256 x 256 RGB pixels
303 //Element element2 = context->elementCreate(DataType::UNSIGNED_8, DataKind::PIXEL_RGB, true, 3);
304 Element element2 = context->elementCreate(DataType::UNSIGNED_8, DataKind::PIXEL_RGBA, true, 4);
305 Type type2 = context->typeCreate(element2, 256, 256, 0, false, false, YuvFormat::YUV_NONE);
306 Allocation allocation2 = context->allocationCreateTyped(type2, AllocationMipmapControl::NONE,
307 (int)AllocationUsageType::SCRIPT,
308 (Ptr)nullptr);
309 context->allocation2DWrite(allocation2, 0, 0, 0, AllocationCubemapFace::POSITIVE_X, 256, 256,
310 _dataOut, 0);
311 Script blur = context->scriptIntrinsicCreate(ScriptIntrinsicID::ID_BLUR, element2);
312 EXPECT_NE(Script(0), blur);
313
314 ScriptKernelID blurKID = context->scriptKernelIDCreate(blur, 0, 2);
315 EXPECT_NE(ScriptKernelID(0), blurKID);
316
317 // ScriptGroup
318 hidl_vec<ScriptKernelID> kernels = {yuv2rgbKID, blurKID};
319 hidl_vec<ScriptKernelID> srcK = {yuv2rgbKID};
320 hidl_vec<ScriptKernelID> dstK = {blurKID};
321 hidl_vec<ScriptFieldID> dstF = {};
322 hidl_vec<Type> types = {type2};
323 ScriptGroup scriptGroup = context->scriptGroupCreate(kernels, srcK, dstK, dstF, types);
324 EXPECT_NE(ScriptGroup(0), scriptGroup);
325
326 context->scriptGroupSetInput(scriptGroup, yuv2rgbKID, allocation1);
327 context->scriptGroupSetOutput(scriptGroup, blurKID, allocation2);
328 context->scriptGroupExecute(scriptGroup);
329
330 // verify contents were changed
331 context->allocation2DRead(allocation2, 0, 0, 0, AllocationCubemapFace::POSITIVE_X, 256, 256,
332 (Ptr)dataOut.data(), (Size)dataOut.size(), 0);
333 bool same = std::all_of(dataOut.begin(), dataOut.end(), [](uint8_t x){ return x != 0; });
334 EXPECT_EQ(true, same);
335}
336*/
337
338/*
339 * Similar to the ScriptGroup test, this test verifies the execution flow of
340 * RenderScript kernels and invokables.
341 *
342 * Calls: scriptFieldIDCreate, closureCreate, scriptInvokeIDCreate,
343 * invokeClosureCreate, closureSetArg, closureSetGlobal, scriptGroup2Create,
344 * scriptGroupExecute
345 *
346 * This test currently still a work in progress, and should be finished by 3/17.
347 * TODO(butlermichael)
348 */
349/*
350TEST_F(RenderscriptHidlTest, ScriptGroup2Test) {
351
352 ScriptFieldID fieldID = context->scriptFieldIDCreate(script, slot);
353 EXPECT_NE(ScriptFieldID(0), fieldID);
354
355 ScriptKernelID kernelID = context->scriptKernelIDCreate(script, slot, sig);
356 EXPECT_NE(ScriptKernelID(0), kernelID);
357
358 Allocation returnValue = 0;
359 hidl_vec<ScriptFieldID> fieldIDS = {};
360 hidl_vec<int64_t> values = {};
361 hidl_vec<int32_t> sizes = {};
362 hidl_veC<Closure> depClosures = {};
363 hidl_vec<ScriptFieldID> depFieldIDS = {};
364 Closure closure1 = context->closureCreate(kernelID, returnValue, fieldIDS, values, sizes,
365 depClosures, depFieldIDS);
366 EXPECT_NE(Closure(0), closure1);
367
368 ScriptInvokeID invokeID = context->scriptInvokeIDCreate(script, slot);
369 EXPECT_NE(ScriptInvokeID(0), invokeID);
370
371 hidl_vec<uint8_t> params = {};
372 hidl_vec<ScriptFieldID> fieldsIDS2 = {};
373 hidl_vec<int64_t> values2 = {};
374 hidl_vec<int32_t> sizes2 = {};
375 Closure closure2 = context->invokeClosureCreate(invokeID, params, fieldIDS2, values2, sizes2);
376 EXPECT_NE(Closure(0), closure2);
377
378 context->closureSetArg(closure, index, value, size);
379 context->closureSetGlobal(closure, fieldID, value, size);
380
381 hidl_string name = "script_group_2_test";
382 hidl_string cacheDir = "data/local/tmp/";
383 hidl_vec<Closures> closures;
384 ScriptGroup2 scriptGroup2 = context->scriptGroup2Create(name, cacheDir, closures);
385 EXPECT_NE(ScriptGroup2(0), scriptGroup2);
386
387 context->scriptGroupExecute(scriptGroup2);
388 // verify script group launched...
389}
390*/