1 //
2 // Copyright (C) 2020 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 #define LOG_TAG "VtsHalSurroundViewTest"
18 
19 #include <android/hardware/automotive/sv/1.0/types.h>
20 #include <android/hardware/automotive/sv/1.0/ISurroundViewService.h>
21 #include <android/hardware/automotive/sv/1.0/ISurroundViewStream.h>
22 #include <android/hardware/automotive/sv/1.0/ISurroundView2dSession.h>
23 #include <android/hardware/automotive/sv/1.0/ISurroundView3dSession.h>
24 #include <android/hardware_buffer.h>
25 #include <android/hidl/allocator/1.0/IAllocator.h>
26 #include <android/hidl/memory/1.0/IMemory.h>
27 #include <hidlmemory/mapping.h>
28 #include <math.h>
29 #include <utils/Log.h>
30 
31 #include <gtest/gtest.h>
32 #include <hidl/GtestPrinter.h>
33 #include <hidl/ServiceManagement.h>
34 
35 #include "SurroundViewStreamHandler.h"
36 
37 using namespace ::android::hardware::automotive::sv::V1_0;
38 using ::android::sp;
39 using ::android::hardware::hidl_vec;
40 using ::android::hardware::hidl_string;
41 using ::android::hidl::allocator::V1_0::IAllocator;
42 using ::android::hidl::memory::V1_0::IMemory;
43 using ::android::hardware::hidl_memory;
44 
45 const int kVertexByteSize = (3 * sizeof(float)) + 4;
46 const int kIdByteSize = 2;
47 
48 // The main test class for Surround View Service
49 class SurroundViewHidlTest : public ::testing::TestWithParam<std::string> {
50 public:
SetUp()51     virtual void SetUp() override {
52         mSurroundViewService = ISurroundViewService::getService(GetParam());
53         ASSERT_NE(mSurroundViewService.get(), nullptr);
54     }
55 
TearDown()56     virtual void TearDown() override {}
57 
58     sp<ISurroundViewService> mSurroundViewService;    // Every test needs access to the service
59 };
60 
TEST_P(SurroundViewHidlTest,startAndStop2dSession)61 TEST_P(SurroundViewHidlTest, startAndStop2dSession) {
62     ALOGD("SurroundViewHidlTest::startAndStop2dSession");
63     sp<ISurroundView2dSession> surroundView2dSession;
64     mSurroundViewService->start2dSession(
65         [&surroundView2dSession](
66             const sp<ISurroundView2dSession>& session, SvResult result) {
67         ASSERT_EQ(result, SvResult::OK);
68         surroundView2dSession = session;
69     });
70 
71     SvResult result = mSurroundViewService->stop2dSession(surroundView2dSession);
72     ASSERT_EQ(result, SvResult::OK);
73 }
74 
TEST_P(SurroundViewHidlTest,stopInvalid2dSession)75 TEST_P(SurroundViewHidlTest, stopInvalid2dSession) {
76     ALOGD("SurroundViewHidlTest::stopInvalid2dSession");
77     sp<ISurroundView2dSession> surroundView2dSession;
78     SvResult result = mSurroundViewService->stop2dSession(surroundView2dSession);
79     ASSERT_NE(result, SvResult::OK);
80 }
81 
TEST_P(SurroundViewHidlTest,startAndStop2dStream)82 TEST_P(SurroundViewHidlTest, startAndStop2dStream) {
83     ALOGD("SurroundViewHidlTest::startAndStop2dStream");
84     sp<ISurroundView2dSession> surroundView2dSession;
85     mSurroundViewService->start2dSession(
86         [&surroundView2dSession](
87             const sp<ISurroundView2dSession>& session, SvResult result) {
88         ASSERT_EQ(result, SvResult::OK);
89         surroundView2dSession = session;
90     });
91 
92     sp<SurroundViewServiceHandler> handler =
93         new SurroundViewServiceHandler(surroundView2dSession);
94 
95     SvResult result = surroundView2dSession->startStream(handler);
96     EXPECT_EQ(result, SvResult::OK);
97 
98     sleep(5);
99 
100     EXPECT_TRUE(handler->checkEventReceived(SvEvent::STREAM_STARTED));
101     EXPECT_GT(handler->getReceiveFramesCount(), 0);
102 
103     surroundView2dSession->stopStream();
104 
105     sleep(1);
106     EXPECT_TRUE(handler->checkEventReceived(SvEvent::STREAM_STOPPED));
107 
108     result = mSurroundViewService->stop2dSession(surroundView2dSession);
109     EXPECT_EQ(result, SvResult::OK);
110 }
111 
TEST_P(SurroundViewHidlTest,start2dStreamWithoutReturningFrames)112 TEST_P(SurroundViewHidlTest, start2dStreamWithoutReturningFrames) {
113     ALOGD("SurroundViewHidlTest::start2dStreamWithoutReturningFrames");
114     sp<ISurroundView2dSession> surroundView2dSession;
115     mSurroundViewService->start2dSession(
116         [&surroundView2dSession](
117             const sp<ISurroundView2dSession>& session, SvResult result) {
118         ASSERT_EQ(result, SvResult::OK);
119         surroundView2dSession = session;
120     });
121 
122     sp<SurroundViewServiceHandler> handler =
123         new SurroundViewServiceHandler(surroundView2dSession);
124     handler->setDoNotReturnFrames(true);
125 
126     SvResult result = surroundView2dSession->startStream(handler);
127     EXPECT_EQ(result, SvResult::OK);
128 
129     sleep(5);
130 
131     EXPECT_TRUE(handler->checkEventReceived(SvEvent::STREAM_STARTED));
132     EXPECT_TRUE(handler->checkEventReceived(SvEvent::FRAME_DROPPED));
133     EXPECT_GT(handler->getReceiveFramesCount(), 0);
134 
135     surroundView2dSession->stopStream();
136 
137     sleep(1);
138     EXPECT_TRUE(handler->checkEventReceived(SvEvent::STREAM_STOPPED));
139 
140     result = mSurroundViewService->stop2dSession(surroundView2dSession);
141     EXPECT_EQ(result, SvResult::OK);
142 }
143 
TEST_P(SurroundViewHidlTest,duplicateStart2dStream)144 TEST_P(SurroundViewHidlTest, duplicateStart2dStream) {
145     ALOGD("SurroundViewHidlTest, duplicateStart2dStream");
146     sp<ISurroundView2dSession> surroundView2dSession;
147     mSurroundViewService->start2dSession(
148         [&surroundView2dSession](
149             const sp<ISurroundView2dSession>& session, SvResult result) {
150         ASSERT_EQ(result, SvResult::OK);
151         surroundView2dSession = session;
152     });
153 
154     sp<SurroundViewServiceHandler> handler =
155         new SurroundViewServiceHandler(surroundView2dSession);
156 
157     SvResult result = surroundView2dSession->startStream(handler);
158     EXPECT_EQ(result, SvResult::OK);
159 
160     result = surroundView2dSession->startStream(handler);
161     EXPECT_NE(result, SvResult::OK);
162 
163     surroundView2dSession->stopStream();
164     mSurroundViewService->stop2dSession(surroundView2dSession);
165 }
166 
TEST_P(SurroundViewHidlTest,stopInvalid2dStream)167 TEST_P(SurroundViewHidlTest, stopInvalid2dStream) {
168     ALOGD("SurroundViewHidlTest, stopInvalid2dStream");
169     sp<ISurroundView2dSession> surroundView2dSession;
170     mSurroundViewService->start2dSession(
171         [&surroundView2dSession](
172             const sp<ISurroundView2dSession>& session, SvResult result) {
173         ASSERT_EQ(result, SvResult::OK);
174         surroundView2dSession = session;
175     });
176 
177     sp<SurroundViewServiceHandler> handler =
178         new SurroundViewServiceHandler(surroundView2dSession);
179 
180     surroundView2dSession->stopStream();
181     mSurroundViewService->stop2dSession(surroundView2dSession);
182 }
183 
TEST_P(SurroundViewHidlTest,validate2dSvFramesDesc)184 TEST_P(SurroundViewHidlTest, validate2dSvFramesDesc) {
185     ALOGD("SurroundViewHidlTest, validate2dSvFramesDesc");
186     sp<ISurroundView2dSession> surroundView2dSession;
187     mSurroundViewService->start2dSession(
188         [&surroundView2dSession](
189             const sp<ISurroundView2dSession>& session, SvResult result) {
190         ASSERT_EQ(result, SvResult::OK);
191         surroundView2dSession = session;
192     });
193 
194     sp<SurroundViewServiceHandler> handler =
195         new SurroundViewServiceHandler(surroundView2dSession);
196 
197     SvResult result = surroundView2dSession->startStream(handler);
198     EXPECT_EQ(result, SvResult::OK);
199 
200     sleep(5);
201 
202     // Validate timestampNs and sequenceId
203     EXPECT_GT(handler->getReceiveFramesCount(), 0);
204     EXPECT_TRUE(handler->areAllFramesValid());
205 
206     // Validate 2d SvFramesDesc. Do not compare nativeHandle since it is not
207     // stored and already verified on the fly.
208     SvFramesDesc frames = handler->getLastReceivedFrames();
209     EXPECT_EQ(frames.svBuffers.size(), 1);
210 
211     SvBuffer svBuffer2d = frames.svBuffers[0];
212     EXPECT_EQ(svBuffer2d.viewId, 0);
213 
214     const AHardwareBuffer_Desc* pDesc =
215         reinterpret_cast<const AHardwareBuffer_Desc *>(&svBuffer2d.hardwareBuffer.description);
216     float mapWidth, mapHeight;
217     surroundView2dSession->get2dMappingInfo([&mapWidth, &mapHeight] (Sv2dMappingInfo info) {
218         mapWidth = info.width;
219         mapHeight = info.height;
220     });
221     EXPECT_EQ(pDesc->height, floor(pDesc->width * (mapHeight / mapWidth)));
222 
223     // Clean up
224     surroundView2dSession->stopStream();
225     result = mSurroundViewService->stop2dSession(surroundView2dSession);
226 }
227 
TEST_P(SurroundViewHidlTest,get2dMappingInfo)228 TEST_P(SurroundViewHidlTest, get2dMappingInfo) {
229     ALOGD("SurroundViewHidlTest, get2dMappingInfo");
230     sp<ISurroundView2dSession> surroundView2dSession;
231     mSurroundViewService->start2dSession(
232         [&surroundView2dSession](
233             const sp<ISurroundView2dSession>& session, SvResult result) {
234         ASSERT_EQ(result, SvResult::OK);
235         surroundView2dSession = session;
236     });
237 
238     surroundView2dSession->get2dMappingInfo([] (Sv2dMappingInfo info) {
239         EXPECT_GT(info.width, 0);
240         EXPECT_GT(info.height, 0);
241     });
242 
243     mSurroundViewService->stop2dSession(surroundView2dSession);
244 }
245 
TEST_P(SurroundViewHidlTest,set2dConfigResolution)246 TEST_P(SurroundViewHidlTest, set2dConfigResolution) {
247     ALOGD("SurroundViewHidlTest, set2dConfigResolution");
248     sp<ISurroundView2dSession> surroundView2dSession;
249     mSurroundViewService->start2dSession(
250         [&surroundView2dSession](
251             const sp<ISurroundView2dSession>& session, SvResult result) {
252         ASSERT_EQ(result, SvResult::OK);
253         surroundView2dSession = session;
254     });
255 
256     sp<SurroundViewServiceHandler> handler =
257         new SurroundViewServiceHandler(surroundView2dSession);
258 
259     SvResult result = surroundView2dSession->startStream(handler);
260     EXPECT_EQ(result, SvResult::OK);
261 
262     sleep(1);
263 
264     // Change config
265     Sv2dConfig config;
266     config.width = 1920;
267     config.blending = SvQuality::HIGH;
268     surroundView2dSession->set2dConfig(config);
269 
270     sleep(1);
271 
272     EXPECT_TRUE(handler->checkEventReceived(SvEvent::CONFIG_UPDATED));
273 
274     // Check width has been changed but not the ratio
275     SvFramesDesc frames = handler->getLastReceivedFrames();
276     EXPECT_EQ(frames.svBuffers.size(), 1);
277     SvBuffer svBuffer2d = frames.svBuffers[0];
278     EXPECT_EQ(svBuffer2d.viewId, 0);
279     const AHardwareBuffer_Desc* pDesc =
280         reinterpret_cast<const AHardwareBuffer_Desc *>(&svBuffer2d.hardwareBuffer.description);
281     EXPECT_EQ(pDesc->width, config.width);
282 
283     float mapWidth, mapHeight;
284     surroundView2dSession->get2dMappingInfo([&mapWidth, &mapHeight] (Sv2dMappingInfo info) {
285         mapWidth = info.width;
286         mapHeight = info.height;
287     });
288     EXPECT_EQ(pDesc->height, floor (pDesc->width * (mapHeight / mapWidth)));
289 
290     // Clean up
291     surroundView2dSession->stopStream();
292     mSurroundViewService->stop2dSession(surroundView2dSession);
293 }
294 
TEST_P(SurroundViewHidlTest,set2dConfigBlending)295 TEST_P(SurroundViewHidlTest, set2dConfigBlending) {
296     ALOGD("SurroundViewHidlTest, set2dConfigBlending");
297     sp<ISurroundView2dSession> surroundView2dSession;
298     mSurroundViewService->start2dSession(
299         [&surroundView2dSession](
300             const sp<ISurroundView2dSession>& session, SvResult result) {
301         ASSERT_EQ(result, SvResult::OK);
302         surroundView2dSession = session;
303     });
304 
305     sp<SurroundViewServiceHandler> handler =
306         new SurroundViewServiceHandler(surroundView2dSession);
307 
308     SvResult result = surroundView2dSession->startStream(handler);
309     EXPECT_EQ(result, SvResult::OK);
310 
311     sleep(1);
312 
313     // Get the width before config changed
314     int oldWidth;
315     SvFramesDesc frames = handler->getLastReceivedFrames();
316     EXPECT_EQ(frames.svBuffers.size(), 1);
317     SvBuffer svBuffer2d = frames.svBuffers[0];
318     const AHardwareBuffer_Desc* pDesc =
319         reinterpret_cast<const AHardwareBuffer_Desc *>(&svBuffer2d.hardwareBuffer.description);
320     oldWidth = pDesc->width;
321 
322     // Change config
323     Sv2dConfig config;
324     config.width = oldWidth;
325     config.blending = SvQuality::LOW;
326     surroundView2dSession->set2dConfig(config);
327 
328     sleep(1);
329 
330     EXPECT_TRUE(handler->checkEventReceived(SvEvent::CONFIG_UPDATED));
331 
332     Sv2dConfig retConfig;
333     surroundView2dSession->get2dConfig([&retConfig] (Sv2dConfig config) {
334         retConfig.width = config.width;
335         retConfig.blending = config.blending;
336     });
337 
338     // Check config blending has been changed but not the width
339     EXPECT_EQ(retConfig.blending, config.blending);
340     EXPECT_EQ(retConfig.width, oldWidth);
341 
342     // Clean up
343     surroundView2dSession->stopStream();
344     mSurroundViewService->stop2dSession(surroundView2dSession);
345 }
346 
TEST_P(SurroundViewHidlTest,projectCameraPointsWithValidCameraId)347 TEST_P(SurroundViewHidlTest, projectCameraPointsWithValidCameraId) {
348     ALOGD("SurroundViewHidlTest, projectCameraPointsWithValidCameraId");
349     sp<ISurroundView2dSession> surroundView2dSession;
350     mSurroundViewService->start2dSession(
351         [&surroundView2dSession](
352             const sp<ISurroundView2dSession>& session, SvResult result) {
353         ASSERT_EQ(result, SvResult::OK);
354         surroundView2dSession = session;
355     });
356 
357     hidl_vec<hidl_string> cameraIds;
358     mSurroundViewService->getCameraIds([&cameraIds](
359             const hidl_vec<hidl_string>& camIds) {
360         cameraIds = camIds;
361     });
362 
363     sp<SurroundViewServiceHandler> handler =
364         new SurroundViewServiceHandler(surroundView2dSession);
365 
366     SvResult result = surroundView2dSession->startStream(handler);
367     EXPECT_EQ(result, SvResult::OK);
368 
369     sleep(1);
370 
371     // Get the width and height of the frame
372     int width, height;
373     SvFramesDesc frames = handler->getLastReceivedFrames();
374     EXPECT_EQ(frames.svBuffers.size(), 1);
375     SvBuffer svBuffer2d = frames.svBuffers[0];
376     const AHardwareBuffer_Desc* pDesc =
377         reinterpret_cast<const AHardwareBuffer_Desc *>(&svBuffer2d.hardwareBuffer.description);
378     width = pDesc->width;
379     height = pDesc->height;
380 
381     float mapWidth, mapHeight, mapCenter[2];
382     surroundView2dSession->get2dMappingInfo(
383         [&mapWidth, &mapHeight, &mapCenter] (Sv2dMappingInfo info) {
384         mapWidth = info.width;
385         mapHeight = info.height;
386         mapCenter[0] = info.center.x;
387         mapCenter[1] = info.center.y;
388     });
389 
390     // Set one valid point and one invalid point
391     hidl_vec<Point2dInt> points2dCamera;
392     points2dCamera.resize(2);
393     points2dCamera[0].x = 0;
394     points2dCamera[0].y = 0;
395     points2dCamera[1].x = width * 2;
396     points2dCamera[1].y = height * 2;
397 
398     surroundView2dSession->projectCameraPoints(
399         points2dCamera,
400         cameraIds[0],
401         [&mapWidth, &mapHeight, &mapCenter] (
402             const hidl_vec<Point2dFloat>& outPoints) {
403             // Make sure point[0] is valid.
404             EXPECT_TRUE(outPoints[0].isValid);
405             EXPECT_GE(outPoints[0].x, mapCenter[0] - mapWidth);
406             EXPECT_LE(outPoints[0].x, mapCenter[0] + mapWidth);
407             EXPECT_GE(outPoints[0].y, mapCenter[1] - mapHeight);
408             EXPECT_LE(outPoints[0].y, mapCenter[1] + mapHeight);
409 
410             // Make sure point[1] is invalid.
411             EXPECT_FALSE(outPoints[1].isValid);
412         });
413 
414     // Clean up
415     surroundView2dSession->stopStream();
416     mSurroundViewService->stop2dSession(surroundView2dSession);
417 }
418 
TEST_P(SurroundViewHidlTest,projectCameraPointsWithInvalidCameraId)419 TEST_P(SurroundViewHidlTest, projectCameraPointsWithInvalidCameraId) {
420     ALOGD("SurroundViewHidlTest, projectCameraPointsWithInvalidCameraId");
421     sp<ISurroundView2dSession> surroundView2dSession;
422     mSurroundViewService->start2dSession(
423         [&surroundView2dSession](
424             const sp<ISurroundView2dSession>& session, SvResult result) {
425         ASSERT_EQ(result, SvResult::OK);
426         surroundView2dSession = session;
427     });
428 
429     hidl_vec<hidl_string> cameraIds;
430     mSurroundViewService->getCameraIds([&cameraIds](
431             const hidl_vec<hidl_string>& camIds) {
432         cameraIds = camIds;
433     });
434 
435     hidl_string invalidCameraId = "INVALID_CAMERA_ID";
436 
437     // In case one of the camera id happens to be identical to
438     // the invalid camera id.
439     for (auto cameraId : cameraIds) {
440         ASSERT_NE(cameraId, invalidCameraId);
441     }
442 
443     // Set one valid point
444     hidl_vec<Point2dInt> points2dCamera;
445     points2dCamera.resize(1);
446     points2dCamera[0].x = 0;
447     points2dCamera[0].y = 0;
448 
449     surroundView2dSession->projectCameraPoints(
450         points2dCamera,
451         invalidCameraId,
452         [] (const hidl_vec<Point2dFloat>& outPoints) {
453             // No points are return due to invalid camera id
454             EXPECT_EQ(outPoints.size(), 0);
455         });
456 
457     // Clean up
458     surroundView2dSession->stopStream();
459     mSurroundViewService->stop2dSession(surroundView2dSession);
460 }
461 
TEST_P(SurroundViewHidlTest,startAndStop3dSession)462 TEST_P(SurroundViewHidlTest, startAndStop3dSession) {
463     ALOGD("SurroundViewHidlTest, startAndStop3dSession");
464     sp<ISurroundView3dSession> surroundView3dSession;
465     mSurroundViewService->start3dSession(
466         [&surroundView3dSession](
467             const sp<ISurroundView3dSession>& session, SvResult result) {
468         ASSERT_EQ(result, SvResult::OK);
469         surroundView3dSession = session;
470     });
471 
472     SvResult result = mSurroundViewService->stop3dSession(surroundView3dSession);
473     EXPECT_EQ(result, SvResult::OK);
474 }
475 
TEST_P(SurroundViewHidlTest,stopInvalid3dSession)476 TEST_P(SurroundViewHidlTest, stopInvalid3dSession) {
477     ALOGD("SurroundViewHidlTest, stopInvalid3dSession");
478     sp<ISurroundView3dSession> surroundView3dSession;
479     SvResult result = mSurroundViewService->stop3dSession(surroundView3dSession);
480     EXPECT_NE(result, SvResult::OK);
481 }
482 
TEST_P(SurroundViewHidlTest,startAndStop3dStream)483 TEST_P(SurroundViewHidlTest, startAndStop3dStream) {
484     ALOGD("SurroundViewHidlTest::startAndStop3dStream");
485     sp<ISurroundView3dSession> surroundView3dSession;
486     mSurroundViewService->start3dSession(
487         [&surroundView3dSession](
488             const sp<ISurroundView3dSession>& session, SvResult result) {
489         ASSERT_EQ(result, SvResult::OK);
490         surroundView3dSession = session;
491     });
492 
493     std::vector<View3d> views(1);
494     SvResult setViewResult = surroundView3dSession->setViews(views);
495     EXPECT_EQ(setViewResult, SvResult::OK);
496 
497     sp<SurroundViewServiceHandler> handler =
498         new SurroundViewServiceHandler(surroundView3dSession);
499 
500     SvResult result = surroundView3dSession->startStream(handler);
501     EXPECT_EQ(result, SvResult::OK);
502 
503     sleep(5);
504 
505     EXPECT_TRUE(handler->checkEventReceived(SvEvent::STREAM_STARTED));
506     EXPECT_GT(handler->getReceiveFramesCount(), 0);
507 
508     surroundView3dSession->stopStream();
509 
510     sleep(1);
511     EXPECT_TRUE(handler->checkEventReceived(SvEvent::STREAM_STOPPED));
512 
513     result = mSurroundViewService->stop3dSession(surroundView3dSession);
514     EXPECT_EQ(result, SvResult::OK);
515 }
516 
TEST_P(SurroundViewHidlTest,start3dStreamWithoutReturningFrames)517 TEST_P(SurroundViewHidlTest, start3dStreamWithoutReturningFrames) {
518     ALOGD("SurroundViewHidlTest::start3dStreamWithoutReturningFrames");
519     sp<ISurroundView3dSession> surroundView3dSession;
520     mSurroundViewService->start3dSession(
521         [&surroundView3dSession](
522             const sp<ISurroundView3dSession>& session, SvResult result) {
523         ASSERT_EQ(result, SvResult::OK);
524         surroundView3dSession = session;
525     });
526 
527     std::vector<View3d> views(1);
528     SvResult setViewResult = surroundView3dSession->setViews(views);
529     EXPECT_EQ(setViewResult, SvResult::OK);
530 
531     sp<SurroundViewServiceHandler> handler =
532         new SurroundViewServiceHandler(surroundView3dSession);
533     handler->setDoNotReturnFrames(true);
534 
535     SvResult result = surroundView3dSession->startStream(handler);
536     EXPECT_EQ(result, SvResult::OK);
537 
538     sleep(5);
539 
540     EXPECT_TRUE(handler->checkEventReceived(SvEvent::STREAM_STARTED));
541     EXPECT_TRUE(handler->checkEventReceived(SvEvent::FRAME_DROPPED));
542     EXPECT_GT(handler->getReceiveFramesCount(), 0);
543 
544     surroundView3dSession->stopStream();
545 
546     sleep(1);
547     EXPECT_TRUE(handler->checkEventReceived(SvEvent::STREAM_STOPPED));
548 
549     result = mSurroundViewService->stop3dSession(surroundView3dSession);
550     EXPECT_EQ(result, SvResult::OK);
551 }
552 
TEST_P(SurroundViewHidlTest,duplicateStart3dStream)553 TEST_P(SurroundViewHidlTest, duplicateStart3dStream) {
554     ALOGD("SurroundViewHidlTest, duplicateStart3dStream");
555     sp<ISurroundView3dSession> surroundView3dSession;
556     mSurroundViewService->start3dSession(
557         [&surroundView3dSession](
558             const sp<ISurroundView3dSession>& session, SvResult result) {
559         ASSERT_EQ(result, SvResult::OK);
560         surroundView3dSession = session;
561     });
562 
563     std::vector<View3d> views(1);
564     SvResult setViewResult = surroundView3dSession->setViews(views);
565     EXPECT_EQ(setViewResult, SvResult::OK);
566 
567     sp<SurroundViewServiceHandler> handler =
568         new SurroundViewServiceHandler(surroundView3dSession);
569 
570     SvResult result = surroundView3dSession->startStream(handler);
571     EXPECT_EQ(result, SvResult::OK);
572 
573     result = surroundView3dSession->startStream(handler);
574     EXPECT_NE(result, SvResult::OK);
575 
576     surroundView3dSession->stopStream();
577     mSurroundViewService->stop3dSession(surroundView3dSession);
578 }
579 
TEST_P(SurroundViewHidlTest,start3dStreamNoViewSetFail)580 TEST_P(SurroundViewHidlTest, start3dStreamNoViewSetFail) {
581     ALOGD("SurroundViewHidlTest, start3dStreamNoViewSetFail");
582     sp<ISurroundView3dSession> surroundView3dSession;
583     mSurroundViewService->start3dSession(
584         [&surroundView3dSession](
585             const sp<ISurroundView3dSession>& session, SvResult result) {
586         ASSERT_EQ(result, SvResult::OK);
587         surroundView3dSession = session;
588     });
589 
590     sp<SurroundViewServiceHandler> handler =
591         new SurroundViewServiceHandler(surroundView3dSession);
592 
593     SvResult result = surroundView3dSession->startStream(handler);
594     EXPECT_EQ(result, SvResult::VIEW_NOT_SET);
595 
596     mSurroundViewService->stop3dSession(surroundView3dSession);
597 }
598 
TEST_P(SurroundViewHidlTest,validate3dSvFramesDesc)599 TEST_P(SurroundViewHidlTest, validate3dSvFramesDesc) {
600     ALOGD("SurroundViewHidlTest, validate3dSvFramesDesc");
601     sp<ISurroundView3dSession> surroundView3dSession;
602     mSurroundViewService->start3dSession(
603         [&surroundView3dSession](
604             const sp<ISurroundView3dSession>& session, SvResult result) {
605         ASSERT_EQ(result, SvResult::OK);
606         surroundView3dSession = session;
607     });
608 
609     sp<SurroundViewServiceHandler> handler =
610         new SurroundViewServiceHandler(surroundView3dSession);
611 
612     std::vector<View3d> views(1);
613     views[0].viewId = 0;
614     SvResult setViewResult = surroundView3dSession->setViews(views);
615     EXPECT_EQ(setViewResult, SvResult::OK);
616 
617     SvResult result = surroundView3dSession->startStream(handler);
618     EXPECT_EQ(result, SvResult::OK);
619 
620     sleep(5);
621 
622     EXPECT_GT(handler->getReceiveFramesCount(), 0);
623     EXPECT_TRUE(handler->areAllFramesValid());
624 
625     // Validate 3d SvFramesDesc when only one view is set.
626     SvFramesDesc frames = handler->getLastReceivedFrames();
627     EXPECT_EQ(frames.svBuffers.size(), 1);
628     EXPECT_EQ(frames.svBuffers[0].viewId, 0);
629 
630     views.resize(3);
631     views[0].viewId = 0;
632     views[1].viewId = 1;
633     views[2].viewId = 2;
634     setViewResult = surroundView3dSession->setViews(views);
635     EXPECT_EQ(setViewResult, SvResult::OK);
636 
637     sleep(1);
638 
639     // Validate 3d SvFramesDesc when multiple views are set.
640     EXPECT_TRUE(handler->areAllFramesValid());
641     frames = handler->getLastReceivedFrames();
642     EXPECT_EQ(frames.svBuffers.size(), 3);
643     EXPECT_EQ(frames.svBuffers[0].viewId, 0);
644     EXPECT_EQ(frames.svBuffers[1].viewId, 1);
645     EXPECT_EQ(frames.svBuffers[2].viewId, 2);
646     EXPECT_EQ(frames.svBuffers[0].hardwareBuffer.description[0],
647               frames.svBuffers[1].hardwareBuffer.description[0]);
648     EXPECT_EQ(frames.svBuffers[0].hardwareBuffer.description[1],
649               frames.svBuffers[1].hardwareBuffer.description[1]);
650     EXPECT_EQ(frames.svBuffers[1].hardwareBuffer.description[0],
651               frames.svBuffers[2].hardwareBuffer.description[0]);
652     EXPECT_EQ(frames.svBuffers[1].hardwareBuffer.description[1],
653               frames.svBuffers[2].hardwareBuffer.description[1]);
654 
655     // Clean up
656     surroundView3dSession->stopStream();
657     result = mSurroundViewService->stop3dSession(surroundView3dSession);
658 }
659 
TEST_P(SurroundViewHidlTest,set3dConfigResolution)660 TEST_P(SurroundViewHidlTest, set3dConfigResolution) {
661     ALOGD("SurroundViewHidlTest, set3dConfigResolution");
662     sp<ISurroundView3dSession> surroundView3dSession;
663     mSurroundViewService->start3dSession(
664         [&surroundView3dSession](
665             const sp<ISurroundView3dSession>& session, SvResult result) {
666         ASSERT_EQ(result, SvResult::OK);
667         surroundView3dSession = session;
668     });
669 
670     sp<SurroundViewServiceHandler> handler =
671         new SurroundViewServiceHandler(surroundView3dSession);
672 
673     std::vector<View3d> views(1);
674     views[0].viewId = 0;
675     SvResult setViewResult = surroundView3dSession->setViews(views);
676     EXPECT_EQ(setViewResult, SvResult::OK);
677     SvResult result = surroundView3dSession->startStream(handler);
678     EXPECT_EQ(result, SvResult::OK);
679 
680     sleep(1);
681 
682     // Change config
683     Sv3dConfig config;
684     config.width = 1920;
685     config.height = 1080;
686     config.carDetails = SvQuality::HIGH;
687     surroundView3dSession->set3dConfig(config);
688 
689     sleep(1);
690 
691     EXPECT_TRUE(handler->checkEventReceived(SvEvent::CONFIG_UPDATED));
692 
693     // Check width has been changed but not the ratio
694     SvFramesDesc frames = handler->getLastReceivedFrames();
695     EXPECT_EQ(frames.svBuffers.size(), 1);
696     SvBuffer svBuffer3d = frames.svBuffers[0];
697     EXPECT_EQ(svBuffer3d.viewId, 0);
698     const AHardwareBuffer_Desc* pDesc =
699         reinterpret_cast<const AHardwareBuffer_Desc *>(&svBuffer3d.hardwareBuffer.description);
700     EXPECT_EQ(pDesc->width, config.width);
701     EXPECT_EQ(pDesc->height, config.height);
702 
703     // Clean up
704     surroundView3dSession->stopStream();
705     mSurroundViewService->stop3dSession(surroundView3dSession);
706 }
707 
TEST_P(SurroundViewHidlTest,set3dConfigCarDetails)708 TEST_P(SurroundViewHidlTest, set3dConfigCarDetails) {
709     ALOGD("SurroundViewHidlTest, set3dConfigCarDetails");
710     sp<ISurroundView3dSession> surroundView3dSession;
711     mSurroundViewService->start3dSession(
712         [&surroundView3dSession](
713             const sp<ISurroundView3dSession>& session, SvResult result) {
714         ASSERT_EQ(result, SvResult::OK);
715         surroundView3dSession = session;
716     });
717 
718     sp<SurroundViewServiceHandler> handler =
719         new SurroundViewServiceHandler(surroundView3dSession);
720 
721     std::vector<View3d> views(1);
722     views[0].viewId = 0;
723     SvResult setViewResult = surroundView3dSession->setViews(views);
724     EXPECT_EQ(setViewResult, SvResult::OK);
725     SvResult result = surroundView3dSession->startStream(handler);
726     EXPECT_EQ(result, SvResult::OK);
727 
728     sleep(1);
729 
730     // Get the width before config changed
731     int oldWidth, oldHeight;
732     SvFramesDesc frames = handler->getLastReceivedFrames();
733     EXPECT_EQ(frames.svBuffers.size(), 1);
734     SvBuffer svBuffer3d = frames.svBuffers[0];
735     const AHardwareBuffer_Desc* pDesc =
736         reinterpret_cast<const AHardwareBuffer_Desc *>(&svBuffer3d.hardwareBuffer.description);
737     oldWidth = pDesc->width;
738     oldHeight = pDesc->height;
739 
740     // Change config
741     Sv3dConfig config;
742     config.width = oldWidth;
743     config.height = oldHeight;
744     config.carDetails = SvQuality::LOW;
745     surroundView3dSession->set3dConfig(config);
746 
747     sleep(1);
748 
749     EXPECT_TRUE(handler->checkEventReceived(SvEvent::CONFIG_UPDATED));
750 
751     Sv3dConfig retConfig;
752     surroundView3dSession->get3dConfig([&retConfig] (Sv3dConfig config) {
753         retConfig.width = config.width;
754         retConfig.height = config.height;
755         retConfig.carDetails = config.carDetails;
756     });
757 
758     // Check config blending has been changed but not the width
759     EXPECT_EQ(retConfig.carDetails, config.carDetails);
760     EXPECT_EQ(retConfig.width, oldWidth);
761     EXPECT_EQ(retConfig.height, oldHeight);
762 
763     // Clean up
764     surroundView3dSession->stopStream();
765     mSurroundViewService->stop3dSession(surroundView3dSession);
766 }
767 
GetMappedSharedMemory(int bytesSize)768 std::pair<hidl_memory, sp<IMemory>> GetMappedSharedMemory(int bytesSize) {
769 
770     const auto nullResult = std::make_pair(hidl_memory(), nullptr);
771 
772     sp<IAllocator> ashmemAllocator = IAllocator::getService("ashmem");
773     if (ashmemAllocator.get() == nullptr) {
774         ALOGE("SurroundViewHidlTest getService ashmem failed");
775         return nullResult;
776     }
777 
778     // Allocate shared memory.
779     hidl_memory hidlMemory;
780     bool allocateSuccess = false;
781     Return<void> result = ashmemAllocator->allocate(bytesSize,
782             [&](bool success, const hidl_memory& hidlMem) {
783                 if (!success) {
784                     return;
785                 }
786                 allocateSuccess = success;
787                 hidlMemory = hidlMem;
788             });
789 
790     // Check result of allocated memory.
791     if (!result.isOk() || !allocateSuccess) {
792         ALOGE("SurroundViewHidlTest allocate shared memory failed");
793         return nullResult;
794     }
795 
796     // Map shared memory.
797     sp<IMemory> pIMemory = mapMemory(hidlMemory);
798     if (pIMemory.get() == nullptr) {
799         ALOGE("SurroundViewHidlTest map shared memory failed");
800         return nullResult;
801     }
802 
803     return std::make_pair(hidlMemory, pIMemory);
804 }
805 
SetIndexOfOverlaysMemory(const std::vector<OverlayMemoryDesc> & overlaysMemDesc,sp<IMemory> pIMemory,int indexPosition,uint16_t indexValue)806 void SetIndexOfOverlaysMemory(
807         const std::vector<OverlayMemoryDesc>& overlaysMemDesc,
808         sp<IMemory> pIMemory, int indexPosition, uint16_t indexValue) {
809 
810     // Count the number of vertices until the index.
811     int totalVerticesCount = 0;
812     for (int i = 0; i < indexPosition; i++) {
813         totalVerticesCount += overlaysMemDesc[i].verticesCount;
814     }
815 
816     const int indexBytePosition = (indexPosition * kIdByteSize) +
817             (kVertexByteSize * totalVerticesCount);
818 
819     uint8_t* pSharedMemoryData = (uint8_t*)((void*)pIMemory->getPointer());
820     pSharedMemoryData += indexBytePosition;
821     uint16_t* pIndex16bit = (uint16_t*)pSharedMemoryData;
822 
823     ALOGD("Setting index at pos %d", indexBytePosition);
824 
825     // Modify shared memory.
826     pIMemory->update();
827     *pIndex16bit = indexValue;
828     pIMemory->commit();
829 }
830 
GetSampleOverlaysData()831 std::pair<OverlaysData, sp<IMemory>> GetSampleOverlaysData() {
832     OverlaysData overlaysData;
833     overlaysData.overlaysMemoryDesc.resize(2);
834 
835     int sharedMemBytesSize = 0;
836     OverlayMemoryDesc overlayMemDesc1, overlayMemDesc2;
837     overlayMemDesc1.id = 0;
838     overlayMemDesc1.verticesCount = 6;
839     overlayMemDesc1.overlayPrimitive = OverlayPrimitive::TRIANGLES;
840     overlaysData.overlaysMemoryDesc[0] = overlayMemDesc1;
841     sharedMemBytesSize += kIdByteSize +
842             kVertexByteSize * overlayMemDesc1.verticesCount;
843 
844     overlayMemDesc2.id = 1;
845     overlayMemDesc2.verticesCount = 4;
846     overlayMemDesc2.overlayPrimitive = OverlayPrimitive::TRIANGLES_STRIP;
847     overlaysData.overlaysMemoryDesc[1] = overlayMemDesc2;
848     sharedMemBytesSize += kIdByteSize +
849             kVertexByteSize * overlayMemDesc2.verticesCount;
850 
851     std::pair<hidl_memory, sp<IMemory>> sharedMem =
852             GetMappedSharedMemory(sharedMemBytesSize);
853     sp<IMemory> pIMemory = sharedMem.second;
854     if (pIMemory.get() == nullptr) {
855         return std::make_pair(OverlaysData(), nullptr);
856     }
857 
858     // Get pointer to shared memory data and set all bytes to 0.
859     uint8_t* pSharedMemoryData = (uint8_t*)((void*)pIMemory->getPointer());
860     pIMemory->update();
861     memset(pSharedMemoryData, 0, sharedMemBytesSize);
862     pIMemory->commit();
863 
864     std::vector<OverlayMemoryDesc> overlaysDesc = {overlayMemDesc1,
865             overlayMemDesc2};
866 
867     // Set indexes in shared memory.
868     SetIndexOfOverlaysMemory(overlaysDesc, pIMemory, 0, overlayMemDesc1.id);
869     SetIndexOfOverlaysMemory(overlaysDesc, pIMemory, 1, overlayMemDesc2.id);
870 
871     overlaysData.overlaysMemoryDesc = overlaysDesc;
872     overlaysData.overlaysMemory = sharedMem.first;
873 
874     return std::make_pair(overlaysData, pIMemory);
875 }
876 
TEST_P(SurroundViewHidlTest,updateOverlaysSuccess)877 TEST_P(SurroundViewHidlTest, updateOverlaysSuccess) {
878     ALOGD("SurroundViewHidlTest, updateOverlaysSuccess");
879 
880     sp<ISurroundView3dSession> surroundView3dSession;
881     mSurroundViewService->start3dSession(
882         [&surroundView3dSession](
883             const sp<ISurroundView3dSession>& session, SvResult result) {
884         ASSERT_EQ(result, SvResult::OK);
885         surroundView3dSession = session;
886     });
887 
888     std::pair<OverlaysData, sp<IMemory>> overlaysData = GetSampleOverlaysData();
889     ASSERT_NE(overlaysData.second, nullptr);
890 
891     SvResult result = surroundView3dSession->updateOverlays(overlaysData.first);
892     EXPECT_EQ(result, SvResult::OK);
893 
894     mSurroundViewService->stop3dSession(surroundView3dSession);
895 }
896 
TEST_P(SurroundViewHidlTest,overlaysDataMismatchIdFail)897 TEST_P(SurroundViewHidlTest, overlaysDataMismatchIdFail) {
898     ALOGD("SurroundViewHidlTest, overlaysDataMismatchIdFail");
899 
900     sp<ISurroundView3dSession> surroundView3dSession;
901     mSurroundViewService->start3dSession(
902         [&surroundView3dSession](
903             const sp<ISurroundView3dSession>& session, SvResult result) {
904         ASSERT_EQ(result, SvResult::OK);
905         surroundView3dSession = session;
906     });
907 
908     std::pair<OverlaysData, sp<IMemory>> overlaysDataMismatchId
909             = GetSampleOverlaysData();
910     ASSERT_NE(overlaysDataMismatchId.second, nullptr);
911 
912     // Set id of second overlay in shared memory to 2 (expected is 1).
913     auto& overlaysDesc = overlaysDataMismatchId.first.overlaysMemoryDesc;
914     auto& pIMemory = overlaysDataMismatchId.second;
915     SetIndexOfOverlaysMemory(overlaysDesc, pIMemory, 1, 2);
916 
917     SvResult result = surroundView3dSession->updateOverlays(
918             overlaysDataMismatchId.first);
919     EXPECT_EQ(result, SvResult::INVALID_ARG);
920 
921     mSurroundViewService->stop3dSession(surroundView3dSession);
922 }
923 
TEST_P(SurroundViewHidlTest,overlaysDataNullMemoryFail)924 TEST_P(SurroundViewHidlTest, overlaysDataNullMemoryFail) {
925     ALOGD("SurroundViewHidlTest, overlaysDataNullMemoryFail");
926 
927     sp<ISurroundView3dSession> surroundView3dSession;
928     mSurroundViewService->start3dSession(
929         [&surroundView3dSession](
930             const sp<ISurroundView3dSession>& session, SvResult result) {
931         ASSERT_EQ(result, SvResult::OK);
932         surroundView3dSession = session;
933     });
934 
935     std::pair<OverlaysData, sp<IMemory>> overlaysDataNullMemory
936             = GetSampleOverlaysData();
937 
938     // Set shared memory to null.
939     overlaysDataNullMemory.first.overlaysMemory = hidl_memory();
940 
941     SvResult result = surroundView3dSession->updateOverlays(
942             overlaysDataNullMemory.first);
943     EXPECT_EQ(result, SvResult::INVALID_ARG);
944 
945     mSurroundViewService->stop3dSession(surroundView3dSession);
946 }
947 
TEST_P(SurroundViewHidlTest,overlaysDataLessThan3VerticesFail)948 TEST_P(SurroundViewHidlTest, overlaysDataLessThan3VerticesFail) {
949     ALOGD("SurroundViewHidlTest, overlaysDataLessThan3VerticesFail");
950 
951     sp<ISurroundView3dSession> surroundView3dSession;
952     mSurroundViewService->start3dSession(
953         [&surroundView3dSession](
954             const sp<ISurroundView3dSession>& session, SvResult result) {
955         ASSERT_EQ(result, SvResult::OK);
956         surroundView3dSession = session;
957     });
958 
959     std::pair<OverlaysData, sp<IMemory>> overlaysData2Vertices
960             = GetSampleOverlaysData();
961 
962     // Set vertices count of second overlay to 2.
963     overlaysData2Vertices.first.overlaysMemoryDesc[1].verticesCount = 2;
964 
965     SvResult result = surroundView3dSession->updateOverlays(
966             overlaysData2Vertices.first);
967     EXPECT_EQ(result, SvResult::INVALID_ARG);
968 
969     mSurroundViewService->stop3dSession(surroundView3dSession);
970 }
971 
TEST_P(SurroundViewHidlTest,overlaysDataVerticesCountFail)972 TEST_P(SurroundViewHidlTest, overlaysDataVerticesCountFail) {
973     ALOGD("SurroundViewHidlTest, overlaysDataVerticesNotMultipleOf3Fail");
974 
975     sp<ISurroundView3dSession> surroundView3dSession;
976     mSurroundViewService->start3dSession(
977         [&surroundView3dSession](
978             const sp<ISurroundView3dSession>& session, SvResult result) {
979         ASSERT_EQ(result, SvResult::OK);
980         surroundView3dSession = session;
981     });
982 
983     OverlaysData overlaysData;
984     overlaysData.overlaysMemoryDesc.resize(1);
985 
986     OverlayMemoryDesc overlayMemDesc1;
987     overlayMemDesc1.id = 0;
988     overlayMemDesc1.verticesCount = 4; // Invalid count for TRIANGLES primitive.
989     overlayMemDesc1.overlayPrimitive = OverlayPrimitive::TRIANGLES;
990     overlaysData.overlaysMemoryDesc[0] = overlayMemDesc1;
991 
992     const int sharedMemBytesSize =
993             2 + sizeof(float) * overlayMemDesc1.verticesCount;
994     auto sharedMem = GetMappedSharedMemory(sharedMemBytesSize);
995 
996     // Set index in shared memory.
997     auto& overlaysDesc = overlaysData.overlaysMemoryDesc;
998     auto& pIMemory = sharedMem.second;
999     SetIndexOfOverlaysMemory(overlaysDesc, pIMemory, 0, overlayMemDesc1.id);
1000 
1001     SvResult result = surroundView3dSession->updateOverlays(overlaysData);
1002     EXPECT_EQ(result, SvResult::INVALID_ARG);
1003 
1004     mSurroundViewService->stop3dSession(surroundView3dSession);
1005 }
1006 
TEST_P(SurroundViewHidlTest,overlaysDataSameIdFail)1007 TEST_P(SurroundViewHidlTest, overlaysDataSameIdFail) {
1008     ALOGD("SurroundViewHidlTest, overlaysDataSameIdFail");
1009 
1010     sp<ISurroundView3dSession> surroundView3dSession;
1011     mSurroundViewService->start3dSession(
1012         [&surroundView3dSession](
1013             const sp<ISurroundView3dSession>& session, SvResult result) {
1014         ASSERT_EQ(result, SvResult::OK);
1015         surroundView3dSession = session;
1016     });
1017 
1018     std::pair<OverlaysData, sp<IMemory>> overlaysDataSameId
1019             = GetSampleOverlaysData();
1020     ASSERT_NE(overlaysDataSameId.second, nullptr);
1021 
1022     // Set id of second overlay as id of first.
1023     auto& overlaysDesc = overlaysDataSameId.first.overlaysMemoryDesc;
1024         auto& pIMemory = overlaysDataSameId.second;
1025     SetIndexOfOverlaysMemory(overlaysDesc, pIMemory, 1, overlaysDesc[0].id);
1026 
1027     SvResult result = surroundView3dSession->updateOverlays(
1028             overlaysDataSameId.first);
1029     EXPECT_EQ(result, SvResult::INVALID_ARG);
1030 
1031     mSurroundViewService->stop3dSession(surroundView3dSession);
1032 }
1033 
TEST_P(SurroundViewHidlTest,projectPointsIncorrectCameraIdFail)1034 TEST_P(SurroundViewHidlTest, projectPointsIncorrectCameraIdFail) {
1035     ALOGD("SurroundViewHidlTest, projectPointsIncorrectCameraIdFail");
1036 
1037     hidl_vec<hidl_string> cameraIds;
1038     mSurroundViewService->getCameraIds([&cameraIds](
1039             const hidl_vec<hidl_string>& camIds) {
1040         cameraIds = camIds;
1041     });
1042     EXPECT_GT(cameraIds.size(), 0);
1043 
1044     sp<ISurroundView3dSession> surroundView3dSession;
1045     mSurroundViewService->start3dSession(
1046         [&surroundView3dSession](
1047             const sp<ISurroundView3dSession>& session, SvResult result) {
1048         ASSERT_EQ(result, SvResult::OK);
1049         surroundView3dSession = session;
1050     });
1051 
1052     Point2dInt cameraPoint;
1053     cameraPoint.x = 0;
1054     cameraPoint.y = 0;
1055     std::vector<Point2dInt> cameraPoints = {cameraPoint};
1056 
1057     hidl_string invalidCameraId = "INVALID_CAMERA_ID";
1058 
1059     std::vector<Point3dFloat> points3d;
1060     surroundView3dSession->projectCameraPointsTo3dSurface(
1061         cameraPoints, invalidCameraId,
1062         [&points3d](const hidl_vec<Point3dFloat>& points3dproj) {
1063                 points3d = points3dproj;
1064             });
1065 
1066     EXPECT_TRUE(points3d.empty());
1067 
1068     mSurroundViewService->stop3dSession(surroundView3dSession);
1069 }
1070 
TEST_P(SurroundViewHidlTest,projectPointsInvalidPointsFail)1071 TEST_P(SurroundViewHidlTest, projectPointsInvalidPointsFail) {
1072     ALOGD("SurroundViewHidlTest, projectPointsInvalidPointsFail");
1073 
1074     hidl_vec<hidl_string> cameraIds;
1075     mSurroundViewService->getCameraIds([&cameraIds](
1076             const hidl_vec<hidl_string>& camIds) {
1077         cameraIds = camIds;
1078     });
1079 
1080     EXPECT_GT(cameraIds.size(), 0);
1081 
1082     sp<ISurroundView3dSession> surroundView3dSession;
1083     mSurroundViewService->start3dSession(
1084         [&surroundView3dSession](
1085             const sp<ISurroundView3dSession>& session, SvResult result) {
1086         ASSERT_EQ(result, SvResult::OK);
1087         surroundView3dSession = session;
1088     });
1089 
1090     sp<SurroundViewServiceHandler> handler =
1091         new SurroundViewServiceHandler(surroundView3dSession);
1092 
1093     std::vector<View3d> views(1);
1094     views[0].viewId = 0;
1095     SvResult setViewResult = surroundView3dSession->setViews(views);
1096     EXPECT_EQ(setViewResult, SvResult::OK);
1097     SvResult result = surroundView3dSession->startStream(handler);
1098     EXPECT_EQ(result, SvResult::OK);
1099 
1100     sleep(1);
1101 
1102     // Get the width and height of the frame
1103     int width, height;
1104     SvFramesDesc frames = handler->getLastReceivedFrames();
1105     EXPECT_EQ(frames.svBuffers.size(), 1);
1106     SvBuffer svBuffer2d = frames.svBuffers[0];
1107     const AHardwareBuffer_Desc* pDesc =
1108         reinterpret_cast<const AHardwareBuffer_Desc *>(&svBuffer2d.hardwareBuffer.description);
1109     width = pDesc->width;
1110     height = pDesc->height;
1111 
1112     Point2dInt cameraPoint;
1113     cameraPoint.x = width * 2;
1114     cameraPoint.y = height * 2;
1115     std::vector<Point2dInt> cameraPoints = {cameraPoint};
1116 
1117     std::vector<Point3dFloat> points3d;
1118     surroundView3dSession->projectCameraPointsTo3dSurface(
1119               cameraPoints, cameraIds[0],
1120         [&points3d](const hidl_vec<Point3dFloat>& points3dproj) {
1121                 points3d = points3dproj;
1122             });
1123 
1124     EXPECT_FALSE(points3d[0].isValid);
1125 
1126     surroundView3dSession->stopStream();
1127     mSurroundViewService->stop3dSession(surroundView3dSession);
1128 }
1129 
1130 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(SurroundViewHidlTest);
1131 INSTANTIATE_TEST_SUITE_P(
1132     PerInstance,
1133     SurroundViewHidlTest,
1134     testing::ValuesIn(
1135         android::hardware::getAllHalInstanceNames(ISurroundViewService::descriptor)
1136     ),
1137     android::hardware::PrintInstanceNameToString
1138 );
1139