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); |
Michael Butler | 7c1ef5b | 2017-03-30 17:20:12 -0700 | [diff] [blame] | 28 | EXPECT_NE(Element(0), element); |
| 29 | |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 30 | Script script = context->scriptIntrinsicCreate(ScriptIntrinsicID::ID_BLUR, element); |
| 31 | EXPECT_NE(Script(0), script); |
| 32 | |
| 33 | context->scriptSetTimeZone(script, "UTF-8"); |
| 34 | } |
| 35 | |
| 36 | /* |
| 37 | * Create a user script “struct_test”, and verified the setters and getters work |
| 38 | * for the global variables. |
| 39 | * |
| 40 | * Calls: scriptCCreate, scriptGetVarV, scriptSetVarI, scriptSetVarJ, |
| 41 | * scriptSetVarF, scriptSetVarD, elementCreate, typeCreate, |
| 42 | * allocationCreateTyped, scriptSetVarObj, scriptSetVarV, scriptSetVarVE |
| 43 | */ |
| 44 | TEST_F(RenderscriptHidlTest, ScriptVarTest) { |
| 45 | hidl_vec<uint8_t> bitcode; |
| 46 | bitcode.setToExternal((uint8_t*)bitCode, bitCodeLength); |
| 47 | Script script = context->scriptCCreate("struct_test", "/data/local/tmp/", bitcode); |
Michael Butler | 7c1ef5b | 2017-03-30 17:20:12 -0700 | [diff] [blame] | 48 | ASSERT_NE(Script(0), script); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 49 | |
| 50 | // arg tests |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame] | 51 | context->scriptSetVarI(script, mExportVarIdx_var_int, 100); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 52 | int resultI = 0; |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame] | 53 | context->scriptGetVarV(script, mExportVarIdx_var_int, sizeof(int), |
| 54 | [&](const hidl_vec<uint8_t>& _data){ resultI = *((int*)_data.data()); }); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 55 | EXPECT_EQ(100, resultI); |
| 56 | |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame] | 57 | context->scriptSetVarJ(script, mExportVarIdx_var_long, 101l); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 58 | int resultJ = 0; |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame] | 59 | context->scriptGetVarV(script, mExportVarIdx_var_long, sizeof(long), |
| 60 | [&](const hidl_vec<uint8_t>& _data){ |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 61 | resultJ = *((long*)_data.data()); }); |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame] | 62 | EXPECT_EQ(101l, resultJ); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 63 | |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame] | 64 | context->scriptSetVarF(script, mExportVarIdx_var_float, 102.0f); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 65 | int resultF = 0.0f; |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame] | 66 | context->scriptGetVarV(script, mExportVarIdx_var_float, sizeof(float), |
| 67 | [&](const hidl_vec<uint8_t>& _data){ |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 68 | resultF = *((float*)_data.data()); }); |
| 69 | EXPECT_EQ(102.0f, resultF); |
| 70 | |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame] | 71 | context->scriptSetVarD(script, mExportVarIdx_var_double, 103.0); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 72 | int resultD = 0.0; |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame] | 73 | context->scriptGetVarV(script, mExportVarIdx_var_double, sizeof(double), |
| 74 | [&](const hidl_vec<uint8_t>& _data){ |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 75 | resultD = *((double*)_data.data()); }); |
| 76 | EXPECT_EQ(103.0, resultD); |
| 77 | |
| 78 | // float1 |
| 79 | Element element = context->elementCreate(DataType::FLOAT_32, DataKind::USER, false, 1); |
Michael Butler | 7c1ef5b | 2017-03-30 17:20:12 -0700 | [diff] [blame] | 80 | ASSERT_NE(Element(0), element); |
| 81 | |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 82 | // 128 x float1 |
| 83 | Type type = context->typeCreate(element, 128, 0, 0, false, false, YuvFormat::YUV_NONE); |
Michael Butler | 7c1ef5b | 2017-03-30 17:20:12 -0700 | [diff] [blame] | 84 | ASSERT_NE(Type(0), type); |
| 85 | |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 86 | // 128 x float1 |
| 87 | Allocation allocationIn = context->allocationCreateTyped(type, AllocationMipmapControl::NONE, |
| 88 | (int)AllocationUsageType::SCRIPT, |
| 89 | (Ptr)nullptr); |
Michael Butler | 7c1ef5b | 2017-03-30 17:20:12 -0700 | [diff] [blame] | 90 | ASSERT_NE(Allocation(0), allocationIn); |
| 91 | |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 92 | Allocation allocationOut = Allocation(0); |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame] | 93 | context->scriptSetVarObj(script, mExportVarIdx_var_allocation, (ObjectBase)allocationIn); |
| 94 | context->scriptGetVarV(script, mExportVarIdx_var_allocation, sizeof(ObjectBase), |
| 95 | [&](const hidl_vec<uint8_t>& _data){ |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 96 | allocationOut = (Allocation) *((ObjectBase*)_data.data()); }); |
| 97 | EXPECT_EQ(allocationOut, allocationIn); |
| 98 | |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame] | 99 | uint32_t valueV = 104u; |
| 100 | hidl_vec<uint8_t> _dataV; |
| 101 | _dataV.setToExternal((uint8_t*)&valueV, sizeof(uint32_t)); |
| 102 | context->scriptSetVarV(script, mExportVarIdx_var_uint32_t, _dataV); |
| 103 | uint32_t resultV = 0u; |
| 104 | context->scriptGetVarV(script, mExportVarIdx_var_uint32_t, sizeof(uint32_t), |
| 105 | [&](const hidl_vec<uint8_t>& _data){ |
| 106 | resultV = *((uint32_t*)_data.data()); }); |
| 107 | EXPECT_EQ(104u, resultV); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 108 | |
| 109 | std::vector<int> dataVE = {1000, 1001}; |
| 110 | std::vector<uint32_t> dimsVE = {1}; |
| 111 | std::vector<int> outVE(2); |
| 112 | hidl_vec<uint8_t> _dataVE; |
| 113 | hidl_vec<uint32_t> _dimsVE; |
| 114 | _dataVE.setToExternal((uint8_t*)dataVE.data(), dataVE.size()*sizeof(int)); |
| 115 | _dimsVE.setToExternal((uint32_t*)dimsVE.data(), dimsVE.size()); |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame] | 116 | // intx2 to represent point2 which is {int, int} |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 117 | Element elementVE = context->elementCreate(DataType::SIGNED_32, DataKind::USER, false, 2); |
Michael Butler | 7c1ef5b | 2017-03-30 17:20:12 -0700 | [diff] [blame] | 118 | ASSERT_NE(Element(0), elementVE); |
| 119 | |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame] | 120 | context->scriptSetVarVE(script, mExportVarIdx_var_point2, _dataVE, elementVE, _dimsVE); |
| 121 | context->scriptGetVarV(script, mExportVarIdx_var_point2, 2*sizeof(int), |
| 122 | [&](const hidl_vec<uint8_t>& _data){ |
| 123 | outVE = std::vector<int>( |
| 124 | (int*)_data.data(), (int*)_data.data() + 2); }); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 125 | EXPECT_EQ(1000, outVE[0]); |
| 126 | EXPECT_EQ(1001, outVE[1]); |
| 127 | } |
| 128 | |
| 129 | /* |
| 130 | * Create a user script “struct_test”, and input and output Allocations. |
| 131 | * Verified the foreach launch correctly for the invoke kernel. |
| 132 | * |
| 133 | * Calls: scriptCCreate, scriptInvoke, scriptGetVarV, scriptInvokeV |
| 134 | */ |
| 135 | TEST_F(RenderscriptHidlTest, ScriptInvokeTest) { |
| 136 | hidl_vec<uint8_t> bitcode; |
| 137 | bitcode.setToExternal((uint8_t*)bitCode, bitCodeLength); |
| 138 | Script script = context->scriptCCreate("struct_test", "/data/local/tmp/", bitcode); |
Michael Butler | 7c1ef5b | 2017-03-30 17:20:12 -0700 | [diff] [blame] | 139 | ASSERT_NE(Script(0), script); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 140 | |
| 141 | // invoke test |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame] | 142 | int resultI = 0; |
| 143 | long resultJ = 0l; |
| 144 | float resultF = 0.0f; |
| 145 | double resultD = 0.0; |
| 146 | uint32_t resultV = 0u; |
| 147 | std::vector<int> resultVE(2); |
| 148 | context->scriptInvoke(script, mExportFuncIdx_function); |
| 149 | context->scriptGetVarV(script, mExportVarIdx_var_int, sizeof(int), |
| 150 | [&](const hidl_vec<uint8_t>& _data){ resultI = *((int*)_data.data()); }); |
| 151 | context->scriptGetVarV(script, mExportVarIdx_var_long, sizeof(long), |
| 152 | [&](const hidl_vec<uint8_t>& _data){ |
| 153 | resultJ = *((long*)_data.data()); }); |
| 154 | context->scriptGetVarV(script, mExportVarIdx_var_float, sizeof(float), |
| 155 | [&](const hidl_vec<uint8_t>& _data){ |
| 156 | resultF = *((float*)_data.data()); }); |
| 157 | context->scriptGetVarV(script, mExportVarIdx_var_double, sizeof(double), |
| 158 | [&](const hidl_vec<uint8_t>& _data){ |
| 159 | resultD = *((double*)_data.data()); }); |
| 160 | context->scriptGetVarV(script, mExportVarIdx_var_uint32_t, sizeof(uint32_t), |
| 161 | [&](const hidl_vec<uint8_t>& _data){ |
| 162 | resultV = *((uint32_t*)_data.data()); }); |
| 163 | context->scriptGetVarV(script, mExportVarIdx_var_point2, 2*sizeof(int), |
| 164 | [&](const hidl_vec<uint8_t>& _data){ |
| 165 | resultVE = std::vector<int>( |
| 166 | (int*)_data.data(), (int*)_data.data() + 2); }); |
| 167 | EXPECT_EQ(1, resultI); |
| 168 | EXPECT_EQ(2l, resultJ); |
| 169 | EXPECT_EQ(3.0f, resultF); |
| 170 | EXPECT_EQ(4.0, resultD); |
| 171 | EXPECT_EQ(5u, resultV); |
| 172 | EXPECT_EQ(6, resultVE[0]); |
| 173 | EXPECT_EQ(7, resultVE[1]); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 174 | |
| 175 | // invokeV test |
| 176 | int functionV_arg = 5; |
| 177 | int functionV_res = 0; |
| 178 | hidl_vec<uint8_t> functionV_data; |
| 179 | functionV_data.setToExternal((uint8_t*)&functionV_arg, sizeof(int)); |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame] | 180 | context->scriptInvokeV(script, mExportFuncIdx_functionV, functionV_data); |
| 181 | context->scriptGetVarV(script, mExportVarIdx_var_int, sizeof(int), |
| 182 | [&](const hidl_vec<uint8_t>& _data){ |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 183 | functionV_res = *((int*)_data.data()); }); |
| 184 | EXPECT_EQ(5, functionV_res); |
| 185 | } |
| 186 | |
| 187 | /* |
| 188 | * Create a user script “struct_test”, and input and output Allocations. |
| 189 | * Verified the foreach launch correctly for the foreach kernel. |
| 190 | * |
| 191 | * Calls: scriptCCreate, elementCreate, typeCreate, allocationCreateTyped, |
| 192 | * allocation1DWrite, scriptForEach, allocationRead |
| 193 | */ |
| 194 | TEST_F(RenderscriptHidlTest, ScriptForEachTest) { |
| 195 | hidl_vec<uint8_t> bitcode; |
| 196 | bitcode.setToExternal((uint8_t*)bitCode, bitCodeLength); |
| 197 | Script script = context->scriptCCreate("struct_test", "/data/local/tmp/", bitcode); |
Michael Butler | 7c1ef5b | 2017-03-30 17:20:12 -0700 | [diff] [blame] | 198 | ASSERT_NE(Script(0), script); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 199 | |
| 200 | // uint8_t |
| 201 | Element element = context->elementCreate(DataType::UNSIGNED_8, DataKind::USER, false, 1); |
Michael Butler | 7c1ef5b | 2017-03-30 17:20:12 -0700 | [diff] [blame] | 202 | ASSERT_NE(Element(0), element); |
| 203 | |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 204 | // 64 x uint8_t |
| 205 | Type type = context->typeCreate(element, 64, 0, 0, false, false, YuvFormat::YUV_NONE); |
Michael Butler | 7c1ef5b | 2017-03-30 17:20:12 -0700 | [diff] [blame] | 206 | ASSERT_NE(Type(0), type); |
| 207 | |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame] | 208 | std::vector<uint8_t> dataIn(64), dataOut(64), expected(64); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 209 | 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] | 210 | 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] | 211 | hidl_vec<uint8_t> _data; |
| 212 | _data.setToExternal((uint8_t*)dataIn.data(), dataIn.size()); |
| 213 | // 64 x float1 |
| 214 | Allocation allocation = context->allocationCreateTyped(type, AllocationMipmapControl::NONE, |
| 215 | (int)AllocationUsageType::SCRIPT, |
| 216 | (Ptr)nullptr); |
Michael Butler | 7c1ef5b | 2017-03-30 17:20:12 -0700 | [diff] [blame] | 217 | ASSERT_NE(Allocation(0), allocation); |
| 218 | |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 219 | Allocation vout = context->allocationCreateTyped(type, AllocationMipmapControl::NONE, |
| 220 | (int)AllocationUsageType::SCRIPT, |
| 221 | (Ptr)nullptr); |
Michael Butler | 7c1ef5b | 2017-03-30 17:20:12 -0700 | [diff] [blame] | 222 | ASSERT_NE(Allocation(0), vout); |
| 223 | |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 224 | context->allocation1DWrite(allocation, 0, 0, (Size)dataIn.size(), _data); |
| 225 | hidl_vec<Allocation> vains; |
| 226 | vains.setToExternal(&allocation, 1); |
| 227 | hidl_vec<uint8_t> params; |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame] | 228 | context->scriptForEach(script, mExportForEachIdx_increment, vains, vout, params, nullptr); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 229 | context->allocationRead(vout, (Ptr)dataOut.data(), (Size)dataOut.size()*sizeof(uint8_t)); |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame] | 230 | EXPECT_EQ(expected, dataOut); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | /* |
| 234 | * Create a user script “struct_test”, and input and output Allocations. |
| 235 | * Verified the foreach launch correctly for the reduction kernel. |
| 236 | * |
| 237 | * Calls: scriptCCreate, elementCreate, typeCreate, allocationCreateTyped, |
| 238 | * allocation1DWrite, scriptReduce, contextFinish, allocationRead |
| 239 | */ |
| 240 | TEST_F(RenderscriptHidlTest, ScriptReduceTest) { |
| 241 | hidl_vec<uint8_t> bitcode; |
| 242 | bitcode.setToExternal((uint8_t*)bitCode, bitCodeLength); |
| 243 | Script script = context->scriptCCreate("struct_test", "/data/local/tmp/", bitcode); |
Michael Butler | 7c1ef5b | 2017-03-30 17:20:12 -0700 | [diff] [blame] | 244 | ASSERT_NE(Script(0), script); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 245 | |
| 246 | // uint8_t |
| 247 | Element element = context->elementCreate(DataType::SIGNED_32, DataKind::USER, false, 1); |
Michael Butler | 7c1ef5b | 2017-03-30 17:20:12 -0700 | [diff] [blame] | 248 | ASSERT_NE(Element(0), element); |
| 249 | |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 250 | // 64 x uint8_t |
| 251 | Type type = context->typeCreate(element, 64, 0, 0, false, false, YuvFormat::YUV_NONE); |
Michael Butler | 7c1ef5b | 2017-03-30 17:20:12 -0700 | [diff] [blame] | 252 | ASSERT_NE(Type(0), type); |
| 253 | |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 254 | Type type2 = context->typeCreate(element, 1, 0, 0, false, false, YuvFormat::YUV_NONE); |
Michael Butler | 7c1ef5b | 2017-03-30 17:20:12 -0700 | [diff] [blame] | 255 | ASSERT_NE(Type(0), type2); |
| 256 | |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 257 | std::vector<int> dataIn(64), dataOut(1); |
| 258 | std::generate(dataIn.begin(), dataIn.end(), [](){ static int val = 0; return val++; }); |
| 259 | hidl_vec<uint8_t> _data; |
| 260 | _data.setToExternal((uint8_t*)dataIn.data(), dataIn.size()*sizeof(int)); |
| 261 | // 64 x float1 |
| 262 | Allocation allocation = context->allocationCreateTyped(type, AllocationMipmapControl::NONE, |
| 263 | (int)AllocationUsageType::SCRIPT, |
| 264 | (Ptr)nullptr); |
Michael Butler | 7c1ef5b | 2017-03-30 17:20:12 -0700 | [diff] [blame] | 265 | ASSERT_NE(Allocation(0), allocation); |
| 266 | |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 267 | Allocation vaout = context->allocationCreateTyped(type2, AllocationMipmapControl::NONE, |
| 268 | (int)AllocationUsageType::SCRIPT, |
| 269 | (Ptr)nullptr); |
Michael Butler | 7c1ef5b | 2017-03-30 17:20:12 -0700 | [diff] [blame] | 270 | ASSERT_NE(Allocation(0), vaout); |
| 271 | |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 272 | context->allocation1DWrite(allocation, 0, 0, (Size)dataIn.size(), _data); |
| 273 | hidl_vec<Allocation> vains; |
| 274 | vains.setToExternal(&allocation, 1); |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame] | 275 | context->scriptReduce(script, mExportReduceIdx_summation, vains, vaout, nullptr); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 276 | context->contextFinish(); |
| 277 | context->allocationRead(vaout, (Ptr)dataOut.data(), (Size)dataOut.size()*sizeof(int)); |
| 278 | // sum of 0, 1, 2, ..., 62, 63 |
| 279 | int sum = 63*64/2; |
| 280 | EXPECT_EQ(sum, dataOut[0]); |
| 281 | } |
| 282 | |
| 283 | /* |
| 284 | * This test creates an allocation and binds it to a data segment in the |
| 285 | * RenderScript script, represented in the bitcode. |
| 286 | * |
| 287 | * Calls: scriptCCreate, elementCreate, typeCreate, allocationCreateTyped, |
Michael Butler | 7c1ef5b | 2017-03-30 17:20:12 -0700 | [diff] [blame] | 288 | * allocation1DWrite, scriptBindAllocation, scriptSetVarV, scriptBindAllocation, |
| 289 | * allocationRead, scriptInvokeV, allocationRead |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 290 | */ |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 291 | TEST_F(RenderscriptHidlTest, ScriptBindTest) { |
| 292 | hidl_vec<uint8_t> bitcode; |
| 293 | bitcode.setToExternal((uint8_t*)bitCode, bitCodeLength); |
| 294 | Script script = context->scriptCCreate("struct_test", "/data/local/tmp/", bitcode); |
Michael Butler | 7c1ef5b | 2017-03-30 17:20:12 -0700 | [diff] [blame] | 295 | ASSERT_NE(Script(0), script); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 296 | |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame] | 297 | // in32 |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 298 | Element element = context->elementCreate(DataType::SIGNED_32, DataKind::USER, false, 1); |
Michael Butler | 7c1ef5b | 2017-03-30 17:20:12 -0700 | [diff] [blame] | 299 | ASSERT_NE(Element(0), element); |
| 300 | |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame] | 301 | // 64 x int32 |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 302 | Type type = context->typeCreate(element, 64, 0, 0, false, false, YuvFormat::YUV_NONE); |
Michael Butler | 7c1ef5b | 2017-03-30 17:20:12 -0700 | [diff] [blame] | 303 | ASSERT_NE(Type(0), type); |
| 304 | |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame] | 305 | // 64 x int32 |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 306 | Allocation allocation = context->allocationCreateTyped(type, AllocationMipmapControl::NONE, |
| 307 | (int)AllocationUsageType::SCRIPT, |
| 308 | (Ptr)nullptr); |
Michael Butler | 7c1ef5b | 2017-03-30 17:20:12 -0700 | [diff] [blame] | 309 | ASSERT_NE(Allocation(0), allocation); |
| 310 | |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame] | 311 | std::vector<int> dataIn(64), dataOut(64), expected(64, 5); |
| 312 | hidl_vec<uint8_t> _data; |
| 313 | _data.setToExternal((uint8_t*)dataIn.data(), dataIn.size()*sizeof(int)); |
| 314 | context->allocation1DWrite(allocation, 0, 0, (Size)dataIn.size(), _data); |
| 315 | context->scriptBindAllocation(script, allocation, mExportVarIdx_var_int_ptr); |
| 316 | int dim = 64; |
| 317 | hidl_vec<uint8_t> _dim; |
| 318 | _dim.setToExternal((uint8_t*)&dim, sizeof(int)); |
| 319 | context->scriptInvokeV(script, mExportFuncIdx_setBuffer, _dim); |
| 320 | context->allocationRead(allocation, (Ptr)dataOut.data(), (Size)dataOut.size()*sizeof(int)); |
| 321 | EXPECT_EQ(expected, dataOut); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 322 | } |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 323 | |
| 324 | /* |
| 325 | * This test groups together two RenderScript intrinsic kernels to run one after |
| 326 | * the other asynchronously with respect to the client. The test configures YuvToRGB(A) and Blur, |
| 327 | * and links them together such that Blur will execute after YuvToRGB(A) and use its result. The |
| 328 | * test checks the data returned to make sure it was changed after passing through the entire |
| 329 | * ScriptGroup. |
| 330 | * |
| 331 | * Calls: elementCreate, typeCreate, allocationCreateTyped, allocation2DWrite, |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame] | 332 | * scriptIntrinsicCreate, scriptKernelIDCreate, scriptFieldIDCreate, |
Michael Butler | 7c1ef5b | 2017-03-30 17:20:12 -0700 | [diff] [blame] | 333 | * scriptGroupCreate, scriptSetVarObj, scriptGroupSetOutput, scriptGroupExecute, |
| 334 | * contextFinish, allocation2DRead |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 335 | */ |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 336 | TEST_F(RenderscriptHidlTest, ScriptGroupTest) { |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame] | 337 | 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] | 338 | hidl_vec<uint8_t> _dataIn, _dataOut; |
| 339 | _dataIn.setToExternal(dataIn.data(), dataIn.size()); |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame] | 340 | _dataOut.setToExternal(dataOut.data(), dataOut.size()); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 341 | |
| 342 | // 256 x 256 YUV pixels |
| 343 | Element element1 = context->elementCreate(DataType::UNSIGNED_8, DataKind::PIXEL_YUV, true, 1); |
Michael Butler | 7c1ef5b | 2017-03-30 17:20:12 -0700 | [diff] [blame] | 344 | ASSERT_NE(Element(0), element1); |
| 345 | |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame] | 346 | Type type1 = context->typeCreate(element1, 256, 256, 0, false, false, YuvFormat::YUV_420_888); |
Michael Butler | 7c1ef5b | 2017-03-30 17:20:12 -0700 | [diff] [blame] | 347 | ASSERT_NE(Type(0), type1); |
| 348 | |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 349 | Allocation allocation1 = context->allocationCreateTyped(type1, AllocationMipmapControl::NONE, |
| 350 | (int)AllocationUsageType::SCRIPT, |
| 351 | (Ptr)nullptr); |
Michael Butler | 7c1ef5b | 2017-03-30 17:20:12 -0700 | [diff] [blame] | 352 | ASSERT_NE(Allocation(0), allocation1); |
| 353 | |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 354 | context->allocation2DWrite(allocation1, 0, 0, 0, AllocationCubemapFace::POSITIVE_X, 256, 256, |
| 355 | _dataIn, 0); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 356 | |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame] | 357 | // 256 x 256 RGBA pixels |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 358 | Element element2 = context->elementCreate(DataType::UNSIGNED_8, DataKind::PIXEL_RGBA, true, 4); |
Michael Butler | 7c1ef5b | 2017-03-30 17:20:12 -0700 | [diff] [blame] | 359 | ASSERT_NE(Element(0), element2); |
| 360 | |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 361 | Type type2 = context->typeCreate(element2, 256, 256, 0, false, false, YuvFormat::YUV_NONE); |
Michael Butler | 7c1ef5b | 2017-03-30 17:20:12 -0700 | [diff] [blame] | 362 | ASSERT_NE(Type(0), type2); |
| 363 | |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 364 | Allocation allocation2 = context->allocationCreateTyped(type2, AllocationMipmapControl::NONE, |
| 365 | (int)AllocationUsageType::SCRIPT, |
| 366 | (Ptr)nullptr); |
Michael Butler | 7c1ef5b | 2017-03-30 17:20:12 -0700 | [diff] [blame] | 367 | ASSERT_NE(Allocation(0), allocation2); |
| 368 | |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 369 | context->allocation2DWrite(allocation2, 0, 0, 0, AllocationCubemapFace::POSITIVE_X, 256, 256, |
| 370 | _dataOut, 0); |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame] | 371 | |
| 372 | // create scripts |
| 373 | Script yuv2rgb = context->scriptIntrinsicCreate(ScriptIntrinsicID::ID_YUV_TO_RGB, element1); |
Michael Butler | 7c1ef5b | 2017-03-30 17:20:12 -0700 | [diff] [blame] | 374 | ASSERT_NE(Script(0), yuv2rgb); |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame] | 375 | |
| 376 | ScriptKernelID yuv2rgbKID = context->scriptKernelIDCreate(yuv2rgb, 0, 2); |
Michael Butler | 7c1ef5b | 2017-03-30 17:20:12 -0700 | [diff] [blame] | 377 | ASSERT_NE(ScriptKernelID(0), yuv2rgbKID); |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame] | 378 | |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 379 | Script blur = context->scriptIntrinsicCreate(ScriptIntrinsicID::ID_BLUR, element2); |
Michael Butler | 7c1ef5b | 2017-03-30 17:20:12 -0700 | [diff] [blame] | 380 | ASSERT_NE(Script(0), blur); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 381 | |
| 382 | ScriptKernelID blurKID = context->scriptKernelIDCreate(blur, 0, 2); |
Michael Butler | 7c1ef5b | 2017-03-30 17:20:12 -0700 | [diff] [blame] | 383 | ASSERT_NE(ScriptKernelID(0), blurKID); |
| 384 | |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame] | 385 | ScriptFieldID blurFID = context->scriptFieldIDCreate(blur, 1); |
Michael Butler | 7c1ef5b | 2017-03-30 17:20:12 -0700 | [diff] [blame] | 386 | ASSERT_NE(ScriptFieldID(0), blurFID); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 387 | |
| 388 | // ScriptGroup |
| 389 | hidl_vec<ScriptKernelID> kernels = {yuv2rgbKID, blurKID}; |
| 390 | hidl_vec<ScriptKernelID> srcK = {yuv2rgbKID}; |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame] | 391 | hidl_vec<ScriptKernelID> dstK = {ScriptKernelID(0)}; |
| 392 | hidl_vec<ScriptFieldID> dstF = {blurFID}; |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 393 | hidl_vec<Type> types = {type2}; |
| 394 | ScriptGroup scriptGroup = context->scriptGroupCreate(kernels, srcK, dstK, dstF, types); |
Michael Butler | 7c1ef5b | 2017-03-30 17:20:12 -0700 | [diff] [blame] | 395 | ASSERT_NE(ScriptGroup(0), scriptGroup); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 396 | |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame] | 397 | context->scriptSetVarObj(yuv2rgb, 0, (ObjectBase)allocation1); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 398 | context->scriptGroupSetOutput(scriptGroup, blurKID, allocation2); |
| 399 | context->scriptGroupExecute(scriptGroup); |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame] | 400 | context->contextFinish(); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 401 | |
| 402 | // verify contents were changed |
| 403 | context->allocation2DRead(allocation2, 0, 0, 0, AllocationCubemapFace::POSITIVE_X, 256, 256, |
| 404 | (Ptr)dataOut.data(), (Size)dataOut.size(), 0); |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame] | 405 | EXPECT_NE(zeros, dataOut); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 406 | } |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 407 | |
| 408 | /* |
| 409 | * Similar to the ScriptGroup test, this test verifies the execution flow of |
| 410 | * RenderScript kernels and invokables. |
| 411 | * |
Michael Butler | 7c1ef5b | 2017-03-30 17:20:12 -0700 | [diff] [blame] | 412 | * Calls: scriptCCreate, elementCreate, typeCreate, allocationCreateTyped, |
| 413 | * allocation1DWrite, scriptFieldIDCreate, scriptInvokeIDCreate, |
| 414 | * invokeClosureCreate, closureCreate, closureSetGlobal, scriptGroup2Create, |
| 415 | * scriptGroupExecute, allocationRead |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 416 | */ |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 417 | TEST_F(RenderscriptHidlTest, ScriptGroup2Test) { |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame] | 418 | hidl_vec<uint8_t> bitcode; |
| 419 | bitcode.setToExternal((uint8_t*)bitCode, bitCodeLength); |
| 420 | Script script = context->scriptCCreate("struct_test", "/data/local/tmp/", bitcode); |
Michael Butler | 7c1ef5b | 2017-03-30 17:20:12 -0700 | [diff] [blame] | 421 | ASSERT_NE(Script(0), script); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 422 | |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame] | 423 | std::vector<uint8_t> dataIn(128, 128), dataOut(128, 0), expected(128, 7+1); |
| 424 | hidl_vec<uint8_t> _dataIn, _dataOut; |
| 425 | _dataIn.setToExternal(dataIn.data(), dataIn.size()); |
| 426 | |
| 427 | // 256 x 256 YUV pixels |
| 428 | Element element = context->elementCreate(DataType::UNSIGNED_8, DataKind::USER, false, 1); |
Michael Butler | 7c1ef5b | 2017-03-30 17:20:12 -0700 | [diff] [blame] | 429 | ASSERT_NE(Element(0), element); |
| 430 | |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame] | 431 | Type type = context->typeCreate(element, 128, 0, 0, false, false, YuvFormat::YUV_NONE); |
Michael Butler | 7c1ef5b | 2017-03-30 17:20:12 -0700 | [diff] [blame] | 432 | ASSERT_NE(Type(0), type); |
| 433 | |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame] | 434 | Allocation allocation = context->allocationCreateTyped(type, AllocationMipmapControl::NONE, |
| 435 | (int)AllocationUsageType::SCRIPT, |
| 436 | (Ptr)nullptr); |
Michael Butler | 7c1ef5b | 2017-03-30 17:20:12 -0700 | [diff] [blame] | 437 | ASSERT_NE(Allocation(0), allocation); |
| 438 | |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame] | 439 | context->allocation1DWrite(allocation, 0, 0, (Size)_dataIn.size(), _dataIn); |
| 440 | |
| 441 | ScriptFieldID fieldID = context->scriptFieldIDCreate(script, mExportVarIdx_var_allocation); |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame] | 442 | ASSERT_NE(ScriptFieldID(0), fieldID); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 443 | |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame] | 444 | // invoke |
| 445 | ScriptInvokeID invokeID = context->scriptInvokeIDCreate(script, mExportFuncIdx_setAllocation); |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame] | 446 | ASSERT_NE(ScriptInvokeID(0), invokeID); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 447 | |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame] | 448 | int dim = 128; |
| 449 | hidl_vec<uint8_t> params; |
| 450 | params.setToExternal((uint8_t*)&dim, sizeof(dim)); |
| 451 | hidl_vec<ScriptFieldID> fieldIDS1 = {fieldID}; |
| 452 | hidl_vec<int64_t> values1 = {int64_t(0)}; |
| 453 | hidl_vec<int32_t> sizes1 = {int32_t(0)}; |
| 454 | Closure closure1 = context->invokeClosureCreate(invokeID, params, fieldIDS1, values1, sizes1); |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame] | 455 | ASSERT_NE(Closure(0), closure1); |
| 456 | |
| 457 | // kernel |
| 458 | ScriptKernelID kernelID = context->scriptKernelIDCreate(script, mExportForEachIdx_increment, 3); |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame] | 459 | ASSERT_NE(ScriptKernelID(0), kernelID); |
| 460 | |
| 461 | hidl_vec<ScriptFieldID> fieldIDS2 = {ScriptFieldID(0)}; |
| 462 | hidl_vec<int64_t> values2 = {(int64_t)(intptr_t)allocation}; |
| 463 | hidl_vec<int32_t> sizes2 = {-1 /* allocation */}; |
| 464 | hidl_vec<Closure> depClosures2 = {closure1}; |
| 465 | hidl_vec<ScriptFieldID> depFieldIDS2 = {fieldID}; |
| 466 | Closure closure2 = context->closureCreate(kernelID, allocation /* returnValue */, fieldIDS2, |
| 467 | values2, sizes2, depClosures2, depFieldIDS2); |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame] | 468 | ASSERT_NE(Closure(0), closure2); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 469 | |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame] | 470 | // set argument |
| 471 | context->closureSetGlobal(closure1, fieldID, (int64_t)(intptr_t)allocation, |
| 472 | -1 /* allocation */); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 473 | |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame] | 474 | // execute |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 475 | hidl_string name = "script_group_2_test"; |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame] | 476 | hidl_string cacheDir = "/data/local/tmp"; |
| 477 | hidl_vec<Closure> closures = {closure1, closure2}; |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 478 | ScriptGroup2 scriptGroup2 = context->scriptGroup2Create(name, cacheDir, closures); |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame] | 479 | ASSERT_NE(ScriptGroup2(0), scriptGroup2); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 480 | |
| 481 | context->scriptGroupExecute(scriptGroup2); |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame] | 482 | context->allocationRead(allocation, (Ptr)dataOut.data(), (Size)dataOut.size()*sizeof(uint8_t)); |
| 483 | EXPECT_EQ(expected, dataOut); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 484 | } |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame] | 485 | |
| 486 | /* |
| 487 | * Similar to the ScriptGroup test, this test verifies a single kernel can be |
| 488 | * called by ScriptGroup with an unbound allocation specified before launch |
| 489 | * |
Michael Butler | 7c1ef5b | 2017-03-30 17:20:12 -0700 | [diff] [blame] | 490 | * Calls: scriptCCreate, elementCreate, typeCreate, allocationCreateTyped, |
| 491 | * allocation1DWrite, scriptKernelIDCreate, closureCreate, closureSetArg, |
| 492 | * scriptGroup2Create, scriptGroupExecute, allocationRead |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame] | 493 | */ |
| 494 | TEST_F(RenderscriptHidlTest, ScriptGroup2KernelTest) { |
| 495 | hidl_vec<uint8_t> bitcode; |
| 496 | bitcode.setToExternal((uint8_t*)bitCode, bitCodeLength); |
| 497 | Script script = context->scriptCCreate("struct_test", "/data/local/tmp/", bitcode); |
Michael Butler | 7c1ef5b | 2017-03-30 17:20:12 -0700 | [diff] [blame] | 498 | ASSERT_NE(Script(0), script); |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame] | 499 | |
| 500 | std::vector<uint8_t> dataIn(128, 128), dataOut(128, 0), expected(128, 128 + 1); |
| 501 | hidl_vec<uint8_t> _dataIn, _dataOut; |
| 502 | _dataIn.setToExternal(dataIn.data(), dataIn.size()); |
| 503 | |
| 504 | // 256 x 256 YUV pixels |
| 505 | Element element = context->elementCreate(DataType::UNSIGNED_8, DataKind::USER, false, 1); |
Michael Butler | 7c1ef5b | 2017-03-30 17:20:12 -0700 | [diff] [blame] | 506 | ASSERT_NE(Element(0), element); |
| 507 | |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame] | 508 | Type type = context->typeCreate(element, 128, 0, 0, false, false, YuvFormat::YUV_NONE); |
Michael Butler | 7c1ef5b | 2017-03-30 17:20:12 -0700 | [diff] [blame] | 509 | ASSERT_NE(Type(0), type); |
| 510 | |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame] | 511 | Allocation allocation = context->allocationCreateTyped(type, AllocationMipmapControl::NONE, |
| 512 | (int)AllocationUsageType::SCRIPT, |
| 513 | (Ptr)nullptr); |
Michael Butler | 7c1ef5b | 2017-03-30 17:20:12 -0700 | [diff] [blame] | 514 | ASSERT_NE(Allocation(0), allocation); |
| 515 | |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame] | 516 | context->allocation1DWrite(allocation, 0, 0, (Size)_dataIn.size(), _dataIn); |
| 517 | |
| 518 | // kernel |
| 519 | ScriptKernelID kernelID = context->scriptKernelIDCreate(script, mExportForEachIdx_increment, 3); |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame] | 520 | ASSERT_NE(ScriptKernelID(0), kernelID); |
| 521 | |
| 522 | hidl_vec<ScriptFieldID> fieldIDS = {ScriptFieldID(0)}; |
| 523 | hidl_vec<int64_t> values = {int64_t(0)}; |
| 524 | hidl_vec<int32_t> sizes = {int32_t(0)}; |
| 525 | hidl_vec<Closure> depClosures = {Closure(0)}; |
| 526 | hidl_vec<ScriptFieldID> depFieldIDS = {ScriptFieldID(0)}; |
| 527 | Closure closure = context->closureCreate(kernelID, allocation /* returnValue */, fieldIDS, |
| 528 | values, sizes, depClosures, depFieldIDS); |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame] | 529 | ASSERT_NE(Closure(0), closure); |
| 530 | |
| 531 | // set argument |
| 532 | context->closureSetArg(closure, 0 /* first argument */, (Ptr)allocation, -1); |
| 533 | |
| 534 | // execute |
| 535 | hidl_string name = "script_group_2_test"; |
| 536 | hidl_string cacheDir = "/data/local/tmp"; |
| 537 | hidl_vec<Closure> closures = {closure}; |
| 538 | ScriptGroup2 scriptGroup2 = context->scriptGroup2Create(name, cacheDir, closures); |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame] | 539 | ASSERT_NE(ScriptGroup2(0), scriptGroup2); |
| 540 | |
| 541 | context->scriptGroupExecute(scriptGroup2); |
| 542 | context->allocationRead(allocation, (Ptr)dataOut.data(), (Size)dataOut.size()*sizeof(uint8_t)); |
| 543 | EXPECT_EQ(expected, dataOut); |
| 544 | } |