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 | da8c2c1 | 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); |
Michael Butler | 7c1ef5b | 2017-03-30 17:20:12 -0700 | [diff] [blame^] | 49 | ASSERT_NE(Element(0), element); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 50 | |
| 51 | // Type create test |
| 52 | Type type = context->typeCreate(element, 1, 0, 0, false, false, YuvFormat::YUV_NONE); |
Michael Butler | 7c1ef5b | 2017-03-30 17:20:12 -0700 | [diff] [blame^] | 53 | ASSERT_NE(Type(0), type); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 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); |
Michael Butler | 7c1ef5b | 2017-03-30 17:20:12 -0700 | [diff] [blame^] | 60 | ASSERT_NE(Allocation(0), allocation); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 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); |
Michael Butler | 7c1ef5b | 2017-03-30 17:20:12 -0700 | [diff] [blame^] | 77 | ASSERT_NE(Element(0), element); |
| 78 | |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 79 | // 128 x float1 |
| 80 | 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^] | 81 | ASSERT_NE(Type(0), type); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 82 | |
| 83 | std::vector<uint32_t> elementMetadata(5); |
| 84 | context->elementGetNativeMetadata(element, [&](const hidl_vec<uint32_t>& _metadata){ |
| 85 | elementMetadata = _metadata; }); |
| 86 | EXPECT_EQ(DataType::FLOAT_32, (DataType)elementMetadata[0]); |
| 87 | EXPECT_EQ(DataKind::USER, (DataKind)elementMetadata[1]); |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame] | 88 | EXPECT_EQ(false, elementMetadata[2]); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 89 | EXPECT_EQ(1u, (uint32_t)elementMetadata[3]); |
| 90 | EXPECT_EQ(0u, (uint32_t)elementMetadata[4]); |
| 91 | |
| 92 | std::vector<OpaqueHandle> typeMetadata(6); |
| 93 | context->typeGetNativeMetadata(type, [&typeMetadata](const hidl_vec<OpaqueHandle>& _metadata){ |
| 94 | typeMetadata = _metadata; }); |
| 95 | EXPECT_EQ(128u, (uint32_t)typeMetadata[0]); |
| 96 | EXPECT_EQ(0u, (uint32_t)typeMetadata[1]); |
| 97 | EXPECT_EQ(0u, (uint32_t)typeMetadata[2]); |
| 98 | EXPECT_NE(true, typeMetadata[3]); |
| 99 | EXPECT_NE(true, typeMetadata[4]); |
| 100 | EXPECT_EQ(element, (Element)typeMetadata[5]); |
| 101 | } |
| 102 | |
| 103 | /* |
| 104 | * Create a Allocation, and verified allocationGetPointer and allocationResize1D |
| 105 | * return valid values. |
| 106 | * |
| 107 | * Calls: elementCreate, typeCreate, allocationCreateTyped, |
| 108 | * allocationGetPointer, allocationResize1D |
| 109 | */ |
| 110 | TEST_F(RenderscriptHidlTest, ResizeTest) { |
| 111 | // float1 |
| 112 | Element element = context->elementCreate(DataType::FLOAT_32, DataKind::USER, false, 1); |
Michael Butler | 7c1ef5b | 2017-03-30 17:20:12 -0700 | [diff] [blame^] | 113 | ASSERT_NE(Element(0), element); |
| 114 | |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 115 | // 128 x float1 |
| 116 | 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^] | 117 | ASSERT_NE(Type(0), type); |
| 118 | |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 119 | // 128 x float1 |
| 120 | Allocation allocation = context->allocationCreateTyped(type, AllocationMipmapControl::NONE, |
| 121 | (int)AllocationUsageType::SCRIPT, |
| 122 | (Ptr)nullptr); |
Michael Butler | 7c1ef5b | 2017-03-30 17:20:12 -0700 | [diff] [blame^] | 123 | ASSERT_NE(Allocation(0), allocation); |
| 124 | |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 125 | Ptr dataPtr1, dataPtr2; |
| 126 | Size stride; |
| 127 | context->allocationGetPointer(allocation, 0, AllocationCubemapFace::POSITIVE_X, 0, |
| 128 | [&](Ptr _dataPtr, Size _stride){ |
| 129 | dataPtr1 = _dataPtr; stride = _stride; }); |
Michael Butler | 7c1ef5b | 2017-03-30 17:20:12 -0700 | [diff] [blame^] | 130 | EXPECT_EQ(Size(0), stride); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 131 | |
| 132 | context->allocationResize1D(allocation, 1024*1024); |
| 133 | context->allocationGetPointer(allocation, 0, AllocationCubemapFace::POSITIVE_X, 0, |
| 134 | [&](Ptr _dataPtr, Size _stride){ |
| 135 | dataPtr2 = _dataPtr; stride = _stride; }); |
Michael Butler | 7c1ef5b | 2017-03-30 17:20:12 -0700 | [diff] [blame^] | 136 | EXPECT_EQ(Size(0), stride); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 137 | EXPECT_NE(dataPtr1, dataPtr2); |
| 138 | } |
| 139 | |
| 140 | /* |
| 141 | * Test creates two allocations, one with IO_INPUT and one with IO_OUTPUT. The |
| 142 | * NativeWindow (Surface) is retrieved from one allocation and set to the other. |
| 143 | * |
| 144 | * Calls: elementCreate, typeCreate, allocationCreateTyped, allocation2DWrite, |
| 145 | * allocationGetNativeWindow, allocationSetNativeWindow, allocationIoSend, |
| 146 | * allocationIoReceive, allocation2DRead |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 147 | */ |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 148 | TEST_F(RenderscriptHidlTest, NativeWindowIoTest) { |
| 149 | // uint8x4 |
| 150 | Element element = context->elementCreate(DataType::UNSIGNED_8, DataKind::USER, false, 4); |
Michael Butler | 7c1ef5b | 2017-03-30 17:20:12 -0700 | [diff] [blame^] | 151 | ASSERT_NE(Element(0), element); |
| 152 | |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 153 | // 512 x 512 x uint8x4 |
| 154 | Type type = context->typeCreate(element, 512, 512, 0, false, false, YuvFormat::YUV_NONE); |
Michael Butler | 7c1ef5b | 2017-03-30 17:20:12 -0700 | [diff] [blame^] | 155 | ASSERT_NE(Type(0), type); |
| 156 | |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 157 | std::vector<uint32_t> dataIn(512*512), dataOut(512*512); |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame] | 158 | 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] | 159 | hidl_vec<uint8_t> _data; |
| 160 | _data.setToExternal((uint8_t*)dataIn.data(), dataIn.size()*sizeof(uint32_t)); |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame] | 161 | // 512 x 512 x uint8x4 |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 162 | Allocation allocationRecv = context->allocationCreateTyped(type, AllocationMipmapControl::NONE, |
| 163 | (int)(AllocationUsageType::SCRIPT |
| 164 | | AllocationUsageType::IO_INPUT), |
| 165 | (Ptr)nullptr); |
Michael Butler | 7c1ef5b | 2017-03-30 17:20:12 -0700 | [diff] [blame^] | 166 | ASSERT_NE(Allocation(0), allocationRecv); |
| 167 | |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 168 | Allocation allocationSend = context->allocationCreateTyped(type, AllocationMipmapControl::NONE, |
| 169 | (int)(AllocationUsageType::SCRIPT |
| 170 | | AllocationUsageType::IO_OUTPUT), |
| 171 | (Ptr)nullptr); |
Michael Butler | 7c1ef5b | 2017-03-30 17:20:12 -0700 | [diff] [blame^] | 172 | ASSERT_NE(Allocation(0), allocationSend); |
| 173 | |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 174 | NativeWindow nativeWindow = context->allocationGetNativeWindow(allocationRecv); |
Michael Butler | 7c1ef5b | 2017-03-30 17:20:12 -0700 | [diff] [blame^] | 175 | ASSERT_NE(NativeWindow(0), nativeWindow); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 176 | |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame] | 177 | ((ANativeWindow *)nativeWindow)->incStrong(nullptr); |
| 178 | |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 179 | context->allocationSetNativeWindow(allocationSend, nativeWindow); |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame] | 180 | context->allocation2DWrite(allocationSend, 0, 0, 0, AllocationCubemapFace::POSITIVE_X, 512, 512, |
| 181 | _data, 0); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 182 | context->allocationIoSend(allocationSend); |
| 183 | context->allocationIoReceive(allocationRecv); |
| 184 | context->allocation2DRead(allocationRecv, 0, 0, 0, AllocationCubemapFace::POSITIVE_X, 512, 512, |
| 185 | (Ptr)dataOut.data(), (Size)dataOut.size()*sizeof(uint32_t), 0); |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame] | 186 | EXPECT_EQ(dataIn, dataOut); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 187 | } |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 188 | |
| 189 | /* |
| 190 | * Three allocations are created, two with IO_INPUT and one with IO_OUTPUT. The |
| 191 | * two allocations with IO_INPUT are made to share the same BufferQueue. |
| 192 | * |
| 193 | * Calls: elementCreate, typeCreate, allocationCreateTyped, |
Michael Butler | 7c1ef5b | 2017-03-30 17:20:12 -0700 | [diff] [blame^] | 194 | * allocationSetupBufferQueue, allocationShareBufferQueue, |
| 195 | * allocationGetNativeWindow, allocationSetNativeWindow, |
| 196 | * allocation2DWrite, allocation2DRead, allocationIoSend, |
| 197 | * allocationIoReceive |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 198 | */ |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 199 | TEST_F(RenderscriptHidlTest, BufferQueueTest) { |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame] | 200 | // uint8x4 |
| 201 | Element element = context->elementCreate(DataType::UNSIGNED_8, DataKind::USER, false, 4); |
Michael Butler | 7c1ef5b | 2017-03-30 17:20:12 -0700 | [diff] [blame^] | 202 | ASSERT_NE(Element(0), element); |
| 203 | |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame] | 204 | // 512 x 512 x uint8x4 |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 205 | Type type = context->typeCreate(element, 512, 512, 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<uint32_t> dataIn(512*512), dataOut1(512*512), dataOut2(512*512); |
| 209 | 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] | 210 | hidl_vec<uint8_t> _data; |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame] | 211 | _data.setToExternal((uint8_t*)dataIn.data(), dataIn.size()*sizeof(uint32_t)); |
| 212 | // 512 x 512 x uint8x4 |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 213 | Allocation allocationRecv1 = context->allocationCreateTyped(type, AllocationMipmapControl::NONE, |
| 214 | (int)(AllocationUsageType::SCRIPT |
| 215 | | AllocationUsageType::IO_INPUT), |
| 216 | (Ptr)nullptr); |
Michael Butler | 7c1ef5b | 2017-03-30 17:20:12 -0700 | [diff] [blame^] | 217 | ASSERT_NE(Allocation(0), allocationRecv1); |
| 218 | |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 219 | Allocation allocationRecv2 = context->allocationCreateTyped(type, AllocationMipmapControl::NONE, |
| 220 | (int)(AllocationUsageType::SCRIPT |
| 221 | | AllocationUsageType::IO_INPUT), |
| 222 | (Ptr)nullptr); |
Michael Butler | 7c1ef5b | 2017-03-30 17:20:12 -0700 | [diff] [blame^] | 223 | ASSERT_NE(Allocation(0), allocationRecv2); |
| 224 | |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame] | 225 | Allocation allocationSend = context->allocationCreateTyped(type, AllocationMipmapControl::NONE, |
| 226 | (int)(AllocationUsageType::SCRIPT |
| 227 | | AllocationUsageType::IO_INPUT), |
| 228 | (Ptr)nullptr); |
Michael Butler | 7c1ef5b | 2017-03-30 17:20:12 -0700 | [diff] [blame^] | 229 | ASSERT_NE(Allocation(0), allocationSend); |
| 230 | |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 231 | context->allocationSetupBufferQueue(allocationRecv1, 2); |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame] | 232 | context->allocationShareBufferQueue(allocationRecv2, allocationRecv1); |
| 233 | |
| 234 | NativeWindow nativeWindow1 = context->allocationGetNativeWindow(allocationRecv1); |
Michael Butler | 7c1ef5b | 2017-03-30 17:20:12 -0700 | [diff] [blame^] | 235 | ASSERT_NE(NativeWindow(0), nativeWindow1); |
| 236 | |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame] | 237 | NativeWindow nativeWindow2 = context->allocationGetNativeWindow(allocationRecv2); |
Michael Butler | 7c1ef5b | 2017-03-30 17:20:12 -0700 | [diff] [blame^] | 238 | ASSERT_NE(NativeWindow(0), nativeWindow2); |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame] | 239 | EXPECT_EQ(nativeWindow2, nativeWindow1); |
| 240 | |
| 241 | ((ANativeWindow *)nativeWindow1)->incStrong(nullptr); |
| 242 | |
| 243 | context->allocationSetNativeWindow(allocationSend, nativeWindow1); |
| 244 | context->allocation2DWrite(allocationSend, 0, 0, 0, AllocationCubemapFace::POSITIVE_X, 512, 512, |
| 245 | _data, 0); |
| 246 | context->allocationIoSend(allocationSend); |
| 247 | context->allocationIoReceive(allocationRecv1); |
| 248 | context->allocation2DRead(allocationRecv1, 0, 0, 0, AllocationCubemapFace::POSITIVE_X, 512, 512, |
| 249 | (Ptr)dataOut1.data(), (Size)dataOut1.size()*sizeof(uint32_t), 0); |
| 250 | EXPECT_EQ(dataIn, dataOut1); |
| 251 | |
| 252 | context->allocation2DWrite(allocationSend, 0, 0, 0, AllocationCubemapFace::POSITIVE_X, 512, 512, |
| 253 | _data, 0); |
| 254 | context->allocationIoSend(allocationSend); |
| 255 | context->allocationIoReceive(allocationRecv2); |
| 256 | context->allocation2DRead(allocationRecv2, 0, 0, 0, AllocationCubemapFace::POSITIVE_X, 512, 512, |
| 257 | (Ptr)dataOut2.data(), (Size)dataOut2.size()*sizeof(uint32_t), 0); |
| 258 | EXPECT_EQ(dataIn, dataOut2); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 259 | } |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 260 | |
| 261 | /* |
| 262 | * This test sets up the message queue, sends a message, peeks at the message, |
| 263 | * and reads it back. |
| 264 | * |
| 265 | * Calls: contextInitToClient, contextSendMessage, contextPeekMessage, |
| 266 | * contextGetMessage, contextDeinitToClient, contextLog |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 267 | */ |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 268 | TEST_F(RenderscriptHidlTest, ContextMessageTest) { |
| 269 | context->contextInitToClient(); |
| 270 | |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame] | 271 | const char * message = "correct"; |
| 272 | std::vector<char> messageSend(message, message + sizeof(message)); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 273 | hidl_vec<uint8_t> _data; |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame] | 274 | _data.setToExternal((uint8_t*)messageSend.data(), messageSend.size()); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 275 | context->contextSendMessage(0, _data); |
| 276 | MessageToClientType messageType; |
| 277 | size_t size; |
| 278 | uint32_t subID; |
| 279 | context->contextPeekMessage([&](MessageToClientType _type, Size _size, uint32_t _subID){ |
| 280 | messageType = _type; size = (uint32_t)_size; subID = _subID; }); |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame] | 281 | std::vector<char> messageRecv(size, '\0'); |
| 282 | context->contextGetMessage(messageRecv.data(), messageRecv.size(), |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 283 | [&](MessageToClientType _type, Size _size){ |
| 284 | messageType = _type; size = (uint32_t)_size; }); |
Michael Butler | da8c2c1 | 2017-03-17 13:02:53 -0700 | [diff] [blame] | 285 | EXPECT_EQ(messageSend, messageRecv); |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 286 | |
| 287 | context->contextDeinitToClient(); |
| 288 | context->contextLog(); |
| 289 | } |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 290 | |
| 291 | /* |
| 292 | * Call through a bunch of APIs and make sure they don’t crash. Assign the name |
| 293 | * of a object and check getName returns the name just set. |
| 294 | * |
| 295 | * Calls: contextSetPriority, contextSetCacheDir, elementCreate, assignName, |
| 296 | * contextFinish, getName, objDestroy, samplerCreate |
| 297 | */ |
| 298 | TEST_F(RenderscriptHidlTest, MiscellaneousTests) { |
| 299 | context->contextSetPriority(ThreadPriorities::NORMAL); |
| 300 | context->contextSetCacheDir("/data/local/tmp/temp/"); |
| 301 | |
| 302 | Element element = context->elementCreate(DataType::UNSIGNED_8, DataKind::USER, false, 1); |
Michael Butler | 7c1ef5b | 2017-03-30 17:20:12 -0700 | [diff] [blame^] | 303 | ASSERT_NE(Element(0), element); |
| 304 | |
Michael Butler | 2d4d6d9 | 2017-03-01 15:32:30 -0800 | [diff] [blame] | 305 | std::string nameIn = "element_test_name"; |
| 306 | std::string nameOut = "not_name"; |
| 307 | hidl_string _nameIn; |
| 308 | _nameIn.setToExternal(nameIn.c_str(), nameIn.length()); |
| 309 | context->assignName(element, _nameIn); |
| 310 | context->contextFinish(); |
| 311 | context->getName(element, [&](const hidl_string& _name){ nameOut = _name.c_str(); }); |
| 312 | EXPECT_EQ("element_test_name", nameOut); |
| 313 | |
| 314 | context->objDestroy(element); |
| 315 | |
| 316 | Sampler sampler = context->samplerCreate(SamplerValue::LINEAR, SamplerValue::LINEAR, |
| 317 | SamplerValue::LINEAR, SamplerValue::LINEAR, |
| 318 | SamplerValue::LINEAR, 8.0f); |
| 319 | EXPECT_NE(Sampler(0), sampler); |
| 320 | } |