xref: /aosp_15_r20/hardware/interfaces/renderscript/1.0/vts/functional/VtsMiscellaneousTests.cpp (revision 4d7e907c777eeecc4c5bd7cf640a754fac206ff7)
1*4d7e907cSAndroid Build Coastguard Worker /*
2*4d7e907cSAndroid Build Coastguard Worker  * Copyright (C) 2017 The Android Open Source Project
3*4d7e907cSAndroid Build Coastguard Worker  *
4*4d7e907cSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*4d7e907cSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*4d7e907cSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*4d7e907cSAndroid Build Coastguard Worker  *
8*4d7e907cSAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
9*4d7e907cSAndroid Build Coastguard Worker  *
10*4d7e907cSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*4d7e907cSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*4d7e907cSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*4d7e907cSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*4d7e907cSAndroid Build Coastguard Worker  * limitations under the License.
15*4d7e907cSAndroid Build Coastguard Worker  */
16*4d7e907cSAndroid Build Coastguard Worker 
17*4d7e907cSAndroid Build Coastguard Worker #include "VtsHalRenderscriptV1_0TargetTest.h"
18*4d7e907cSAndroid Build Coastguard Worker #include <system/window.h>
19*4d7e907cSAndroid Build Coastguard Worker 
20*4d7e907cSAndroid Build Coastguard Worker /*
21*4d7e907cSAndroid Build Coastguard Worker  * ContextCreateAndDestroy:
22*4d7e907cSAndroid Build Coastguard Worker  * Creates a RenderScript context and immediately destroys the context.
23*4d7e907cSAndroid Build Coastguard Worker  * Since create and destroy calls are a part of SetUp() and TearDown(),
24*4d7e907cSAndroid Build Coastguard Worker  * the test definition is intentionally kept empty
25*4d7e907cSAndroid Build Coastguard Worker  *
26*4d7e907cSAndroid Build Coastguard Worker  * Calls: getService<IDevice>, contextCreate, contextDestroy
27*4d7e907cSAndroid Build Coastguard Worker  */
TEST_P(RenderscriptHidlTest,ContextCreateAndDestroy)28*4d7e907cSAndroid Build Coastguard Worker TEST_P(RenderscriptHidlTest, ContextCreateAndDestroy) {}
29*4d7e907cSAndroid Build Coastguard Worker 
30*4d7e907cSAndroid Build Coastguard Worker /*
31*4d7e907cSAndroid Build Coastguard Worker  * Create an Element and verify the return value is valid.
32*4d7e907cSAndroid Build Coastguard Worker  *
33*4d7e907cSAndroid Build Coastguard Worker  * Calls: elementCreate
34*4d7e907cSAndroid Build Coastguard Worker  */
TEST_P(RenderscriptHidlTest,ElementCreate)35*4d7e907cSAndroid Build Coastguard Worker TEST_P(RenderscriptHidlTest, ElementCreate) {
36*4d7e907cSAndroid Build Coastguard Worker     Element element = context->elementCreate(DataType::FLOAT_32, DataKind::USER, false, 1);
37*4d7e907cSAndroid Build Coastguard Worker     EXPECT_NE(Element(0), element);
38*4d7e907cSAndroid Build Coastguard Worker }
39*4d7e907cSAndroid Build Coastguard Worker 
40*4d7e907cSAndroid Build Coastguard Worker /*
41*4d7e907cSAndroid Build Coastguard Worker  * Create an Element, a Type and an Allocation of that type, and verify the
42*4d7e907cSAndroid Build Coastguard Worker  * return values are valid.
43*4d7e907cSAndroid Build Coastguard Worker  *
44*4d7e907cSAndroid Build Coastguard Worker  * Calls: elementCreate, typeCreate, allocationCreateTyped, allocationGetType
45*4d7e907cSAndroid Build Coastguard Worker  */
TEST_P(RenderscriptHidlTest,ElementTypeAllocationCreate)46*4d7e907cSAndroid Build Coastguard Worker TEST_P(RenderscriptHidlTest, ElementTypeAllocationCreate) {
47*4d7e907cSAndroid Build Coastguard Worker     // Element create test
48*4d7e907cSAndroid Build Coastguard Worker     Element element = context->elementCreate(DataType::FLOAT_32, DataKind::USER, false, 1);
49*4d7e907cSAndroid Build Coastguard Worker     ASSERT_NE(Element(0), element);
50*4d7e907cSAndroid Build Coastguard Worker 
51*4d7e907cSAndroid Build Coastguard Worker     // Type create test
52*4d7e907cSAndroid Build Coastguard Worker     Type type = context->typeCreate(element, 1, 0, 0, false, false, YuvFormat::YUV_NONE);
53*4d7e907cSAndroid Build Coastguard Worker     ASSERT_NE(Type(0), type);
54*4d7e907cSAndroid Build Coastguard Worker 
55*4d7e907cSAndroid Build Coastguard Worker     // Allocation create test
56*4d7e907cSAndroid Build Coastguard Worker     Allocation allocation = context->allocationCreateTyped(type, AllocationMipmapControl::NONE,
57*4d7e907cSAndroid Build Coastguard Worker                                                            (int)((uint32_t)AllocationUsageType::ALL
58*4d7e907cSAndroid Build Coastguard Worker                                                            & ~(uint32_t)AllocationUsageType::OEM),
59*4d7e907cSAndroid Build Coastguard Worker                                                            (Ptr)nullptr);
60*4d7e907cSAndroid Build Coastguard Worker     ASSERT_NE(Allocation(0), allocation);
61*4d7e907cSAndroid Build Coastguard Worker 
62*4d7e907cSAndroid Build Coastguard Worker     // Allocation type test
63*4d7e907cSAndroid Build Coastguard Worker     Type type2 = context->allocationGetType(allocation);
64*4d7e907cSAndroid Build Coastguard Worker     EXPECT_EQ(type, type2);
65*4d7e907cSAndroid Build Coastguard Worker }
66*4d7e907cSAndroid Build Coastguard Worker 
67*4d7e907cSAndroid Build Coastguard Worker /*
68*4d7e907cSAndroid Build Coastguard Worker  * Create an Element, a Type of the Element, and verify the native metadata can
69*4d7e907cSAndroid Build Coastguard Worker  * be retrieved correctly.
70*4d7e907cSAndroid Build Coastguard Worker  *
71*4d7e907cSAndroid Build Coastguard Worker  * Calls: elementCreate, typeCreate, elementGetNativeMetadata,
72*4d7e907cSAndroid Build Coastguard Worker  * typeGetNativeMetadata
73*4d7e907cSAndroid Build Coastguard Worker  */
TEST_P(RenderscriptHidlTest,MetadataTest)74*4d7e907cSAndroid Build Coastguard Worker TEST_P(RenderscriptHidlTest, MetadataTest) {
75*4d7e907cSAndroid Build Coastguard Worker     // float1
76*4d7e907cSAndroid Build Coastguard Worker     Element element = context->elementCreate(DataType::FLOAT_32, DataKind::USER, false, 1);
77*4d7e907cSAndroid Build Coastguard Worker     ASSERT_NE(Element(0), element);
78*4d7e907cSAndroid Build Coastguard Worker 
79*4d7e907cSAndroid Build Coastguard Worker     // 128 x float1
80*4d7e907cSAndroid Build Coastguard Worker     Type type = context->typeCreate(element, 128, 0, 0, false, false, YuvFormat::YUV_NONE);
81*4d7e907cSAndroid Build Coastguard Worker     ASSERT_NE(Type(0), type);
82*4d7e907cSAndroid Build Coastguard Worker 
83*4d7e907cSAndroid Build Coastguard Worker     std::vector<uint32_t> elementMetadata(5);
84*4d7e907cSAndroid Build Coastguard Worker     context->elementGetNativeMetadata(element, [&](const hidl_vec<uint32_t>& _metadata){
85*4d7e907cSAndroid Build Coastguard Worker                                           elementMetadata = _metadata; });
86*4d7e907cSAndroid Build Coastguard Worker     EXPECT_EQ(DataType::FLOAT_32, (DataType)elementMetadata[0]);
87*4d7e907cSAndroid Build Coastguard Worker     EXPECT_EQ(DataKind::USER, (DataKind)elementMetadata[1]);
88*4d7e907cSAndroid Build Coastguard Worker     EXPECT_EQ(false, elementMetadata[2]);
89*4d7e907cSAndroid Build Coastguard Worker     EXPECT_EQ(1u, (uint32_t)elementMetadata[3]);
90*4d7e907cSAndroid Build Coastguard Worker     EXPECT_EQ(0u, (uint32_t)elementMetadata[4]);
91*4d7e907cSAndroid Build Coastguard Worker 
92*4d7e907cSAndroid Build Coastguard Worker     std::vector<OpaqueHandle> typeMetadata(6);
93*4d7e907cSAndroid Build Coastguard Worker     context->typeGetNativeMetadata(type, [&typeMetadata](const hidl_vec<OpaqueHandle>& _metadata){
94*4d7e907cSAndroid Build Coastguard Worker                                    typeMetadata = _metadata; });
95*4d7e907cSAndroid Build Coastguard Worker     EXPECT_EQ(128u, (uint32_t)typeMetadata[0]);
96*4d7e907cSAndroid Build Coastguard Worker     EXPECT_EQ(0u, (uint32_t)typeMetadata[1]);
97*4d7e907cSAndroid Build Coastguard Worker     EXPECT_EQ(0u, (uint32_t)typeMetadata[2]);
98*4d7e907cSAndroid Build Coastguard Worker     EXPECT_NE(true, typeMetadata[3]);
99*4d7e907cSAndroid Build Coastguard Worker     EXPECT_NE(true, typeMetadata[4]);
100*4d7e907cSAndroid Build Coastguard Worker     EXPECT_EQ(element, (Element)typeMetadata[5]);
101*4d7e907cSAndroid Build Coastguard Worker }
102*4d7e907cSAndroid Build Coastguard Worker 
103*4d7e907cSAndroid Build Coastguard Worker /*
104*4d7e907cSAndroid Build Coastguard Worker  * Create a Allocation, and verified allocationGetPointer and allocationResize1D
105*4d7e907cSAndroid Build Coastguard Worker  * return valid values.
106*4d7e907cSAndroid Build Coastguard Worker  *
107*4d7e907cSAndroid Build Coastguard Worker  * Calls: elementCreate, typeCreate, allocationCreateTyped,
108*4d7e907cSAndroid Build Coastguard Worker  * allocationGetPointer, allocationResize1D
109*4d7e907cSAndroid Build Coastguard Worker  */
TEST_P(RenderscriptHidlTest,ResizeTest)110*4d7e907cSAndroid Build Coastguard Worker TEST_P(RenderscriptHidlTest, ResizeTest) {
111*4d7e907cSAndroid Build Coastguard Worker     // float1
112*4d7e907cSAndroid Build Coastguard Worker     Element element = context->elementCreate(DataType::FLOAT_32, DataKind::USER, false, 1);
113*4d7e907cSAndroid Build Coastguard Worker     ASSERT_NE(Element(0), element);
114*4d7e907cSAndroid Build Coastguard Worker 
115*4d7e907cSAndroid Build Coastguard Worker     // 128 x float1
116*4d7e907cSAndroid Build Coastguard Worker     Type type = context->typeCreate(element, 128, 0, 0, false, false, YuvFormat::YUV_NONE);
117*4d7e907cSAndroid Build Coastguard Worker     ASSERT_NE(Type(0), type);
118*4d7e907cSAndroid Build Coastguard Worker 
119*4d7e907cSAndroid Build Coastguard Worker     // 128 x float1
120*4d7e907cSAndroid Build Coastguard Worker     Allocation allocation = context->allocationCreateTyped(type, AllocationMipmapControl::NONE,
121*4d7e907cSAndroid Build Coastguard Worker                                                            (int)AllocationUsageType::SCRIPT,
122*4d7e907cSAndroid Build Coastguard Worker                                                            (Ptr)nullptr);
123*4d7e907cSAndroid Build Coastguard Worker     ASSERT_NE(Allocation(0), allocation);
124*4d7e907cSAndroid Build Coastguard Worker 
125*4d7e907cSAndroid Build Coastguard Worker     Ptr dataPtr1, dataPtr2;
126*4d7e907cSAndroid Build Coastguard Worker     Size stride;
127*4d7e907cSAndroid Build Coastguard Worker     context->allocationGetPointer(allocation, 0, AllocationCubemapFace::POSITIVE_X, 0,
128*4d7e907cSAndroid Build Coastguard Worker                                   [&](Ptr _dataPtr, Size _stride){
129*4d7e907cSAndroid Build Coastguard Worker                                       dataPtr1 = _dataPtr; stride = _stride; });
130*4d7e907cSAndroid Build Coastguard Worker     EXPECT_EQ(Size(0), stride);
131*4d7e907cSAndroid Build Coastguard Worker 
132*4d7e907cSAndroid Build Coastguard Worker     context->allocationResize1D(allocation, 1024*1024);
133*4d7e907cSAndroid Build Coastguard Worker     context->allocationGetPointer(allocation, 0, AllocationCubemapFace::POSITIVE_X, 0,
134*4d7e907cSAndroid Build Coastguard Worker                                   [&](Ptr _dataPtr, Size _stride){
135*4d7e907cSAndroid Build Coastguard Worker                                       dataPtr2 = _dataPtr; stride = _stride; });
136*4d7e907cSAndroid Build Coastguard Worker     EXPECT_EQ(Size(0), stride);
137*4d7e907cSAndroid Build Coastguard Worker     EXPECT_NE(dataPtr1, dataPtr2);
138*4d7e907cSAndroid Build Coastguard Worker }
139*4d7e907cSAndroid Build Coastguard Worker 
140*4d7e907cSAndroid Build Coastguard Worker /*
141*4d7e907cSAndroid Build Coastguard Worker  * Test creates two allocations, one with IO_INPUT and one with IO_OUTPUT. The
142*4d7e907cSAndroid Build Coastguard Worker  * NativeWindow (Surface) is retrieved from one allocation and set to the other.
143*4d7e907cSAndroid Build Coastguard Worker  *
144*4d7e907cSAndroid Build Coastguard Worker  * Calls: elementCreate, typeCreate, allocationCreateTyped, allocation2DWrite,
145*4d7e907cSAndroid Build Coastguard Worker  * allocationGetNativeWindow, allocationSetNativeWindow, allocationIoSend,
146*4d7e907cSAndroid Build Coastguard Worker  * allocationIoReceive, allocation2DRead
147*4d7e907cSAndroid Build Coastguard Worker  */
TEST_P(RenderscriptHidlTest,NativeWindowIoTest)148*4d7e907cSAndroid Build Coastguard Worker TEST_P(RenderscriptHidlTest, NativeWindowIoTest) {
149*4d7e907cSAndroid Build Coastguard Worker     // uint8x4
150*4d7e907cSAndroid Build Coastguard Worker     Element element = context->elementCreate(DataType::UNSIGNED_8, DataKind::USER, false, 4);
151*4d7e907cSAndroid Build Coastguard Worker     ASSERT_NE(Element(0), element);
152*4d7e907cSAndroid Build Coastguard Worker 
153*4d7e907cSAndroid Build Coastguard Worker     // 512 x 512 x uint8x4
154*4d7e907cSAndroid Build Coastguard Worker     Type type = context->typeCreate(element, 512, 512, 0, false, false, YuvFormat::YUV_NONE);
155*4d7e907cSAndroid Build Coastguard Worker     ASSERT_NE(Type(0), type);
156*4d7e907cSAndroid Build Coastguard Worker 
157*4d7e907cSAndroid Build Coastguard Worker     std::vector<uint32_t> dataIn(512*512), dataOut(512*512);
158*4d7e907cSAndroid Build Coastguard Worker     std::generate(dataIn.begin(), dataIn.end(), [](){ static uint32_t val = 0; return val++; });
159*4d7e907cSAndroid Build Coastguard Worker     hidl_vec<uint8_t> _data;
160*4d7e907cSAndroid Build Coastguard Worker     _data.setToExternal((uint8_t*)dataIn.data(), dataIn.size()*sizeof(uint32_t));
161*4d7e907cSAndroid Build Coastguard Worker     // 512 x 512 x uint8x4
162*4d7e907cSAndroid Build Coastguard Worker     Allocation allocationRecv = context->allocationCreateTyped(type, AllocationMipmapControl::NONE,
163*4d7e907cSAndroid Build Coastguard Worker                                                                (int)(AllocationUsageType::SCRIPT
164*4d7e907cSAndroid Build Coastguard Worker                                                                | AllocationUsageType::IO_INPUT),
165*4d7e907cSAndroid Build Coastguard Worker                                                                (Ptr)nullptr);
166*4d7e907cSAndroid Build Coastguard Worker     ASSERT_NE(Allocation(0), allocationRecv);
167*4d7e907cSAndroid Build Coastguard Worker 
168*4d7e907cSAndroid Build Coastguard Worker     Allocation allocationSend = context->allocationCreateTyped(type, AllocationMipmapControl::NONE,
169*4d7e907cSAndroid Build Coastguard Worker                                                                (int)(AllocationUsageType::SCRIPT
170*4d7e907cSAndroid Build Coastguard Worker                                                                | AllocationUsageType::IO_OUTPUT),
171*4d7e907cSAndroid Build Coastguard Worker                                                                (Ptr)nullptr);
172*4d7e907cSAndroid Build Coastguard Worker     ASSERT_NE(Allocation(0), allocationSend);
173*4d7e907cSAndroid Build Coastguard Worker 
174*4d7e907cSAndroid Build Coastguard Worker     NativeWindow nativeWindow = context->allocationGetNativeWindow(allocationRecv);
175*4d7e907cSAndroid Build Coastguard Worker     ASSERT_NE(NativeWindow(0), nativeWindow);
176*4d7e907cSAndroid Build Coastguard Worker 
177*4d7e907cSAndroid Build Coastguard Worker     ((ANativeWindow *)nativeWindow)->incStrong(nullptr);
178*4d7e907cSAndroid Build Coastguard Worker     native_window_api_connect((ANativeWindow*)nativeWindow,
179*4d7e907cSAndroid Build Coastguard Worker                               NATIVE_WINDOW_API_CPU);
180*4d7e907cSAndroid Build Coastguard Worker 
181*4d7e907cSAndroid Build Coastguard Worker     context->allocationSetNativeWindow(allocationSend, nativeWindow);
182*4d7e907cSAndroid Build Coastguard Worker     context->allocation2DWrite(allocationSend, 0, 0, 0, AllocationCubemapFace::POSITIVE_X, 512, 512,
183*4d7e907cSAndroid Build Coastguard Worker                                _data, 0);
184*4d7e907cSAndroid Build Coastguard Worker     context->allocationIoSend(allocationSend);
185*4d7e907cSAndroid Build Coastguard Worker     context->allocationIoReceive(allocationRecv);
186*4d7e907cSAndroid Build Coastguard Worker     context->allocation2DRead(allocationRecv, 0, 0, 0, AllocationCubemapFace::POSITIVE_X, 512, 512,
187*4d7e907cSAndroid Build Coastguard Worker                               (Ptr)dataOut.data(), (Size)dataOut.size()*sizeof(uint32_t), 0);
188*4d7e907cSAndroid Build Coastguard Worker     EXPECT_EQ(dataIn, dataOut);
189*4d7e907cSAndroid Build Coastguard Worker }
190*4d7e907cSAndroid Build Coastguard Worker 
191*4d7e907cSAndroid Build Coastguard Worker /*
192*4d7e907cSAndroid Build Coastguard Worker  * Three allocations are created, two with IO_INPUT and one with IO_OUTPUT. The
193*4d7e907cSAndroid Build Coastguard Worker  * two allocations with IO_INPUT are made to share the same BufferQueue.
194*4d7e907cSAndroid Build Coastguard Worker  *
195*4d7e907cSAndroid Build Coastguard Worker  * Calls: elementCreate, typeCreate, allocationCreateTyped,
196*4d7e907cSAndroid Build Coastguard Worker  * allocationSetupBufferQueue, allocationShareBufferQueue,
197*4d7e907cSAndroid Build Coastguard Worker  * allocationGetNativeWindow, allocationSetNativeWindow,
198*4d7e907cSAndroid Build Coastguard Worker  * allocation2DWrite, allocation2DRead, allocationIoSend,
199*4d7e907cSAndroid Build Coastguard Worker  * allocationIoReceive
200*4d7e907cSAndroid Build Coastguard Worker  */
TEST_P(RenderscriptHidlTest,BufferQueueTest)201*4d7e907cSAndroid Build Coastguard Worker TEST_P(RenderscriptHidlTest, BufferQueueTest) {
202*4d7e907cSAndroid Build Coastguard Worker     // uint8x4
203*4d7e907cSAndroid Build Coastguard Worker     Element element = context->elementCreate(DataType::UNSIGNED_8, DataKind::USER, false, 4);
204*4d7e907cSAndroid Build Coastguard Worker     ASSERT_NE(Element(0), element);
205*4d7e907cSAndroid Build Coastguard Worker 
206*4d7e907cSAndroid Build Coastguard Worker     // 512 x 512 x uint8x4
207*4d7e907cSAndroid Build Coastguard Worker     Type type = context->typeCreate(element, 512, 512, 0, false, false, YuvFormat::YUV_NONE);
208*4d7e907cSAndroid Build Coastguard Worker     ASSERT_NE(Type(0), type);
209*4d7e907cSAndroid Build Coastguard Worker 
210*4d7e907cSAndroid Build Coastguard Worker     std::vector<uint32_t> dataIn(512*512), dataOut1(512*512), dataOut2(512*512);
211*4d7e907cSAndroid Build Coastguard Worker     std::generate(dataIn.begin(), dataIn.end(), [](){ static uint32_t val = 0; return val++; });
212*4d7e907cSAndroid Build Coastguard Worker     hidl_vec<uint8_t> _data;
213*4d7e907cSAndroid Build Coastguard Worker     _data.setToExternal((uint8_t*)dataIn.data(), dataIn.size()*sizeof(uint32_t));
214*4d7e907cSAndroid Build Coastguard Worker     // 512 x 512 x uint8x4
215*4d7e907cSAndroid Build Coastguard Worker     Allocation allocationRecv1 = context->allocationCreateTyped(type, AllocationMipmapControl::NONE,
216*4d7e907cSAndroid Build Coastguard Worker                                                                 (int)(AllocationUsageType::SCRIPT
217*4d7e907cSAndroid Build Coastguard Worker                                                                 | AllocationUsageType::IO_INPUT),
218*4d7e907cSAndroid Build Coastguard Worker                                                                 (Ptr)nullptr);
219*4d7e907cSAndroid Build Coastguard Worker     ASSERT_NE(Allocation(0), allocationRecv1);
220*4d7e907cSAndroid Build Coastguard Worker 
221*4d7e907cSAndroid Build Coastguard Worker     Allocation allocationRecv2 = context->allocationCreateTyped(type, AllocationMipmapControl::NONE,
222*4d7e907cSAndroid Build Coastguard Worker                                                                 (int)(AllocationUsageType::SCRIPT
223*4d7e907cSAndroid Build Coastguard Worker                                                                 | AllocationUsageType::IO_INPUT),
224*4d7e907cSAndroid Build Coastguard Worker                                                                 (Ptr)nullptr);
225*4d7e907cSAndroid Build Coastguard Worker     ASSERT_NE(Allocation(0), allocationRecv2);
226*4d7e907cSAndroid Build Coastguard Worker 
227*4d7e907cSAndroid Build Coastguard Worker     Allocation allocationSend  = context->allocationCreateTyped(type, AllocationMipmapControl::NONE,
228*4d7e907cSAndroid Build Coastguard Worker                                                                 (int)(AllocationUsageType::SCRIPT
229*4d7e907cSAndroid Build Coastguard Worker                                                                 | AllocationUsageType::IO_INPUT),
230*4d7e907cSAndroid Build Coastguard Worker                                                                 (Ptr)nullptr);
231*4d7e907cSAndroid Build Coastguard Worker     ASSERT_NE(Allocation(0), allocationSend);
232*4d7e907cSAndroid Build Coastguard Worker 
233*4d7e907cSAndroid Build Coastguard Worker     context->allocationSetupBufferQueue(allocationRecv1, 2);
234*4d7e907cSAndroid Build Coastguard Worker     context->allocationShareBufferQueue(allocationRecv2, allocationRecv1);
235*4d7e907cSAndroid Build Coastguard Worker 
236*4d7e907cSAndroid Build Coastguard Worker     NativeWindow nativeWindow1 = context->allocationGetNativeWindow(allocationRecv1);
237*4d7e907cSAndroid Build Coastguard Worker     ASSERT_NE(NativeWindow(0), nativeWindow1);
238*4d7e907cSAndroid Build Coastguard Worker 
239*4d7e907cSAndroid Build Coastguard Worker     NativeWindow nativeWindow2 = context->allocationGetNativeWindow(allocationRecv2);
240*4d7e907cSAndroid Build Coastguard Worker     ASSERT_NE(NativeWindow(0), nativeWindow2);
241*4d7e907cSAndroid Build Coastguard Worker     EXPECT_EQ(nativeWindow2, nativeWindow1);
242*4d7e907cSAndroid Build Coastguard Worker 
243*4d7e907cSAndroid Build Coastguard Worker     ((ANativeWindow *)nativeWindow1)->incStrong(nullptr);
244*4d7e907cSAndroid Build Coastguard Worker     native_window_api_connect((ANativeWindow*)nativeWindow1,
245*4d7e907cSAndroid Build Coastguard Worker                               NATIVE_WINDOW_API_CPU);
246*4d7e907cSAndroid Build Coastguard Worker 
247*4d7e907cSAndroid Build Coastguard Worker     context->allocationSetNativeWindow(allocationSend, nativeWindow1);
248*4d7e907cSAndroid Build Coastguard Worker     context->allocation2DWrite(allocationSend, 0, 0, 0, AllocationCubemapFace::POSITIVE_X, 512, 512,
249*4d7e907cSAndroid Build Coastguard Worker                                _data, 0);
250*4d7e907cSAndroid Build Coastguard Worker     context->allocationIoSend(allocationSend);
251*4d7e907cSAndroid Build Coastguard Worker     context->allocationIoReceive(allocationRecv1);
252*4d7e907cSAndroid Build Coastguard Worker     context->allocation2DRead(allocationRecv1, 0, 0, 0, AllocationCubemapFace::POSITIVE_X, 512, 512,
253*4d7e907cSAndroid Build Coastguard Worker                               (Ptr)dataOut1.data(), (Size)dataOut1.size()*sizeof(uint32_t), 0);
254*4d7e907cSAndroid Build Coastguard Worker     EXPECT_EQ(dataIn, dataOut1);
255*4d7e907cSAndroid Build Coastguard Worker 
256*4d7e907cSAndroid Build Coastguard Worker     context->allocation2DWrite(allocationSend, 0, 0, 0, AllocationCubemapFace::POSITIVE_X, 512, 512,
257*4d7e907cSAndroid Build Coastguard Worker                                _data, 0);
258*4d7e907cSAndroid Build Coastguard Worker     context->allocationIoSend(allocationSend);
259*4d7e907cSAndroid Build Coastguard Worker     context->allocationIoReceive(allocationRecv2);
260*4d7e907cSAndroid Build Coastguard Worker     context->allocation2DRead(allocationRecv2, 0, 0, 0, AllocationCubemapFace::POSITIVE_X, 512, 512,
261*4d7e907cSAndroid Build Coastguard Worker                               (Ptr)dataOut2.data(), (Size)dataOut2.size()*sizeof(uint32_t), 0);
262*4d7e907cSAndroid Build Coastguard Worker     EXPECT_EQ(dataIn, dataOut2);
263*4d7e907cSAndroid Build Coastguard Worker }
264*4d7e907cSAndroid Build Coastguard Worker 
265*4d7e907cSAndroid Build Coastguard Worker /*
266*4d7e907cSAndroid Build Coastguard Worker  * This test sets up the message queue, sends a message, peeks at the message,
267*4d7e907cSAndroid Build Coastguard Worker  * and reads it back.
268*4d7e907cSAndroid Build Coastguard Worker  *
269*4d7e907cSAndroid Build Coastguard Worker  * Calls: contextInitToClient, contextSendMessage, contextPeekMessage,
270*4d7e907cSAndroid Build Coastguard Worker  * contextGetMessage, contextDeinitToClient, contextLog
271*4d7e907cSAndroid Build Coastguard Worker  */
TEST_P(RenderscriptHidlTest,ContextMessageTest)272*4d7e907cSAndroid Build Coastguard Worker TEST_P(RenderscriptHidlTest, ContextMessageTest) {
273*4d7e907cSAndroid Build Coastguard Worker     context->contextInitToClient();
274*4d7e907cSAndroid Build Coastguard Worker 
275*4d7e907cSAndroid Build Coastguard Worker     const char * message = "correct";
276*4d7e907cSAndroid Build Coastguard Worker     std::vector<char> messageSend(message, message + sizeof(message));
277*4d7e907cSAndroid Build Coastguard Worker     hidl_vec<uint8_t> _data;
278*4d7e907cSAndroid Build Coastguard Worker     _data.setToExternal((uint8_t*)messageSend.data(), messageSend.size());
279*4d7e907cSAndroid Build Coastguard Worker     context->contextSendMessage(0, _data);
280*4d7e907cSAndroid Build Coastguard Worker     MessageToClientType messageType;
281*4d7e907cSAndroid Build Coastguard Worker     size_t size;
282*4d7e907cSAndroid Build Coastguard Worker     uint32_t subID;
283*4d7e907cSAndroid Build Coastguard Worker     context->contextPeekMessage([&](MessageToClientType _type, Size _size, uint32_t _subID){
284*4d7e907cSAndroid Build Coastguard Worker                                 messageType = _type; size = (uint32_t)_size; subID = _subID; });
285*4d7e907cSAndroid Build Coastguard Worker     std::vector<char> messageRecv(size, '\0');
286*4d7e907cSAndroid Build Coastguard Worker     context->contextGetMessage(messageRecv.data(), messageRecv.size(),
287*4d7e907cSAndroid Build Coastguard Worker                                [&](MessageToClientType _type, Size _size){
288*4d7e907cSAndroid Build Coastguard Worker                                messageType = _type; size = (uint32_t)_size; });
289*4d7e907cSAndroid Build Coastguard Worker     EXPECT_EQ(messageSend, messageRecv);
290*4d7e907cSAndroid Build Coastguard Worker 
291*4d7e907cSAndroid Build Coastguard Worker     context->contextDeinitToClient();
292*4d7e907cSAndroid Build Coastguard Worker     context->contextLog();
293*4d7e907cSAndroid Build Coastguard Worker }
294*4d7e907cSAndroid Build Coastguard Worker 
295*4d7e907cSAndroid Build Coastguard Worker /*
296*4d7e907cSAndroid Build Coastguard Worker  * Call through a bunch of APIs and make sure they don’t crash. Assign the name
297*4d7e907cSAndroid Build Coastguard Worker  * of a object and check getName returns the name just set.
298*4d7e907cSAndroid Build Coastguard Worker  *
299*4d7e907cSAndroid Build Coastguard Worker  * Calls: contextSetPriority, contextSetCacheDir, elementCreate, assignName,
300*4d7e907cSAndroid Build Coastguard Worker  * contextFinish, getName, objDestroy, samplerCreate
301*4d7e907cSAndroid Build Coastguard Worker  */
TEST_P(RenderscriptHidlTest,MiscellaneousTests)302*4d7e907cSAndroid Build Coastguard Worker TEST_P(RenderscriptHidlTest, MiscellaneousTests) {
303*4d7e907cSAndroid Build Coastguard Worker     context->contextSetPriority(ThreadPriorities::NORMAL);
304*4d7e907cSAndroid Build Coastguard Worker     context->contextSetCacheDir("/data/local/tmp/temp/");
305*4d7e907cSAndroid Build Coastguard Worker 
306*4d7e907cSAndroid Build Coastguard Worker     Element element = context->elementCreate(DataType::UNSIGNED_8, DataKind::USER, false, 1);
307*4d7e907cSAndroid Build Coastguard Worker     ASSERT_NE(Element(0), element);
308*4d7e907cSAndroid Build Coastguard Worker 
309*4d7e907cSAndroid Build Coastguard Worker     std::string nameIn = "element_test_name";
310*4d7e907cSAndroid Build Coastguard Worker     std::string nameOut = "not_name";
311*4d7e907cSAndroid Build Coastguard Worker     hidl_string _nameIn;
312*4d7e907cSAndroid Build Coastguard Worker     _nameIn.setToExternal(nameIn.c_str(), nameIn.length());
313*4d7e907cSAndroid Build Coastguard Worker     context->assignName(element, _nameIn);
314*4d7e907cSAndroid Build Coastguard Worker     context->contextFinish();
315*4d7e907cSAndroid Build Coastguard Worker     context->getName(element, [&](const hidl_string& _name){ nameOut = _name.c_str(); });
316*4d7e907cSAndroid Build Coastguard Worker     EXPECT_EQ("element_test_name", nameOut);
317*4d7e907cSAndroid Build Coastguard Worker 
318*4d7e907cSAndroid Build Coastguard Worker     context->objDestroy(element);
319*4d7e907cSAndroid Build Coastguard Worker 
320*4d7e907cSAndroid Build Coastguard Worker     Sampler sampler = context->samplerCreate(SamplerValue::LINEAR, SamplerValue::LINEAR,
321*4d7e907cSAndroid Build Coastguard Worker                                              SamplerValue::LINEAR, SamplerValue::LINEAR,
322*4d7e907cSAndroid Build Coastguard Worker                                              SamplerValue::LINEAR, 8.0f);
323*4d7e907cSAndroid Build Coastguard Worker     EXPECT_NE(Sampler(0), sampler);
324*4d7e907cSAndroid Build Coastguard Worker }
325