From 2fd4e9d71dd77eb9c094cb89ef1acd1c464309a2 Mon Sep 17 00:00:00 2001 From: kunal rai Date: Thu, 3 Aug 2023 11:25:33 +0530 Subject: [PATCH] Refactored automotiveSvV1.0_fuzzer The following are the updates to the fuzzer: 1. Added checks to the fuzzer to prevent fuzzer errors. 2. Updated the scope of the `handler` variable to avoid it going out of scope. 3. Moved `startstream` outside to ensure the proper opening of the stream. Test: ./automotiveSvV1.0_fuzzer Bug: 295788054 Change-Id: Ia5181ce999618cd2f6781d3681e937baa47e7071 --- .../tests/fuzzer/AutomotiveSvV1_0Fuzzer.cpp | 92 +++++++++++-------- 1 file changed, 54 insertions(+), 38 deletions(-) diff --git a/automotive/sv/1.0/default/tests/fuzzer/AutomotiveSvV1_0Fuzzer.cpp b/automotive/sv/1.0/default/tests/fuzzer/AutomotiveSvV1_0Fuzzer.cpp index 98834f5561..4c4cc70f53 100644 --- a/automotive/sv/1.0/default/tests/fuzzer/AutomotiveSvV1_0Fuzzer.cpp +++ b/automotive/sv/1.0/default/tests/fuzzer/AutomotiveSvV1_0Fuzzer.cpp @@ -41,27 +41,24 @@ constexpr size_t kMaxSvBuffers = 10; void SurroundViewFuzzer::invoke2dSessionAPI() { sp surroundView2dSession; + sp handler; + mSurroundViewService->start2dSession( + [&surroundView2dSession](const sp& session, SvResult result) { + if (result == SvResult::OK) { + surroundView2dSession = session; + } + }); + + if (surroundView2dSession && !mIs2dStreamStarted) { + handler = sp::make(surroundView2dSession); + if (surroundView2dSession->startStream(handler) == SvResult::OK) { + mIs2dStreamStarted = true; + } + } while (mFuzzedDataProvider.remaining_bytes() > 0) { auto surroundView2dFunc = mFuzzedDataProvider.PickValueInArray< const std::function>({ - [&]() { - mSurroundViewService->start2dSession( - [&surroundView2dSession](const sp& session, - SvResult result) { - if (result == SvResult::OK) { - surroundView2dSession = session; - } - }); - }, - [&]() { - if (surroundView2dSession) { - sp handler = - sp::make(surroundView2dSession); - surroundView2dSession->startStream(handler); - mIs2dStreamStarted = true; - } - }, [&]() { if (surroundView2dSession) { surroundView2dSession->get2dMappingInfo( @@ -69,7 +66,7 @@ void SurroundViewFuzzer::invoke2dSessionAPI() { } }, [&]() { - if (surroundView2dSession) { + if (surroundView2dSession && mIs2dStreamStarted) { Sv2dConfig config; config.width = mFuzzedDataProvider.ConsumeIntegralInRange( kMinConfigDimension, kMaxConfigDimension); @@ -149,8 +146,11 @@ void SurroundViewFuzzer::invoke2dSessionAPI() { } }, [&]() { - mSurroundViewService->stop2dSession( + SvResult result = mSurroundViewService->stop2dSession( mFuzzedDataProvider.ConsumeBool() ? surroundView2dSession : nullptr); + if (result == SvResult::OK) { + mIs2dStreamStarted = false; + } }, }); surroundView2dFunc(); @@ -159,30 +159,39 @@ void SurroundViewFuzzer::invoke2dSessionAPI() { if (surroundView2dSession && mIs2dStreamStarted) { surroundView2dSession->stopStream(); } + + if (surroundView2dSession) { + mSurroundViewService->stop2dSession(surroundView2dSession); + } } void SurroundViewFuzzer::invoke3dSessionAPI() { sp surroundView3dSession; + sp handler; + mSurroundViewService->start3dSession( + [&surroundView3dSession](const sp& session, SvResult result) { + if (result == SvResult::OK) { + surroundView3dSession = session; + } + }); + + const size_t numViews = mFuzzedDataProvider.ConsumeIntegralInRange(1, kMaxViews); + std::vector views(numViews); + for (size_t i = 0; i < numViews; ++i) { + views[i].viewId = mFuzzedDataProvider.ConsumeIntegral(); + } + surroundView3dSession->setViews(views); + + if (surroundView3dSession) { + handler = sp::make(surroundView3dSession); + + if (surroundView3dSession->startStream(handler) == SvResult::OK) { + mIs3dStreamStarted = true; + } + } while (mFuzzedDataProvider.remaining_bytes() > 0) { auto surroundView3dFunc = mFuzzedDataProvider.PickValueInArray< const std::function>({ - [&]() { - mSurroundViewService->start3dSession( - [&surroundView3dSession](const sp& session, - SvResult result) { - if (result == SvResult::OK) { - surroundView3dSession = session; - } - }); - }, - [&]() { - if (surroundView3dSession) { - sp handler = - sp::make(surroundView3dSession); - surroundView3dSession->startStream(handler); - mIs3dStreamStarted = true; - } - }, [&]() { if (surroundView3dSession) { const size_t numViews = @@ -195,7 +204,7 @@ void SurroundViewFuzzer::invoke3dSessionAPI() { } }, [&]() { - if (surroundView3dSession) { + if (surroundView3dSession && mIs3dStreamStarted) { Sv3dConfig config; config.width = mFuzzedDataProvider.ConsumeIntegralInRange( kMinConfigDimension, kMaxConfigDimension); @@ -306,8 +315,11 @@ void SurroundViewFuzzer::invoke3dSessionAPI() { } }, [&]() { - mSurroundViewService->stop3dSession( + SvResult result = mSurroundViewService->stop3dSession( mFuzzedDataProvider.ConsumeBool() ? surroundView3dSession : nullptr); + if (result == SvResult::OK) { + mIs3dStreamStarted = false; + } }, }); surroundView3dFunc(); @@ -315,6 +327,10 @@ void SurroundViewFuzzer::invoke3dSessionAPI() { if (surroundView3dSession && mIs3dStreamStarted) { surroundView3dSession->stopStream(); } + + if (surroundView3dSession) { + mSurroundViewService->stop3dSession(surroundView3dSession); + } } void SurroundViewFuzzer::process() {