graphics: clean up allocator VTS tests

Add libVtsHalGraphicsAllocatorUtils which provides a wrapper to
IAllocator.  Port tests to be based on
libVtsHalGraphicsAllocatorUtils.

Test: manual
Change-Id: I6d56160dc4fa6e5106cc55e75cdd923f15635317
diff --git a/graphics/allocator/2.0/vts/functional/Android.bp b/graphics/allocator/2.0/vts/functional/Android.bp
index fdc91ae..c3a16fb 100644
--- a/graphics/allocator/2.0/vts/functional/Android.bp
+++ b/graphics/allocator/2.0/vts/functional/Android.bp
@@ -14,6 +14,25 @@
 // limitations under the License.
 //
 
+cc_library_static {
+    name: "libVtsHalGraphicsAllocatorTestUtils",
+    srcs: ["VtsHalGraphicsAllocatorTestUtils.cpp"],
+    shared_libs: [
+        "android.hardware.graphics.allocator@2.0",
+    ],
+    static_libs: [
+        "VtsHalHidlTargetBaseTest",
+    ],
+    cflags: [
+        "-Wall",
+        "-Wextra",
+        "-Werror",
+        "-O0",
+        "-g",
+    ],
+    export_include_dirs: ["."],
+}
+
 cc_test {
     name: "VtsHalGraphicsAllocatorV2_0TargetTest",
     srcs: ["VtsHalGraphicsAllocatorV2_0TargetTest.cpp"],
@@ -27,8 +46,14 @@
         "libutils",
         "android.hardware.graphics.allocator@2.0",
     ],
-    static_libs: ["VtsHalHidlTargetBaseTest"],
+    static_libs: [
+        "libVtsHalGraphicsAllocatorTestUtils",
+        "VtsHalHidlTargetBaseTest",
+    ],
     cflags: [
+        "-Wall",
+        "-Wextra",
+        "-Werror",
         "-O0",
         "-g",
     ]
