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

Commit 89d09ddb authored by Chia-I Wu's avatar Chia-I Wu
Browse files

graphics: clean up mapper VTS tests

Add libVtsHalGraphicsMapperUtils which provides a wrapper to
IMapper.  Port tests to be based on libVtsHalGraphicsMapperUtils.

Test: manual
Change-Id: I0639df178fd0a94153b48733930bb13f2d0aa930
parent 69505c68
Loading
Loading
Loading
Loading
+29 −1
Original line number Diff line number Diff line
@@ -14,6 +14,27 @@
// limitations under the License.
//

cc_library_static {
    name: "libVtsHalGraphicsMapperTestUtils",
    srcs: ["VtsHalGraphicsMapperTestUtils.cpp"],
    shared_libs: [
        "android.hardware.graphics.allocator@2.0",
        "android.hardware.graphics.mapper@2.0",
    ],
    static_libs: [
        "VtsHalHidlTargetBaseTest",
        "libVtsHalGraphicsAllocatorTestUtils",
    ],
    cflags: [
        "-Wall",
        "-Wextra",
        "-Werror",
        "-O0",
        "-g",
    ],
    export_include_dirs: ["."],
}

cc_test {
    name: "VtsHalGraphicsMapperV2_0TargetTest",
    srcs: ["VtsHalGraphicsMapperV2_0TargetTest.cpp"],
@@ -30,8 +51,15 @@ cc_test {
        "android.hardware.graphics.mapper@2.0",
        "android.hardware.graphics.common@1.0",
    ],
    static_libs: ["VtsHalHidlTargetBaseTest"],
    static_libs: [
        "libVtsHalGraphicsAllocatorTestUtils",
        "libVtsHalGraphicsMapperTestUtils",
        "VtsHalHidlTargetBaseTest",
    ],
    cflags: [
        "-Wall",
        "-Wextra",
        "-Werror",
        "-O0",
        "-g",
    ]
+257 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <VtsHalHidlTargetBaseTest.h>

#include "VtsHalGraphicsMapperTestUtils.h"

namespace android {
namespace hardware {
namespace graphics {
namespace mapper {
namespace V2_0 {
namespace tests {

using android::hardware::graphics::allocator::V2_0::Buffer;
using android::hardware::graphics::allocator::V2_0::BufferDescriptor;
using android::hardware::graphics::allocator::V2_0::Error;

Mapper::Mapper() { init(); }

void Mapper::init() {
  mMapper = ::testing::VtsHalHidlTargetBaseTest::getService<IMapper>();
  ASSERT_NE(nullptr, mMapper.get()) << "failed to get mapper service";
  ASSERT_FALSE(mMapper->isRemote()) << "mapper is not in passthrough mode";
}

Mapper::~Mapper() {
  for (auto it : mHandles) {
    while (it.second) {
      EXPECT_EQ(Error::NONE, mMapper->release(it.first))
          << "failed to release handle " << it.first;
      it.second--;
    }
  }
  mHandles.clear();
}

sp<IMapper> Mapper::getRaw() const { return mMapper; }

void Mapper::retain(const native_handle_t* handle) {
  Error error = mMapper->retain(handle);
  ASSERT_EQ(Error::NONE, error) << "failed to retain handle " << handle;

  mHandles[handle]++;
}

void Mapper::release(const native_handle_t* handle) {
  Error error = mMapper->release(handle);
  ASSERT_EQ(Error::NONE, error) << "failed to release handle " << handle;

  if (--mHandles[handle] == 0) {
    mHandles.erase(handle);
  }
}

Mapper::Dimensions Mapper::getDimensions(const native_handle_t* handle) {
  Dimensions dimensions = {};
  mMapper->getDimensions(handle, [&](const auto& tmpError, const auto& tmpWidth,
                                     const auto& tmpHeight) {
    ASSERT_EQ(Error::NONE, tmpError)
        << "failed to get dimensions for handle " << handle;
    dimensions.width = tmpWidth;
    dimensions.height = tmpHeight;
  });

  return dimensions;
}

PixelFormat Mapper::getFormat(const native_handle_t* handle) {
  PixelFormat format = static_cast<PixelFormat>(0);
  mMapper->getFormat(handle, [&](const auto& tmpError, const auto& tmpFormat) {
    ASSERT_EQ(Error::NONE, tmpError)
        << "failed to get format for handle " << handle;
    format = tmpFormat;
  });

  return format;
}

uint32_t Mapper::getLayerCount(const native_handle_t* handle) {
  uint32_t count = 0;
  mMapper->getLayerCount(
      handle, [&](const auto& tmpError, const auto& tmpCount) {
        ASSERT_EQ(Error::NONE, tmpError)
            << "failed to get layer count for handle " << handle;
        count = tmpCount;
      });

  return count;
}

uint64_t Mapper::getProducerUsageMask(const native_handle_t* handle) {
  uint64_t usageMask = 0;
  mMapper->getProducerUsageMask(
      handle, [&](const auto& tmpError, const auto& tmpUsageMask) {
        ASSERT_EQ(Error::NONE, tmpError)
            << "failed to get producer usage mask for handle " << handle;
        usageMask = tmpUsageMask;
      });

  return usageMask;
}

uint64_t Mapper::getConsumerUsageMask(const native_handle_t* handle) {
  uint64_t usageMask = 0;
  mMapper->getConsumerUsageMask(
      handle, [&](const auto& tmpError, const auto& tmpUsageMask) {
        ASSERT_EQ(Error::NONE, tmpError)
            << "failed to get consumer usage mask for handle " << handle;
        usageMask = tmpUsageMask;
      });

  return usageMask;
}

BackingStore Mapper::getBackingStore(const native_handle_t* handle) {
  BackingStore backingStore = 0;
  mMapper->getBackingStore(
      handle, [&](const auto& tmpError, const auto& tmpBackingStore) {
        ASSERT_EQ(Error::NONE, tmpError)
            << "failed to get backing store for handle " << handle;
        backingStore = tmpBackingStore;
      });

  return backingStore;
}

uint32_t Mapper::getStride(const native_handle_t* handle) {
  uint32_t stride = 0;
  mMapper->getStride(handle, [&](const auto& tmpError, const auto& tmpStride) {
    ASSERT_EQ(Error::NONE, tmpError)
        << "failed to get stride for handle " << handle;
    stride = tmpStride;
  });

  return stride;
}

void* Mapper::lock(const native_handle_t* handle, uint64_t producerUsageMask,
                   uint64_t consumerUsageMask,
                   const IMapper::Rect& accessRegion, int acquireFence) {
  NATIVE_HANDLE_DECLARE_STORAGE(acquireFenceStorage, 0, 1);
  native_handle_t* acquireFenceHandle = nullptr;
  if (acquireFence >= 0) {
    acquireFenceHandle = native_handle_init(acquireFenceStorage, 0, 1);
    acquireFenceHandle->data[0] = acquireFence;
  }

  void* data = nullptr;
  mMapper->lock(
      handle, producerUsageMask, consumerUsageMask, accessRegion,
      acquireFenceHandle, [&](const auto& tmpError, const auto& tmpData) {
        ASSERT_EQ(Error::NONE, tmpError) << "failed to lock handle " << handle;
        data = tmpData;
      });

  if (acquireFence >= 0) {
    close(acquireFence);
  }

  return data;
}

FlexLayout Mapper::lockFlex(const native_handle_t* handle,
                            uint64_t producerUsageMask,
                            uint64_t consumerUsageMask,
                            const IMapper::Rect& accessRegion,
                            int acquireFence) {
  NATIVE_HANDLE_DECLARE_STORAGE(acquireFenceStorage, 0, 1);
  native_handle_t* acquireFenceHandle = nullptr;
  if (acquireFence >= 0) {
    acquireFenceHandle = native_handle_init(acquireFenceStorage, 0, 1);
    acquireFenceHandle->data[0] = acquireFence;
  }

  FlexLayout layout = {};
  mMapper->lockFlex(handle, producerUsageMask, consumerUsageMask, accessRegion,
                    acquireFenceHandle,
                    [&](const auto& tmpError, const auto& tmpLayout) {
                      ASSERT_EQ(Error::NONE, tmpError)
                          << "failed to lockFlex handle " << handle;
                      layout = tmpLayout;
                    });

  if (acquireFence >= 0) {
    close(acquireFence);
  }

  return layout;
}

int Mapper::unlock(const native_handle_t* handle) {
  int releaseFence = -1;
  mMapper->unlock(handle, [&](const auto& tmpError,
                              const auto& tmpReleaseFence) {
    ASSERT_EQ(Error::NONE, tmpError) << "failed to unlock handle " << handle;

    auto handle = tmpReleaseFence.getNativeHandle();
    if (handle) {
      ASSERT_EQ(0, handle->numInts) << "invalid fence handle " << handle;
      if (handle->numFds == 1) {
        releaseFence = dup(handle->data[0]);
        ASSERT_LT(0, releaseFence) << "failed to dup fence fd";
      } else {
        ASSERT_EQ(0, handle->numFds) << " invalid fence handle " << handle;
      }
    }
  });

  return releaseFence;
}

const native_handle_t* Mapper::allocate(
    std::unique_ptr<AllocatorClient>& allocatorClient,
    const IAllocatorClient::BufferDescriptorInfo& info) {
  BufferDescriptor descriptor = allocatorClient->createDescriptor(info);
  if (::testing::Test::HasFatalFailure()) {
    return nullptr;
  }

  Buffer buffer = allocatorClient->allocate(descriptor);
  if (::testing::Test::HasFatalFailure()) {
    allocatorClient->destroyDescriptor(descriptor);
    return nullptr;
  }

  const native_handle_t* handle =
      allocatorClient->exportHandle(descriptor, buffer);
  if (handle) {
    retain(handle);
  }

  allocatorClient->free(buffer);
  allocatorClient->destroyDescriptor(descriptor);

  return handle;
}

}  // namespace tests
}  // namespace V2_0
}  // namespace mapper
}  // namespace graphics
}  // namespace hardware
}  // namespace android
+97 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef VTS_HAL_GRAPHICS_MAPPER_UTILS
#define VTS_HAL_GRAPHICS_MAPPER_UTILS

#include <memory>
#include <unordered_map>

#include <android/hardware/graphics/mapper/2.0/IMapper.h>
#include <utils/StrongPointer.h>

#include "VtsHalGraphicsAllocatorTestUtils.h"

namespace android {
namespace hardware {
namespace graphics {
namespace mapper {
namespace V2_0 {
namespace tests {

using android::hardware::graphics::common::V1_0::PixelFormat;
using android::hardware::graphics::allocator::V2_0::IAllocatorClient;
using android::hardware::graphics::allocator::V2_0::tests::AllocatorClient;

// A wrapper to IMapper.
class Mapper {
 public:
  Mapper();
  ~Mapper();

  sp<IMapper> getRaw() const;

  void retain(const native_handle_t* handle);
  void release(const native_handle_t* handle);

  struct Dimensions {
    uint32_t width;
    uint32_t height;
  };
  Dimensions getDimensions(const native_handle_t* handle);

  PixelFormat getFormat(const native_handle_t* handle);
  uint32_t getLayerCount(const native_handle_t* handle);
  uint64_t getProducerUsageMask(const native_handle_t* handle);
  uint64_t getConsumerUsageMask(const native_handle_t* handle);
  BackingStore getBackingStore(const native_handle_t* handle);
  uint32_t getStride(const native_handle_t* handle);

  // We use fd instead of hidl_handle in these functions to pass fences
  // in and out of the mapper.  The ownership of the fd is always transferred
  // with each of these functions.
  void* lock(const native_handle_t* handle, uint64_t producerUsageMask,
             uint64_t consumerUsageMask, const IMapper::Rect& accessRegion,
             int acquireFence);
  FlexLayout lockFlex(const native_handle_t* handle, uint64_t producerUsageMask,
                      uint64_t consumerUsageMask,
                      const IMapper::Rect& accessRegion, int acquireFence);
  int unlock(const native_handle_t* handle);

  // Requests AllocatorClient to allocate a buffer, export the handle, and
  // register the handle with mapper.
  const native_handle_t* allocate(
      std::unique_ptr<AllocatorClient>& allocatorClient,
      const IAllocatorClient::BufferDescriptorInfo& info);

 private:
  void init();

  sp<IMapper> mMapper;

  // Keep track of all registered (retained) handles.  When a test fails with
  // ASSERT_*, the destructor will release the handles for the test.
  std::unordered_map<const native_handle_t*, uint64_t> mHandles;
};

}  // namespace tests
}  // namespace V2_0
}  // namespace mapper
}  // namespace graphics
}  // namespace hardware
}  // namespace android

#endif  // VTS_HAL_GRAPHICS_MAPPER_UTILS
+56 −197
Original line number Diff line number Diff line
@@ -17,10 +17,9 @@
#define LOG_TAG "graphics_mapper_hidl_hal_test"

#include <android-base/logging.h>
#include <android/hardware/graphics/allocator/2.0/IAllocator.h>
#include <android/hardware/graphics/mapper/2.0/IMapper.h>
#include <VtsHalHidlTargetBaseTest.h>
#include <sync/sync.h>
#include "VtsHalGraphicsMapperTestUtils.h"

namespace android {
namespace hardware {
@@ -31,24 +30,14 @@ namespace tests {
namespace {

using namespace android::hardware::graphics::allocator::V2_0;
using namespace android::hardware::graphics::common::V1_0;
using namespace android::hardware::graphics::allocator::V2_0::tests;

class GraphicsMapperHidlTest : public ::testing::VtsHalHidlTargetBaseTest {
 protected:
  void SetUp() override {
    mAllocator = ::testing::VtsHalHidlTargetBaseTest::getService<IAllocator>();
    ASSERT_NE(mAllocator, nullptr);

    mAllocator->createClient([this](const auto& error, const auto& client) {
      if (error == Error::NONE) {
        mAllocatorClient = client;
      }
    });
    ASSERT_NE(mAllocatorClient, nullptr);

    mMapper = ::testing::VtsHalHidlTargetBaseTest::getService<IMapper>();
    ASSERT_NE(nullptr, mMapper.get());
    ASSERT_FALSE(mMapper->isRemote());
    ASSERT_NO_FATAL_FAILURE(mAllocator = std::make_unique<Allocator>());
    ASSERT_NO_FATAL_FAILURE(mAllocatorClient = mAllocator->createClient());
    ASSERT_NO_FATAL_FAILURE(mMapper = std::make_unique<Mapper>());

    mDummyDescriptorInfo.width = 64;
    mDummyDescriptorInfo.height = 64;
@@ -62,134 +51,51 @@ class GraphicsMapperHidlTest : public ::testing::VtsHalHidlTargetBaseTest {

  void TearDown() override {}

  const native_handle_t* allocate(
      const IAllocatorClient::BufferDescriptorInfo& info) {
    // create descriptor
    Error err = Error::NO_RESOURCES;
    BufferDescriptor descriptor;
    mAllocatorClient->createDescriptor(
        info, [&](const auto& tmpError, const auto& tmpDescriptor) {
          err = tmpError;
          descriptor = tmpDescriptor;
        });
    if (err != Error::NONE) {
      return nullptr;
    }

    // allocate buffer
    hidl_vec<BufferDescriptor> descriptors;
    hidl_vec<Buffer> buffers;
    descriptors.setToExternal(&descriptor, 1);
    err = Error::NO_RESOURCES;
    mAllocatorClient->allocate(
        descriptors, [&](const auto& tmpError, const auto& tmpBuffers) {
          err = tmpError;
          buffers = tmpBuffers;
        });
    if ((err != Error::NONE && err != Error::NOT_SHARED) ||
        buffers.size() != 1) {
      mAllocatorClient->destroyDescriptor(descriptors[0]);
      return nullptr;
    }

    // export handle
    err = Error::NO_RESOURCES;
    const native_handle_t* handle = nullptr;
    mAllocatorClient->exportHandle(
        descriptors[0], buffers[0],
        [&](const auto& tmpError, const auto& tmpHandle) {
          err = tmpError;
          if (err != Error::NONE) {
            return;
          }

          handle = native_handle_clone(tmpHandle);
          if (!handle) {
            err = Error::NO_RESOURCES;
            return;
          }

          err = mMapper->retain(handle);
          if (err != Error::NONE) {
            native_handle_close(handle);
            native_handle_delete(const_cast<native_handle_t*>(handle));
            handle = nullptr;
          }
        });

    mAllocatorClient->destroyDescriptor(descriptors[0]);
    mAllocatorClient->free(buffers[0]);

    if (err != Error::NONE) {
      return nullptr;
    }

    return handle;
  }

  sp<IMapper> mMapper;

  std::unique_ptr<Allocator> mAllocator;
  std::unique_ptr<AllocatorClient> mAllocatorClient;
  std::unique_ptr<Mapper> mMapper;
  IAllocatorClient::BufferDescriptorInfo mDummyDescriptorInfo{};

 private:
  sp<IAllocator> mAllocator;
  sp<IAllocatorClient> mAllocatorClient;
};

/**
 * Test IMapper::retain and IMapper::release.
 */
TEST_F(GraphicsMapperHidlTest, RetainRelease) {
  const native_handle_t* buffer = allocate(mDummyDescriptorInfo);
  ASSERT_NE(buffer, nullptr);
  const native_handle_t* buffer;
  ASSERT_NO_FATAL_FAILURE(
      buffer = mMapper->allocate(mAllocatorClient, mDummyDescriptorInfo));

  const int maxRefs = 10;
  for (int i = 0; i < maxRefs; i++) {
    auto err = mMapper->retain(buffer);
    EXPECT_EQ(Error::NONE, err);
    ASSERT_NO_FATAL_FAILURE(mMapper->retain(buffer));
  }
  for (int i = 0; i < maxRefs; i++) {
    auto err = mMapper->release(buffer);
    EXPECT_EQ(Error::NONE, err);
    ASSERT_NO_FATAL_FAILURE(mMapper->release(buffer));
  }

  auto err = mMapper->release(buffer);
  EXPECT_EQ(Error::NONE, err);
  ASSERT_NO_FATAL_FAILURE(mMapper->release(buffer));
}

/**
 * Test IMapper::get* getters.
 */
TEST_F(GraphicsMapperHidlTest, Getters) {
  const native_handle_t* buffer = allocate(mDummyDescriptorInfo);
  ASSERT_NE(buffer, nullptr);
  const native_handle_t* buffer;
  ASSERT_NO_FATAL_FAILURE(
      buffer = mMapper->allocate(mAllocatorClient, mDummyDescriptorInfo));

  IAllocatorClient::BufferDescriptorInfo info = {};

  Error err = Error::NO_RESOURCES;
  IAllocatorClient::BufferDescriptorInfo info{};
  mMapper->getDimensions(buffer, [&](const auto& tmpError, const auto& tmpWidth,
                                     const auto& tmpHeight) {
    err = tmpError;
    info.width = tmpWidth;
    info.height = tmpHeight;
  });
  EXPECT_EQ(Error::NONE, err);
  mMapper->getFormat(buffer, [&](const auto& tmpError, const auto& tmpFormat) {
    err = tmpError;
    info.format = tmpFormat;
  });
  EXPECT_EQ(Error::NONE, err);
  mMapper->getProducerUsageMask(
      buffer, [&](const auto& tmpError, const auto& tmpUsage) {
        err = tmpError;
        info.producerUsageMask = tmpUsage;
      });
  EXPECT_EQ(Error::NONE, err);
  mMapper->getConsumerUsageMask(
      buffer, [&](const auto& tmpError, const auto& tmpUsage) {
        err = tmpError;
        info.consumerUsageMask = tmpUsage;
      });
  EXPECT_EQ(Error::NONE, err);
  Mapper::Dimensions dimensions;
  ASSERT_NO_FATAL_FAILURE(dimensions = mMapper->getDimensions(buffer));
  info.width = dimensions.width;
  info.height = dimensions.height;

  ASSERT_NO_FATAL_FAILURE(info.format = mMapper->getFormat(buffer));
  ASSERT_NO_FATAL_FAILURE(info.producerUsageMask =
                              mMapper->getProducerUsageMask(buffer));
  ASSERT_NO_FATAL_FAILURE(info.consumerUsageMask =
                              mMapper->getConsumerUsageMask(buffer));

  EXPECT_EQ(mDummyDescriptorInfo.width, info.width);
  EXPECT_EQ(mDummyDescriptorInfo.height, info.height);
@@ -197,24 +103,11 @@ TEST_F(GraphicsMapperHidlTest, Getters) {
  EXPECT_EQ(mDummyDescriptorInfo.producerUsageMask, info.producerUsageMask);
  EXPECT_EQ(mDummyDescriptorInfo.consumerUsageMask, info.consumerUsageMask);

  BackingStore store = 0;
  mMapper->getBackingStore(buffer,
                           [&](const auto& tmpError, const auto& tmpStore) {
                             err = tmpError;
                             store = tmpStore;
                           });
  EXPECT_EQ(Error::NONE, err);
  ASSERT_NO_FATAL_FAILURE(mMapper->getBackingStore(buffer));

  uint32_t stride = 0;
  mMapper->getStride(buffer, [&](const auto& tmpError, const auto& tmpStride) {
    err = tmpError;
    stride = tmpStride;
  });
  EXPECT_EQ(Error::NONE, err);
  uint32_t stride;
  ASSERT_NO_FATAL_FAILURE(stride = mMapper->getStride(buffer));
  EXPECT_LE(info.width, stride);

  err = mMapper->release(buffer);
  EXPECT_EQ(Error::NONE, err);
}

/**
@@ -222,79 +115,45 @@ TEST_F(GraphicsMapperHidlTest, Getters) {
 */
TEST_F(GraphicsMapperHidlTest, LockBasic) {
  const auto& info = mDummyDescriptorInfo;
  const native_handle_t* buffer = allocate(info);
  ASSERT_NE(buffer, nullptr);

  Error err = Error::NO_RESOURCES;
  uint32_t stride = 0;
  mMapper->getStride(buffer, [&](const auto& tmpError, const auto& tmpStride) {
    err = tmpError;
    stride = tmpStride;
  });
  EXPECT_EQ(Error::NONE, err);
  const native_handle_t* buffer;
  ASSERT_NO_FATAL_FAILURE(
      buffer = mMapper->allocate(mAllocatorClient, mDummyDescriptorInfo));

  uint32_t stride;
  ASSERT_NO_FATAL_FAILURE(stride = mMapper->getStride(buffer));

  // lock buffer for writing
  const IMapper::Rect region{0, 0, static_cast<int32_t>(info.width),
                             static_cast<int32_t>(info.height)};
  hidl_handle acquireFence(nullptr);
  int fence = -1;
  uint32_t* data;
  err = Error::NO_RESOURCES;
  mMapper->lock(buffer, info.producerUsageMask, 0, region, acquireFence,
          [&](const auto& tmpError, const auto& tmpData) {
            err = tmpError;
            data = static_cast<uint32_t*>(tmpData);
          });
  ASSERT_NO_FATAL_FAILURE(
      data = static_cast<uint32_t*>(
          mMapper->lock(buffer, info.producerUsageMask, 0, region, fence)));

  if (err == Error::NONE) {
  for (uint32_t y = 0; y < info.height; y++) {
    for (uint32_t x = 0; x < info.width; x++) {
      data[stride * y + x] = info.height * y + x;
    }
  }
  } else {
    EXPECT_EQ(Error::NONE, err);
  }

  err = Error::NO_RESOURCES;
  mMapper->unlock(buffer, [&](const auto& tmpError, const auto& tmpReleaseFence) {
            err = tmpError;
            auto handle = tmpReleaseFence.getNativeHandle();
            if (handle && handle->numFds == 1) {
                sync_wait(handle->data[0], -1);
                close(handle->data[0]);
            }
          });
  EXPECT_EQ(Error::NONE, err);
  ASSERT_NO_FATAL_FAILURE(fence = mMapper->unlock(buffer));

  // lock buffer for reading
  mMapper->lock(buffer, 0, info.consumerUsageMask, region, acquireFence,
          [&](const auto& tmpError, const auto& tmpData) {
            err = tmpError;
            data = static_cast<uint32_t*>(tmpData);
          });
  if (err == Error::NONE) {
  ASSERT_NO_FATAL_FAILURE(
      data = static_cast<uint32_t*>(
          mMapper->lock(buffer, 0, info.consumerUsageMask, region, fence)));
  for (uint32_t y = 0; y < info.height; y++) {
    for (uint32_t x = 0; x < info.width; x++) {
      EXPECT_EQ(info.height * y + x, data[stride * y + x]);
    }
  }
  } else {
    EXPECT_EQ(Error::NONE, err);
  }

  err = Error::NO_RESOURCES;
  mMapper->unlock(buffer, [&](const auto& tmpError, const auto& tmpReleaseFence) {
            err = tmpError;
            auto handle = tmpReleaseFence.getNativeHandle();
            if (handle && handle->numFds == 1) {
                sync_wait(handle->data[0], -1);
                close(handle->data[0]);
  ASSERT_NO_FATAL_FAILURE(fence = mMapper->unlock(buffer));
  if (fence >= 0) {
    close(fence);
  }
          });
  EXPECT_EQ(Error::NONE, err);

  err = mMapper->release(buffer);
  EXPECT_EQ(Error::NONE, err);
}

}  // namespace anonymous