OSDN Git Service

Move utility classes in a separate static target
authorDaniel Nicoara <dnicoara@google.com>
Tue, 30 May 2017 19:38:30 +0000 (15:38 -0400)
committerDaniel Nicoara <dnicoara@google.com>
Tue, 30 May 2017 19:53:19 +0000 (15:53 -0400)
Split up utility classes that can be re-used in other IComposer related
tests (such as the IVrComposerClient tests).

Changes:
 * Move GraphicsComposerCallback into separate module
 * Extract TestCommandReader in separate module
 * Extract Composer::execute() from test class

Bug: 38203529
Test: Compiled
Change-Id: I0d1193469e9dd94c477a63058f98111c162dfa99

graphics/composer/2.1/vts/functional/Android.bp
graphics/composer/2.1/vts/functional/GraphicsComposerCallback.cpp [new file with mode: 0644]
graphics/composer/2.1/vts/functional/GraphicsComposerCallback.h [new file with mode: 0644]
graphics/composer/2.1/vts/functional/TestCommandReader.cpp [new file with mode: 0644]
graphics/composer/2.1/vts/functional/TestCommandReader.h [new file with mode: 0644]
graphics/composer/2.1/vts/functional/VtsHalGraphicsComposerTestUtils.cpp
graphics/composer/2.1/vts/functional/VtsHalGraphicsComposerTestUtils.h
graphics/composer/2.1/vts/functional/VtsHalGraphicsComposerV2_1TargetTest.cpp