diff --git a/graphics/allocator/2.0/vts/functional/VtsHalGraphicsAllocatorTestUtils.cpp b/graphics/allocator/2.0/vts/functional/VtsHalGraphicsAllocatorTestUtils.cpp
new file mode 100644
index 0000000..141743b
--- /dev/null
+++ b/graphics/allocator/2.0/vts/functional/VtsHalGraphicsAllocatorTestUtils.cpp
@@ -0,0 +1,183 @@
+/*
+ * 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 "VtsHalGraphicsAllocatorTestUtils.h"
+
+namespace android {
+namespace hardware {
+namespace graphics {
+namespace allocator {
+namespace V2_0 {
+namespace tests {
+
+Allocator::Allocator() { init(); }
+
+void Allocator::init() {
+  mAllocator = ::testing::VtsHalHidlTargetBaseTest::getService<IAllocator>();
+  ASSERT_NE(nullptr, mAllocator.get()) << "failed to get allocator service";
+
+  std::vector<IAllocator::Capability> capabilities = getCapabilities();
+  mCapabilities.insert(capabilities.begin(), capabilities.end());
+}
+
+sp<IAllocator> Allocator::getRaw() const { return mAllocator; }
+
+bool Allocator::hasCapability(IAllocator::Capability capability) const {
+  return mCapabilities.count(capability) > 0;
+}
+
+std::vector<IAllocator::Capability> Allocator::getCapabilities() {
+  std::vector<IAllocator::Capability> capabilities;
+  mAllocator->getCapabilities(
+      [&](const auto& tmpCapabilities) { capabilities = tmpCapabilities; });
+
+  return capabilities;
+}
+
+std::string Allocator::dumpDebugInfo() {
+  std::string debugInfo;
+  mAllocator->dumpDebugInfo(
+      [&](const auto& tmpDebugInfo) { debugInfo = tmpDebugInfo.c_str(); });
+
+  return debugInfo;
+}
+
+std::unique_ptr<AllocatorClient> Allocator::createClient() {
+  std::unique_ptr<AllocatorClient> client;
+  mAllocator->createClient([&](const auto& tmpError, const auto& tmpClient) {
+    ASSERT_EQ(Error::NONE, tmpError) << "failed to create client";
+    client = std::make_unique<AllocatorClient>(tmpClient);
+  });
+
+  return client;
+}
+
+AllocatorClient::AllocatorClient(const sp<IAllocatorClient>& client)
+    : mClient(client) {}
+
+AllocatorClient::~AllocatorClient() {
+  for (auto buffer : mBuffers) {
+    EXPECT_EQ(Error::NONE, mClient->free(buffer))
+        << "failed to free buffer " << buffer;
+  }
+  mBuffers.clear();
+
+  for (auto descriptor : mDescriptors) {
+    EXPECT_EQ(Error::NONE, mClient->destroyDescriptor(descriptor))
+        << "failed to destroy descriptor " << descriptor;
+  }
+  mDescriptors.clear();
+}
+
+sp<IAllocatorClient> AllocatorClient::getRaw() const { return mClient; }
+
+BufferDescriptor AllocatorClient::createDescriptor(
+    const IAllocatorClient::BufferDescriptorInfo& info) {
+  BufferDescriptor descriptor = 0;
+  mClient->createDescriptor(
+      info, [&](const auto& tmpError, const auto& tmpDescriptor) {
+        ASSERT_EQ(Error::NONE, tmpError) << "failed to create descriptor";
+        descriptor = tmpDescriptor;
+
+        EXPECT_TRUE(mDescriptors.insert(descriptor).second)
+            << "duplicated descriptor id " << descriptor;
+      });
+
+  return descriptor;
+}
+
+void AllocatorClient::destroyDescriptor(BufferDescriptor descriptor) {
+  ASSERT_EQ(Error::NONE, mClient->destroyDescriptor(descriptor))
+      << "failed to destroy descriptor " << descriptor;
+
+  mDescriptors.erase(descriptor);
+}
+
+Error AllocatorClient::testAllocate(
+    const std::vector<BufferDescriptor>& descriptors) {
+  return mClient->testAllocate(descriptors);
+}
+
+bool AllocatorClient::testAllocate(BufferDescriptor descriptor) {
+  std::vector<BufferDescriptor> descriptors(1, descriptor);
+  Error error = testAllocate(descriptors);
+  return (error == Error::NONE || error == Error::NOT_SHARED);
+}
+
+Error AllocatorClient::allocate(
+    const std::vector<BufferDescriptor>& descriptors,
+    std::vector<Buffer>& buffers) {
+  Error error = Error::NO_RESOURCES;
+  mClient->allocate(descriptors, [&](const auto& tmpError,
+                                     const auto& tmpBuffers) {
+    ASSERT_TRUE(tmpError == Error::NONE || tmpError == Error::NOT_SHARED)
+        << "failed to allocate buffer";
+    ASSERT_EQ(descriptors.size(), tmpBuffers.size()) << "invalid buffer count";
+
+    error = tmpError;
+    buffers = tmpBuffers;
+
+    for (auto buffer : buffers) {
+      EXPECT_TRUE(mBuffers.insert(buffer).second)
+          << "duplicated buffer id " << buffer;
+    }
+  });
+
+  return error;
+}
+
+Buffer AllocatorClient::allocate(BufferDescriptor descriptor) {
+  std::vector<BufferDescriptor> descriptors(1, descriptor);
+  std::vector<Buffer> buffers;
+  allocate(descriptors, buffers);
+  if (::testing::Test::HasFatalFailure()) {
+    return 0;
+  }
+
+  return buffers[0];
+}
+
+void AllocatorClient::free(Buffer buffer) {
+  ASSERT_EQ(Error::NONE, mClient->free(buffer))
+      << "failed to free buffer " << buffer;
+
+  mBuffers.erase(buffer);
+}
+
+native_handle_t* AllocatorClient::exportHandle(BufferDescriptor descriptor,
+                                               Buffer buffer) {
+  native_handle_t* handle;
+  mClient->exportHandle(
+      descriptor, buffer, [&](const auto& tmpError, const auto& tmpHandle) {
+        ASSERT_EQ(Error::NONE, tmpError) << "failed to export buffer handle";
+        ASSERT_NE(nullptr, tmpHandle.getNativeHandle())
+            << "invalid buffer handle";
+
+        handle = native_handle_clone(tmpHandle.getNativeHandle());
+        ASSERT_NE(nullptr, handle) << "failed to clone handle";
+      });
+
+  return handle;
+}
+
+}  // namespace tests
+}  // namespace V2_0
+}  // namespace allocator
+}  // namespace graphics
+}  // namespace hardware
+}  // namespace android
diff --git a/graphics/allocator/2.0/vts/functional/VtsHalGraphicsAllocatorTestUtils.h b/graphics/allocator/2.0/vts/functional/VtsHalGraphicsAllocatorTestUtils.h
new file mode 100644
index 0000000..c9bfe8f
--- /dev/null
+++ b/graphics/allocator/2.0/vts/functional/VtsHalGraphicsAllocatorTestUtils.h
@@ -0,0 +1,98 @@
+/*
+ * 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_ALLOCATOR_UTILS
+#define VTS_HAL_GRAPHICS_ALLOCATOR_UTILS
+
+#include <memory>
+#include <string>
+#include <unordered_set>
+#include <vector>
+
+#include <android/hardware/graphics/allocator/2.0/IAllocator.h>
+#include <utils/StrongPointer.h>
+
+namespace android {
+namespace hardware {
+namespace graphics {
+namespace allocator {
+namespace V2_0 {
+namespace tests {
+
+class AllocatorClient;
+
+// A wrapper to IAllocator.
+class Allocator {
+ public:
+  Allocator();
+
+  sp<IAllocator> getRaw() const;
+
+  // Returns true when the allocator supports the specified capability.
+  bool hasCapability(IAllocator::Capability capability) const;
+
+  std::vector<IAllocator::Capability> getCapabilities();
+  std::string dumpDebugInfo();
+  std::unique_ptr<AllocatorClient> createClient();
+
+ private:
+  void init();
+
+  sp<IAllocator> mAllocator;
+  std::unordered_set<IAllocator::Capability> mCapabilities;
+};
+
+// A wrapper to IAllocatorClient.
+class AllocatorClient {
+ public:
+  AllocatorClient(const sp<IAllocatorClient>& client);
+  ~AllocatorClient();
+
+  sp<IAllocatorClient> getRaw() const;
+
+  BufferDescriptor createDescriptor(
+      const IAllocatorClient::BufferDescriptorInfo& info);
+  void destroyDescriptor(BufferDescriptor descriptor);
+
+  Error testAllocate(const std::vector<BufferDescriptor>& descriptors);
+  bool testAllocate(BufferDescriptor descriptor);
+
+  Error allocate(const std::vector<BufferDescriptor>& descriptors,
+                 std::vector<Buffer>& buffers);
+  Buffer allocate(BufferDescriptor descriptor);
+  void free(Buffer buffer);
+
+  // Returns a handle to the buffer.  The ownership of the handle is
+  // transferred to the caller.
+  native_handle_t* exportHandle(BufferDescriptor descriptor, Buffer buffer);
+
+ private:
+  sp<IAllocatorClient> mClient;
+
+  // Keep track of all descriptors and buffers.  When a test fails with
+  // ASSERT_*, the destructor will clean up the resources for the test.
+  std::unordered_set<BufferDescriptor> mDescriptors;
+  std::unordered_set<Buffer> mBuffers;
+};
+
+}  // namespace tests
+}  // namespace V2_0
+}  // namespace allocator
+}  // namespace graphics
+}  // namespace hardware
+}  // namespace android
+
+#endif  // VTS_HAL_GRAPHICS_ALLOCATOR_UTILS
diff --git a/graphics/allocator/2.0/vts/functional/VtsHalGraphicsAllocatorV2_0TargetTest.cpp b/graphics/allocator/2.0/vts/functional/VtsHalGraphicsAllocatorV2_0TargetTest.cpp
index a8ced8c..2e3ed73 100644
--- a/graphics/allocator/2.0/vts/functional/VtsHalGraphicsAllocatorV2_0TargetTest.cpp
+++ b/graphics/allocator/2.0/vts/functional/VtsHalGraphicsAllocatorV2_0TargetTest.cpp
@@ -16,12 +16,11 @@
 
 #define LOG_TAG "graphics_allocator_hidl_hal_test"
 
-#include <unordered_set>
-
 #include <android-base/logging.h>
-#include <android/hardware/graphics/allocator/2.0/IAllocator.h>
 #include <VtsHalHidlTargetBaseTest.h>
 
+#include "VtsHalGraphicsAllocatorTestUtils.h"
+
 namespace android {
 namespace hardware {
 namespace graphics {
@@ -34,55 +33,18 @@
 
 #define CHECK_FEATURE_OR_SKIP(FEATURE_NAME)                 \
   do {                                                      \
-    if (!hasCapability(FEATURE_NAME)) {                     \
+    if (!mAllocator->hasCapability(FEATURE_NAME)) {         \
       std::cout << "[  SKIPPED ] Feature " << #FEATURE_NAME \
                 << " not supported" << std::endl;           \
       return;                                               \
     }                                                       \
   } while (0)
 
-class TempDescriptor {
- public:
-  TempDescriptor(const sp<IAllocatorClient>& client,
-                 const IAllocatorClient::BufferDescriptorInfo& info)
-      : mClient(client), mError(Error::NO_RESOURCES) {
-    mClient->createDescriptor(
-        info, [&](const auto& tmpError, const auto& tmpDescriptor) {
-          mError = tmpError;
-          mDescriptor = tmpDescriptor;
-        });
-  }
-
-  ~TempDescriptor() {
-    if (mError == Error::NONE) {
-      mClient->destroyDescriptor(mDescriptor);
-    }
-  }
-
-  bool isValid() const { return (mError == Error::NONE); }
-
-  operator BufferDescriptor() const { return mDescriptor; }
-
- private:
-  sp<IAllocatorClient> mClient;
-  Error mError;
-  BufferDescriptor mDescriptor;
-};
-
 class GraphicsAllocatorHidlTest : 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) {
-        mClient = client;
-      }
-    });
-    ASSERT_NE(mClient, nullptr);
-
-    initCapabilities();
+    ASSERT_NO_FATAL_FAILURE(mAllocator = std::make_unique<Allocator>());
+    ASSERT_NO_FATAL_FAILURE(mClient = mAllocator->createClient());
 
     mDummyDescriptorInfo.width = 64;
     mDummyDescriptorInfo.height = 64;
@@ -96,66 +58,27 @@
 
   void TearDown() override {}
 
-  /**
-   * Initialize the set of supported capabilities.
-   */
-  void initCapabilities() {
-    mAllocator->getCapabilities([this](const auto& capabilities) {
-      std::vector<IAllocator::Capability> caps = capabilities;
-      mCapabilities.insert(caps.cbegin(), caps.cend());
-    });
-  }
-
-  /**
-   * Test whether a capability is supported.
-   */
-  bool hasCapability(IAllocator::Capability capability) const {
-    return (mCapabilities.count(capability) > 0);
-  }
-
-  sp<IAllocator> mAllocator;
-  sp<IAllocatorClient> mClient;
+  std::unique_ptr<Allocator> mAllocator;
+  std::unique_ptr<AllocatorClient> mClient;
   IAllocatorClient::BufferDescriptorInfo mDummyDescriptorInfo{};
