Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 25 | TEST_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 | */ |
| 42 | TEST_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 Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame^] | 49 | context->scriptSetVarI(script, mExportVarIdx_var_int, 100); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 50 | int resultI = 0; |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame^] | 51 | context->scriptGetVarV(script, mExportVarIdx_var_int, sizeof(int), |
| 52 | [&](const hidl_vec<uint8_t>& _data){ resultI = *((int*)_data.data()); }); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 53 | EXPECT_EQ(100, resultI); |
| 54 | |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame^] | 55 | context->scriptSetVarJ(script, mExportVarIdx_var_long, 101l); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 56 | int resultJ = 0; |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame^] | 57 | context->scriptGetVarV(script, mExportVarIdx_var_long, sizeof(long), |
| 58 | [&](const hidl_vec<uint8_t>& _data){ |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 59 | resultJ = *((long*)_data.data()); }); |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame^] | 60 | EXPECT_EQ(101l, resultJ); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 61 | |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame^] | 62 | context->scriptSetVarF(script, mExportVarIdx_var_float, 102.0f); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 63 | int resultF = 0.0f; |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame^] | 64 | context->scriptGetVarV(script, mExportVarIdx_var_float, sizeof(float), |
| 65 | [&](const hidl_vec<uint8_t>& _data){ |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 66 | resultF = *((float*)_data.data()); }); |
| 67 | EXPECT_EQ(102.0f, resultF); |
| 68 | |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame^] | 69 | context->scriptSetVarD(script, mExportVarIdx_var_double, 103.0); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 70 | int resultD = 0.0; |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame^] | 71 | context->scriptGetVarV(script, mExportVarIdx_var_double, sizeof(double), |
| 72 | [&](const hidl_vec<uint8_t>& _data){ |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 73 | 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 Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame^] | 85 | 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 Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 88 | allocationOut = (Allocation) *((ObjectBase*)_data.data()); }); |
| 89 | EXPECT_EQ(allocationOut, allocationIn); |
| 90 | |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame^] | 91 | 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 Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 100 | |
| 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 Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame^] | 108 | // intx2 to represent point2 which is {int, int} |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 109 | Element elementVE = context->elementCreate(DataType::SIGNED_32, DataKind::USER, false, 2); |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame^] | 110 | 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 Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 115 | 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 | */ |
| 125 | TEST_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 Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame^] | 132 | 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 Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 164 | |
| 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 Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame^] | 170 | context->scriptInvokeV(script, mExportFuncIdx_functionV, functionV_data); |
| 171 | context->scriptGetVarV(script, mExportVarIdx_var_int, sizeof(int), |
| 172 | [&](const hidl_vec<uint8_t>& _data){ |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 173 | 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 | */ |
| 184 | TEST_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 Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame^] | 194 | std::vector<uint8_t> dataIn(64), dataOut(64), expected(64); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 195 | std::generate(dataIn.begin(), dataIn.end(), [](){ static uint8_t val = 0; return val++; }); |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame^] | 196 | std::generate(expected.begin(), expected.end(), [](){ static uint8_t val = 1; return val++; }); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 197 | 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 Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame^] | 210 | context->scriptForEach(script, mExportForEachIdx_increment, vains, vout, params, nullptr); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 211 | context->allocationRead(vout, (Ptr)dataOut.data(), (Size)dataOut.size()*sizeof(uint8_t)); |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame^] | 212 | EXPECT_EQ(expected, dataOut); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 213 | } |
| 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 | */ |
| 222 | TEST_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 Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame^] | 247 | context->scriptReduce(script, mExportReduceIdx_summation, vains, vaout, nullptr); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 248 | 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 Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame^] | 260 | * scriptSetVarV, scriptBindAllocation, allocationRead |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 261 | */ |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 262 | TEST_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 Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame^] | 268 | // in32 |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 269 | Element element = context->elementCreate(DataType::SIGNED_32, DataKind::USER, false, 1); |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame^] | 270 | // 64 x int32 |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 271 | Type type = context->typeCreate(element, 64, 0, 0, false, false, YuvFormat::YUV_NONE); |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame^] | 272 | // 64 x int32 |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 273 | Allocation allocation = context->allocationCreateTyped(type, AllocationMipmapControl::NONE, |
| 274 | (int)AllocationUsageType::SCRIPT, |
| 275 | (Ptr)nullptr); |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame^] | 276 | 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 Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 287 | } |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 288 | |
| 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 Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame^] | 297 | * scriptIntrinsicCreate, scriptKernelIDCreate, scriptFieldIDCreate, |
| 298 | * scriptGroupCreate, scriptGroupSetOutput, scriptGroupExecute, allocation2DRead |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 299 | */ |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 300 | TEST_F(RenderscriptHidlTest, ScriptGroupTest) { |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame^] | 301 | std::vector<uint8_t> dataIn(256*256*1, 128), dataOut(256*256*4, 0), zeros(256*256*4, 0); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 302 | hidl_vec<uint8_t> _dataIn, _dataOut; |
| 303 | _dataIn.setToExternal(dataIn.data(), dataIn.size()); |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame^] | 304 | _dataOut.setToExternal(dataOut.data(), dataOut.size()); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 305 | |
| 306 | // 256 x 256 YUV pixels |
| 307 | Element element1 = context->elementCreate(DataType::UNSIGNED_8, DataKind::PIXEL_YUV, true, 1); |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame^] | 308 | Type type1 = context->typeCreate(element1, 256, 256, 0, false, false, YuvFormat::YUV_420_888); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 309 | 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 Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 314 | |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame^] | 315 | // 256 x 256 RGBA pixels |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 316 | 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 Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame^] | 323 | |
| 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 Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 331 | 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 Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame^] | 336 | ScriptFieldID blurFID = context->scriptFieldIDCreate(blur, 1); |
| 337 | EXPECT_NE(ScriptFieldID(0), blurFID); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 338 | |
| 339 | // ScriptGroup |
| 340 | hidl_vec<ScriptKernelID> kernels = {yuv2rgbKID, blurKID}; |
| 341 | hidl_vec<ScriptKernelID> srcK = {yuv2rgbKID}; |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame^] | 342 | hidl_vec<ScriptKernelID> dstK = {ScriptKernelID(0)}; |
| 343 | hidl_vec<ScriptFieldID> dstF = {blurFID}; |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 344 | hidl_vec<Type> types = {type2}; |
| 345 | ScriptGroup scriptGroup = context->scriptGroupCreate(kernels, srcK, dstK, dstF, types); |
| 346 | EXPECT_NE(ScriptGroup(0), scriptGroup); |
| 347 | |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame^] | 348 | context->scriptSetVarObj(yuv2rgb, 0, (ObjectBase)allocation1); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 349 | context->scriptGroupSetOutput(scriptGroup, blurKID, allocation2); |
| 350 | context->scriptGroupExecute(scriptGroup); |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame^] | 351 | context->contextFinish(); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 352 | |
| 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 Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame^] | 356 | EXPECT_NE(zeros, dataOut); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 357 | } |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 358 | |
| 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 Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame^] | 364 | * invokeClosureCreate, closureSetGlobal, scriptGroup2Create, scriptGroupExecute |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 365 | */ |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 366 | TEST_F(RenderscriptHidlTest, ScriptGroup2Test) { |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame^] | 367 | 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 Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 371 | |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame^] | 372 | 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 Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 385 | EXPECT_NE(ScriptFieldID(0), fieldID); |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame^] | 386 | ASSERT_NE(ScriptFieldID(0), fieldID); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 387 | |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame^] | 388 | // invoke |
| 389 | ScriptInvokeID invokeID = context->scriptInvokeIDCreate(script, mExportFuncIdx_setAllocation); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 390 | EXPECT_NE(ScriptInvokeID(0), invokeID); |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame^] | 391 | ASSERT_NE(ScriptInvokeID(0), invokeID); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 392 | |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame^] | 393 | 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 Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 415 | EXPECT_NE(Closure(0), closure2); |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame^] | 416 | ASSERT_NE(Closure(0), closure2); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 417 | |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame^] | 418 | // set argument |
| 419 | context->closureSetGlobal(closure1, fieldID, (int64_t)(intptr_t)allocation, |
| 420 | -1 /* allocation */); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 421 | |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame^] | 422 | // execute |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 423 | hidl_string name = "script_group_2_test"; |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame^] | 424 | hidl_string cacheDir = "/data/local/tmp"; |
| 425 | hidl_vec<Closure> closures = {closure1, closure2}; |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 426 | ScriptGroup2 scriptGroup2 = context->scriptGroup2Create(name, cacheDir, closures); |
| 427 | EXPECT_NE(ScriptGroup2(0), scriptGroup2); |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame^] | 428 | ASSERT_NE(ScriptGroup2(0), scriptGroup2); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 429 | |
| 430 | context->scriptGroupExecute(scriptGroup2); |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame^] | 431 | context->allocationRead(allocation, (Ptr)dataOut.data(), (Size)dataOut.size()*sizeof(uint8_t)); |
| 432 | EXPECT_EQ(expected, dataOut); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 433 | } |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame^] | 434 | |
| 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 | */ |
| 442 | TEST_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 | } |