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