-
- private:
-  std::unordered_set<IAllocator::Capability> mCapabilities;
 };
 
 TEST_F(GraphicsAllocatorHidlTest, GetCapabilities) {
-  auto ret = mAllocator->getCapabilities([](const auto& capabilities) {
-    std::vector<IAllocator::Capability> caps = capabilities;
-    for (auto cap : caps) {
-      EXPECT_NE(IAllocator::Capability::INVALID, cap);
-    }
-  });
-
-  ASSERT_TRUE(ret.isOk());
+  auto capabilities = mAllocator->getCapabilities();
+  for (auto cap : capabilities) {
+    EXPECT_NE(IAllocator::Capability::INVALID, cap);
+  }
 }
 
 TEST_F(GraphicsAllocatorHidlTest, DumpDebugInfo) {
-  auto ret = mAllocator->dumpDebugInfo([](const auto&) {
-    // nothing to do
-  });
-
-  ASSERT_TRUE(ret.isOk());
+  mAllocator->dumpDebugInfo();
 }
 
 TEST_F(GraphicsAllocatorHidlTest, CreateDestroyDescriptor) {
-  Error error;
   BufferDescriptor descriptor;
-  auto ret = mClient->createDescriptor(
-      mDummyDescriptorInfo,
-      [&](const auto& tmpError, const auto& tmpDescriptor) {
-        error = tmpError;
-        descriptor = tmpDescriptor;
-      });
-
-  ASSERT_TRUE(ret.isOk());
-  ASSERT_EQ(Error::NONE, error);
-
-  auto err_ret = mClient->destroyDescriptor(descriptor);
-  ASSERT_TRUE(err_ret.isOk());
-  ASSERT_EQ(Error::NONE, static_cast<Error>(err_ret));
+  ASSERT_NO_FATAL_FAILURE(descriptor =
+                              mClient->createDescriptor(mDummyDescriptorInfo));
+  mClient->destroyDescriptor(descriptor);
 }
 
 /**
@@ -164,18 +87,11 @@
 TEST_F(GraphicsAllocatorHidlTest, TestAllocateBasic) {
   CHECK_FEATURE_OR_SKIP(IAllocator::Capability::TEST_ALLOCATE);
 
-  TempDescriptor descriptor(mClient, mDummyDescriptorInfo);
-  ASSERT_TRUE(descriptor.isValid());
+  BufferDescriptor descriptor;
+  ASSERT_NO_FATAL_FAILURE(descriptor =
+                              mClient->createDescriptor(mDummyDescriptorInfo));
 
-  hidl_vec<BufferDescriptor> descriptors;
-  descriptors.resize(1);
-  descriptors[0] = descriptor;
-
-  auto ret = mClient->testAllocate(descriptors);
-  ASSERT_TRUE(ret.isOk());
-
-  auto error = static_cast<Error>(ret);
-  ASSERT_TRUE(error == Error::NONE || error == Error::NOT_SHARED);
+  ASSERT_TRUE(mClient->testAllocate(descriptor));
 }
 
 /**
@@ -184,18 +100,16 @@
 TEST_F(GraphicsAllocatorHidlTest, TestAllocateArray) {
   CHECK_FEATURE_OR_SKIP(IAllocator::Capability::TEST_ALLOCATE);
 
-  TempDescriptor descriptor(mClient, mDummyDescriptorInfo);
-  ASSERT_TRUE(descriptor.isValid());
+  BufferDescriptor descriptor;
+  ASSERT_NO_FATAL_FAILURE(descriptor =
+                              mClient->createDescriptor(mDummyDescriptorInfo));
 
   hidl_vec<BufferDescriptor> descriptors;
   descriptors.resize(2);
   descriptors[0] = descriptor;
   descriptors[1] = descriptor;
 
-  auto ret = mClient->testAllocate(descriptors);
-  ASSERT_TRUE(ret.isOk());
-
-  auto error = static_cast<Error>(ret);
+  auto error = mClient->testAllocate(descriptors);
   ASSERT_TRUE(error == Error::NONE || error == Error::NOT_SHARED);
 }
 
@@ -203,41 +117,27 @@
  * Test allocate/free with a single buffer descriptor.
  */
 TEST_F(GraphicsAllocatorHidlTest, AllocateFreeBasic) {
-  TempDescriptor descriptor(mClient, mDummyDescriptorInfo);
-  ASSERT_TRUE(descriptor.isValid());
+  BufferDescriptor descriptor;
+  ASSERT_NO_FATAL_FAILURE(descriptor =
+                              mClient->createDescriptor(mDummyDescriptorInfo));
 
-  hidl_vec<BufferDescriptor> descriptors;
-  descriptors.resize(1);
-  descriptors[0] = descriptor;
+  Buffer buffer;
+  ASSERT_NO_FATAL_FAILURE(buffer = mClient->allocate(descriptor));
 
-  Error error;
-  std::vector<Buffer> buffers;
-  auto ret = mClient->allocate(
-      descriptors, [&](const auto& tmpError, const auto& tmpBuffers) {
-        error = tmpError;
-        buffers = tmpBuffers;
-      });
-
-  ASSERT_TRUE(ret.isOk());
-  ASSERT_TRUE(error == Error::NONE || error == Error::NOT_SHARED);
-  EXPECT_EQ(1u, buffers.size());
-
-  if (!buffers.empty()) {
-    auto err_ret = mClient->free(buffers[0]);
-    EXPECT_TRUE(err_ret.isOk());
-    EXPECT_EQ(Error::NONE, static_cast<Error>(err_ret));
-  }
+  mClient->free(buffer);
 }
 
 /**
  * Test allocate/free with an array of buffer descriptors.
  */
 TEST_F(GraphicsAllocatorHidlTest, AllocateFreeArray) {
-  TempDescriptor descriptor1(mClient, mDummyDescriptorInfo);
-  ASSERT_TRUE(descriptor1.isValid());
+  BufferDescriptor descriptor1;
+  ASSERT_NO_FATAL_FAILURE(descriptor1 =
+                              mClient->createDescriptor(mDummyDescriptorInfo));
 
-  TempDescriptor descriptor2(mClient, mDummyDescriptorInfo);
-  ASSERT_TRUE(descriptor2.isValid());
+  BufferDescriptor descriptor2;
+  ASSERT_NO_FATAL_FAILURE(descriptor2 =
+                              mClient->createDescriptor(mDummyDescriptorInfo));
 
   hidl_vec<BufferDescriptor> descriptors;
   descriptors.resize(3);
@@ -245,54 +145,27 @@
   descriptors[1] = descriptor1;
   descriptors[2] = descriptor2;
 
-  Error error;
   std::vector<Buffer> buffers;
-  auto ret = mClient->allocate(
-      descriptors, [&](const auto& tmpError, const auto& tmpBuffers) {
-        error = tmpError;
-        buffers = tmpBuffers;
-      });
-
-  ASSERT_TRUE(ret.isOk());
-  ASSERT_TRUE(error == Error::NONE || error == Error::NOT_SHARED);
-  EXPECT_EQ(descriptors.size(), buffers.size());
+  ASSERT_NO_FATAL_FAILURE(mClient->allocate(descriptors, buffers));
 
   for (auto buf : buffers) {
-    auto err_ret = mClient->free(buf);
-    EXPECT_TRUE(err_ret.isOk());
-    EXPECT_EQ(Error::NONE, static_cast<Error>(err_ret));
+    mClient->free(buf);
   }
 }
 
 TEST_F(GraphicsAllocatorHidlTest, ExportHandle) {
-  TempDescriptor descriptor(mClient, mDummyDescriptorInfo);
-  ASSERT_TRUE(descriptor.isValid());
+  BufferDescriptor descriptor;
+  ASSERT_NO_FATAL_FAILURE(descriptor =
+                              mClient->createDescriptor(mDummyDescriptorInfo));
 
-  hidl_vec<BufferDescriptor> descriptors;
-  descriptors.resize(1);
-  descriptors[0] = descriptor;
+  Buffer buffer;
+  ASSERT_NO_FATAL_FAILURE(buffer = mClient->allocate(descriptor));
 
-  Error error;
-  std::vector<Buffer> buffers;
-  auto ret = mClient->allocate(
-      descriptors, [&](const auto& tmpError, const auto& tmpBuffers) {
-        error = tmpError;
-        buffers = tmpBuffers;
-      });
+  native_handle_t* handle;
+  ASSERT_NO_FATAL_FAILURE(handle = mClient->exportHandle(descriptor, buffer));
 
-  ASSERT_TRUE(ret.isOk());
-  ASSERT_TRUE(error == Error::NONE || error == Error::NOT_SHARED);
-  ASSERT_EQ(1u, buffers.size());
-
-  ret = mClient->exportHandle(
-      descriptors[0], buffers[0],
-      [&](const auto& tmpError, const auto&) { error = tmpError; });
-  EXPECT_TRUE(ret.isOk());
-  EXPECT_EQ(Error::NONE, error);
-
-  auto err_ret = mClient->free(buffers[0]);
-  EXPECT_TRUE(err_ret.isOk());
-  EXPECT_EQ(Error::NONE, static_cast<Error>(err_ret));
+  native_handle_close(handle);
+  native_handle_delete(handle);
 }
 
 }  // namespace anonymous