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 | * This test creates a 1D Allocation with 128 Float Elements, and two float |
| 21 | * vector dataIn & dataOut. dataIn is pre-populated with data, and copied into |
| 22 | * the Allocation using allocation1DWrite. Then the Allocation is copied into |
| 23 | * dataOut with allocation1DRead. |
| 24 | * |
| 25 | * Calls: elementCreate, typeCreate, allocationCreateTyped, allocation1DWrite, |
| 26 | * allocation1DRead |
| 27 | * |
| 28 | * Expect: dataIn & dataOut are the same. |
| 29 | */ |
| 30 | TEST_F(RenderscriptHidlTest, Simple1DCopyTest) { |
| 31 | // float1 |
| 32 | Element element = context->elementCreate(DataType::FLOAT_32, DataKind::USER, false, 1); |
| 33 | // 128 x float1 |
| 34 | Type type = context->typeCreate(element, 128, 0, 0, false, false, YuvFormat::YUV_NONE); |
| 35 | // 128 x float1 |
| 36 | Allocation allocation = context->allocationCreateTyped(type, AllocationMipmapControl::NONE, |
| 37 | (int)AllocationUsageType::SCRIPT, |
| 38 | (Ptr)nullptr); |
| 39 | std::vector<float> dataIn(128), dataOut(128); |
| 40 | std::generate(dataIn.begin(), dataIn.end(), [](){ static int val = 0; return (float)val++; }); |
| 41 | hidl_vec<uint8_t> _data; |
| 42 | _data.setToExternal((uint8_t*)dataIn.data(), dataIn.size()*sizeof(float)); |
| 43 | context->allocation1DWrite(allocation, 0, 0, (Size)dataIn.size(), _data); |
| 44 | context->allocation1DRead(allocation, 0, 0, (uint32_t)dataOut.size(), (Ptr)dataOut.data(), |
| 45 | (Size)dataOut.size()*sizeof(float)); |
Michael Butler | 54fa8d4 | 2017-03-17 13:02:53 -0700 | [diff] [blame^] | 46 | EXPECT_EQ(dataIn, dataOut); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | /* |
| 50 | * This test creates a 2D Allocation with 128 * 128 Float Elements, and two |
| 51 | * float vector dataIn & dataOut. dataIn is pre-populated with data, and copied |
| 52 | * into the Allocation using allocation2DWrite. Then the Allocation is copied |
| 53 | * into dataOut with allocation2DRead. |
| 54 | * |
| 55 | * Calls: elementCreate, typeCreate, allocationCreateTyped, allocation2DWrite, |
| 56 | * allocation2DRead |
| 57 | * |
| 58 | * Expect: dataIn & dataOut are the same. |
| 59 | */ |
| 60 | TEST_F(RenderscriptHidlTest, Simple2DCopyTest) { |
| 61 | // float1 |
| 62 | Element element = context->elementCreate(DataType::FLOAT_32, DataKind::USER, false, 1); |
| 63 | // 128 x 128 x float1 |
| 64 | Type type = context->typeCreate(element, 128, 128, 0, false, false, YuvFormat::YUV_NONE); |
| 65 | // 128 x 128 x float1 |
| 66 | Allocation allocation = context->allocationCreateTyped(type, AllocationMipmapControl::NONE, |
| 67 | (int)AllocationUsageType::SCRIPT, |
| 68 | (Ptr)nullptr); |
| 69 | std::vector<float> dataIn(128*128), dataOut(128*128); |
| 70 | std::generate(dataIn.begin(), dataIn.end(), [](){ static int val = 0; return (float)val++; }); |
| 71 | hidl_vec<uint8_t> _data; |
| 72 | _data.setToExternal((uint8_t*)dataIn.data(), dataIn.size()*sizeof(float)); |
| 73 | context->allocation2DWrite(allocation, 0, 0, 0, AllocationCubemapFace::POSITIVE_X, 128, 128, |
| 74 | _data, 0); |
| 75 | context->allocation2DRead(allocation, 0, 0, 0, AllocationCubemapFace::POSITIVE_X, 128, 128, |
| 76 | (Ptr)dataOut.data(), (Size)dataOut.size()*sizeof(float), 0); |
Michael Butler | 54fa8d4 | 2017-03-17 13:02:53 -0700 | [diff] [blame^] | 77 | EXPECT_EQ(dataIn, dataOut); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | /* |
| 81 | * This test creates a 3D Allocation with 32 * 32 * 32 Float Elements, and two |
| 82 | * float vector dataIn & dataOut. dataIn is pre-populated with data, and copied |
| 83 | * into the Allocation using allocation3DWrite. Then the Allocation is copied |
| 84 | * into dataOut with allocation3DRead. |
| 85 | * |
| 86 | * Calls: elementCreate, typeCreate, allocationCreateTyped, allocation3DWrite, |
| 87 | * allocation3DRead |
| 88 | * |
| 89 | * Expect: dataIn & dataOut are the same. |
| 90 | */ |
| 91 | TEST_F(RenderscriptHidlTest, Simple3DCopyTest) { |
| 92 | // float1 |
| 93 | Element element = context->elementCreate(DataType::FLOAT_32, DataKind::USER, false, 1); |
| 94 | // 32 x 32 x 32 x float1 |
| 95 | Type type = context->typeCreate(element, 32, 32, 32, false, false, YuvFormat::YUV_NONE); |
| 96 | // 32 x 32 x 32 x float1 |
| 97 | Allocation allocation = context->allocationCreateTyped(type, AllocationMipmapControl::NONE, |
| 98 | (int)AllocationUsageType::SCRIPT, |
| 99 | (Ptr)nullptr); |
| 100 | std::vector<float> dataIn(32*32*32), dataOut(32*32*32); |
| 101 | std::generate(dataIn.begin(), dataIn.end(), [](){ static int val = 0; return (float)val++; }); |
| 102 | hidl_vec<uint8_t> _data; |
| 103 | _data.setToExternal((uint8_t*)dataIn.data(), dataIn.size()*sizeof(float)); |
| 104 | context->allocation3DWrite(allocation, 0, 0, 0, 0, 32, 32, 32, _data, 0); |
| 105 | context->allocation3DRead(allocation, 0, 0, 0, 0, 32, 32, 32, (Ptr)dataOut.data(), |
| 106 | (Size)dataOut.size()*sizeof(float), 0); |
Michael Butler | 54fa8d4 | 2017-03-17 13:02:53 -0700 | [diff] [blame^] | 107 | EXPECT_EQ(dataIn, dataOut); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | /* |
| 111 | * This test creates a 2D Allocation with 512 * 512 Float Elements with |
| 112 | * allocationCreateFromBitmap, and two float vector dataIn & dataOut. dataIn is |
| 113 | * pre-populated with data, and copied into the Allocation using |
| 114 | * allocationCopyToBitmap. Then the Allocation is copied into dataOut with |
| 115 | * allocationRead. |
| 116 | * |
| 117 | * Calls: elementCreate, typeCreate, allocationCreateFromBitmap, |
| 118 | * allocationCopyToBitmap, allocationRead |
| 119 | * |
| 120 | * Expect: dataIn & dataOut are the same. |
| 121 | */ |
| 122 | TEST_F(RenderscriptHidlTest, SimpleBitmapTest) { |
| 123 | // float1 |
| 124 | Element element = context->elementCreate(DataType::FLOAT_32, DataKind::USER, false, 1); |
| 125 | // 512 x 512 x float1 |
| 126 | Type type = context->typeCreate(element, 512, 512, 0, false, false, YuvFormat::YUV_NONE); |
| 127 | std::vector<float> dataIn(512*512), dataOut1(512*512), dataOut2(512*512); |
| 128 | std::generate(dataIn.begin(), dataIn.end(), [](){ static int val = 0; return (float)val++; }); |
| 129 | hidl_vec<uint8_t> _data; |
| 130 | _data.setToExternal((uint8_t*)dataIn.data(), dataIn.size()*sizeof(float)); |
| 131 | // 512 x 512 x float1 |
| 132 | Allocation allocation = context->allocationCreateFromBitmap(type, |
| 133 | AllocationMipmapControl::NONE, |
| 134 | _data, |
| 135 | (int)AllocationUsageType::SCRIPT); |
Michael Butler | 54fa8d4 | 2017-03-17 13:02:53 -0700 | [diff] [blame^] | 136 | EXPECT_NE(Allocation(0), allocation); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 137 | |
| 138 | context->allocationCopyToBitmap(allocation, (Ptr)dataOut1.data(), |
| 139 | (Size)dataOut1.size()*sizeof(float)); |
Michael Butler | 54fa8d4 | 2017-03-17 13:02:53 -0700 | [diff] [blame^] | 140 | EXPECT_EQ(dataIn, dataOut1); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 141 | |
| 142 | context->allocationRead(allocation, (Ptr)dataOut2.data(), (Size)dataOut2.size()*sizeof(float)); |
Michael Butler | 54fa8d4 | 2017-03-17 13:02:53 -0700 | [diff] [blame^] | 143 | EXPECT_EQ(dataIn, dataOut2); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | /* |
| 147 | * This test creates two 2D Allocations, one with 512 * 512 Float Elements, the |
| 148 | * other with 256 * 256 Float Elements. The larger Allocation is pre-populated |
| 149 | * with dataIn, and copied into the smaller Allocation using |
| 150 | * allocationCopy2DRange. Then the Allocation is copied into dataOut with |
| 151 | * allocationRead. |
| 152 | * |
| 153 | * Calls: elementCreate, typeCreate, allocationCreateFromBitmap, |
| 154 | * allocationCreateTyped, allocationCopy2DRange, allocationRead |
| 155 | * |
| 156 | * Expect: dataIn & dataOut are the same. |
| 157 | */ |
| 158 | TEST_F(RenderscriptHidlTest, AllocationCopy2DRangeTest) { |
| 159 | // float1 |
| 160 | Element element = context->elementCreate(DataType::FLOAT_32, DataKind::USER, false, 1); |
| 161 | // 512 x 512 x float1 |
| 162 | Type typeSrc = context->typeCreate(element, 512, 512, 0, false, false, YuvFormat::YUV_NONE); |
| 163 | // 256 x 256 x float1 |
| 164 | Type typeDst = context->typeCreate(element, 256, 256, 0, false, false, YuvFormat::YUV_NONE); |
| 165 | std::vector<float> dataIn(512*512), dataOut(256*256), expected(256*256); |
| 166 | std::generate(dataIn.begin(), dataIn.end(), [](){ static int val = 0; return (float)val++; }); |
| 167 | hidl_vec<uint8_t> _data; |
| 168 | _data.setToExternal((uint8_t*)dataIn.data(), dataIn.size()*sizeof(float)); |
| 169 | // 512 x 512 x float1 |
| 170 | Allocation allocSrc = context->allocationCreateFromBitmap(typeSrc, |
| 171 | AllocationMipmapControl::NONE, _data, |
| 172 | (int)AllocationUsageType::SCRIPT); |
| 173 | // 256 x 256 x float1 |
| 174 | Allocation allocDst = context->allocationCreateTyped(typeDst, AllocationMipmapControl::NONE, |
| 175 | (int)AllocationUsageType::SCRIPT, |
| 176 | (Ptr)nullptr); |
| 177 | context->allocationCopy2DRange(allocDst, 0, 0, 0, AllocationCubemapFace::POSITIVE_X, 256, 256, |
| 178 | allocSrc, 128, 128, 0, AllocationCubemapFace::POSITIVE_X); |
| 179 | context->allocationRead(allocDst, (Ptr)dataOut.data(), (Size)dataOut.size()*sizeof(float)); |
| 180 | for (int i = 0; i < 256; ++i) { |
| 181 | for (int j = 0; j < 256; ++j) { |
| 182 | expected[i*256 + j] = dataIn[(i+128)*512 + (j+128)]; |
| 183 | } |
| 184 | } |
| 185 | EXPECT_EQ(expected, dataOut); |
| 186 | } |
| 187 | |
| 188 | /* |
| 189 | * This test creates two 3D Allocations, one with 128 * 128 * 128 Float |
| 190 | * Elements, the other with 64 * 64 * 64 Float Elements. The larger Allocation |
| 191 | * is pre-populated with dataIn, and copied into the smaller Allocation using |
| 192 | * allocationCopy3DRange. Then the Allocation is copied into dataOut with |
| 193 | * allocationRead. |
| 194 | * |
| 195 | * Calls: elementCreate, typeCreate, allocationCreateTyped, allocation3DWrite, |
| 196 | * allocationCopy3DRange, allocationRead |
| 197 | * |
| 198 | * Expect: dataIn & dataOut are the same. |
| 199 | */ |
| 200 | TEST_F(RenderscriptHidlTest, AllocationCopy3DRangeTest) { |
| 201 | // float1 |
| 202 | Element element = context->elementCreate(DataType::FLOAT_32, DataKind::USER, false, 1); |
| 203 | // 128 x 128 x 128 x float1 |
| 204 | Type typeSrc = context->typeCreate(element, 128, 128, 128, false, false, YuvFormat::YUV_NONE); |
| 205 | // 64 x 64 x 64 x float1 |
| 206 | Type typeDst = context->typeCreate(element, 64, 64, 64, false, false, YuvFormat::YUV_NONE); |
| 207 | std::vector<float> dataIn(128*128*128), dataOut(64*64*64), expected(64*64*64); |
| 208 | std::generate(dataIn.begin(), dataIn.end(), [](){ static int val = 0; return (float)val++; }); |
| 209 | hidl_vec<uint8_t> _data; |
| 210 | _data.setToExternal((uint8_t*)dataIn.data(), dataIn.size()*sizeof(float)); |
| 211 | // 512 x 512 x float1 |
| 212 | Allocation allocSrc = context->allocationCreateTyped(typeSrc, AllocationMipmapControl::NONE, |
| 213 | (int)AllocationUsageType::SCRIPT, |
| 214 | (Ptr)nullptr); |
| 215 | // 256 x 256 x float1 |
| 216 | Allocation allocDst = context->allocationCreateTyped(typeDst, AllocationMipmapControl::NONE, |
| 217 | (int)AllocationUsageType::SCRIPT, |
| 218 | (Ptr)nullptr); |
| 219 | context->allocation3DWrite(allocSrc, 0, 0, 0, 0, 128, 128, 128, _data, 128*sizeof(float)); |
| 220 | context->allocationCopy3DRange(allocDst, 0, 0, 0, 0, 64, 64, 64, allocSrc, 32, 32, 32, 0); |
| 221 | context->allocationRead(allocDst, (Ptr)dataOut.data(), (Size)dataOut.size()*sizeof(float)); |
| 222 | for (int i = 0; i < 64; ++i) { |
| 223 | for (int j = 0; j < 64; ++j) { |
| 224 | for (int k = 0; k < 64; ++k) { |
| 225 | expected[i*64*64 + j*64 + k] = dataIn[(i+32)*128*128 + (j+32)*128 + (k+32)]; |
| 226 | } |
| 227 | } |
| 228 | } |
| 229 | EXPECT_EQ(expected, dataOut); |
| 230 | } |
| 231 | |
| 232 | /* |
| 233 | * This test creates one 2D Allocations, one with 512 * 512 Float Elements, and |
| 234 | * one 2D AllocationAdapter with a window of 256 * 256 based on the Allocation. |
| 235 | * The Allocation is pre-populated with dataIn. Then the Allocation is copied |
| 236 | * into dataOut with allocationRead on the AllocationAdapter. |
| 237 | * |
| 238 | * Calls: elementCreate, typeCreate, allocationCreateFromBitmap, |
| 239 | * allocationAdapterCreate, allocationAdapterOffset, allocation2DRead |
| 240 | * |
| 241 | * Expect: dataIn & dataOut are the same. |
| 242 | */ |
| 243 | TEST_F(RenderscriptHidlTest, SimpleAdapterTest) { |
| 244 | // float1 |
| 245 | Element element = context->elementCreate(DataType::FLOAT_32, DataKind::USER, false, 1); |
| 246 | // 512 x 512 x float1 |
| 247 | Type type = context->typeCreate(element, 512, 512, 0, false, false, YuvFormat::YUV_NONE); |
| 248 | std::vector<float> dataIn(512*512), dataOut(256*256), expected; |
| 249 | std::generate(dataIn.begin(), dataIn.end(), [](){ static int val = 0; return (float)val++; }); |
| 250 | hidl_vec<uint8_t> _data; |
| 251 | _data.setToExternal((uint8_t*)dataIn.data(), dataIn.size()*sizeof(float)); |
| 252 | // 512 x 512 x float1 |
| 253 | Allocation allocation = context->allocationCreateFromBitmap(type, |
| 254 | AllocationMipmapControl::NONE, |
| 255 | _data, |
| 256 | (int)AllocationUsageType::SCRIPT); |
| 257 | // 256 x 256 x float1 |
| 258 | Type subType = context->typeCreate(element, 256, 256, 0, false, false, YuvFormat::YUV_NONE); |
| 259 | // 256 x 256 x float1 |
| 260 | AllocationAdapter allocationAdapter = context->allocationAdapterCreate(subType, allocation); |
| 261 | EXPECT_NE(AllocationAdapter(0), allocationAdapter); |
| 262 | |
| 263 | std::vector<uint32_t> offsets(9, 0); |
| 264 | offsets[0] = 128; |
| 265 | offsets[1] = 128; |
| 266 | hidl_vec<uint32_t> _offsets; |
| 267 | _offsets.setToExternal(offsets.data(), offsets.size()); |
| 268 | // origin at (128,128) |
| 269 | context->allocationAdapterOffset(allocationAdapter, _offsets); |
| 270 | |
| 271 | context->allocation2DRead(allocationAdapter, 0, 0, 0, AllocationCubemapFace::POSITIVE_X, 256, |
| 272 | 256, (Ptr)dataOut.data(), (Size)dataOut.size()*sizeof(float), 0); |
| 273 | for (int i = 128; i < 128 + 256; ++i) { |
| 274 | for (int j = 128; j < 128 + 256; ++j) { |
| 275 | expected.push_back(i * 512 + j); |
| 276 | } |
| 277 | } |
| 278 | EXPECT_EQ(expected, dataOut); |
| 279 | } |
| 280 | |
| 281 | /* |
| 282 | * This test creates one 2D Allocations, one with 64 * 64 USIGNED_8 Elements, |
| 283 | * and with AllocationMipmapControl::FULL. The Allocation is pre-populated with |
| 284 | * dataIn and the mipmaps are filled with allocationGenerateMipmaps. Then |
| 285 | * dataOut is then overridden with allocation2DRead. |
| 286 | * |
| 287 | * Calls: elementCreate, typeCreate, allocationCreateTyped, allocation2DWrite, |
| 288 | * allocationGenerateMipmaps, allocationSyncAll, allocation2DRead |
| 289 | * |
| 290 | * Expect: dataIn & dataOut are the same. |
| 291 | */ |
| 292 | TEST_F(RenderscriptHidlTest, SimpleMipmapTest) { |
| 293 | // uint8_t |
| 294 | Element element = context->elementCreate(DataType::UNSIGNED_8, DataKind::USER, false, 1); |
| 295 | // 64 x 64 x uint8_t |
| 296 | Type type = context->typeCreate(element, 64, 64, 0, true, false, YuvFormat::YUV_NONE); |
| 297 | std::vector<uint8_t> dataIn(64*64), dataOut(32*32), expected(32*32); |
| 298 | std::generate(dataIn.begin(), dataIn.end(), |
| 299 | [](){ static int val = 0; return (uint8_t)(0xFF & val++); }); |
| 300 | hidl_vec<uint8_t> _data; |
| 301 | _data.setToExternal((uint8_t*)dataIn.data(), dataIn.size()*sizeof(uint8_t)); |
| 302 | // 64 x 64 x uint8_t |
| 303 | Allocation allocation = context->allocationCreateTyped(type, AllocationMipmapControl::FULL, |
| 304 | (int)AllocationUsageType::SCRIPT, |
| 305 | (Ptr)nullptr); |
| 306 | context->allocation2DWrite(allocation, 0, 0, 0, AllocationCubemapFace::POSITIVE_X, 64, 64, |
| 307 | _data, 64*sizeof(uint8_t)); |
| 308 | context->allocationGenerateMipmaps(allocation); |
| 309 | context->allocationSyncAll(allocation, AllocationUsageType::SCRIPT); |
| 310 | context->allocation2DRead(allocation, 0, 0, 1, AllocationCubemapFace::POSITIVE_X, 32, 32, |
| 311 | (Ptr)dataOut.data(), (Size)dataOut.size()*sizeof(uint8_t), |
| 312 | 32*sizeof(uint8_t)); |
| 313 | for (int i = 0; i < 32; ++i) { |
| 314 | for (int j = 0; j < 32; ++j) { |
| 315 | expected[i*32 + j] = ((uint32_t)dataIn[i*2*64 + j*2] + dataIn[i*2*64 + j*2 + 1] + |
| 316 | dataIn[i*2*64 + j*2 + 64] + dataIn[i*2*64 + j*2 + 64+1]) / 4; |
| 317 | } |
| 318 | } |
| 319 | EXPECT_EQ(expected, dataOut); |
| 320 | } |
| 321 | |
| 322 | /* |
| 323 | * This test creates one 2D Allocations, one with 128 * 128 Float Elements with |
| 324 | * allocationCubeCreateFromBitmap. The Allocation is pre-populated with dataIn |
| 325 | * and the mipmaps are filled with allocationGenerateMipmaps. Then dataOut is |
| 326 | * then overridden with allocation2DRead. |
| 327 | * |
| 328 | * Calls: elementCreate, typeCreate, allocationCubeCreateFromBitmap, |
| 329 | * allocation2DRead |
| 330 | * |
| 331 | * Expect: dataIn & dataOut are the same. |
| 332 | */ |
| 333 | TEST_F(RenderscriptHidlTest, SimpleCubemapTest) { |
| 334 | // float1 |
| 335 | Element element = context->elementCreate(DataType::FLOAT_32, DataKind::USER, false, 1); |
| 336 | // 128 x 128 x float1 |
| 337 | Type type = context->typeCreate(element, 128, 128, 0, false, true, YuvFormat::YUV_NONE); |
| 338 | std::vector<float> dataIn(128*128*6), dataOut(128*128), expected(128*128); |
| 339 | std::generate(dataIn.begin(), dataIn.end(), [](){ static int val = 0; return (float)val++; }); |
| 340 | hidl_vec<uint8_t> _data; |
| 341 | _data.setToExternal((uint8_t*)dataIn.data(), dataIn.size()*sizeof(float)); |
| 342 | // 128 x 128 x float1 x 6 |
| 343 | Allocation allocation = context->allocationCubeCreateFromBitmap( |
| 344 | type, AllocationMipmapControl::NONE, _data, (int)AllocationUsageType::SCRIPT); |
| 345 | EXPECT_NE(Allocation(0), allocation); |
| 346 | |
| 347 | context->allocation2DRead(allocation, 0, 0, 0, AllocationCubemapFace::NEGATIVE_Z, 128, |
| 348 | 128, (Ptr)dataOut.data(), (Size)dataOut.size()*sizeof(float), |
| 349 | 128*sizeof(float)); |
| 350 | for (int i = 0; i < 128; ++i) { |
| 351 | for (int j = 0; j < 128; ++j) { |
| 352 | expected[i*128 + j] = i*128*6 + j + 128*5; |
| 353 | } |
| 354 | } |
| 355 | EXPECT_EQ(expected, dataOut); |
| 356 | } |
| 357 | |
| 358 | /* |
| 359 | * This test creates a complex element type (uint8_t, uint32_t) out of known |
| 360 | * elements. It then verifies the element structure was created correctly. |
Michael Butler | 54fa8d4 | 2017-03-17 13:02:53 -0700 | [diff] [blame^] | 361 | * Finally, the test creates a 1-wide, 1-dimension allocation of this type |
| 362 | * and transfers memory to and from a single cell of this Allocation. |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 363 | * |
| 364 | * Calls: elementCreate, elementComplexCreate, elementGetSubElements, |
| 365 | * typeCreate, allocationCreateTyped, allocationElementWrite, |
| 366 | * allocationElementRead |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 367 | */ |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 368 | TEST_F(RenderscriptHidlTest, ComplexElementTest) { |
| 369 | Element element1 = context->elementCreate(DataType::UNSIGNED_8, DataKind::USER, false, 1); |
| 370 | Element element2 = context->elementCreate(DataType::UNSIGNED_32, DataKind::USER, false, 1); |
| 371 | |
| 372 | hidl_vec<Element> eins = {element1, element2}; |
| 373 | hidl_vec<hidl_string> names = {hidl_string("first"), hidl_string("second")}; |
Michael Butler | 54fa8d4 | 2017-03-17 13:02:53 -0700 | [diff] [blame^] | 374 | hidl_vec<Size> arraySizesPtr = {1, 1}; |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 375 | Element element3 = context->elementComplexCreate(eins, names, arraySizesPtr); |
| 376 | EXPECT_NE(Element(0), element3); |
| 377 | |
| 378 | std::vector<Element> ids; |
| 379 | std::vector<std::string> namesOut; |
| 380 | std::vector<Size> arraySizesOut; |
| 381 | context->elementGetSubElements(element3, 2, [&](const hidl_vec<Element>& _ids, |
| 382 | const hidl_vec<hidl_string>& _names, |
| 383 | const hidl_vec<Size>& _arraySizes){ |
| 384 | ids = _ids; |
| 385 | namesOut.push_back(_names[0]); |
| 386 | namesOut.push_back(_names[1]); |
| 387 | arraySizesOut = _arraySizes; |
| 388 | }); |
Michael Butler | 54fa8d4 | 2017-03-17 13:02:53 -0700 | [diff] [blame^] | 389 | EXPECT_EQ(element1, ids[0]); |
| 390 | EXPECT_EQ(element2, ids[1]); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 391 | EXPECT_EQ("first", namesOut[0]); |
| 392 | EXPECT_EQ("second", namesOut[1]); |
Michael Butler | 54fa8d4 | 2017-03-17 13:02:53 -0700 | [diff] [blame^] | 393 | EXPECT_EQ(Size(1), arraySizesOut[0]); |
| 394 | EXPECT_EQ(Size(1), arraySizesOut[1]); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 395 | |
Michael Butler | 54fa8d4 | 2017-03-17 13:02:53 -0700 | [diff] [blame^] | 396 | // 1 x (uint8_t, uint32_t) |
| 397 | Type type = context->typeCreate(element3, 1, 0, 0, false, false, YuvFormat::YUV_NONE); |
| 398 | // 1 x (uint8_t, uint32_t) |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 399 | Allocation allocation = context->allocationCreateTyped(type, AllocationMipmapControl::NONE, |
| 400 | (int)AllocationUsageType::SCRIPT, |
| 401 | (Ptr)nullptr); |
Michael Butler | 54fa8d4 | 2017-03-17 13:02:53 -0700 | [diff] [blame^] | 402 | std::vector<uint32_t> dataIn(1), dataOut(1); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 403 | std::generate(dataIn.begin(), dataIn.end(), [](){ static uint32_t val = 0; return val++; }); |
| 404 | hidl_vec<uint8_t> _data; |
| 405 | _data.setToExternal((uint8_t*)dataIn.data(), dataIn.size()*sizeof(uint32_t)); |
| 406 | context->allocationElementWrite(allocation, 0, 0, 0, 0, _data, 1); |
| 407 | context->allocationElementRead(allocation, 0, 0, 0, 0, (Ptr)dataOut.data(), |
| 408 | (Size)dataOut.size()*sizeof(uint32_t), 1); |
Michael Butler | 54fa8d4 | 2017-03-17 13:02:53 -0700 | [diff] [blame^] | 409 | EXPECT_EQ(dataIn, dataOut); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 410 | } |