From 3ad137edbb28fb1b728cf6222affbfd1b67933c5 Mon Sep 17 00:00:00 2001 From: Shuzhen Wang Date: Sun, 16 Apr 2023 21:24:40 -0700 Subject: [PATCH] Camera: VTS: Fix fence fd double close Fence fd is closed when processCaptureResult returns. In order to wait for the release fence *after* processCaptureResult returns, the fence fd needs to be duped. Test: Vendor testing Bug: 241281568 Change-Id: Ib74f9bb141802713b476a2ef48a2252125a7915d --- camera/provider/aidl/vts/camera_aidl_test.cpp | 2 +- camera/provider/aidl/vts/camera_aidl_test.h | 14 ++++++++++++++ camera/provider/aidl/vts/device_cb.cpp | 4 ++-- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/camera/provider/aidl/vts/camera_aidl_test.cpp b/camera/provider/aidl/vts/camera_aidl_test.cpp index 137c521c2b..ef3ce4f91f 100644 --- a/camera/provider/aidl/vts/camera_aidl_test.cpp +++ b/camera/provider/aidl/vts/camera_aidl_test.cpp @@ -148,7 +148,7 @@ void CameraAidlTest::waitForReleaseFence( const native_handle_t* releaseFenceHandle = bufferAndTimestamp.buffer.releaseFence; if (releaseFenceHandle != nullptr && releaseFenceHandle->numFds == 1 && releaseFenceHandle->data[0] >= 0) { - releaseFence = new android::Fence(releaseFenceHandle->data[0]); + releaseFence = new android::Fence(dup(releaseFenceHandle->data[0])); } if (releaseFence && releaseFence->isValid()) { releaseFence->wait(/*ms*/ 300); diff --git a/camera/provider/aidl/vts/camera_aidl_test.h b/camera/provider/aidl/vts/camera_aidl_test.h index 9fa84d36d1..f1de68fa68 100644 --- a/camera/provider/aidl/vts/camera_aidl_test.h +++ b/camera/provider/aidl/vts/camera_aidl_test.h @@ -478,6 +478,20 @@ class CameraAidlTest : public ::testing::TestWithParam { hasInputBuffer(hasInput), collectedResult(1, 10), expectedPhysicalResults(extraPhysicalResult) {} + + ~InFlightRequest() { + for (auto& buffer : resultOutputBuffers) { + native_handle_t* acquireFenceHandle = const_cast( + buffer.buffer.acquireFence); + native_handle_close(acquireFenceHandle); + native_handle_delete(acquireFenceHandle); + + native_handle_t* releaseFenceHandle = const_cast( + buffer.buffer.releaseFence); + native_handle_close(releaseFenceHandle); + native_handle_delete(releaseFenceHandle); + } + } }; static bool matchDeviceName(const std::string& deviceName, const std::string& providerType, diff --git a/camera/provider/aidl/vts/device_cb.cpp b/camera/provider/aidl/vts/device_cb.cpp index ca2f904c0a..7e0969aeae 100644 --- a/camera/provider/aidl/vts/device_cb.cpp +++ b/camera/provider/aidl/vts/device_cb.cpp @@ -428,8 +428,8 @@ bool DeviceCb::processCaptureResultLocked( bufferId, outputBuffer, buffer.status, - ::android::makeFromAidl(buffer.acquireFence), - ::android::makeFromAidl(buffer.releaseFence)}; + ::android::dupFromAidl(buffer.acquireFence), + ::android::dupFromAidl(buffer.releaseFence)}; streamBufferAndTimestamp.timeStamp = systemTime(); request->resultOutputBuffers.push_back(streamBufferAndTimestamp); }