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" |
Michael Butler | 54fa8d4 | 2017-03-17 13:02:53 -0700 | [diff] [blame^] | 18 | #include <system/window.h> |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 19 | |
| 20 | /* |
| 21 | * ContextCreateAndDestroy: |
| 22 | * Creates a RenderScript context and immediately destroys the context. |
| 23 | * Since create and destroy calls are a part of SetUp() and TearDown(), |
| 24 | * the test definition is intentionally kept empty |
| 25 | * |
| 26 | * Calls: getService<IDevice>, contextCreate, contextDestroy |
| 27 | */ |
| 28 | TEST_F(RenderscriptHidlTest, ContextCreateAndDestroy) {} |
| 29 | |
| 30 | /* |
| 31 | * Create an Element and verify the return value is valid. |
| 32 | * |
| 33 | * Calls: elementCreate |
| 34 | */ |
| 35 | TEST_F(RenderscriptHidlTest, ElementCreate) { |
| 36 | Element element = context->elementCreate(DataType::FLOAT_32, DataKind::USER, false, 1); |
| 37 | EXPECT_NE(Element(0), element); |
| 38 | } |
| 39 | |
| 40 | /* |
| 41 | * Create an Element, a Type and an Allocation of that type, and verify the |
| 42 | * return values are valid. |
| 43 | * |
| 44 | * Calls: elementCreate, typeCreate, allocationCreateTyped, allocationGetType |
| 45 | */ |
| 46 | TEST_F(RenderscriptHidlTest, ElementTypeAllocationCreate) { |
| 47 | // Element create test |
| 48 | Element element = context->elementCreate(DataType::FLOAT_32, DataKind::USER, false, 1); |
| 49 | EXPECT_NE(Element(0), element); |
| 50 | |
| 51 | // Type create test |
| 52 | Type type = context->typeCreate(element, 1, 0, 0, false, false, YuvFormat::YUV_NONE); |
| 53 | EXPECT_NE(Type(0), type); |
| 54 | |
| 55 | // Allocation create test |
| 56 | Allocation allocation = context->allocationCreateTyped(type, AllocationMipmapControl::NONE, |
| 57 | (int)((uint32_t)AllocationUsageType::ALL |
| 58 | & ~(uint32_t)AllocationUsageType::OEM), |
| 59 | (Ptr)nullptr); |
| 60 | EXPECT_NE(Allocation(0), allocation); |
| 61 | |
| 62 | // Allocation type test |
| 63 | Type type2 = context->allocationGetType(allocation); |
| 64 | EXPECT_EQ(type, type2); |
| 65 | } |
| 66 | |
| 67 | /* |
| 68 | * Create an Element, a Type of the Element, and verify the native metadata can |
| 69 | * be retrieved correctly. |
| 70 | * |
| 71 | * Calls: elementCreate, typeCreate, elementGetNativeMetadata, |
| 72 | * typeGetNativeMetadata |
| 73 | */ |
| 74 | TEST_F(RenderscriptHidlTest, MetadataTest) { |
| 75 | // float1 |
| 76 | Element element = context->elementCreate(DataType::FLOAT_32, DataKind::USER, false, 1); |
| 77 | // 128 x float1 |
| 78 | Type type = context->typeCreate(element, 128, 0, 0, false, false, YuvFormat::YUV_NONE); |
| 79 | |
| 80 | std::vector<uint32_t> elementMetadata(5); |
| 81 | context->elementGetNativeMetadata(element, [&](const hidl_vec<uint32_t>& _metadata){ |
| 82 | elementMetadata = _metadata; }); |
| 83 | EXPECT_EQ(DataType::FLOAT_32, (DataType)elementMetadata[0]); |
| 84 | EXPECT_EQ(DataKind::USER, (DataKind)elementMetadata[1]); |
Michael Butler | 54fa8d4 | 2017-03-17 13:02:53 -0700 | [diff] [blame^] | 85 | EXPECT_EQ(false, elementMetadata[2]); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 86 | EXPECT_EQ(1u, (uint32_t)elementMetadata[3]); |
| 87 | EXPECT_EQ(0u, (uint32_t)elementMetadata[4]); |
| 88 | |
| 89 | std::vector<OpaqueHandle> typeMetadata(6); |
| 90 | context->typeGetNativeMetadata(type, [&typeMetadata](const hidl_vec<OpaqueHandle>& _metadata){ |
| 91 | typeMetadata = _metadata; }); |
| 92 | EXPECT_EQ(128u, (uint32_t)typeMetadata[0]); |
| 93 | EXPECT_EQ(0u, (uint32_t)typeMetadata[1]); |
| 94 | EXPECT_EQ(0u, (uint32_t)typeMetadata[2]); |
| 95 | EXPECT_NE(true, typeMetadata[3]); |
| 96 | EXPECT_NE(true, typeMetadata[4]); |
| 97 | EXPECT_EQ(element, (Element)typeMetadata[5]); |
| 98 | } |
| 99 | |
| 100 | /* |
| 101 | * Create a Allocation, and verified allocationGetPointer and allocationResize1D |
| 102 | * return valid values. |
| 103 | * |
| 104 | * Calls: elementCreate, typeCreate, allocationCreateTyped, |
| 105 | * allocationGetPointer, allocationResize1D |
| 106 | */ |
| 107 | TEST_F(RenderscriptHidlTest, ResizeTest) { |
| 108 | // float1 |
| 109 | Element element = context->elementCreate(DataType::FLOAT_32, DataKind::USER, false, 1); |
| 110 | // 128 x float1 |
| 111 | Type type = context->typeCreate(element, 128, 0, 0, false, false, YuvFormat::YUV_NONE); |
| 112 | // 128 x float1 |
| 113 | Allocation allocation = context->allocationCreateTyped(type, AllocationMipmapControl::NONE, |
| 114 | (int)AllocationUsageType::SCRIPT, |
| 115 | (Ptr)nullptr); |
| 116 | Ptr dataPtr1, dataPtr2; |
| 117 | Size stride; |
| 118 | context->allocationGetPointer(allocation, 0, AllocationCubemapFace::POSITIVE_X, 0, |
| 119 | [&](Ptr _dataPtr, Size _stride){ |
| 120 | dataPtr1 = _dataPtr; stride = _stride; }); |
| 121 | EXPECT_EQ(0ul, stride); |
| 122 | |
| 123 | context->allocationResize1D(allocation, 1024*1024); |
| 124 | context->allocationGetPointer(allocation, 0, AllocationCubemapFace::POSITIVE_X, 0, |
| 125 | [&](Ptr _dataPtr, Size _stride){ |
| 126 | dataPtr2 = _dataPtr; stride = _stride; }); |
| 127 | EXPECT_EQ(0ul, stride); |
| 128 | EXPECT_NE(dataPtr1, dataPtr2); |
| 129 | } |
| 130 | |
| 131 | /* |
| 132 | * Test creates two allocations, one with IO_INPUT and one with IO_OUTPUT. The |
| 133 | * NativeWindow (Surface) is retrieved from one allocation and set to the other. |
| 134 | * |
| 135 | * Calls: elementCreate, typeCreate, allocationCreateTyped, allocation2DWrite, |
| 136 | * allocationGetNativeWindow, allocationSetNativeWindow, allocationIoSend, |
| 137 | * allocationIoReceive, allocation2DRead |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 138 | */ |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 139 | TEST_F(RenderscriptHidlTest, NativeWindowIoTest) { |
| 140 | // uint8x4 |
| 141 | Element element = context->elementCreate(DataType::UNSIGNED_8, DataKind::USER, false, 4); |
| 142 | // 512 x 512 x uint8x4 |
| 143 | Type type = context->typeCreate(element, 512, 512, 0, false, false, YuvFormat::YUV_NONE); |
| 144 | std::vector<uint32_t> dataIn(512*512), dataOut(512*512); |
Michael Butler | 54fa8d4 | 2017-03-17 13:02:53 -0700 | [diff] [blame^] | 145 | std::generate(dataIn.begin(), dataIn.end(), [](){ static uint32_t val = 0; return val++; }); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 146 | hidl_vec<uint8_t> _data; |
| 147 | _data.setToExternal((uint8_t*)dataIn.data(), dataIn.size()*sizeof(uint32_t)); |
Michael Butler | 54fa8d4 | 2017-03-17 13:02:53 -0700 | [diff] [blame^] | 148 | // 512 x 512 x uint8x4 |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 149 | Allocation allocationRecv = context->allocationCreateTyped(type, AllocationMipmapControl::NONE, |
| 150 | (int)(AllocationUsageType::SCRIPT |
| 151 | | AllocationUsageType::IO_INPUT), |
| 152 | (Ptr)nullptr); |
| 153 | Allocation allocationSend = context->allocationCreateTyped(type, AllocationMipmapControl::NONE, |
| 154 | (int)(AllocationUsageType::SCRIPT |
| 155 | | AllocationUsageType::IO_OUTPUT), |
| 156 | (Ptr)nullptr); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 157 | NativeWindow nativeWindow = context->allocationGetNativeWindow(allocationRecv); |
| 158 | EXPECT_NE(NativeWindow(0), nativeWindow); |
| 159 | |
Michael Butler | 54fa8d4 | 2017-03-17 13:02:53 -0700 | [diff] [blame^] | 160 | ((ANativeWindow *)nativeWindow)->incStrong(nullptr); |
| 161 | |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 162 | context->allocationSetNativeWindow(allocationSend, nativeWindow); |
Michael Butler | 54fa8d4 | 2017-03-17 13:02:53 -0700 | [diff] [blame^] | 163 | context->allocation2DWrite(allocationSend, 0, 0, 0, AllocationCubemapFace::POSITIVE_X, 512, 512, |
| 164 | _data, 0); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 165 | context->allocationIoSend(allocationSend); |
| 166 | context->allocationIoReceive(allocationRecv); |
| 167 | context->allocation2DRead(allocationRecv, 0, 0, 0, AllocationCubemapFace::POSITIVE_X, 512, 512, |
| 168 | (Ptr)dataOut.data(), (Size)dataOut.size()*sizeof(uint32_t), 0); |
Michael Butler | 54fa8d4 | 2017-03-17 13:02:53 -0700 | [diff] [blame^] | 169 | EXPECT_EQ(dataIn, dataOut); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 170 | } |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 171 | |
| 172 | /* |
| 173 | * Three allocations are created, two with IO_INPUT and one with IO_OUTPUT. The |
| 174 | * two allocations with IO_INPUT are made to share the same BufferQueue. |
| 175 | * |
| 176 | * Calls: elementCreate, typeCreate, allocationCreateTyped, |
| 177 | * allocationCreateFromBitmap, allocationSetupBufferQueue, |
| 178 | * allocationShareBufferQueue |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 179 | */ |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 180 | TEST_F(RenderscriptHidlTest, BufferQueueTest) { |
Michael Butler | 54fa8d4 | 2017-03-17 13:02:53 -0700 | [diff] [blame^] | 181 | // uint8x4 |
| 182 | Element element = context->elementCreate(DataType::UNSIGNED_8, DataKind::USER, false, 4); |
| 183 | // 512 x 512 x uint8x4 |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 184 | Type type = context->typeCreate(element, 512, 512, 0, false, false, YuvFormat::YUV_NONE); |
Michael Butler | 54fa8d4 | 2017-03-17 13:02:53 -0700 | [diff] [blame^] | 185 | std::vector<uint32_t> dataIn(512*512), dataOut1(512*512), dataOut2(512*512); |
| 186 | std::generate(dataIn.begin(), dataIn.end(), [](){ static uint32_t val = 0; return val++; }); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 187 | hidl_vec<uint8_t> _data; |
Michael Butler | 54fa8d4 | 2017-03-17 13:02:53 -0700 | [diff] [blame^] | 188 | _data.setToExternal((uint8_t*)dataIn.data(), dataIn.size()*sizeof(uint32_t)); |
| 189 | // 512 x 512 x uint8x4 |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 190 | Allocation allocationRecv1 = context->allocationCreateTyped(type, AllocationMipmapControl::NONE, |
| 191 | (int)(AllocationUsageType::SCRIPT |
| 192 | | AllocationUsageType::IO_INPUT), |
| 193 | (Ptr)nullptr); |
| 194 | Allocation allocationRecv2 = context->allocationCreateTyped(type, AllocationMipmapControl::NONE, |
| 195 | (int)(AllocationUsageType::SCRIPT |
| 196 | | AllocationUsageType::IO_INPUT), |
| 197 | (Ptr)nullptr); |
Michael Butler | 54fa8d4 | 2017-03-17 13:02:53 -0700 | [diff] [blame^] | 198 | Allocation allocationSend = context->allocationCreateTyped(type, AllocationMipmapControl::NONE, |
| 199 | (int)(AllocationUsageType::SCRIPT |
| 200 | | AllocationUsageType::IO_INPUT), |
| 201 | (Ptr)nullptr); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 202 | context->allocationSetupBufferQueue(allocationRecv1, 2); |
Michael Butler | 54fa8d4 | 2017-03-17 13:02:53 -0700 | [diff] [blame^] | 203 | context->allocationShareBufferQueue(allocationRecv2, allocationRecv1); |
| 204 | |
| 205 | NativeWindow nativeWindow1 = context->allocationGetNativeWindow(allocationRecv1); |
| 206 | EXPECT_NE(NativeWindow(0), nativeWindow1); |
| 207 | NativeWindow nativeWindow2 = context->allocationGetNativeWindow(allocationRecv2); |
| 208 | EXPECT_EQ(nativeWindow2, nativeWindow1); |
| 209 | |
| 210 | ((ANativeWindow *)nativeWindow1)->incStrong(nullptr); |
| 211 | |
| 212 | context->allocationSetNativeWindow(allocationSend, nativeWindow1); |
| 213 | context->allocation2DWrite(allocationSend, 0, 0, 0, AllocationCubemapFace::POSITIVE_X, 512, 512, |
| 214 | _data, 0); |
| 215 | context->allocationIoSend(allocationSend); |
| 216 | context->allocationIoReceive(allocationRecv1); |
| 217 | context->allocation2DRead(allocationRecv1, 0, 0, 0, AllocationCubemapFace::POSITIVE_X, 512, 512, |
| 218 | (Ptr)dataOut1.data(), (Size)dataOut1.size()*sizeof(uint32_t), 0); |
| 219 | EXPECT_EQ(dataIn, dataOut1); |
| 220 | |
| 221 | context->allocation2DWrite(allocationSend, 0, 0, 0, AllocationCubemapFace::POSITIVE_X, 512, 512, |
| 222 | _data, 0); |
| 223 | context->allocationIoSend(allocationSend); |
| 224 | context->allocationIoReceive(allocationRecv2); |
| 225 | context->allocation2DRead(allocationRecv2, 0, 0, 0, AllocationCubemapFace::POSITIVE_X, 512, 512, |
| 226 | (Ptr)dataOut2.data(), (Size)dataOut2.size()*sizeof(uint32_t), 0); |
| 227 | EXPECT_EQ(dataIn, dataOut2); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 228 | } |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 229 | |
| 230 | /* |
| 231 | * This test sets up the message queue, sends a message, peeks at the message, |
| 232 | * and reads it back. |
| 233 | * |
| 234 | * Calls: contextInitToClient, contextSendMessage, contextPeekMessage, |
| 235 | * contextGetMessage, contextDeinitToClient, contextLog |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 236 | */ |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 237 | TEST_F(RenderscriptHidlTest, ContextMessageTest) { |
| 238 | context->contextInitToClient(); |
| 239 | |
Michael Butler | 54fa8d4 | 2017-03-17 13:02:53 -0700 | [diff] [blame^] | 240 | const char * message = "correct"; |
| 241 | std::vector<char> messageSend(message, message + sizeof(message)); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 242 | hidl_vec<uint8_t> _data; |
Michael Butler | 54fa8d4 | 2017-03-17 13:02:53 -0700 | [diff] [blame^] | 243 | _data.setToExternal((uint8_t*)messageSend.data(), messageSend.size()); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 244 | context->contextSendMessage(0, _data); |
| 245 | MessageToClientType messageType; |
| 246 | size_t size; |
| 247 | uint32_t subID; |
| 248 | context->contextPeekMessage([&](MessageToClientType _type, Size _size, uint32_t _subID){ |
| 249 | messageType = _type; size = (uint32_t)_size; subID = _subID; }); |
Michael Butler | 54fa8d4 | 2017-03-17 13:02:53 -0700 | [diff] [blame^] | 250 | std::vector<char> messageRecv(size, '\0'); |
| 251 | context->contextGetMessage(messageRecv.data(), messageRecv.size(), |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 252 | [&](MessageToClientType _type, Size _size){ |
| 253 | messageType = _type; size = (uint32_t)_size; }); |
Michael Butler | 54fa8d4 | 2017-03-17 13:02:53 -0700 | [diff] [blame^] | 254 | EXPECT_EQ(messageSend, messageRecv); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 255 | |
| 256 | context->contextDeinitToClient(); |
| 257 | context->contextLog(); |
| 258 | } |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 259 | |
| 260 | /* |
| 261 | * Call through a bunch of APIs and make sure they don’t crash. Assign the name |
| 262 | * of a object and check getName returns the name just set. |
| 263 | * |
| 264 | * Calls: contextSetPriority, contextSetCacheDir, elementCreate, assignName, |
| 265 | * contextFinish, getName, objDestroy, samplerCreate |
| 266 | */ |
| 267 | TEST_F(RenderscriptHidlTest, MiscellaneousTests) { |
| 268 | context->contextSetPriority(ThreadPriorities::NORMAL); |
| 269 | context->contextSetCacheDir("/data/local/tmp/temp/"); |
| 270 | |
| 271 | Element element = context->elementCreate(DataType::UNSIGNED_8, DataKind::USER, false, 1); |
| 272 | std::string nameIn = "element_test_name"; |
| 273 | std::string nameOut = "not_name"; |
| 274 | hidl_string _nameIn; |
| 275 | _nameIn.setToExternal(nameIn.c_str(), nameIn.length()); |
| 276 | context->assignName(element, _nameIn); |
| 277 | context->contextFinish(); |
| 278 | context->getName(element, [&](const hidl_string& _name){ nameOut = _name.c_str(); }); |
| 279 | EXPECT_EQ("element_test_name", nameOut); |
| 280 | |
| 281 | context->objDestroy(element); |
| 282 | |
| 283 | Sampler sampler = context->samplerCreate(SamplerValue::LINEAR, SamplerValue::LINEAR, |
| 284 | SamplerValue::LINEAR, SamplerValue::LINEAR, |
| 285 | SamplerValue::LINEAR, 8.0f); |
| 286 | EXPECT_NE(Sampler(0), sampler); |
| 287 | } |