Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 682cfa13 authored by Alina Kalyakina's avatar Alina Kalyakina
Browse files

Add gralloc tests for locking without CPU usage

Add GraphicsMapperHidlTest#LockUnlockNoCPUUsage and
GraphicsMapperStableCTests#LockUnlockNoCPUUsage.
The tests try to lock buffer without CPU usage.

Bug: 346894869
Test: https://android-build.corp.google.com/builds/abtd/run/L15900030005005775, https://android-build.corp.google.com/builds/abtd/run/L64000030005004833
Change-Id: I32a468ff889cf403239e4b10831d6e16e63ae2b9
parent a99ec307
Loading
Loading
Loading
Loading
+32 −0
Original line number Diff line number Diff line
@@ -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
 */
+36 −0
Original line number Diff line number Diff line
@@ -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
 */