blob: 39d63ca9f956bd6a95ccd5ab27f59d53fa252759 [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);
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 */
74TEST_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 Butlerda8c2c12017-03-17 13:02:53 -070085 EXPECT_EQ(false, elementMetadata[2]);
Michael Butler2d4d6d92017-03-01 15:32:30 -080086 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 */
107TEST_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 Butler2d4d6d92017-03-01 15:32:30 -0800138 */
Michael Butler2d4d6d92017-03-01 15:32:30 -0800139TEST_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 Butlerda8c2c12017-03-17 13:02:53 -0700145 std::generate(dataIn.begin(), dataIn.end(), [](){ static uint32_t val = 0; return val++; });
Michael Butler2d4d6d92017-03-01 15:32:30 -0800146 hidl_vec<uint8_t> _data;
147 _data.setToExternal((uint8_t*)dataIn.data(), dataIn.size()*sizeof(uint32_t));
Michael Butlerda8c2c12017-03-17 13:02:53 -0700148 // 512 x 512 x uint8x4
Michael Butler2d4d6d92017-03-01 15:32:30 -0800149 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 Butler2d4d6d92017-03-01 15:32:30 -0800157 NativeWindow nativeWindow = context->allocationGetNativeWindow(allocationRecv);
158 EXPECT_NE(NativeWindow(0), nativeWindow);
159
Michael Butlerda8c2c12017-03-17 13:02:53 -0700160 ((ANativeWindow *)nativeWindow)->incStrong(nullptr);
161
Michael Butler2d4d6d92017-03-01 15:32:30 -0800162 context->allocationSetNativeWindow(allocationSend, nativeWindow);
Michael Butlerda8c2c12017-03-17 13:02:53 -0700163 context->allocation2DWrite(allocationSend, 0, 0, 0, AllocationCubemapFace::POSITIVE_X, 512, 512,
164 _data, 0);
Michael Butler2d4d6d92017-03-01 15:32:30 -0800165 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 Butlerda8c2c12017-03-17 13:02:53 -0700169 EXPECT_EQ(dataIn, dataOut);
Michael Butler2d4d6d92017-03-01 15:32:30 -0800170}
Michael Butler2d4d6d92017-03-01 15:32:30 -0800171
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 Butler2d4d6d92017-03-01 15:32:30 -0800179 */
Michael Butler2d4d6d92017-03-01 15:32:30 -0800180TEST_F(RenderscriptHidlTest, BufferQueueTest) {
Michael Butlerda8c2c12017-03-17 13:02:53 -0700181 // uint8x4
182 Element element = context->elementCreate(DataType::UNSIGNED_8, DataKind::USER, false, 4);
183 // 512 x 512 x uint8x4
Michael Butler2d4d6d92017-03-01 15:32:30 -0800184 Type type = context->typeCreate(element, 512, 512, 0, false, false, YuvFormat::YUV_NONE);
Michael Butlerda8c2c12017-03-17 13:02:53 -0700185 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 Butler2d4d6d92017-03-01 15:32:30 -0800187 hidl_vec<uint8_t> _data;
Michael Butlerda8c2c12017-03-17 13:02:53 -0700188 _data.setToExternal((uint8_t*)dataIn.data(), dataIn.size()*sizeof(uint32_t));
189 // 512 x 512 x uint8x4
Michael Butler2d4d6d92017-03-01 15:32:30 -0800190 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 Butlerda8c2c12017-03-17 13:02:53 -0700198 Allocation allocationSend = context->allocationCreateTyped(type, AllocationMipmapControl::NONE,
199 (int)(AllocationUsageType::SCRIPT
200 | AllocationUsageType::IO_INPUT),
201 (Ptr)nullptr);
Michael Butler2d4d6d92017-03-01 15:32:30 -0800202 context->allocationSetupBufferQueue(allocationRecv1, 2);
Michael Butlerda8c2c12017-03-17 13:02:53 -0700203 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 Butler2d4d6d92017-03-01 15:32:30 -0800228}
Michael Butler2d4d6d92017-03-01 15:32:30 -0800229
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 Butler2d4d6d92017-03-01 15:32:30 -0800236 */
Michael Butler2d4d6d92017-03-01 15:32:30 -0800237TEST_F(RenderscriptHidlTest, ContextMessageTest) {
238 context->contextInitToClient();
239
Michael Butlerda8c2c12017-03-17 13:02:53 -0700240 const char * message = "correct";
241 std::vector<char> messageSend(message, message + sizeof(message));
Michael Butler2d4d6d92017-03-01 15:32:30 -0800242 hidl_vec<uint8_t> _data;
Michael Butlerda8c2c12017-03-17 13:02:53 -0700243 _data.setToExternal((uint8_t*)messageSend.data(), messageSend.size());
Michael Butler2d4d6d92017-03-01 15:32:30 -0800244 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 Butlerda8c2c12017-03-17 13:02:53 -0700250 std::vector<char> messageRecv(size, '\0');
251 context->contextGetMessage(messageRecv.data(), messageRecv.size(),
Michael Butler2d4d6d92017-03-01 15:32:30 -0800252 [&](MessageToClientType _type, Size _size){
253 messageType = _type; size = (uint32_t)_size; });
Michael Butlerda8c2c12017-03-17 13:02:53 -0700254 EXPECT_EQ(messageSend, messageRecv);
Michael Butler2d4d6d92017-03-01 15:32:30 -0800255
256 context->contextDeinitToClient();
257 context->contextLog();
258}
Michael Butler2d4d6d92017-03-01 15:32:30 -0800259
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 */
267TEST_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}