index 66323d4..2e87144 100644 (file)
 cc_library_static {
     name: "libVtsHalGraphicsComposerTestUtils",
     defaults: ["hidl_defaults"],
-    srcs: ["VtsHalGraphicsComposerTestUtils.cpp"],
-    shared_libs: ["android.hardware.graphics.composer@2.1"],
+    srcs: [
+        "GraphicsComposerCallback.cpp",
+        "TestCommandReader.cpp",
+        "VtsHalGraphicsComposerTestUtils.cpp",
+    ],
+    shared_libs: [
+        "android.hardware.graphics.composer@2.1",
+        "libfmq",
+        "libsync",
+    ],
     static_libs: [
+        "libhwcomposer-command-buffer",
         "VtsHalHidlTargetTestBase",
     ],
     cflags: [
@@ -28,6 +37,7 @@ cc_library_static {
         "-Werror",
         "-O0",
         "-g",
+        "-DLOG_TAG=\"GraphicsComposerTestUtils\"",
     ],
     export_include_dirs: ["."],
 }
diff --git a/graphics/composer/2.1/vts/functional/GraphicsComposerCallback.cpp b/graphics/composer/2.1/vts/functional/GraphicsComposerCallback.cpp
new file mode 100644 (file)
index 0000000..0ad440c
--- /dev/null
@@ -0,0 +1,93 @@
+/*
+ * 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 "GraphicsComposerCallback.h"
+
+namespace android {
+namespace hardware {
+namespace graphics {
+namespace composer {
+namespace V2_1 {
+namespace tests {
+
+void GraphicsComposerCallback::setVsyncAllowed(bool allowed) {
+  std::lock_guard<std::mutex> lock(mMutex);
+  mVsyncAllowed = allowed;
+}
+
+std::vector<Display> GraphicsComposerCallback::getDisplays() const {
+  std::lock_guard<std::mutex> lock(mMutex);
+  return std::vector<Display>(mDisplays.begin(), mDisplays.end());
+}
+
+int GraphicsComposerCallback::getInvalidHotplugCount() const {
+  std::lock_guard<std::mutex> lock(mMutex);
+  return mInvalidHotplugCount;
+}
+
+int GraphicsComposerCallback::getInvalidRefreshCount() const {
+  std::lock_guard<std::mutex> lock(mMutex);
+  return mInvalidRefreshCount;
+}
+
+int GraphicsComposerCallback::getInvalidVsyncCount() const {
+  std::lock_guard<std::mutex> lock(mMutex);
+  return mInvalidVsyncCount;
+}
+
+Return<void> GraphicsComposerCallback::onHotplug(Display display,
+                                                 Connection connection) {
+  std::lock_guard<std::mutex> lock(mMutex);
+
+  if (connection == Connection::CONNECTED) {
+    if (!mDisplays.insert(display).second) {
+      mInvalidHotplugCount++;
+    }
+  } else if (connection == Connection::DISCONNECTED) {
+    if (!mDisplays.erase(display)) {
+      mInvalidHotplugCount++;
+    }
+  }
+
+  return Void();
+}
+
+Return<void> GraphicsComposerCallback::onRefresh(Display display) {
+  std::lock_guard<std::mutex> lock(mMutex);
+
+  if (mDisplays.count(display) == 0) {
+    mInvalidRefreshCount++;
+  }
+
+  return Void();
+}
+
+Return<void> GraphicsComposerCallback::onVsync(Display display, int64_t) {
+  std::lock_guard<std::mutex> lock(mMutex);
+
+  if (!mVsyncAllowed || mDisplays.count(display) == 0) {
+    mInvalidVsyncCount++;
+  }
+
+  return Void();
+}
+
+}  // namespace tests
+}  // namespace V2_1
+}  // namespace composer
+}  // namespace graphics
+}  // namespace hardware
+}  // namespace android
diff --git a/graphics/composer/2.1/vts/functional/GraphicsComposerCallback.h b/graphics/composer/2.1/vts/functional/GraphicsComposerCallback.h
new file mode 100644 (file)
index 0000000..ada7d09
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+ * 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 GRAPHICS_COMPOSER_CALLBACK_H
+#define GRAPHICS_COMPOSER_CALLBACK_H
+
+#include <android/hardware/graphics/composer/2.1/IComposerCallback.h>
+
+#include <mutex>
+#include <unordered_set>
+
+namespace android {
+namespace hardware {
+namespace graphics {
+namespace composer {
+namespace V2_1 {
+namespace tests {
+
+// IComposerCallback to be installed with IComposerClient::registerCallback.
+class GraphicsComposerCallback : public IComposerCallback {
+ public:
+  void setVsyncAllowed(bool allowed);
+
+  std::vector<Display> getDisplays() const;
+
+  int getInvalidHotplugCount() const;
+
+  int getInvalidRefreshCount() const;
+
+  int getInvalidVsyncCount() const;
+
+ private:
+  Return<void> onHotplug(Display display, Connection connection) override;
+  Return<void> onRefresh(Display display) override;
+  Return<void> onVsync(Display display, int64_t) override;
+
+  mutable std::mutex mMutex;
+  // the set of all currently connected displays
+  std::unordered_set<Display> mDisplays;
+  // true only when vsync is enabled
+  bool mVsyncAllowed = false;
+
+  // track invalid callbacks
+  int mInvalidHotplugCount = 0;
+  int mInvalidRefreshCount = 0;
+  int mInvalidVsyncCount = 0;
+};
+
+}  // namespace tests
+}  // namespace V2_1
+}  // namespace composer
+}  // namespace graphics
+}  // namespace hardware
+}  // namespace android
+
+#endif  // GRAPHICS_COMPOSER_CALLBACK_H
diff --git a/graphics/composer/2.1/vts/functional/TestCommandReader.cpp b/graphics/composer/2.1/vts/functional/TestCommandReader.cpp
new file mode 100644 (file)
index 0000000..b1f9aca
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ * 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 "TestCommandReader.h"
+
+#include <gtest/gtest.h>
+
+namespace android {
+namespace hardware {
+namespace graphics {
+namespace composer {
+namespace V2_1 {
+namespace tests {
+
+void TestCommandReader::parse() {
+  while (!isEmpty()) {
+    IComposerClient::Command command;
+    uint16_t length;
+    ASSERT_TRUE(beginCommand(&command, &length));
+
+    switch (command) {
+      case IComposerClient::Command::SET_ERROR: {
+        ASSERT_EQ(2, length);
+        auto loc = read();
+        auto err = readSigned();
+        GTEST_FAIL() << "unexpected error " << err << " at location " << loc;
+      } break;
+      case IComposerClient::Command::SELECT_DISPLAY:
+      case IComposerClient::Command::SET_CHANGED_COMPOSITION_TYPES:
+      case IComposerClient::Command::SET_DISPLAY_REQUESTS:
+      case IComposerClient::Command::SET_PRESENT_FENCE:
+      case IComposerClient::Command::SET_RELEASE_FENCES:
+        break;
+      default:
+        GTEST_FAIL() << "unexpected return command " << std::hex
+                     << static_cast<int>(command);
+        break;
+    }
+
+    endCommand();
+  }
+}
+
+}  // namespace tests
+}  // namespace V2_1
+}  // namespace composer
+}  // namespace graphics
+}  // namespace hardware
+}  // namespace android
diff --git a/graphics/composer/2.1/vts/functional/TestCommandReader.h b/graphics/composer/2.1/vts/functional/TestCommandReader.h
new file mode 100644 (file)
index 0000000..657a463
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * 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 TEST_COMMAND_READER_H
+#define TEST_COMMAND_READER_H
+
+#include <IComposerCommandBuffer.h>
+
+namespace android {
+namespace hardware {
+namespace graphics {
+namespace composer {
+namespace V2_1 {
+namespace tests {
+
+// A command parser that checks that no error nor unexpected commands are
+// returned.
+class TestCommandReader : public CommandReaderBase {
+ public:
+  // Parse all commands in the return command queue.  Call GTEST_FAIL() for
+  // unexpected errors or commands.
+  void parse();
+};
+
+}  // namespace tests
+}  // namespace V2_1
+}  // namespace composer
+}  // namespace graphics
+}  // namespace hardware
+}  // namespace android
+
+#endif  // TEST_COMMAND_READER_H
index 33cf84c..4e65a95 100644 (file)
@@ -25,10 +25,17 @@ namespace composer {
 namespace V2_1 {
 namespace tests {
 
-Composer::Composer() { init(); }
+Composer::Composer() {
+  mComposer = ::testing::VtsHalHidlTargetTestBase::getService<IComposer>();
+  init();
+}
+
+Composer::Composer(const std::string& name) {
+  mComposer = ::testing::VtsHalHidlTargetTestBase::getService<IComposer>(name);
+  init();
+}
 
 void Composer::init() {
-  mComposer = ::testing::VtsHalHidlTargetTestBase::getService<IComposer>();
   ASSERT_NE(nullptr, mComposer.get()) << "failed to get composer service";
 
   std::vector<IComposer::Capability> capabilities = getCapabilities();
@@ -292,6 +299,39 @@ void ComposerClient::setVsyncEnabled(Display display, bool enabled) {
   ASSERT_EQ(Error::NONE, error) << "failed to set vsync mode";
 }
 
+void ComposerClient::execute(TestCommandReader* reader,
+                             CommandWriterBase* writer) {
+  bool queueChanged = false;
+  uint32_t commandLength = 0;
+  hidl_vec<hidl_handle> commandHandles;
+  ASSERT_TRUE(
+      writer->writeQueue(&queueChanged, &commandLength, &commandHandles));
+
+  if (queueChanged) {
+    auto ret = mClient->setInputCommandQueue(*writer->getMQDescriptor());
+    ASSERT_EQ(Error::NONE, static_cast<Error>(ret));
+    return;
+  }
+
+  mClient->executeCommands(
+      commandLength, commandHandles,
+      [&](const auto& tmpError, const auto& tmpOutQueueChanged,
+          const auto& tmpOutLength, const auto& tmpOutHandles) {
+        ASSERT_EQ(Error::NONE, tmpError);
+
+        if (tmpOutQueueChanged) {
+          mClient->getOutputCommandQueue(
+              [&](const auto& tmpError, const auto& tmpDescriptor) {
+                ASSERT_EQ(Error::NONE, tmpError);
+                reader->setMQDescriptor(tmpDescriptor);
+              });
+        }
+
+        ASSERT_TRUE(reader->readQueue(tmpOutLength, tmpOutHandles));
+        reader->parse();
+      });
+}
+
 }  // namespace tests
 }  // namespace V2_1
 }  // namespace composer
index 4b57264..4e69f61 100644 (file)
 #include <unordered_set>
 #include <vector>
 
+#include <IComposerCommandBuffer.h>
 #include <android/hardware/graphics/composer/2.1/IComposer.h>
 #include <utils/StrongPointer.h>
 
+#include "TestCommandReader.h"
+
 namespace android {
 namespace hardware {
 namespace graphics {
@@ -44,6 +47,7 @@ class ComposerClient;
 class Composer {
  public:
   Composer();
+  explicit Composer(const std::string& name);
 
   sp<IComposer> getRaw() const;
 
@@ -102,6 +106,8 @@ class ComposerClient {
   void setPowerMode(Display display, IComposerClient::PowerMode mode);
   void setVsyncEnabled(Display display, bool enabled);
 
+  void execute(TestCommandReader* reader, CommandWriterBase* writer);
+
  private:
   sp<IComposerClient> mClient;
 
index 387222f..c77b7d3 100644 (file)
@@ -16,8 +16,9 @@
 
 #define LOG_TAG "graphics_composer_hidl_hal_test"
 
-#include <IComposerCommandBuffer.h>
 #include <android-base/logging.h>
+#include "GraphicsComposerCallback.h"
+#include "TestCommandReader.h"
 #include "VtsHalGraphicsComposerTestUtils.h"
 #include "VtsHalGraphicsMapperTestUtils.h"
 
@@ -49,83 +50,6 @@ using android::hardware::graphics::mapper::V2_0::IMapper;
 using android::hardware::graphics::mapper::V2_0::tests::Gralloc;
 using GrallocError = android::hardware::graphics::mapper::V2_0::Error;
 
-// IComposerCallback to be installed with IComposerClient::registerCallback.
-class GraphicsComposerCallback : public IComposerCallback {
- public:
-  void setVsyncAllowed(bool allowed) {
-    std::lock_guard<std::mutex> lock(mMutex);
-    mVsyncAllowed = allowed;
-  }
-
-  std::vector<Display> getDisplays() const {
-    std::lock_guard<std::mutex> lock(mMutex);
-    return std::vector<Display>(mDisplays.begin(), mDisplays.end());
-  }
-
-  int getInvalidHotplugCount() const {
-    std::lock_guard<std::mutex> lock(mMutex);
-    return mInvalidHotplugCount;
-  }
-
-  int getInvalidRefreshCount() const {
-    std::lock_guard<std::mutex> lock(mMutex);
-    return mInvalidRefreshCount;
-  }
-
-  int getInvalidVsyncCount() const {
-    std::lock_guard<std::mutex> lock(mMutex);
-    return mInvalidVsyncCount;
-  }
-
- private:
-  Return<void> onHotplug(Display display, Connection connection) override {
-    std::lock_guard<std::mutex> lock(mMutex);
-
-    if (connection == Connection::CONNECTED) {
-      if (!mDisplays.insert(display).second) {
-        mInvalidHotplugCount++;
-      }
-    } else if (connection == Connection::DISCONNECTED) {
-      if (!mDisplays.erase(display)) {
-        mInvalidHotplugCount++;
-      }
-    }
-
-    return Void();
-  }
-
-  Return<void> onRefresh(Display display) override {
-    std::lock_guard<std::mutex> lock(mMutex);
-
-    if (mDisplays.count(display) == 0) {
-      mInvalidRefreshCount++;
-    }
-
-    return Void();
-  }
-
-  Return<void> onVsync(Display display, int64_t) override {
-    std::lock_guard<std::mutex> lock(mMutex);
-
-    if (!mVsyncAllowed || mDisplays.count(display) == 0) {
-      mInvalidVsyncCount++;
-    }
-
-    return Void();
-  }
-
-  mutable std::mutex mMutex;
-  // the set of all currently connected displays
-  std::unordered_set<Display> mDisplays;
-  // true only when vsync is enabled
-  bool mVsyncAllowed = false;
-
-  // track invalid callbacks
-  int mInvalidHotplugCount = 0;
-  int mInvalidRefreshCount = 0;
-  int mInvalidVsyncCount = 0;
-};
-
 class GraphicsComposerHidlTest : public ::testing::VtsHalHidlTargetTestBase {
  protected:
   void SetUp() override {
@@ -404,7 +328,7 @@ class GraphicsComposerHidlCommandTest : public GraphicsComposerHidlTest {
     ASSERT_NO_FATAL_FAILURE(mGralloc = std::make_unique<Gralloc>());
 
     mWriter = std::make_unique<CommandWriterBase>(1024);
-    mReader = std::make_unique<CommandReader>();
+    mReader = std::make_unique<TestCommandReader>();
   }
 
   void TearDown() override {
@@ -423,78 +347,10 @@ class GraphicsComposerHidlCommandTest : public GraphicsComposerHidlTest {
       return mGralloc->allocate(info);
   }
 
-  void execute() {
-    bool queueChanged = false;
-    uint32_t commandLength = 0;
-    hidl_vec<hidl_handle> commandHandles;
-    ASSERT_TRUE(
-        mWriter->writeQueue(&queueChanged, &commandLength, &commandHandles));
-
-    if (queueChanged) {
-      auto ret = mComposerClient->getRaw()->setInputCommandQueue(
-          *mWriter->getMQDescriptor());
-      ASSERT_EQ(Error::NONE, static_cast<Error>(ret));
-      return;
-    }
-
-    mComposerClient->getRaw()->executeCommands(
-        commandLength, commandHandles,
-        [&](const auto& tmpError, const auto& tmpOutQueueChanged,
-            const auto& tmpOutLength, const auto& tmpOutHandles) {
-          ASSERT_EQ(Error::NONE, tmpError);
-
-          if (tmpOutQueueChanged) {
-            mComposerClient->getRaw()->getOutputCommandQueue(
-                [&](const auto& tmpError, const auto& tmpDescriptor) {
-                  ASSERT_EQ(Error::NONE, tmpError);
-                  mReader->setMQDescriptor(tmpDescriptor);
-                });
-          }
-
-          ASSERT_TRUE(mReader->readQueue(tmpOutLength, tmpOutHandles));
-          mReader->parse();
-        });
-  }
-
-  // A command parser that checks that no error nor unexpected commands are
-  // returned.
-  class CommandReader : public CommandReaderBase {
-   public:
-    // Parse all commands in the return command queue.  Call GTEST_FAIL() for
-    // unexpected errors or commands.
-    void parse() {
-      while (!isEmpty()) {
-        IComposerClient::Command command;
-        uint16_t length;
-        ASSERT_TRUE(beginCommand(&command, &length));
-
-        switch (command) {
-          case IComposerClient::Command::SET_ERROR: {
-            ASSERT_EQ(2, length);
-            auto loc = read();
-            auto err = readSigned();
-            GTEST_FAIL() << "unexpected error " << err << " at location "
-                         << loc;
-          } break;
-          case IComposerClient::Command::SELECT_DISPLAY:
-          case IComposerClient::Command::SET_CHANGED_COMPOSITION_TYPES:
-          case IComposerClient::Command::SET_DISPLAY_REQUESTS:
-          case IComposerClient::Command::SET_PRESENT_FENCE:
-          case IComposerClient::Command::SET_RELEASE_FENCES:
-            break;
-          default:
-            GTEST_FAIL() << "unexpected return command " << std::hex
-                         << static_cast<int>(command);
-            break;
-        }
-
-        endCommand();
-      }
-    }
-  };
+  void execute() { mComposerClient->execute(mReader.get(), mWriter.get()); }
 
   std::unique_ptr<CommandWriterBase> mWriter;
-  std::unique_ptr<CommandReader> mReader;
+  std::unique_ptr<TestCommandReader> mReader;
 
  private:
   std::unique_ptr<Gralloc> mGralloc;