Merge "Add gralloc tests for locking without CPU usage" into main

This commit is contained in:
Treehugger Robot
2024-07-11 11:39:42 +00:00
committed by Android (Google) Code Review
2 changed files with 68 additions and 0 deletions

View File

@@ -718,6 +718,38 @@ TEST_P(GraphicsMapperHidlTest, LockUnlockBasic) {
ASSERT_NO_FATAL_FAILURE(fence.reset(mGralloc->unlock(bufferHandle)));
}
/**
* Test IMapper::lock and IMapper::unlock with no CPU usage requested.
*/
TEST_P(GraphicsMapperHidlTest, LockUnlockNoCPUUsage) {
const auto& info = mDummyDescriptorInfo;
const native_handle_t* bufferHandle;
uint32_t stride;
ASSERT_NO_FATAL_FAILURE(
bufferHandle = mGralloc->allocate(info, true, Tolerance::kToleranceStrict, &stride));
// lock buffer with 0 usage
const IMapper::Rect region{0, 0, static_cast<int32_t>(info.width),
static_cast<int32_t>(info.height)};
hidl_handle acquireFenceHandle;
auto buffer = const_cast<native_handle_t*>(bufferHandle);
mGralloc->getMapper()->lock(buffer, 0, region, acquireFenceHandle,
[&](const auto& tmpError, const auto& /*tmpData*/) {
EXPECT_EQ(Error::BAD_VALUE, tmpError)
<< "Locking with 0 access succeeded";
});
mGralloc->getMapper()->unlock(buffer, [&](const auto& tmpError, const auto&) {
EXPECT_EQ(Error::BAD_BUFFER, tmpError)
<< "Unlocking not locked buffer succeeded";
});
mGralloc->freeBuffer(bufferHandle);
}
/**
* Test multiple operations associated with different color formats
*/

View File

@@ -749,6 +749,42 @@ TEST_P(GraphicsMapperStableCTests, LockUnlockBasic) {
}
}
/**
* Test IMapper::lock and IMapper::unlock with no CPU usage requested.
*/
TEST_P(GraphicsMapperStableCTests, LockUnlockNoCPUUsage) {
constexpr auto usage = BufferUsage::CPU_READ_NEVER | BufferUsage::CPU_WRITE_NEVER;
auto buffer = allocate({
.name = {"VTS_TEMP"},
.width = 64,
.height = 64,
.layerCount = 1,
.format = PixelFormat::RGBA_8888,
.usage = usage,
.reservedSize = 0,
});
ASSERT_NE(nullptr, buffer.get());
// lock buffer for writing
const auto& info = buffer->info();
const ARect region{0, 0, info.width, info.height};
auto handle = buffer->import();
uint8_t* data = nullptr;
EXPECT_EQ(AIMAPPER_ERROR_BAD_VALUE,
mapper()->v5.lock(*handle, static_cast<int64_t>(info.usage),
region, -1,(void**)&data))
<< "Locking with 0 access succeeded";
int releaseFence = -1;
EXPECT_EQ(AIMAPPER_ERROR_BAD_BUFFER,
mapper()->v5.unlock(*handle, &releaseFence))
<< "Unlocking not locked buffer succeeded";
if (releaseFence != -1) {
close(releaseFence);
}
}
/**
* Test multiple operations associated with different color formats
*/