blob: 23b09ac53c00d5b284db8862ffab9cdae0bd0b35 [file] [log] [blame]
Michael Butler2d4d6d92017-03-01 15:32:30 -08001/*
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 Butlerda8c2c12017-03-17 13:02:53 -070018#include <system/window.h>
Michael Butler2d4d6d92017-03-01 15:32:30 -080019
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 */
28TEST_F(RenderscriptHidlTest, ContextCreateAndDestroy) {}
29
30/*
31 * Create an Element and verify the return value is valid.
32 *
33 * Calls: elementCreate
34 */
35TEST_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 */
46TEST_F(RenderscriptHidlTest, ElementTypeAllocationCreate) {
47 // Element create test
48 Element element = context->elementCreate(DataType::FLOAT_32, DataKind::USER, false, 1);
Michael Butler7c1ef5b2017-03-30 17:20:12 -070049 ASSERT_NE(Element(0), element);
Michael Butler2d4d6d92017-03-01 15:32:30 -080050
51 // Type create test
52 Type type = context->typeCreate(element, 1, 0, 0, false, false, YuvFormat::YUV_NONE);
Michael Butler7c1ef5b2017-03-30 17:20:12 -070053 ASSERT_NE(Type(0), type);
Michael Butler2d4d6d92017-03-01 15:32:30 -080054
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 Butler7c1ef5b2017-03-30 17:20:12 -070060 ASSERT_NE(Allocation(0), allocation);
Michael Butler2d4d6d92017-03-01 15:32:30 -080061
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 */
74TEST_F(RenderscriptHidlTest, MetadataTest) {
75 // float1
76 Element element = context->elementCreate(DataType::FLOAT_32, DataKind::USER, false, 1);
Michael Butler7c1ef5b2017-03-30 17:20:12 -070077 ASSERT_NE(Element(0), element);
78
Michael Butler2d4d6d92017-03-01 15:32:30 -080079 // 128 x float1
80 Type type = context->typeCreate(element, 128, 0, 0, false, false, YuvFormat::YUV_NONE);
Michael Butler7c1ef5b2017-03-30 17:20:12 -070081 ASSERT_NE(Type(0), type);
Michael Butler2d4d6d92017-03-01 15:32:30 -080082
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 Butlerda8c2c12017-03-17 13:02:53 -070088 EXPECT_EQ(false, elementMetadata[2]);
Michael Butler2d4d6d92017-03-01 15:32:30 -080089 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 */
110TEST_F(RenderscriptHidlTest, ResizeTest) {
111 // float1
112 Element element = context->elementCreate(DataType::FLOAT_32, DataKind::USER, false, 1);
Michael Butler7c1ef5b2017-03-30 17:20:12 -0700113 ASSERT_NE(Element(0), element);
114
Michael Butler2d4d6d92017-03-01 15:32:30 -0800115 // 128 x float1
116 Type type = context->typeCreate(element, 128, 0, 0, false, false, YuvFormat::YUV_NONE);
Michael Butler7c1ef5b2017-03-30 17:20:12 -0700117 ASSERT_NE(Type(0), type);
118
Michael Butler2d4d6d92017-03-01 15:32:30 -0800119 // 128 x float1
120 Allocation allocation = context->allocationCreateTyped(type, AllocationMipmapControl::NONE,
121 (int)AllocationUsageType::SCRIPT,
122 (Ptr)nullptr);
Michael Butler7c1ef5b2017-03-30 17:20:12 -0700123 ASSERT_NE(Allocation(0), allocation);
124
Michael Butler2d4d6d92017-03-01 15:32:30 -0800125 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 Butler7c1ef5b2017-03-30 17:20:12 -0700130 EXPECT_EQ(Size(0), stride);
Michael Butler2d4d6d92017-03-01 15:32:30 -0800131
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 Butler7c1ef5b2017-03-30 17:20:12 -0700136 EXPECT_EQ(Size(0), stride);
Michael Butler2d4d6d92017-03-01 15:32:30 -0800137 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 Butler2d4d6d92017-03-01 15:32:30 -0800147 */
Michael Butler2d4d6d92017-03-01 15:32:30 -0800148TEST_F(RenderscriptHidlTest, NativeWindowIoTest) {
149 // uint8x4
150 Element element = context->elementCreate(DataType::UNSIGNED_8, DataKind::USER, false, 4);
Michael Butler7c1ef5b2017-03-30 17:20:12 -0700151 ASSERT_NE(Element(0), element);
152
Michael Butler2d4d6d92017-03-01 15:32:30 -0800153 // 512 x 512 x uint8x4
154 Type type = context->typeCreate(element, 512, 512, 0, false, false, YuvFormat::YUV_NONE);
Michael Butler7c1ef5b2017-03-30 17:20:12 -0700155 ASSERT_NE(Type(0), type);
156
Michael Butler2d4d6d92017-03-01 15:32:30 -0800157 std::vector<uint32_t> dataIn(512*512), dataOut(512*512);
Michael Butlerda8c2c12017-03-17 13:02:53 -0700158 std::generate(dataIn.begin(), dataIn.end(), [](){ static uint32_t val = 0; return val++; });
Michael Butler2d4d6d92017-03-01 15:32:30 -0800159 hidl_vec<uint8_t> _data;
160 _data.setToExternal((uint8_t*)dataIn.data(), dataIn.size()*sizeof(uint32_t));
Michael Butlerda8c2c12017-03-17 13:02:53 -0700161 // 512 x 512 x uint8x4
Michael Butler2d4d6d92017-03-01 15:32:30 -0800162 Allocation allocationRecv = context->allocationCreateTyped(type, AllocationMipmapControl::NONE,
163 (int)(AllocationUsageType::SCRIPT
164 | AllocationUsageType::IO_INPUT),
165 (Ptr)nullptr);
Michael Butler7c1ef5b2017-03-30 17:20:12 -0700166 ASSERT_NE(Allocation(0), allocationRecv);
167
Michael Butler2d4d6d92017-03-01 15:32:30 -0800168 Allocation allocationSend = context->allocationCreateTyped(type, AllocationMipmapControl::NONE,
169 (int)(AllocationUsageType::SCRIPT
170 | AllocationUsageType::IO_OUTPUT),
171 (Ptr)nullptr);
Michael Butler7c1ef5b2017-03-30 17:20:12 -0700172 ASSERT_NE(Allocation(0), allocationSend);
173
Michael Butler2d4d6d92017-03-01 15:32:30 -0800174 NativeWindow nativeWindow = context->allocationGetNativeWindow(allocationRecv);
Michael Butler7c1ef5b2017-03-30 17:20:12 -0700175 ASSERT_NE(NativeWindow(0), nativeWindow);
Michael Butler2d4d6d92017-03-01 15:32:30 -0800176
Michael Butlerda8c2c12017-03-17 13:02:53 -0700177 ((ANativeWindow *)nativeWindow)->incStrong(nullptr);
178
Michael Butler2d4d6d92017-03-01 15:32:30 -0800179 context->allocationSetNativeWindow(allocationSend, nativeWindow);
Michael Butlerda8c2c12017-03-17 13:02:53 -0700180 context->allocation2DWrite(allocationSend, 0, 0, 0, AllocationCubemapFace::POSITIVE_X, 512, 512,
181 _data, 0);
Michael Butler2d4d6d92017-03-01 15:32:30 -0800182 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 Butlerda8c2c12017-03-17 13:02:53 -0700186 EXPECT_EQ(dataIn, dataOut);
Michael Butler2d4d6d92017-03-01 15:32:30 -0800187}
Michael Butler2d4d6d92017-03-01 15:32:30 -0800188
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 Butler7c1ef5b2017-03-30 17:20:12 -0700194 * allocationSetupBufferQueue, allocationShareBufferQueue,
195 * allocationGetNativeWindow, allocationSetNativeWindow,
196 * allocation2DWrite, allocation2DRead, allocationIoSend,
197 * allocationIoReceive
Michael Butler2d4d6d92017-03-01 15:32:30 -0800198 */
Michael Butler2d4d6d92017-03-01 15:32:30 -0800199TEST_F(RenderscriptHidlTest, BufferQueueTest) {
Michael Butlerda8c2c12017-03-17 13:02:53 -0700200 // uint8x4
201 Element element = context->elementCreate(DataType::UNSIGNED_8, DataKind::USER, false, 4);
Michael Butler7c1ef5b2017-03-30 17:20:12 -0700202 ASSERT_NE(Element(0), element);
203
Michael Butlerda8c2c12017-03-17 13:02:53 -0700204 // 512 x 512 x uint8x4
Michael Butler2d4d6d92017-03-01 15:32:30 -0800205 Type type = context->typeCreate(element, 512, 512, 0, false, false, YuvFormat::YUV_NONE);
Michael Butler7c1ef5b2017-03-30 17:20:12 -0700206 ASSERT_NE(Type(0), type);
207
Michael Butlerda8c2c12017-03-17 13:02:53 -0700208 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 Butler2d4d6d92017-03-01 15:32:30 -0800210 hidl_vec<uint8_t> _data;
Michael Butlerda8c2c12017-03-17 13:02:53 -0700211 _data.setToExternal((uint8_t*)dataIn.data(), dataIn.size()*sizeof(uint32_t));
212 // 512 x 512 x uint8x4
Michael Butler2d4d6d92017-03-01 15:32:30 -0800213 Allocation allocationRecv1 = context->allocationCreateTyped(type, AllocationMipmapControl::NONE,
214 (int)(AllocationUsageType::SCRIPT
215 | AllocationUsageType::IO_INPUT),
216 (Ptr)nullptr);
Michael Butler7c1ef5b2017-03-30 17:20:12 -0700217 ASSERT_NE(Allocation(0), allocationRecv1);
218
Michael Butler2d4d6d92017-03-01 15:32:30 -0800219 Allocation allocationRecv2 = context->allocationCreateTyped(type, AllocationMipmapControl::NONE,
220 (int)(AllocationUsageType::SCRIPT
221 | AllocationUsageType::IO_INPUT),
222 (Ptr)nullptr);
Michael Butler7c1ef5b2017-03-30 17:20:12 -0700223 ASSERT_NE(Allocation(0), allocationRecv2);
224
Michael Butlerda8c2c12017-03-17 13:02:53 -0700225 Allocation allocationSend = context->allocationCreateTyped(type, AllocationMipmapControl::NONE,
226 (int)(AllocationUsageType::SCRIPT
227 | AllocationUsageType::IO_INPUT),
228 (Ptr)nullptr);
Michael Butler7c1ef5b2017-03-30 17:20:12 -0700229 ASSERT_NE(Allocation(0), allocationSend);
230
Michael Butler2d4d6d92017-03-01 15:32:30 -0800231 context->allocationSetupBufferQueue(allocationRecv1, 2);
Michael Butlerda8c2c12017-03-17 13:02:53 -0700232 context->allocationShareBufferQueue(allocationRecv2, allocationRecv1);
233
234 NativeWindow nativeWindow1 = context->allocationGetNativeWindow(allocationRecv1);
Michael Butler7c1ef5b2017-03-30 17:20:12 -0700235 ASSERT_NE(NativeWindow(0), nativeWindow1);
236
Michael Butlerda8c2c12017-03-17 13:02:53 -0700237 NativeWindow nativeWindow2 = context->allocationGetNativeWindow(allocationRecv2);
Michael Butler7c1ef5b2017-03-30 17:20:12 -0700238 ASSERT_NE(NativeWindow(0), nativeWindow2);
Michael Butlerda8c2c12017-03-17 13:02:53 -0700239 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 Butler2d4d6d92017-03-01 15:32:30 -0800259}
Michael Butler2d4d6d92017-03-01 15:32:30 -0800260
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 Butler2d4d6d92017-03-01 15:32:30 -0800267 */
Michael Butler2d4d6d92017-03-01 15:32:30 -0800268TEST_F(RenderscriptHidlTest, ContextMessageTest) {
269 context->contextInitToClient();
270
Michael Butlerda8c2c12017-03-17 13:02:53 -0700271 const char * message = "correct";
272 std::vector<char> messageSend(message, message + sizeof(message));
Michael Butler2d4d6d92017-03-01 15:32:30 -0800273 hidl_vec<uint8_t> _data;
Michael Butlerda8c2c12017-03-17 13:02:53 -0700274 _data.setToExternal((uint8_t*)messageSend.data(), messageSend.size());
Michael Butler2d4d6d92017-03-01 15:32:30 -0800275 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 Butlerda8c2c12017-03-17 13:02:53 -0700281 std::vector<char> messageRecv(size, '\0');
282 context->contextGetMessage(messageRecv.data(), messageRecv.size(),
Michael Butler2d4d6d92017-03-01 15:32:30 -0800283 [&](MessageToClientType _type, Size _size){
284 messageType = _type; size = (uint32_t)_size; });
Michael Butlerda8c2c12017-03-17 13:02:53 -0700285 EXPECT_EQ(messageSend, messageRecv);
Michael Butler2d4d6d92017-03-01 15:32:30 -0800286
287 context->contextDeinitToClient();
288 context->contextLog();
289}
Michael Butler2d4d6d92017-03-01 15:32:30 -0800290
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 */
298TEST_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 Butler7c1ef5b2017-03-30 17:20:12 -0700303 ASSERT_NE(Element(0), element);
304
Michael Butler2d4d6d92017-03-01 15:32:30 -0800305 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}